JAL-629 Tests for FileUtils. Tidying counter substitutions. Fixing PAE opening.
[jalview.git] / src / jalview / bin / Commands.java
index e4be614..9ff95e3 100644 (file)
@@ -403,6 +403,14 @@ public class Commands
           SequenceI seq = getSpecifiedSequence(af, subId);
           if (seq == null)
           {
+            // Could not find sequence from subId, let's assume the first
+            // sequence in the alignframe
+            AlignmentI al = af.getCurrentView().getAlignment();
+            seq = al.getSequenceAt(0);
+          }
+
+          if (seq == null)
+          {
             Console.warn("Could not find sequence for argument "
                     + Arg.STRUCTURE.argString() + "=" + val);
             // you probably want to continue here, not break
@@ -417,7 +425,6 @@ public class Commands
             Console.debug("Using structure file (from argument) '"
                     + structureFile.getAbsolutePath() + "'");
           }
-
           // TRY THIS
           /*
            * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
@@ -428,7 +435,6 @@ public class Commands
            * SequenceI[] { selectedSequence });
            * 
            */
-
           /* THIS DOESN'T WORK */
           else if (seq.getAllPDBEntries() != null
                   && seq.getAllPDBEntries().size() > 0)
@@ -479,7 +485,7 @@ public class Commands
       }
     }
 
-    // load a pAE file if given
+    // load a PAE file if given
     if (avm.containsArg(Arg.PAEMATRIX))
     {
       AlignFrame af = afMap.get(id);
@@ -503,7 +509,7 @@ public class Commands
           }
           String structid = null;
           String structfile = null;
-          String seqid = null;
+          int seqindex = SubVals.NOTSET;
           if (subVals.notSet())
           {
             ArgValue likelyStructure = avm
@@ -518,6 +524,9 @@ public class Commands
               else
               {
                 structfile = likelyStructure.getValue();
+                Console.debug(
+                        "##### Using closest previous structure argument '"
+                                + structfile + "'");
               }
             }
           }
@@ -532,27 +541,26 @@ public class Commands
           if (structfile != null)
           {
             Console.info("##### Attaching paeFile '" + paePath + "' to "
-                    + "structfile=" + subVals.get("structfile"));
+                    + "structfile=" + structfile);
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
-                    paeFile, subVals.getIndex(), subVals.get("structfile"),
-                    true, false, paeLabel);
+                    paeFile, seqindex, structfile, true, false, paeLabel);
           }
           else if (structid != null)
           {
             Console.info("##### Attaching paeFile '" + paePath + "' to "
-                    + "structid=" + subVals.get("structid"));
+                    + "structid=" + structid);
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
-                    paeFile, subVals.getIndex(), subVals.get("structid"),
-                    true, true, paeLabel);
+                    paeFile, seqindex, subVals.get("structid"), true, true,
+                    paeLabel);
           }
           else
           {
+            seqindex = subVals.getIndex();
             Console.debug("##### Attaching paeFile '" + paePath
-                    + "' to sequence index " + subVals.getIndex());
+                    + "' to sequence index " + seqindex);
             EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
-                    paeFile, subVals.getIndex(), null, false, false,
-                    paeLabel);
-            // required to readjust the height and position of the pAE
+                    paeFile, seqindex, null, false, false, paeLabel);
+            // required to readjust the height and position of the PAE
             // annotation
           }
           for (AlignmentViewPanel ap : af.getAlignPanels())
@@ -646,15 +654,17 @@ public class Commands
 
   private SequenceI getSpecifiedSequence(AlignFrame af, SubVals subId)
   {
+    if (subId == null)
+      return null;
     AlignmentI al = af.getCurrentView().getAlignment();
-    if (-1 < subId.getIndex()
-            && subId.getIndex() < al.getSequences().size())
+    if (subId.has("seqid"))
     {
-      return al.getSequenceAt(subId.getIndex());
+      return al.findName(subId.get("seqid"));
     }
-    else if (subId.has("seqid"))
+    else if (-1 < subId.getIndex()
+            && subId.getIndex() < al.getSequences().size())
     {
-      return al.findName(subId.get("seqid"));
+      return al.getSequenceAt(subId.getIndex());
     }
     return null;
   }