1 package jalview.ext.archaeopteryx;
3 import jalview.analysis.SequenceIdMatcher;
4 import jalview.datamodel.SequenceI;
5 import jalview.ext.forester.ForesterDataConversions;
7 import java.util.HashMap;
11 import org.forester.phylogeny.Phylogeny;
12 import org.forester.phylogeny.PhylogenyNode;
14 public class AptxNodeAssociation
15 implements ExternalLoadedTreeAssociationI
17 SequenceI[] alignSequences;
21 Map<SequenceI, PhylogenyNode> alignmentWithNodes;
23 Map<PhylogenyNode, SequenceI> nodesWithAlignment;
25 public AptxNodeAssociation(SequenceI[] alignmentSequences,
28 alignSequences = alignmentSequences;
30 alignmentWithNodes = new HashMap<>(alignSequences.length);
31 nodesWithAlignment = new HashMap<>(alignSequences.length);
38 * Tries to match sequences from Jalview with tree nodes in Archaeopteryx and
39 * fills in the tree node with sequence data if a match is found.
41 * Partially refactored from the old Jalview TreeModel
42 * associateLeavesToSequences method.
48 public void associateLeavesToSequences()
51 SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
53 List<PhylogenyNode> leaves = tree.getExternalNodes();
54 SequenceI nodeSequence;
55 String nodeSequenceName;
57 for (PhylogenyNode treeNode : leaves)
59 nodeSequenceName = treeNode.getName();
61 nodeSequence = algnIds.findIdMatch(nodeSequenceName);
62 if (nodeSequence != null)
64 org.forester.phylogeny.data.Sequence foresterNodeSeq = ForesterDataConversions
65 .createForesterSequence(nodeSequence, true);
66 treeNode.getNodeData().setSequence(foresterNodeSeq);
68 ExternalTreeBuilderI.putWithDuplicationCheck(alignmentWithNodes,
69 nodeSequence, treeNode);
70 ExternalTreeBuilderI.putWithDuplicationCheck(nodesWithAlignment,
71 treeNode, nodeSequence);
80 public Map<SequenceI, PhylogenyNode> getAlignmentWithNodes()
82 return alignmentWithNodes;
85 public Map<PhylogenyNode, SequenceI> getNodesWithAlignment()
87 return nodesWithAlignment;
91 // SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
93 // List<PhylogenyNode> leaves = aptxTree.getExternalNodes();
95 // int namesleft = seqs.length;
96 // SequenceI nodeSequence;
97 // String nodeSequenceName;
98 // List<SequenceI> one2many = new ArrayList<>();
99 // int countOne2Many = 0;
101 // for (PhylogenyNode treeNode : leaves)
103 // nodeSequenceName = treeNode.getName();
104 // nodeSequence = null;
106 // if (namesleft > -1)
108 // nodeSequence = algnIds.findIdMatch(nodeSequenceName);
111 // if (nodeSequence != null)
113 // org.forester.phylogeny.data.Sequence foresterNodeSeq =
114 // ForesterDataConversions.createForesterSequence(nodeSequence, true);
116 // treeNode.getNodeData().setSequence(foresterNodeSeq);
117 // if (one2many.contains(nodeSequence))
120 // if (jalview.bin.Cache.log.isDebugEnabled())
122 // jalview.bin.Cache.log.debug("One 2 many relationship for"
123 // +nodeSequence.getName());
128 // one2many.add(nodeSequence);
134 // treeNode.setCollapse(true); // collapse nodes that couldn't be connected
138 // // treeNode.setElement( new Sequence(nodeSequenceName,
139 // "THISISAPLACEHOLDER"));
140 // // treeNode.setPlaceholder(true);
143 // if (jalview.bin.Cache.log.isDebugEnabled() && countOne2Many > 0)
145 // jalview.bin.Cache.log.debug("There were " + countOne2Many
146 // + "alignment sequence ids (out of" + one2many.size()
147 // + " unique ids) linked to two or more leaves.");