1 package jalview.ext.treeviewer;
3 import jalview.analysis.SequenceIdMatcher;
4 import jalview.datamodel.SequenceI;
5 import jalview.util.MappingUtils;
7 import java.util.HashMap;
8 import java.util.Iterator;
11 public class LoadedTreeSequenceAssociation
12 implements LoadedTreeAssociationI
14 SequenceI[] alignSequences;
18 Map<SequenceI, TreeNodeI> alignmentWithNodes;
20 Map<TreeNodeI, SequenceI> nodesWithAlignment;
22 public LoadedTreeSequenceAssociation(SequenceI[] alignmentSequences,
25 alignSequences = alignmentSequences;
27 alignmentWithNodes = new HashMap<>(alignSequences.length);
28 nodesWithAlignment = new HashMap<>(alignSequences.length);
33 * Tries to match sequences from Jalview with tree nodes in Archaeopteryx and
34 * fills in the tree node with sequence data if a match is found.
36 * Partially refactored from the old Jalview TreeModel
37 * associateLeavesToSequences method.
43 public void associateLeavesToSequences()
46 SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
47 SequenceI nodeSequence;
48 String nodeSequenceName;
52 for (final Iterator<TreeNodeI> iter = tree
53 .iterateInPreOrder(); iter
56 TreeNodeI treeNode = iter.next();
57 nodeSequenceName = treeNode.getNodeName();
59 nodeSequence = algnIds.findIdMatch(nodeSequenceName);
60 if (nodeSequence != null)
62 // is there already a sequence present for the node?
63 // If so, does it actually match Jalview's sequence?
64 if (treeNode.getSequence() != null)
66 if (!(treeNode.getSequence().getSequenceAsString()
67 .equals(nodeSequence.getSequenceAsString())))
70 "Sequence detected in tree node that does not match corresponding Jalview sequence:"
72 // which sequence gets precedence?
79 treeNode.setSequence(nodeSequence);
81 MappingUtils.putWithDuplicationCheck(alignmentWithNodes,
82 nodeSequence, treeNode);
83 MappingUtils.putWithDuplicationCheck(nodesWithAlignment, treeNode,
97 public Map<SequenceI, TreeNodeI> getAlignmentWithNodes()
99 return alignmentWithNodes;
103 public Map<TreeNodeI, SequenceI> getNodesWithAlignment()
105 return nodesWithAlignment;