--- /dev/null
+package jalview.ext.archaeopteryx;
+
+import jalview.analysis.SequenceIdMatcher;
+import jalview.datamodel.SequenceI;
+import jalview.ext.forester.DataConversions;
+import jalview.ext.treeviewer.ExternalLoadedTreeAssociationI;
+import jalview.util.MappingUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.forester.phylogeny.Phylogeny;
+import org.forester.phylogeny.PhylogenyNode;
+
+public class LoadedTreeAssociation
+ implements ExternalLoadedTreeAssociationI
+{
+ SequenceI[] alignSequences;
+
+ Phylogeny tree;
+
+ Map<SequenceI, PhylogenyNode> alignmentWithNodes;
+
+ Map<PhylogenyNode, SequenceI> nodesWithAlignment;
+
+ public LoadedTreeAssociation(SequenceI[] alignmentSequences,
+ Phylogeny aptxTree)
+ {
+ alignSequences = alignmentSequences;
+ tree = aptxTree;
+ alignmentWithNodes = new HashMap<>(alignSequences.length);
+ nodesWithAlignment = new HashMap<>(alignSequences.length);
+
+ }
+
+
+
+ /**
+ * Tries to match sequences from Jalview with tree nodes in Archaeopteryx and
+ * fills in the tree node with sequence data if a match is found.
+ *
+ * Partially refactored from the old Jalview TreeModel
+ * associateLeavesToSequences method.
+ *
+ * @param seqs
+ * @param aptxTree
+ */
+ @Override
+ public void associateLeavesToSequences()
+
+ {
+ SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences);
+
+ List<PhylogenyNode> leaves = tree.getExternalNodes();
+ SequenceI nodeSequence;
+ String nodeSequenceName;
+
+ for (PhylogenyNode treeNode : leaves)
+ {
+ nodeSequenceName = treeNode.getName();
+
+ nodeSequence = algnIds.findIdMatch(nodeSequenceName);
+ if (nodeSequence != null)
+ {
+ org.forester.phylogeny.data.Sequence foresterNodeSeq = DataConversions
+ .createForesterSequence(nodeSequence, true);
+ treeNode.getNodeData().setSequence(foresterNodeSeq);
+
+ MappingUtils.putWithDuplicationCheck(alignmentWithNodes,
+ nodeSequence, treeNode);
+ MappingUtils.putWithDuplicationCheck(nodesWithAlignment,
+ treeNode, nodeSequence);
+
+
+ }
+
+ }
+
+ }
+
+
+
+ public Map<SequenceI, PhylogenyNode> getAlignmentWithNodes()
+ {
+ return alignmentWithNodes;
+ }
+
+ public Map<PhylogenyNode, SequenceI> getNodesWithAlignment()
+ {
+ return nodesWithAlignment;
+ }
+
+ // {
+ // 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();
+ //
+ // }
+
+}
+
+
+
+
+
+