import jalview.datamodel.SequenceI;
import jalview.ext.forester.ForesterDataConversions;
-import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.forester.phylogeny.Phylogeny;
import org.forester.phylogeny.PhylogenyNode;
public class AptxNodeAssociation
- implements ExternalLoadedTreeAssociationI<Phylogeny>
+ implements ExternalLoadedTreeAssociationI
{
SequenceI[] alignSequences;
Phylogeny tree;
+ Map<SequenceI, PhylogenyNode> alignmentWithNodes;
+
+ Map<PhylogenyNode, SequenceI> nodesWithAlignment;
+
public AptxNodeAssociation(SequenceI[] alignmentSequences,
Phylogeny aptxTree)
{
alignSequences = alignmentSequences;
tree = aptxTree;
+ alignmentWithNodes = new HashMap<>(alignSequences.length);
+ nodesWithAlignment = new HashMap<>(alignSequences.length);
}
* @param aptxTree
*/
@Override
- public void associateLeavesToSequences(SequenceI[] seqs,
- Phylogeny aptxTree)
+ public void associateLeavesToSequences()
+
{
- SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
+ SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
- List<PhylogenyNode> leaves = aptxTree.getExternalNodes();
- int namesleft = seqs.length;
+
+ List<PhylogenyNode> leaves = tree.getExternalNodes();
SequenceI nodeSequence;
String nodeSequenceName;
- List<SequenceI> one2many = new ArrayList<>();
- int countOne2Many = 0;
for (PhylogenyNode treeNode : leaves)
{
nodeSequenceName = treeNode.getName();
- nodeSequence = null;
-
- if (namesleft > -1)
- {
- nodeSequence = algnIds.findIdMatch(nodeSequenceName);
- }
+ nodeSequence = algnIds.findIdMatch(nodeSequenceName);
if (nodeSequence != null)
{
- org.forester.phylogeny.data.Sequence foresterNodeSeq = ForesterDataConversions.createForesterSequence(nodeSequence, true);
-
+ org.forester.phylogeny.data.Sequence foresterNodeSeq = ForesterDataConversions
+ .createForesterSequence(nodeSequence, true);
treeNode.getNodeData().setSequence(foresterNodeSeq);
- if (one2many.contains(nodeSequence))
- {
- countOne2Many++;
- if (jalview.bin.Cache.log.isDebugEnabled())
- {
- jalview.bin.Cache.log.debug("One 2 many relationship for"
- +nodeSequence.getName());
- }
- }
- else
- {
- one2many.add(nodeSequence);
- namesleft--;
- }
- }
- else
- {
- // treeNode.setElement( new Sequence(nodeSequenceName, "THISISAPLACEHOLDER"));
- // treeNode.setPlaceholder(true);
+
+ alignmentWithNodes.put(nodeSequence, treeNode);
+ nodesWithAlignment.put(treeNode, nodeSequence);
}
+
}
- if (jalview.bin.Cache.log.isDebugEnabled() && countOne2Many > 0)
- {
- jalview.bin.Cache.log.debug("There were " + countOne2Many
- + "alignment sequence ids (out of" + one2many.size()
- + " unique ids) linked to two or more leaves.");
- }
- one2many.clear();
}
+ // {
+ // SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
+ //
+ // List<PhylogenyNode> leaves = aptxTree.getExternalNodes();
+ //
+ // int namesleft = seqs.length;
+ // SequenceI nodeSequence;
+ // String nodeSequenceName;
+ // List<SequenceI> one2many = new ArrayList<>();
+ // int countOne2Many = 0;
+ //
+ // for (PhylogenyNode treeNode : leaves)
+ // {
+ // nodeSequenceName = treeNode.getName();
+ // nodeSequence = null;
+ //
+ // if (namesleft > -1)
+ // {
+ // nodeSequence = algnIds.findIdMatch(nodeSequenceName);
+ // }
+ //
+ // if (nodeSequence != null)
+ // {
+ // org.forester.phylogeny.data.Sequence foresterNodeSeq =
+ // ForesterDataConversions.createForesterSequence(nodeSequence, true);
+ //
+ // treeNode.getNodeData().setSequence(foresterNodeSeq);
+ // if (one2many.contains(nodeSequence))
+ // {
+ // countOne2Many++;
+ // if (jalview.bin.Cache.log.isDebugEnabled())
+ // {
+ // jalview.bin.Cache.log.debug("One 2 many relationship for"
+ // +nodeSequence.getName());
+ // }
+ // }
+ // else
+ // {
+ // one2many.add(nodeSequence);
+ // namesleft--;
+ // }
+ // }
+ // else
+ // {
+ // treeNode.setCollapse(true); // collapse nodes that couldn't be connected
+ // // to a sequence
+ //
+ //
+ // // treeNode.setElement( new Sequence(nodeSequenceName,
+ // "THISISAPLACEHOLDER"));
+ // // treeNode.setPlaceholder(true);
+ // }
+ // }
+ // if (jalview.bin.Cache.log.isDebugEnabled() && countOne2Many > 0)
+ // {
+ // jalview.bin.Cache.log.debug("There were " + countOne2Many
+ // + "alignment sequence ids (out of" + one2many.size()
+ // + " unique ids) linked to two or more leaves.");
+ // }
+ // one2many.clear();
+ //
+ // }
+
}