Clover icon

Coverage Report

  1. Project Clover database Fri Jun 19 2026 11:35:32 BST
  2. Package jalview.ws.dbsources

File EBIAlphaFoldTest.java

 
checkImportPAEForStructure:  no contact map found for AF-0000000203848083-model_v1|B ...
checkImportPAEToStructure: Exception importing paefile 'examples/AlphaFold/AF-Q5VSL9...
 

Code metrics

0
41
7
1
168
137
10
0.24
5.86
7
1.43

Classes

Class Line # Actions
EBIAlphaFoldTest 30 41 10
0.833333383.3%
 

Contributing tests

This file is covered by 15 tests. .

Source view

1    package jalview.ws.dbsources;
2   
3    import static org.junit.Assert.assertNotEquals;
4   
5    import java.io.File;
6    import java.io.FileInputStream;
7    import java.io.FileNotFoundException;
8    import java.io.IOException;
9   
10    import org.json.simple.parser.ParseException;
11    import org.testng.Assert;
12    import org.testng.FileAssert;
13    import org.testng.annotations.BeforeClass;
14    import org.testng.annotations.DataProvider;
15    import org.testng.annotations.Test;
16   
17    import jalview.analysis.AlignmentUtils;
18    import jalview.datamodel.Alignment;
19    import jalview.datamodel.AlignmentI;
20    import jalview.datamodel.Sequence;
21    import jalview.datamodel.SequenceI;
22    import jalview.gui.Desktop;
23    import jalview.gui.JvOptionPane;
24    import jalview.io.DataSourceType;
25    import jalview.io.FileLoader;
26    import jalview.structure.StructureMapping;
27    import jalview.structure.StructureSelectionManager;
28    import jalview.ws.datamodel.alphafold.PAEContactMatrix;
29   
 
30    public class EBIAlphaFoldTest
31    {
32   
 
33  1 toggle @BeforeClass(alwaysRun = true)
34    public void setUpJvOptionPane()
35    {
36  1 JvOptionPane.setInteractiveMode(false);
37  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
38    }
39   
 
40  1 toggle @DataProvider(name = "getExamplePAEfiles")
41    public Object[][] getExamplePAEfiles()
42    {
43  1 return new String[][] {
44    //
45    { "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json" },
46    { "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" },
47    { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" },
48    {"examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4_cmp.json" },
49    {"examples/AlphaFold/AF-0000000203848083-predicted_aligned_error_v1.json" },
50    //
51    };
52    }
53   
 
54  5 toggle @Test(groups = { "Functional" }, dataProvider = "getExamplePAEfiles")
55    public void checkPAEimport(String paeFile) throws Exception
56    {
57  5 PAEContactMatrix cm = new PAEContactMatrix(
58    new Sequence("Dummy/1-2000", "ASDASDA"),
59    EBIAlfaFold.parseJSONtoPAEContactMatrix(
60    new FileInputStream(paeFile)));
61  5 Assert.assertNotEquals(cm.getMax(), 0.0f, "No data from " + paeFile);
62    }
63   
 
64  5 toggle @Test(groups = { "Functional" }, dataProvider = "getPDBandPAEfiles")
65    public void checkImportPAEToStructure(String pdbFile, String paeFile)
66    {
67  5 FileInputStream paeInput = null;
68  5 try
69    {
70  5 paeInput = new FileInputStream(paeFile);
71    } catch (FileNotFoundException e)
72    {
73  0 e.printStackTrace();
74  0 FileAssert.assertFile(new File(paeFile),
75    "Test file '" + paeFile + "' doesn't seem to exist");
76    }
77  5 SequenceI seq = new Sequence("Dummy/1-2000", "ASDASDA");
78  5 AlignmentI al = new Alignment(new SequenceI[] { seq });
79  5 StructureSelectionManager ssm = StructureSelectionManager
80    .getStructureSelectionManager(Desktop.instance);
81  5 StructureMapping sm = new StructureMapping(seq, pdbFile, null, null,
82    null, null);
83  5 ssm.addStructureMapping(sm);
84   
85  5 StructureMapping[] smArray = ssm.getMapping(pdbFile);
86   
87  5 try
88    {
89  5 Test failure here boolean done = EBIAlfaFold.importPaeJSONAsContactMatrixToStructure(
90    smArray, paeInput, "label");
91  4 Assert.assertTrue(done,
92    "Import of '" + paeFile + "' didn't complete successfully");
93    } catch (IOException | ParseException e)
94    {
95  0 Test failure here Assert.fail("Exception importing paefile '" + paeFile + "'", e);
96    }
97    }
98   
 
99  2 toggle @DataProvider(name = "getPDBandPAEfiles")
100    public Object[][] getPDBandPAEfiles()
101    {
102  2 return new String[][] {
103    //
104    /*
105    */
106    { "examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3.pdb",
107    "examples/test_fab41.result/test_fab41_unrelaxed_rank_1_model_3_scores.json" },
108    { "examples/AlphaFold/AF-A0A1U8FD60-F1-model_v4.pdb",
109    "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" },
110    { "examples/AlphaFold/AF-Q5VSL9-F1-model_v4.pdb",
111    "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" },
112    { "examples/AlphaFold/AF-Q5VSL9-F1-model_v4.pdb",
113    "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4_cmp.json" },
114    { "examples/AlphaFold/AF-0000000203848083-model_v1.cif","examples/AlphaFold/AF-0000000203848083-predicted_aligned_error_v1.json" },
115    /*
116    */
117    };
118    }
119   
120    /**
121    * import PAE and structure as a fresh alignment
122    * @param pdbFile
123    * @param paeFile
124    */
 
125  5 toggle @Test(groups = { "Functional" }, dataProvider = "getPDBandPAEfiles")
126    public void checkImportPAEForStructure(String pdbFile, String paeFile) throws Exception
127    {
128  5 FileInputStream paeInput = null;
129  5 try
130    {
131  5 paeInput = new FileInputStream(paeFile);
132    } catch (FileNotFoundException e)
133    {
134  0 e.printStackTrace();
135  0 FileAssert.assertFile(new File(paeFile),
136    "Test file '" + paeFile + "' doesn't seem to exist");
137    }
138  5 String mp=new File(pdbFile).getAbsolutePath();
139  5 AlignmentI al = new FileLoader().LoadFileWaitTillLoaded(mp, DataSourceType.FILE).getViewport().getAlignment();
140   
141  5 StructureSelectionManager ssm = StructureSelectionManager
142    .getStructureSelectionManager(Desktop.instance);
143  5 String[] chainIds = new String[al.getHeight()];
144  5 int s=0;
145  5 for (SequenceI sq:al.getSequences())
146    {
147  6 chainIds[s++]=sq.getDatasetSequence().getAllPDBEntries().get(0).getChainCode();
148    }
149   
150    // lower level call - should do everything
151   
152  5 ssm.computeMapping(false, al.getSequencesArray(), chainIds, mp, DataSourceType.FILE, null, null, paeFile, true);
153  5 AlignmentUtils.addAllReferenceAnnotations(al);
154   
155  5 for (SequenceI sq:al.getSequences()) {
156  6 String failed=" no contact map found for "+sq.getName();
157  6 Assert.assertTrue(sq.getContactMaps()!=null,failed);
158  6 Test failure here Assert.assertEquals(sq.getContactMaps().size(),1,failed);
159    }
160    }
161   
 
162  0 toggle @Test(groups = { "Network" })
163    public void testPing() throws Exception
164    {
165  0 String version = EBIAlfaFold.pingAPIVersion();
166  0 assertNotEquals("", version);
167    }
168    }