JAL-629 bootstrap args and properties. Remember index of args for 'previous structure...
[jalview.git] / src / jalview / bin / Commands.java
index faf2c9c..a0a3e59 100644 (file)
@@ -14,8 +14,9 @@ import java.util.Map;
 import jalview.analysis.AlignmentUtils;
 import jalview.api.AlignmentViewPanel;
 import jalview.bin.ArgParser.Arg;
+import jalview.bin.ArgParser.ArgValue;
 import jalview.bin.ArgParser.ArgValues;
-import jalview.bin.ArgParser.SubVal;
+import jalview.bin.ArgParser.SubVals;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
@@ -133,8 +134,9 @@ public class Commands
 
       boolean first = true;
       AlignFrame af;
-      for (String openFile : ArgParser.getValues(m, Arg.OPEN))
+      for (ArgValue av : ArgParser.getArgValueList(m, Arg.OPEN))
       {
+        String openFile = av.getValue();
         if (openFile == null)
           continue;
 
@@ -219,8 +221,9 @@ public class Commands
           {
             try
             {
-              tempfacType = StructureImportSettings.TFType.valueOf(ArgParser
-                      .getValue(m, Arg.TEMPFAC).toUpperCase(Locale.ROOT));
+              tempfacType = StructureImportSettings.TFType
+                      .valueOf(ArgParser.getArgValue(m, Arg.TEMPFAC)
+                              .getValue().toUpperCase(Locale.ROOT));
               Console.debug("Obtained Temperature Factor type of '"
                       + tempfacType + "'");
             } catch (IllegalArgumentException e)
@@ -362,9 +365,10 @@ public class Commands
       AlignFrame af = afMap.get(id);
       if (ArgParser.getArgValues(m, Arg.STRUCTURE) != null)
       {
-        for (String val : ArgParser.getValues(m, Arg.STRUCTURE))
+        for (ArgValue av : ArgParser.getArgValueList(m, Arg.STRUCTURE))
         {
-          SubVal subId = new SubVal(val);
+          String val = av.getValue();
+          SubVals subId = new SubVals(val);
           SequenceI seq = getSpecifiedSequence(af, subId);
           if (seq == null)
           {
@@ -375,9 +379,10 @@ public class Commands
             continue;
           }
           File structureFile = null;
-          if (subId.content != null && subId.content.length() != 0)
+          if (subId.getContent() != null
+                  && subId.getContent().length() != 0)
           {
-            structureFile = new File(subId.content);
+            structureFile = new File(subId.getContent());
             Console.debug("Using structure file (from argument) '"
                     + structureFile.getAbsolutePath() + "'");
           }
@@ -416,15 +421,16 @@ public class Commands
     }
 
     // load a pAE file if given
-    if (ArgParser.getValues(m, Arg.PAEMATRIX) != null)
+    if (ArgParser.getArgValueList(m, Arg.PAEMATRIX) != null)
     {
       AlignFrame af = afMap.get(id);
       if (af != null)
       {
-        for (String val : ArgParser.getValues(m, Arg.PAEMATRIX))
+        for (ArgValue av : ArgParser.getArgValueList(m, Arg.PAEMATRIX))
         {
-          SubVal subVal = ArgParser.getSubVal(val);
-          File paeFile = new File(subVal.content);
+          String val = av.getValue();
+          SubVals subVals = ArgParser.getSubVals(val);
+          File paeFile = new File(subVals.getContent());
           String paePath = null;
           try
           {
@@ -435,36 +441,34 @@ public class Commands
             Console.warn(
                     "Problem with the PAE file path: '" + paePath + "'");
           }
-          String structId = "structid".equals(subVal.keyName)
-                  ? subVal.keyValue
-                  : null;
-          if (subVal.notSet())
+          String structId = subVals.get("structid");
+          if (subVals.notSet())
           {
             // take structid from pdbfilename
           }
-          if ("structfile".equals(subVal.keyName))
+          if (subVals.has("structfile"))
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
-                    + subVal.keyName + "=" + subVal.keyValue);
+                    + "structfile=" + subVals.get("structfile"));
             EBIAlfaFold.addAlphaFoldPAEToStructure(
                     af.getCurrentView().getAlignment(), paeFile,
-                    subVal.index, subVal.keyValue, false);
+                    subVals.getIndex(), subVals.get("structfile"), false);
           }
-          else if ("structid".equals(subVal.keyName))
+          else if (subVals.has("structid"))
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
-                    + subVal.keyName + "=" + subVal.keyValue);
+                    + "structid=" + subVals.get("structid"));
             EBIAlfaFold.addAlphaFoldPAEToStructure(
                     af.getCurrentView().getAlignment(), paeFile,
-                    subVal.index, subVal.keyValue, true);
+                    subVals.getIndex(), subVals.get("structid"), true);
           }
           else
           {
             Console.debug("***** Attaching paeFile '" + paePath
-                    + "' to sequence index " + subVal.index);
+                    + "' to sequence index " + subVals.getIndex());
             EBIAlfaFold.addAlphaFoldPAEToSequence(
                     af.getCurrentView().getAlignment(), paeFile,
-                    subVal.index, null);
+                    subVals.getIndex(), null);
             // required to readjust the height and position of the pAE
             // annotation
           }
@@ -503,17 +507,18 @@ public class Commands
       return;
     }
 
-    if (ArgParser.getValues(m, Arg.IMAGE) != null)
+    if (ArgParser.getArgValueList(m, Arg.IMAGE) != null)
     {
-      for (String val : ArgParser.getValues(m, Arg.IMAGE))
+      for (ArgValue av : ArgParser.getArgValueList(m, Arg.IMAGE))
       {
-        SubVal subVal = new SubVal(val);
+        String val = av.getValue();
+        SubVals subVal = new SubVals(val);
         String type = "png"; // default
-        String fileName = subVal.content;
+        String fileName = subVal.getContent();
         File file = new File(fileName);
-        if ("type".equals(subVal.keyName))
+        if (subVal.has("type"))
         {
-          type = subVal.keyValue;
+          type = subVal.get("type");
         }
         else if (fileName != null)
         {
@@ -552,16 +557,17 @@ public class Commands
     }
   }
 
-  private SequenceI getSpecifiedSequence(AlignFrame af, SubVal subId)
+  private SequenceI getSpecifiedSequence(AlignFrame af, SubVals subId)
   {
     AlignmentI al = af.getCurrentView().getAlignment();
-    if (-1 < subId.index && subId.index < al.getSequences().size())
+    if (-1 < subId.getIndex()
+            && subId.getIndex() < al.getSequences().size())
     {
-      return al.getSequenceAt(subId.index);
+      return al.getSequenceAt(subId.getIndex());
     }
-    else if ("id".equals(subId.keyName))
+    else if (subId.has("seqid"))
     {
-      return al.findName(subId.keyValue);
+      return al.findName(subId.get("seqid"));
     }
     return null;
   }