From 6982c3abcd6c6d29a4288759af92c9a96dc783db Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Tue, 9 Jan 2018 17:14:11 +0000 Subject: [PATCH] JAL-2805 getNodeSequences returns a list now instead of array (size isn't certain beforehand) --- src/jalview/ext/archaeopteryx/Tree.java | 8 +++++--- src/jalview/ext/forester/io/NexusFile.java | 8 +++++--- src/jalview/ext/forester/io/PhyloXmlFile.java | 4 +++- src/jalview/ext/treeviewer/TreeI.java | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/Tree.java b/src/jalview/ext/archaeopteryx/Tree.java index d0133a1..e5a2016 100644 --- a/src/jalview/ext/archaeopteryx/Tree.java +++ b/src/jalview/ext/archaeopteryx/Tree.java @@ -5,7 +5,9 @@ import jalview.ext.treeviewer.TreeFrameI; import jalview.ext.treeviewer.TreeI; import jalview.ext.treeviewer.TreeNodeI; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.forester.archaeopteryx.Archaeopteryx; import org.forester.phylogeny.Phylogeny; @@ -153,9 +155,9 @@ public class Tree implements TreeI } @Override - public SequenceI[] getNodeSequences() + public List getNodeSequences() { - SequenceI[] treeSeqs = new SequenceI[tree.getNodeCount()]; + List treeSeqs = new ArrayList<>(); Iterator iter = iterateInPreOrder(); int i = 0; while (iter.hasNext()) @@ -164,7 +166,7 @@ public class Tree implements TreeI SequenceI nodeSeq = iter.next().getSequence(); if (nodeSeq != null) { - treeSeqs[i++] = nodeSeq; + treeSeqs.add(nodeSeq); } } return treeSeqs; diff --git a/src/jalview/ext/forester/io/NexusFile.java b/src/jalview/ext/forester/io/NexusFile.java index 2db46cc..51f3bc3 100644 --- a/src/jalview/ext/forester/io/NexusFile.java +++ b/src/jalview/ext/forester/io/NexusFile.java @@ -8,6 +8,7 @@ import jalview.io.FileParse; import java.io.File; import java.io.IOException; +import java.util.List; public class NexusFile extends AlignFile { @@ -30,12 +31,13 @@ public class NexusFile extends AlignFile TreeParserI parser = ForesterParser .createNexusParser(new File(getDataName())); TreeI[] trees = parser.parse(); - for (TreeI tree : trees) { - for (SequenceI seq : tree.getNodeSequences()) { + List treeSeqs = trees[0].getNodeSequences(); + for (SequenceI seq : treeSeqs) + { seqs.add(seq); } } } -} + diff --git a/src/jalview/ext/forester/io/PhyloXmlFile.java b/src/jalview/ext/forester/io/PhyloXmlFile.java index e64845c..3cb3223 100644 --- a/src/jalview/ext/forester/io/PhyloXmlFile.java +++ b/src/jalview/ext/forester/io/PhyloXmlFile.java @@ -8,6 +8,7 @@ import jalview.io.FileParse; import java.io.File; import java.io.IOException; +import java.util.List; public class PhyloXmlFile extends AlignFile { @@ -30,7 +31,8 @@ public class PhyloXmlFile extends AlignFile TreeParserI parser = ForesterParser .createPhyloXmlParser(new File(getDataName())); TreeI[] trees = parser.parse(); - for (SequenceI seq : trees[0].getNodeSequences()) + List treeSeqs = trees[0].getNodeSequences(); + for (SequenceI seq : treeSeqs) { seqs.add(seq); } diff --git a/src/jalview/ext/treeviewer/TreeI.java b/src/jalview/ext/treeviewer/TreeI.java index 9bc20da..335b196 100644 --- a/src/jalview/ext/treeviewer/TreeI.java +++ b/src/jalview/ext/treeviewer/TreeI.java @@ -3,6 +3,7 @@ package jalview.ext.treeviewer; import jalview.datamodel.SequenceI; import java.util.Iterator; +import java.util.List; public interface TreeI { @@ -16,7 +17,7 @@ public interface TreeI public String[] getAllLeafNames(); - public SequenceI[] getNodeSequences(); + public List getNodeSequences(); public void setTreeName(String treeTitle); -- 1.7.10.2