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