JAL-629 changes merged in from develop fixed it. Deleted duplicate example PAE file.
[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.testng.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.Alignment;
16 import jalview.datamodel.AlignmentI;
17 import jalview.datamodel.Sequence;
18 import jalview.datamodel.SequenceI;
19 import jalview.gui.Desktop;
20 import jalview.gui.JvOptionPane;
21 import jalview.structure.StructureMapping;
22 import jalview.structure.StructureSelectionManager;
23 import jalview.ws.datamodel.alphafold.PAEContactMatrix;
24
25 public class EBIAlphaFoldTest
26 {
27
28   @BeforeClass(alwaysRun = true)
29   public void setUpJvOptionPane()
30   {
31     JvOptionPane.setInteractiveMode(false);
32     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
33   }
34
35   @DataProvider(name = "getExamplePAEfiles")
36   public Object[][] getExamplePAEfiles()
37   {
38     return new String[][] {
39         //
40         { "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json" },
41         { "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" },
42         { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" },
43         //
44     };
45   }
46
47   @Test(groups = { "Functional" }, dataProvider = "getExamplePAEfiles")
48   public void checkPAEimport(String paeFile) throws Exception
49   {
50     PAEContactMatrix cm = new PAEContactMatrix(
51             new Sequence("Dummy/1-2000", "ASDASDA"),
52             EBIAlfaFold.parseJSONtoPAEContactMatrix(
53                     new FileInputStream(paeFile)));
54     Assert.assertNotEquals(cm.getMax(), 0.0f, "No data from " + paeFile);
55   }
56
57   @Test(groups = { "Functional" }, dataProvider = "getPDBandPAEfiles")
58   public void checkImportPAEToStructure(String pdbFile, String paeFile)
59   {
60     FileInputStream paeInput = null;
61     try
62     {
63       paeInput = new FileInputStream(paeFile);
64     } catch (FileNotFoundException e)
65     {
66       e.printStackTrace();
67       FileAssert.assertFile(new File(paeFile),
68               "Test file '" + paeFile + "' doesn't seem to exist");
69     }
70     SequenceI seq = new Sequence("Dummy/1-2000", "ASDASDA");
71     AlignmentI al = new Alignment(new SequenceI[] { seq });
72     StructureSelectionManager ssm = StructureSelectionManager
73             .getStructureSelectionManager(Desktop.instance);
74     StructureMapping sm = new StructureMapping(seq, pdbFile, null, null,
75             null, null);
76     ssm.addStructureMapping(sm);
77
78     StructureMapping[] smArray = ssm.getMapping(pdbFile);
79
80     try
81     {
82       boolean done = EBIAlfaFold.importPaeJSONAsContactMatrixToStructure(
83               smArray, paeInput, "label");
84       Assert.assertTrue(done,
85               "Import of '" + paeFile + "' didn't complete successfully");
86     } catch (IOException | ParseException e)
87     {
88       Assert.fail("Exception importing paefile '" + paeFile + "'", e);
89     }
90   }
91
92   @DataProvider(name = "getPDBandPAEfiles")
93   public Object[][] getPDBandPAEfiles()
94   {
95     return new String[][] {
96         //
97         /*
98          */
99         { "examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
100             "examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json" },
101         { "examples/AlphaFold/AF-A0A1U8FD60-F1-model_v4.pdb",
102             "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" },
103         { "examples/AlphaFold/AF-Q5VSL9-F1-model_v4.pdb",
104             "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" },
105         /*
106          */
107     };
108   }
109
110 }