package jalview.ext.archaeopteryx; import jalview.analysis.SequenceIdMatcher; import jalview.datamodel.SequenceI; import java.util.ArrayList; import java.util.List; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; public class JalviewToAptxAssociation implements JalviewToSequenceAssociationI { SequenceI[] alignSequences; Phylogeny tree; public JalviewToAptxAssociation(SequenceI[] alignmentSequences, Phylogeny aptxTree) { alignSequences = alignmentSequences; tree = aptxTree; } /** * 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(SequenceI[] seqs, Phylogeny aptxTree) { SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs); List leaves = aptxTree.getExternalNodes(); int namesleft = seqs.length; SequenceI nodeSequence; String nodeSequenceName; List 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) { //treeNode.setElement(nodeSequence); 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); } } // 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(); } }