From 65978c743b220b70bcc370b7340cb280b776c6c3 Mon Sep 17 00:00:00 2001 From: kjvdheide Date: Tue, 14 Nov 2017 16:56:50 +0000 Subject: [PATCH] JAL-2805 more sensible interface method params --- .../ext/archaeopteryx/AptxNodeAssociation.java | 127 +++++++++++++------- .../ExternalLoadedTreeAssociationI.java | 13 +- .../ext/forester/io/ExternalTreeParserI.java | 2 +- 3 files changed, 89 insertions(+), 53 deletions(-) diff --git a/src/jalview/ext/archaeopteryx/AptxNodeAssociation.java b/src/jalview/ext/archaeopteryx/AptxNodeAssociation.java index ffa3ae5..5d126f3 100644 --- a/src/jalview/ext/archaeopteryx/AptxNodeAssociation.java +++ b/src/jalview/ext/archaeopteryx/AptxNodeAssociation.java @@ -4,24 +4,31 @@ import jalview.analysis.SequenceIdMatcher; import jalview.datamodel.SequenceI; import jalview.ext.forester.ForesterDataConversions; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.forester.phylogeny.Phylogeny; import org.forester.phylogeny.PhylogenyNode; public class AptxNodeAssociation - implements ExternalLoadedTreeAssociationI + implements ExternalLoadedTreeAssociationI { SequenceI[] alignSequences; Phylogeny tree; + Map alignmentWithNodes; + + Map nodesWithAlignment; + public AptxNodeAssociation(SequenceI[] alignmentSequences, Phylogeny aptxTree) { alignSequences = alignmentSequences; tree = aptxTree; + alignmentWithNodes = new HashMap<>(alignSequences.length); + nodesWithAlignment = new HashMap<>(alignSequences.length); } @@ -38,64 +45,98 @@ public class AptxNodeAssociation * @param aptxTree */ @Override - public void associateLeavesToSequences(SequenceI[] seqs, - Phylogeny aptxTree) + public void associateLeavesToSequences() + { - SequenceIdMatcher algnIds = new SequenceIdMatcher(seqs); + SequenceIdMatcher algnIds = new SequenceIdMatcher(alignSequences); - List leaves = aptxTree.getExternalNodes(); - int namesleft = seqs.length; + + List leaves = tree.getExternalNodes(); 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); - } + nodeSequence = algnIds.findIdMatch(nodeSequenceName); if (nodeSequence != null) { - org.forester.phylogeny.data.Sequence foresterNodeSeq = ForesterDataConversions.createForesterSequence(nodeSequence, true); - + 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.setElement( new Sequence(nodeSequenceName, "THISISAPLACEHOLDER")); - // treeNode.setPlaceholder(true); + + alignmentWithNodes.put(nodeSequence, treeNode); + nodesWithAlignment.put(treeNode, nodeSequence); } + } - 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(); } + // { + // 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) + // { + // 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(); + // + // } + } diff --git a/src/jalview/ext/archaeopteryx/ExternalLoadedTreeAssociationI.java b/src/jalview/ext/archaeopteryx/ExternalLoadedTreeAssociationI.java index 5e820b7..cf58e46 100644 --- a/src/jalview/ext/archaeopteryx/ExternalLoadedTreeAssociationI.java +++ b/src/jalview/ext/archaeopteryx/ExternalLoadedTreeAssociationI.java @@ -1,19 +1,14 @@ package jalview.ext.archaeopteryx; -import jalview.datamodel.SequenceI; - /** * Interface for associating the leaves of a loaded in (not calculated) tree to - * the alignment sequences in Jalview. Note that this will take anything as a - * Tree object as no assumptions can be made about the inheritance structure of - * Tree (besides being an Object). + * the alignment sequences in Jalview. * * @author kjvanderheide * - * @param - * Tree object. + * */ -interface ExternalLoadedTreeAssociationI +interface ExternalLoadedTreeAssociationI { - public void associateLeavesToSequences(SequenceI[] seqs, T tree); + public void associateLeavesToSequences(); } diff --git a/src/jalview/ext/forester/io/ExternalTreeParserI.java b/src/jalview/ext/forester/io/ExternalTreeParserI.java index 2d912a1..e1210d1 100644 --- a/src/jalview/ext/forester/io/ExternalTreeParserI.java +++ b/src/jalview/ext/forester/io/ExternalTreeParserI.java @@ -10,7 +10,7 @@ import javax.swing.JInternalFrame; * @author kjvanderheide * * @param - * Frame containing the tree viewer. + * Frame of the tree viewer. */ public interface ExternalTreeParserI { -- 1.7.10.2