JAL-629 refactoring TFType. Remove i18n identification of annotation.
[jalview.git] / src / jalview / bin / Commands.java
index 2a71e74..c08dd23 100644 (file)
@@ -16,7 +16,9 @@ import jalview.bin.ArgParser.Arg;
 import jalview.bin.ArgParser.ArgValues;
 import jalview.bin.ArgParser.SubVal;
 import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.annotations.AlphaFoldAnnotationRowBuilder;
 import jalview.gui.AlignFrame;
 import jalview.gui.AlignmentPanel;
 import jalview.gui.Desktop;
@@ -28,6 +30,8 @@ import jalview.io.FileFormatI;
 import jalview.io.FileLoader;
 import jalview.io.HtmlSvgOutput;
 import jalview.io.IdentifyFile;
+import jalview.structure.StructureImportSettings;
+import jalview.structure.StructureImportSettings.TFType;
 import jalview.util.HttpUtils;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
@@ -187,13 +191,13 @@ public class Commands
            */
 
           // get kind of temperature factor annotation
-          AlignmentAnnotation.TFType tempfacType = null;
+          StructureImportSettings.TFType tempfacType = TFType.DEFAULT;
           if ((!ArgParser.getBoolean(m, Arg.NOTEMPFAC))
                   && ArgParser.getArgValues(m, Arg.TEMPFAC) != null)
           {
             try
             {
-              tempfacType = AlignmentAnnotation.TFType.valueOf(ArgParser
+              tempfacType = StructureImportSettings.TFType.valueOf(ArgParser
                       .getValue(m, Arg.TEMPFAC).toUpperCase(Locale.ROOT));
               Console.debug("Obtained Temperature Factor type of '"
                       + tempfacType + "'");
@@ -204,8 +208,8 @@ public class Commands
                       .append(Arg.TEMPFAC.getName()).append(" to '")
                       .append(tempfacType)
                       .append("', ignoring.  Valid values are: ");
-              Iterator<AlignmentAnnotation.TFType> it = Arrays
-                      .stream(AlignmentAnnotation.TFType.values())
+              Iterator<StructureImportSettings.TFType> it = Arrays
+                      .stream(StructureImportSettings.TFType.values())
                       .iterator();
               while (it.hasNext())
               {
@@ -220,8 +224,11 @@ public class Commands
           Console.debug(
                   "Opening '" + openFile + "' in new alignment frame");
           FileLoader fileLoader = new FileLoader(!headless);
-          af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol, format,
-                  tempfacType);
+
+          StructureImportSettings.setTemperatureFactorType(tempfacType);
+
+          af = fileLoader.LoadFileWaitTillLoaded(openFile, protocol,
+                  format);
 
           // wrap alignment?
           if (ArgParser.getBoolean(m, Arg.WRAP))
@@ -250,8 +257,7 @@ public class Commands
             // do this better (annotation types?)
             List<String> hideThese = new ArrayList<>();
             hideThese.add("Temperature Factor");
-            hideThese.add(MessageManager
-                    .getString("label.alphafold_reliability"));
+            hideThese.add(AlphaFoldAnnotationRowBuilder.LABEL);
             AlignmentUtils.showOrHideSequenceAnnotations(
                     af.getCurrentView().getAlignment(), hideThese, null,
                     false, false);
@@ -322,11 +328,20 @@ public class Commands
         {
           SubVal subVal = ArgParser.getSubVal(val);
           File paeFile = new File(subVal.content);
-          EBIAlfaFold.addAlphaFoldPAE(af.getCurrentView().getAlignment(),
-                  paeFile, subVal.index,
-                  "id".equals(subVal.keyName) ? subVal.keyValue : null);
-          // required to readjust the height and position of the pAE
-          // annotation
+          if ("structid".equals(subVal.index))
+          {
+            EBIAlfaFold.addAlphaFoldPAEToStructure(
+                    af.getCurrentView().getAlignment(), paeFile,
+                    subVal.index, subVal.keyValue);
+          }
+          else
+          {
+            EBIAlfaFold.addAlphaFoldPAEToSequence(af.getCurrentView().getAlignment(),
+                    paeFile, subVal.index,
+                    "id".equals(subVal.keyName) ? subVal.keyValue : null);
+            // required to readjust the height and position of the pAE
+            // annotation
+          }
           for (AlignmentViewPanel ap : af.getAlignPanels())
           {
             ap.adjustAnnotationHeight();
@@ -429,15 +444,21 @@ public class Commands
         switch (type)
         {
         case "svg":
+          Console.debug("Outputting type '" + type + "' to " + fileName);
           af.createSVG(file);
           break;
         case "png":
+          Console.debug("Outputting type '" + type + "' to " + fileName);
           af.createPNG(file);
           break;
         case "html":
+          Console.debug("Outputting type '" + type + "' to " + fileName);
           HtmlSvgOutput htmlSVG = new HtmlSvgOutput(af.alignPanel);
           htmlSVG.exportHTML(fileName);
           break;
+        default:
+          Console.warn("--image type '" + type + "' not known. Ignoring");
+          break;
         }
       }
     }
@@ -445,24 +466,15 @@ public class Commands
 
   private SequenceI getSpecifiedSequence(AlignFrame af, SubVal subId)
   {
-    SequenceI seq = null;
-    SequenceI[] sequences = af.getCurrentView().getAlignment()
-            .getSequencesArray();
-    if (-1 < subId.index && subId.index < sequences.length)
+    AlignmentI al = af.getCurrentView().getAlignment();
+    if (-1 < subId.index && subId.index < al.getSequences().size())
     {
-      seq = sequences[subId.index];
+      return al.getSequenceAt(subId.index);
     }
     else if ("id".equals(subId.keyName))
     {
-      for (SequenceI s : sequences)
-      {
-        if (s.getDisplayId(false).equals(subId.keyValue))
-        {
-          seq = s;
-          break;
-        }
-      }
+      return al.findName(subId.keyValue);
     }
-    return seq;
+    return null;
   }
 }