1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Description: looking for the right index in placements JSONArray
Original code assumes the edge_num information is in the first position in the
JSONArray placements, which is not always the case. We insert a loop to look
for the right position.
Author: Pierre Gruet <pgtdebian@free.fr>
Forwarded: https://github.com/smirarab/sepp/issues/86
Last-Update: 2020-10-08
@@ -162,14 +162,19 @@
HashMap<String, String> labelMap = mapTrees(jsonTree, baseTree);
JSONArray placements = json.getJSONArray("placements");
+ JSONArray fields = json.getJSONArray("fields");
+ int locEdgeNum=0;
+ while (! fields.getString(locEdgeNum).equals("edge_num")) {
+ locEdgeNum++;
+ }
for (Iterator<JSONObject> iterator = placements.iterator(); iterator.hasNext();) {
JSONObject placement = iterator.next();
JSONArray p = placement.getJSONArray("p");
for (Iterator<JSONArray> itp = p.iterator(); itp.hasNext();) {
JSONArray pr = itp.next();
- String newLab = (String) labelMap.get(pr.getString(0));
- pr.set(0, new Integer(newLab));
+ String newLab = (String) labelMap.get(pr.getString(locEdgeNum));
+ pr.set(locEdgeNum, new Integer(newLab));
if (pr.getDouble(3) > ((Double) mainEdgeLen.get(newLab))
.doubleValue())
@@ -205,6 +205,12 @@
HashMap < String, String > labelMap = mapTreeBranchNames(jsonTree, originalTree);
JSONArray placements = json.getJSONArray("placements");
+ JSONArray fields = json.getJSONArray("fields");
+
+ int locEdgeNum=0;
+ while (! fields.getString(locEdgeNum).equals("edge_num")) {
+ locEdgeNum++;
+ }
for (Iterator < JSONObject > iterator = placements.iterator(); iterator.hasNext();) {
JSONObject placement = iterator.next();
@@ -254,8 +260,8 @@
/*
* Adjust the placement edge label
*/
- String newLab = (String) labelMap.get(precord.getString(0));
- newRecord.set(0, new Integer(newLab));
+ String newLab = (String) labelMap.get(precord.getString(locEdgeNum));
+ newRecord.set(locEdgeNum, new Integer(newLab));
/*
* Adjust edge length values to correspond to somewhere on the main tree.
* TODO: This is pretty bad. We should fix this.
|