JAL-629 Adding PAE and TFType at structure loading time. Display PAE automatically
[jalview.git] / src / jalview / gui / StructureChooser.java
index 3fce931..fc73c27 100644 (file)
@@ -28,9 +28,11 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
 
@@ -45,11 +47,16 @@ import javax.swing.table.AbstractTableModel;
 
 import com.stevesoft.pat.Regex;
 
+import jalview.analysis.AlignmentUtils;
+import jalview.api.AlignmentViewPanel;
 import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.bin.Console;
 import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.PDBEntry;
+import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.ext.jmol.JmolParser;
 import jalview.fts.api.FTSData;
@@ -1711,10 +1718,21 @@ public class StructureChooser extends GStructureChooser
           AlignmentPanel ap, SequenceI seq, boolean prompt,
           String sFilename, TFType tft, String paeFilename)
   {
-    boolean headless = false;
+    openStructureFileForSequence(ssm, sc, ap, seq, prompt, sFilename, tft,
+            paeFilename, false, true);
+  }
+
+  public static void openStructureFileForSequence(
+          StructureSelectionManager ssm, StructureChooser sc,
+          AlignmentPanel ap, SequenceI seq, boolean prompt,
+          String sFilename, TFType tft, String paeFilename,
+          boolean forceHeadless, boolean showAnnotations)
+  {
+    boolean headless = forceHeadless;
     if (sc == null)
     {
       headless = true;
+      prompt = false;
       sc = new StructureChooser(new SequenceI[] { seq }, seq, ap, false);
     }
     if (ssm == null)
@@ -1724,11 +1742,38 @@ public class StructureChooser extends GStructureChooser
             sFilename, DataSourceType.FILE, seq, prompt, Desktop.instance,
             tft, paeFilename);
 
-    StructureViewer sViewer = sc.launchStructureViewer(ssm,
-            new PDBEntry[]
-            { fileEntry }, ap, new SequenceI[] { seq });
+    // if headless, "false" in the sc constructor above will avoid GUI behaviour
+    // in sc.launchStructureViewer()
+    sc.launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
+            new SequenceI[]
+            { seq });
 
     if (headless)
       sc.mainFrame.dispose();
+
+    if (showAnnotations)
+      showReferenceAnnotationsForSequence(ap.alignFrame, seq);
+  }
+
+  public static void showReferenceAnnotationsForSequence(AlignFrame af,
+          SequenceI sequence)
+  {
+    AlignViewport av = af.getCurrentView();
+    AlignmentI al = av.getAlignment();
+
+    List<SequenceI> forSequences = new ArrayList<>();
+    forSequences.add(sequence);
+    final Map<SequenceI, List<AlignmentAnnotation>> candidates = new LinkedHashMap<>();
+    AlignmentUtils.findAddableReferenceAnnotations(forSequences, null,
+            candidates, al);
+    final SequenceGroup selectionGroup = av.getSelectionGroup();
+    AlignmentUtils.addReferenceAnnotations(candidates, al, selectionGroup);
+    for (AlignmentViewPanel ap : af.getAlignPanels())
+    {
+      // required to readjust the height and position of the PAE
+      // annotation
+      ap.adjustAnnotationHeight();
+    }
+
   }
 }