Merge branch 'develop' into spike/JAL-4047/JAL-4048_columns_in_sequenceID
[jalview.git] / test / jalview / gui / StructureChooserTest.java
index b74baf1..dd5cd4c 100644 (file)
@@ -24,15 +24,23 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.AssertJUnit.assertNotNull;
 import static org.testng.AssertJUnit.assertTrue;
 
+import java.io.File;
 import java.util.Collection;
+import java.util.List;
 import java.util.Vector;
 
 import org.junit.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+import jalview.api.AlignViewportI;
+import jalview.bin.Cache;
+import jalview.bin.Jalview;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
@@ -43,8 +51,15 @@ import jalview.fts.service.pdb.PDBFTSRestClient;
 import jalview.fts.service.pdb.PDBFTSRestClientTest;
 import jalview.fts.service.threedbeacons.TDBeaconsFTSRestClient;
 import jalview.fts.threedbeacons.TDBeaconsFTSRestClientTest;
+import jalview.gui.StructureViewer.ViewerType;
 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
+import jalview.io.FileLoader;
+import jalview.io.IdentifyFile;
 import jalview.jbgui.FilterOption;
+import jalview.structure.StructureImportSettings.TFType;
 import junit.extensions.PA;
 
 @Test(singleThreaded = true)
@@ -259,4 +274,147 @@ public class StructureChooserTest
     assertEquals("abcde12345afg",
             PDBStructureChooserQuerySource.sanitizeSeqName(name));
   }
+
+  @Test(groups = { "Functional" }, dataProvider = "openStructureFileParams")
+  public void openStructureFileForSequenceTest(String alfile, String seqid,
+          String sFilename, TFType tft, String paeFilename,
+          boolean showRefAnnotations, boolean doXferSettings,
+          ViewerType viewerType, int seqNum, int annNum, int viewerNum,
+          String propsFile)
+  {
+    Cache.loadProperties(
+            propsFile == null ? "test/jalview/io/testProps.jvprops"
+                    : propsFile);
+
+    Jalview.main(
+            propsFile == null ? null : new String[]
+            { "--props", propsFile });
+    if (Desktop.instance != null)
+      Desktop.instance.closeAll_actionPerformed(null);
+    JvOptionPane.setInteractiveMode(false);
+    JvOptionPane.setMockResponse(JvOptionPane.OK_OPTION);
+
+    FileLoader fileLoader = new FileLoader(true);
+    FileFormatI format = null;
+    File alFile = new File(alfile);
+    try
+    {
+      format = new IdentifyFile().identify(alFile, DataSourceType.FILE);
+    } catch (FileFormatException e1)
+    {
+      Assert.fail(
+              "Unknown file format for '" + alFile.getAbsolutePath() + "'");
+    }
+
+    AlignFrame af = fileLoader.LoadFileWaitTillLoaded(alFile,
+            DataSourceType.FILE, format);
+    AlignmentPanel ap = af.alignPanel;
+    Assert.assertNotNull("No alignPanel", ap);
+
+    AlignmentI al = ap.getAlignment();
+    Assert.assertNotNull(al);
+
+    SequenceI seq = al.findName(seqid);
+    Assert.assertNotNull("Sequence '" + seqid + "' not found in alignment",
+            seq);
+
+    StructureChooser.openStructureFileForSequence(null, null, ap, seq,
+            false, sFilename, tft, paeFilename, false, showRefAnnotations,
+            doXferSettings, viewerType);
+
+    List<SequenceI> seqs = al.getSequences();
+    Assert.assertNotNull(seqs);
+
+    Assert.assertEquals("Wrong number of sequences", seqNum, seqs.size());
+
+    AlignViewportI av = ap.getAlignViewport();
+    Assert.assertNotNull(av);
+
+    AlignmentAnnotation[] aas = al.getAlignmentAnnotation();
+    int visibleAnn = 0;
+    for (AlignmentAnnotation aa : aas)
+    {
+      if (aa.visible)
+        visibleAnn++;
+    }
+    Assert.assertEquals("Wrong number of viewed annotations", annNum,
+            visibleAnn);
+
+    if (viewerNum > -1)
+    {
+      try
+      {
+        Thread.sleep(100);
+      } catch (InterruptedException e)
+      {
+        // TODO Auto-generated catch block
+        e.printStackTrace();
+      }
+      List<StructureViewerBase> openViewers = Desktop.instance
+              .getStructureViewers(ap, null);
+      Assert.assertNotNull(openViewers);
+      int count = 0;
+      for (StructureViewerBase svb : openViewers)
+      {
+        if (svb.isVisible())
+          count++;
+      }
+      Assert.assertEquals("Wrong number of structure viewers opened",
+              viewerNum, count);
+
+    }
+
+    if (af != null)
+    {
+      af.setVisible(false);
+      af.dispose();
+    }
+  }
+
+  @DataProvider(name = "openStructureFileParams")
+  public Object[][] openStructureFileParams()
+  {
+    /*
+        String alFile,
+        String seqid,
+        String structureFilename,
+        TFType tft,
+        String paeFilename,
+        boolean showRefAnnotations,
+        boolean doXferSettings, // false for Commands
+        ViewerType viewerType,
+        int seqNum,
+        int annNum,
+        int viewerNum,
+        String propsFile
+     */
+    return new Object[][] {
+        /*
+        */
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.DEFAULT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            true, false, null, 15, 7, 0, null },
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            true, false, null, 15, 7, 0, null },
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            false, false, null, 15, 4, 0, null },
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.DEFAULT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            true, false, ViewerType.JMOL, 15, 7, 1, null },
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            true, false, ViewerType.JMOL, 15, 7, 1, null },
+        { "examples/uniref50.fa", "FER1_SPIOL",
+            "examples/AlphaFold/AF-P00221-F1-model_v4.cif", TFType.PLDDT,
+            "examples/AlphaFold/AF-P00221-F1-predicted_aligned_error_v4.json",
+            false, false, ViewerType.JMOL, 15, 4, 1, null }, };
+  }
+
 }