JAL-629 improvements to argparser toString. Improvements to cli paeFile structure...
[jalview.git] / src / jalview / bin / Commands.java
index 24a3c22..67c0c64 100644 (file)
@@ -16,6 +16,7 @@ import jalview.api.AlignmentViewPanel;
 import jalview.bin.argparser.Arg;
 import jalview.bin.argparser.ArgParser;
 import jalview.bin.argparser.ArgValue;
+import jalview.bin.argparser.ArgValues;
 import jalview.bin.argparser.ArgValuesMap;
 import jalview.bin.argparser.SubVals;
 import jalview.datamodel.AlignmentAnnotation;
@@ -489,6 +490,7 @@ public class Commands
         {
           String val = av.getValue();
           SubVals subVals = ArgParser.getSubVals(val);
+          String paeLabel = subVals.get("label");
           File paeFile = new File(subVals.getContent());
           String paePath = null;
           try
@@ -500,33 +502,57 @@ public class Commands
             Console.warn(
                     "Problem with the PAE file path: '" + paePath + "'");
           }
-          String structId = subVals.get("structid");
+          String structid = null;
+          String structfile = null;
+          String seqid = null;
           if (subVals.notSet())
           {
-            // take structid from pdbfilename
+            ArgValue likelyStructure = avm
+                    .getClosestPreviousArgValueOfArg(av, Arg.STRUCTURE);
+            if (likelyStructure != null)
+            {
+              SubVals sv = likelyStructure.getSubVals();
+              if (sv != null && sv.has(ArgValues.ID))
+              {
+                structid = sv.get(ArgValues.ID);
+              }
+              else
+              {
+                structfile = likelyStructure.getValue();
+              }
+            }
           }
-          if (subVals.has("structfile"))
+          else if (subVals.has("structfile"))
+          {
+            structfile = subVals.get("structfile");
+          }
+          else if (subVals.has("structid"))
+          {
+            structid = subVals.get("structid");
+          }
+          if (structfile != null)
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
                     + "structfile=" + subVals.get("structfile"));
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
                     paeFile, subVals.getIndex(), subVals.get("structfile"),
-                    true, false);
+                    true, false, paeLabel);
           }
-          else if (subVals.has("structid"))
+          else if (structid != null)
           {
             Console.info("***** Attaching paeFile '" + paePath + "' to "
                     + "structid=" + subVals.get("structid"));
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
                     paeFile, subVals.getIndex(), subVals.get("structid"),
-                    true, true);
+                    true, true, paeLabel);
           }
           else
           {
             Console.debug("***** Attaching paeFile '" + paePath
                     + "' to sequence index " + subVals.getIndex());
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
-                    paeFile, subVals.getIndex(), null, false, false);
+                    paeFile, subVals.getIndex(), null, false, false,
+                    paeLabel);
             // required to readjust the height and position of the pAE
             // annotation
           }