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 // SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs);
82 // List<PhylogenyNode> leaves = aptxTree.getExternalNodes();
84 // int namesleft = seqs.length;
85 // SequenceI nodeSequence;
86 // String nodeSequenceName;
87 // List<SequenceI> one2many = new ArrayList<>();
88 // int countOne2Many = 0;
90 // for (PhylogenyNode treeNode : leaves)
92 // nodeSequenceName = treeNode.getName();
93 // nodeSequence = null;
95 // if (namesleft > -1)
97 // nodeSequence = algnIds.findIdMatch(nodeSequenceName);
100 // if (nodeSequence != null)
102 // org.forester.phylogeny.data.Sequence foresterNodeSeq =
103 // ForesterDataConversions.createForesterSequence(nodeSequence, true);
105 // treeNode.getNodeData().setSequence(foresterNodeSeq);
106 // if (one2many.contains(nodeSequence))
109 // if (jalview.bin.Cache.log.isDebugEnabled())
111 // jalview.bin.Cache.log.debug("One 2 many relationship for"
112 // +nodeSequence.getName());
117 // one2many.add(nodeSequence);
123 // treeNode.setCollapse(true); // collapse nodes that couldn't be connected
127 // // treeNode.setElement( new Sequence(nodeSequenceName,
128 // "THISISAPLACEHOLDER"));
129 // // treeNode.setPlaceholder(true);
132 // if (jalview.bin.Cache.log.isDebugEnabled() && countOne2Many > 0)
134 // jalview.bin.Cache.log.debug("There were " + countOne2Many
135 // + "alignment sequence ids (out of" + one2many.size()
136 // + " unique ids) linked to two or more leaves.");