JAL-2847 start of cleaning up db loading code
authorkjvdheide <kjvanderheide@dundee.ac.uk>
Sun, 3 Dec 2017 16:30:05 +0000 (16:30 +0000)
committerkjvdheide <kjvanderheide@dundee.ac.uk>
Sun, 3 Dec 2017 16:30:05 +0000 (16:30 +0000)
src/jalview/ext/archaeopteryx/AptxInit.java
src/jalview/ext/archaeopteryx/LoadedTreeSequenceAssociation.java [moved from src/jalview/ext/archaeopteryx/LoadedTreeAssociation.java with 97% similarity]
src/jalview/gui/AlignFrame.java

index 805cc6c..b9a7ae2 100644 (file)
@@ -108,20 +108,20 @@ public final class AptxInit
       Desktop.instance.startLoading(filePath);
     }
     boolean nhx_or_nexus = false;
-    final PhylogenyParser p = ParserUtils.createParserDependingOnFileType(
+    final PhylogenyParser parser = ParserUtils.createParserDependingOnFileType(
             treeFile, VALIDATE_PHYLOXML_XSD);
-    if (p instanceof NHXParser)
+    if (parser instanceof NHXParser)
     {
       nhx_or_nexus = true;
-      final NHXParser nhx = (NHXParser) p;
+      final NHXParser nhx = (NHXParser) parser;
       nhx.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
       nhx.setIgnoreQuotes(false);
       nhx.setTaxonomyExtraction(TAXONOMY_EXTRACTION);
     }
-    else if (p instanceof NexusPhylogeniesParser)
+    else if (parser instanceof NexusPhylogeniesParser)
     {
       nhx_or_nexus = true;
-      final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) p;
+      final NexusPhylogeniesParser nex = (NexusPhylogeniesParser) parser;
       nex.setReplaceUnderscores(REPLACE_NHX_UNDERSCORES);
       nex.setIgnoreQuotes(false);
     }
@@ -129,20 +129,20 @@ public final class AptxInit
 //    {
 //      MainFrameApplication.warnIfNotPhyloXmlValidation(APTX_CONFIG);
 //    }
-    Phylogeny[] phylogenies = PhylogenyMethods.readPhylogenies(p, treeFile);
-    MainFrame[] aptxFrames = new MainFrame[phylogenies.length];
+    Phylogeny[] trees = PhylogenyMethods.readPhylogenies(parser, treeFile);
+    MainFrame[] aptxFrames = new MainFrame[trees.length];
     String treeTitle = treeFile.getName();
 
-    for (int i = 0; i < phylogenies.length; i++)
+    for (int i = 0; i < trees.length; i++)
       {
-      Phylogeny tree = phylogenies[i];
+      Phylogeny tree = trees[i];
 
       if (nhx_or_nexus && INTERNAL_NUMBERS_AS_CONFIDENCE)
       {
         PhylogenyMethods.transferInternalNodeNamesToConfidence(tree, "");
       }
-
       aptxFrames[i] = createAptxFrame(tree, viewport, treeTitle);
+
     }
     if (Desktop.instance != null)
     {
@@ -193,10 +193,6 @@ public final class AptxInit
   public static MainFrame[] createInstancesFromDb(int databaseIndex,
           AlignmentViewport viewport)
   {
-    if (Desktop.desktop != null)
-    {
-      // Desktop.desktop.startLoading(treeTitle);
-    }
 
     URL url = null;
     Phylogeny[] trees = null;
@@ -209,22 +205,25 @@ public final class AptxInit
             client.getInstructions() + "\n(Reference: "
                     + client.getReference() + ")",
             client.getDescription(), JvOptionPane.QUESTION_MESSAGE);
+
     if ((identifier != null) && (identifier.trim().length() > 0))
     {
+      if (Desktop.instance != null)
+      {
+        Desktop.instance.startLoading(identifier);
+      }
+
       identifier = identifier.trim();
       if (client.isQueryInteger())
       {
         identifier = identifier.replaceAll("^\\D+", "");
-        int id = -1;
+
+        int id;
         try
         {
           id = Integer.parseInt(identifier);
         } catch (final NumberFormatException e)
         {
-          id = -1;
-        }
-        if (id < 1)
-        {
           JvOptionPane.showInternalMessageDialog(Desktop.desktop,
                   "Identifier is expected to be a number",
                   "Can not open URL", JvOptionPane.ERROR_MESSAGE);
@@ -471,17 +470,16 @@ public final class AptxInit
   {
     MainFrame aptxApp = Archaeopteryx.createApplication(aptxTree,
             APTX_CONFIG, treeTitle);
-    // addPartitioningSlider(aptxApp);
 
-
-    LoadedTreeAssociation bindAptxNodes = new LoadedTreeAssociation(
+    LoadedTreeSequenceAssociation bindAptxNodes = new LoadedTreeSequenceAssociation(
             jalviewAlignport.getAlignment().getSequencesArray(), aptxTree);
-
     bindAptxNodes.associateLeavesToSequences();
+
     bindNodesToJalviewSequences(aptxApp, jalviewAlignport,
             bindAptxNodes.getAlignmentWithNodes(),
             bindAptxNodes.getNodesWithAlignment());
-    bindFrameToJalview(aptxApp);
+    bindTreeViewFrameToJalview(aptxApp);
+
     return aptxApp;
   }
 
@@ -503,7 +501,8 @@ public final class AptxInit
   }
 
 
-  public static MainFrame bindFrameToJalview(final MainFrame aptxApp)
+  public static MainFrame bindTreeViewFrameToJalview(
+          final MainFrame aptxApp)
   {
     int width = 400;
     int height = 550;
@@ -13,7 +13,7 @@ import java.util.Map;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyNode;
 
-public class LoadedTreeAssociation
+public class LoadedTreeSequenceAssociation
         implements ExternalLoadedTreeAssociationI
 {
   SequenceI[] alignSequences;
@@ -24,7 +24,7 @@ public class LoadedTreeAssociation
 
   Map<PhylogenyNode, SequenceI> nodesWithAlignment;
 
-  public LoadedTreeAssociation(SequenceI[] alignmentSequences,
+  public LoadedTreeSequenceAssociation(SequenceI[] alignmentSequences,
           Phylogeny aptxTree)
   {
     alignSequences = alignmentSequences;
index 97120fc..5f26925 100644 (file)
@@ -4031,6 +4031,11 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     }
   }
 
+  /**
+   * Disgustingly hardcoded atm.
+   * 
+   * @param databaseIndex
+   */
   public void chooseTreeDb(int databaseIndex)
   {
     AptxInit.createInstancesFromDb(databaseIndex, viewport);