JAL-2805 more sensible interface method params
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 14 Nov 2017 16:56:50 +0000 (16:56 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Tue, 14 Nov 2017 16:56:50 +0000 (16:56 +0000)
src/jalview/ext/archaeopteryx/AptxNodeAssociation.java
src/jalview/ext/archaeopteryx/ExternalLoadedTreeAssociationI.java
src/jalview/ext/forester/io/ExternalTreeParserI.java

index ffa3ae5..5d126f3 100644 (file)
@@ -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<Phylogeny>
+        implements ExternalLoadedTreeAssociationI
 {
   SequenceI[] alignSequences;
 
   Phylogeny tree;
 
+  Map<SequenceI, PhylogenyNode> alignmentWithNodes;
+
+  Map<PhylogenyNode, SequenceI> 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<PhylogenyNode> leaves = aptxTree.getExternalNodes();
 
-    int namesleft = seqs.length;
+
+    List<PhylogenyNode> leaves = tree.getExternalNodes();
     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);
-      }
 
+      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<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();
+  //
+  // }
+
 }
 
 
index 5e820b7..cf58e46 100644 (file)
@@ -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 <T>
- *          Tree object.
+ * 
  */
-interface ExternalLoadedTreeAssociationI<T>
+interface ExternalLoadedTreeAssociationI
 {
-  public void associateLeavesToSequences(SequenceI[] seqs, T tree);
+  public void associateLeavesToSequences();
 }
index 2d912a1..e1210d1 100644 (file)
@@ -10,7 +10,7 @@ import javax.swing.JInternalFrame;
  * @author kjvanderheide
  *
  * @param <F>
- *          Frame containing the tree viewer.
+ *          Frame of the tree viewer.
  */
 public interface ExternalTreeParserI<F extends JInternalFrame>
 {