Merge branch 'features/JAL-4134_treeviewerforcolumns' into develop
[jalview.git] / src / jalview / bin / Commands.java
index 7a6e3ac..b42f08e 100644 (file)
@@ -19,12 +19,16 @@ import jalview.bin.ArgParser.ArgValuesMap;
 import jalview.bin.ArgParser.SubVals;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
+import jalview.datamodel.PDBEntry;
 import jalview.datamodel.SequenceI;
 import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignmentPanel;
+import jalview.gui.AssociatePdbFileWithSeq;
 import jalview.gui.Desktop;
+import jalview.gui.Preferences;
 import jalview.gui.StructureChooser;
+import jalview.gui.StructureViewer;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.DataSourceType;
 import jalview.io.FileFormatException;
@@ -52,11 +56,18 @@ public class Commands
 
   private Map<String, AlignFrame> afMap;
 
+  private static boolean commandArgsProvided = false;
+
+  public static boolean commandArgsProvided()
+  {
+    return commandArgsProvided;
+  }
+
   public static boolean processArgs(ArgParser ap, boolean h)
   {
     argParser = ap;
     headless = h;
-    boolean argsWereParsed = false;
+    boolean argsWereParsed = true;
     if (headless)
     {
       System.setProperty("java.awt.headless", "true");
@@ -70,13 +81,15 @@ public class Commands
         if (id == null)
         {
           cmds.processUnlinked(id);
+          argsWereParsed &= cmds.wereParsed();
         }
         else
         {
           cmds.processLinked(id);
+          argsWereParsed &= cmds.wereParsed();
         }
         cmds.processImages(id);
-        argsWereParsed |= cmds.wereParsed();
+        argsWereParsed &= cmds.wereParsed();
       }
 
     }
@@ -89,7 +102,7 @@ public class Commands
     return argsWereParsed;
   }
 
-  boolean argsWereParsed = false;
+  boolean argsWereParsed = true; // set false as soon as an arg is found
 
   private boolean wereParsed()
   {
@@ -109,14 +122,16 @@ public class Commands
 
   protected void processUnlinked(String id)
   {
-    ArgValuesMap avm = new ArgValuesMap(argParser.linkedArgs(id));
-
     processLinked(id);
   }
 
   protected void processLinked(String id)
   {
-    ArgValuesMap avm = new ArgValuesMap(argParser.linkedArgs(id));
+    ArgValuesMap avm = argParser.linkedArgs(id);
+    if (avm == null)
+      return;
+    else
+      argsWereParsed = false;
 
     /*
     // script to execute after all loading is completed one way or another
@@ -128,11 +143,13 @@ public class Commands
     FileFormatI format = null;
     DataSourceType protocol = null;
     */
-    if (avm.hasValue(Arg.OPEN))
+    if (avm.containsArg(Arg.OPEN))
     {
+      commandArgsProvided = true;
       long progress = -1;
 
       boolean first = true;
+      boolean progressBarSet = false;
       AlignFrame af;
       for (ArgValue av : avm.getArgValueList(Arg.OPEN))
       {
@@ -144,12 +161,13 @@ public class Commands
         if (first)
         {
           first = false;
-          if (!headless)
+          if (!headless && desktop != null)
           {
             desktop.setProgressBar(
                     MessageManager.getString(
                             "status.processing_commandline_args"),
                     progress = System.currentTimeMillis());
+            progressBarSet = true;
           }
         }
 
@@ -216,7 +234,8 @@ public class Commands
 
           // get kind of temperature factor annotation
           StructureImportSettings.TFType tempfacType = TFType.DEFAULT;
-          if ((!avm.getBoolean(Arg.NOTEMPFAC)) && avm.hasValue(Arg.TEMPFAC))
+          if ((!avm.getBoolean(Arg.NOTEMPFAC))
+                  && avm.containsArg(Arg.TEMPFAC))
           {
             try
             {
@@ -261,13 +280,13 @@ public class Commands
           }
 
           // colour aligment?
-          if (avm.hasValue(Arg.COLOUR))
+          if (avm.containsArg(Arg.COLOUR))
           {
             af.changeColour_actionPerformed(avm.getValue(Arg.COLOUR));
           }
 
           // change alignment frame title
-          if (avm.hasValue(Arg.TITLE))
+          if (avm.containsArg(Arg.TITLE))
             af.setTitle(avm.getValue(Arg.TITLE));
 
           /* hacky approach to hiding the annotations */
@@ -297,7 +316,7 @@ public class Commands
            if (showTemperatureFactor)
              */
           {
-            if (avm.hasValue(Arg.TEMPFAC_LABEL))
+            if (avm.containsArg(Arg.TEMPFAC_LABEL))
             {
               AlignmentAnnotation aa = AlignmentUtils
                       .getFirstSequenceAnnotationOfType(
@@ -327,7 +346,7 @@ public class Commands
                     .getStructureSelectionManager(Desktop.instance);
             SequenceI seq = af.alignPanel.getAlignment().getSequenceAt(0);
             ssm.computeMapping(false, new SequenceI[] { seq }, null,
-                    openFile, DataSourceType.FILE, null);
+                    openFile, DataSourceType.FILE, null, null, null);
           }
         }
         else
@@ -350,10 +369,10 @@ public class Commands
         else
         {
           Console.warn("No more files to open");
-          if (desktop != null)
-            desktop.setProgressBar(null, progress);
         }
       }
+      if (progressBarSet && desktop != null)
+        desktop.setProgressBar(null, progress);
 
     }
 
@@ -361,8 +380,9 @@ public class Commands
     if (!avm.getBoolean(Arg.NOSTRUCTURE))
     {
       AlignFrame af = afMap.get(id);
-      if (avm.hasValue(Arg.STRUCTURE))
+      if (avm.containsArg(Arg.STRUCTURE))
       {
+        commandArgsProvided = true;
         for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
         {
           String val = av.getValue();
@@ -384,6 +404,20 @@ public class Commands
             Console.debug("Using structure file (from argument) '"
                     + structureFile.getAbsolutePath() + "'");
           }
+
+          // TRY THIS
+          /*
+           PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+                  .associatePdbWithSeq(selectedPdbFileName,
+                          DataSourceType.FILE, selectedSequence, true,
+                          Desktop.instance);
+                          
+           sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
+                  ap, new SequenceI[]
+                  { selectedSequence });
+          
+           */
+
           /* THIS DOESN'T WORK */
           else if (seq.getAllPDBEntries() != null
                   && seq.getAllPDBEntries().size() > 0)
@@ -410,16 +444,32 @@ public class Commands
           Console.debug("Using structure file "
                   + structureFile.getAbsolutePath());
 
+          PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+                  .associatePdbWithSeq(structureFile.getAbsolutePath(),
+                          DataSourceType.FILE, seq, true, Desktop.instance);
+
           // open structure view
           AlignmentPanel ap = af.alignPanel;
-          StructureChooser.openStructureFileForSequence(ap, seq,
-                  structureFile);
+          if (headless)
+          {
+            Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
+                    StructureViewer.ViewerType.JMOL.toString());
+          }
+
+          // get tft, paeFilename, label?
+          /*
+          ArgValue tftAv = avm.getArgValuesReferringTo("structid", structId,
+                  Arg.TEMPFAC);
+           */
+          StructureChooser.openStructureFileForSequence(null, null, ap, seq,
+                  false, structureFile.getAbsolutePath(), null, null); // tft,
+                                                                       // paeFilename);
         }
       }
     }
 
     // load a pAE file if given
-    if (avm.hasValue(Arg.PAEMATRIX))
+    if (avm.containsArg(Arg.PAEMATRIX))
     {
       AlignFrame af = afMap.get(id);
       if (af != null)
@@ -448,25 +498,24 @@ public class Commands
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
                     + "structfile=" + subVals.get("structfile"));
-            EBIAlfaFold.addAlphaFoldPAEToStructure(
-                    af.getCurrentView().getAlignment(), paeFile,
-                    subVals.getIndex(), subVals.get("structfile"), false);
+            EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
+                    paeFile, subVals.getIndex(), subVals.get("structfile"),
+                    true, false);
           }
           else if (subVals.has("structid"))
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
                     + "structid=" + subVals.get("structid"));
-            EBIAlfaFold.addAlphaFoldPAEToStructure(
-                    af.getCurrentView().getAlignment(), paeFile,
-                    subVals.getIndex(), subVals.get("structid"), true);
+            EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
+                    paeFile, subVals.getIndex(), subVals.get("structid"),
+                    true, true);
           }
           else
           {
             Console.debug("***** Attaching paeFile '" + paePath
                     + "' to sequence index " + subVals.getIndex());
-            EBIAlfaFold.addAlphaFoldPAEToSequence(
-                    af.getCurrentView().getAlignment(), paeFile,
-                    subVals.getIndex(), null);
+            EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
+                    paeFile, subVals.getIndex(), null, false, false);
             // required to readjust the height and position of the pAE
             // annotation
           }
@@ -496,7 +545,7 @@ public class Commands
 
   protected void processImages(String id)
   {
-    ArgValuesMap avm = new ArgValuesMap(argParser.linkedArgs(id));
+    ArgValuesMap avm = argParser.linkedArgs(id);
     AlignFrame af = afMap.get(id);
 
     if (af == null)
@@ -505,7 +554,7 @@ public class Commands
       return;
     }
 
-    if (avm.hasValue(Arg.IMAGE))
+    if (avm.containsArg(Arg.IMAGE))
     {
       for (ArgValue av : avm.getArgValueList(Arg.IMAGE))
       {