JAL-629 Test and fix --annotation --ssannotation args. Added a viewerType arg/subval...
[jalview.git] / test / jalview / ws / dbsources / EBIAlphaFoldTest.java
1 package jalview.ws.dbsources;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.IOException;
7
8 import org.json.simple.parser.ParseException;
9 import org.junit.Assert;
10 import org.testng.FileAssert;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.DataProvider;
13 import org.testng.annotations.Test;
14
15 import jalview.datamodel.Sequence;
16 import jalview.gui.Desktop;
17 import jalview.gui.JvOptionPane;
18 import jalview.structure.StructureMapping;
19 import jalview.structure.StructureSelectionManager;
20 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
21
22 public class EBIAlphaFoldTest
23 {
24
25   @BeforeClass(alwaysRun = true)
26   public void setUpJvOptionPane()
27   {
28     JvOptionPane.setInteractiveMode(false);
29     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
30   }
31
32   @DataProvider(name = "getExamplePAEfiles")
33   public Object[][] getExamplePAEfiles()
34   {
35     return new String[][] { {
36         "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json" },
37         { "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" },
38         { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" },
39         { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4_2023.json" } };
40   }
41
42   @Test(groups = { "Functional" }, dataProvider = "getExamplePAEfiles")
43   public void checkPAEimport(String paeFile) throws Exception
44   {
45     PAEContactMatrix cm = new PAEContactMatrix(
46             new Sequence("Dummy/1-2000", "ASDASDA"),
47             EBIAlfaFold.parseJSONtoPAEContactMatrix(
48                     new FileInputStream(paeFile)));
49     Assert.assertNotEquals("No data from " + paeFile, cm.getMax(), 0);
50   }
51
52   @Test(groups = { "Functional" }, dataProvider = "getPDBandPAEfiles")
53   public void checkImportPAEToStructure(String pdbFile, String paeFile)
54   {
55     FileInputStream paeInput = null;
56     try
57     {
58       paeInput = new FileInputStream(paeFile);
59     } catch (FileNotFoundException e)
60     {
61       e.printStackTrace();
62       FileAssert.assertFile(new File(paeFile),
63               "Test file '" + paeFile + "' doesn't seem to exist");
64     }
65     StructureSelectionManager ssm = StructureSelectionManager
66             .getStructureSelectionManager(Desktop.instance);
67
68     StructureMapping[] smArray = ssm.getMapping(pdbFile);
69
70     try
71     {
72       boolean done = EBIAlfaFold.importPaeJSONAsContactMatrixToStructure(
73               smArray, paeInput, "label");
74       Assert.assertTrue(
75               "Import of '" + paeFile + "' didn't complete successfully",
76               done);
77     } catch (IOException | ParseException e)
78     {
79       e.printStackTrace();
80     }
81
82   }
83 }