From: James Procter Date: Fri, 24 Feb 2023 16:44:48 +0000 (+0000) Subject: JAL-629 JAL-4124 JAL-3855 test to check we can import PAE matrices in a variety of... X-Git-Tag: Release_2_11_3_0~17 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=7f98aeaa190d77fd40dcf80d55faedcace024d6f;p=jalview.git JAL-629 JAL-4124 JAL-3855 test to check we can import PAE matrices in a variety of formats - and fix up a casting issue (again?) --- diff --git a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java index 0349417..48071bd 100644 --- a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java @@ -90,24 +90,24 @@ public class PAEContactMatrix implements ContactMatrixI @SuppressWarnings("unchecked") private void parse_version_2_pAE(Map pae_obj) { - elements = new float[length][length]; // this is never going to be reached by the integer rounding.. or is it ? maxscore = ((Double) MapUtils.getFirst(pae_obj, "max_predicted_aligned_error", "max_pae")).floatValue(); - Iterator> scoreRows = ((List>) MapUtils + List> scoreRows = ((List>) MapUtils .getFirst(pae_obj, "predicted_aligned_error", "pae")) - .iterator(); + ; + elements = new float[scoreRows.size()][scoreRows.size()]; int row = 0, col = 0; - while (scoreRows.hasNext()) + for (List scoreRow:scoreRows) { - Iterator scores = scoreRows.next().iterator(); + Iterator scores = scoreRow.iterator(); while (scores.hasNext()) { Object d = scores.next(); if (d instanceof Double) elements[row][col++] = ((Double) d).longValue(); else - elements[row][col++] = (float) d; + elements[row][col++] = (float) ((Long)d).longValue(); } row++; col = 0; @@ -131,7 +131,7 @@ public class PAEContactMatrix implements ContactMatrixI Iterator cols = ((List) pae_obj.get("residue2")).iterator(); Iterator scores = ((List) pae_obj.get("distance")) .iterator(); - + // assume square matrix elements = new float[length][length]; while (scores.hasNext()) { diff --git a/src/jalview/ws/dbsources/EBIAlfaFold.java b/src/jalview/ws/dbsources/EBIAlfaFold.java index b3bcfd9..72fd8d9 100644 --- a/src/jalview/ws/dbsources/EBIAlfaFold.java +++ b/src/jalview/ws/dbsources/EBIAlfaFold.java @@ -402,8 +402,26 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } } + JSONObject paeDict = parseJSONtoPAEContactMatrix(pae_input); + if (paeDict == null) + { + Console.debug("JSON file did not parse properly."); + return false; + } + ContactMatrixI matrix = new PAEContactMatrix(sequence, + (Map) paeDict); + + AlignmentAnnotation cmannot = sequence.addContactList(matrix); + pdbAlignment.addAnnotation(cmannot); + + return true; + } + + public static JSONObject parseJSONtoPAEContactMatrix( + InputStream pae_input) throws IOException,ParseException + { Object paeJson = Platform.parseJSON(pae_input); - JSONObject paeDict = null; + JSONObject paeDict=null; if (paeJson instanceof JSONObject) { Console.debug("***** paeJson is a JSONObject"); @@ -416,18 +434,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy paeDict = (JSONObject) jsonArray.get(0); } - if (paeDict == null) - { - Console.debug("JSON file did not parse properly."); - return false; - } - ContactMatrixI matrix = new PAEContactMatrix(sequence, - (Map) paeDict); - - AlignmentAnnotation cmannot = sequence.addContactList(matrix); - pdbAlignment.addAnnotation(cmannot); - - return true; + return paeDict; } public static boolean importPaeJSONAsContactMatrixToStructure( @@ -452,7 +459,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy throws IOException, ParseException { - List pae_obj = (List) Platform.parseJSON(paeInput); + JSONObject pae_obj = parseJSONtoPAEContactMatrix(paeInput); if (pae_obj == null) { Console.debug("JSON file did not parse properly."); @@ -460,7 +467,7 @@ public class EBIAlfaFold extends EbiFileRetrievedProxy } ContactMatrixI matrix = new PAEContactMatrix(sm.getSequence(), - (Map) pae_obj.get(0)); + (Map) pae_obj); AlignmentAnnotation cmannot = sm.getSequence().addContactList(matrix); // sm.getSequence().addAlignmentAnnotation(cmannot); diff --git a/test/jalview/ws/dbsources/EBIAlphaFoldTest.java b/test/jalview/ws/dbsources/EBIAlphaFoldTest.java new file mode 100644 index 0000000..20435f4 --- /dev/null +++ b/test/jalview/ws/dbsources/EBIAlphaFoldTest.java @@ -0,0 +1,44 @@ +package jalview.ws.dbsources; + +import java.io.FileInputStream; + +import org.junit.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import jalview.datamodel.Sequence; +import jalview.gui.JvOptionPane; +import jalview.ws.datamodel.alphafold.PAEContactMatrix; + +public class EBIAlphaFoldTest +{ + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + + @DataProvider(name = "getExamplePAEfiles") + public Object[][] getExamplePAEfiles() + { + return new String[][] { { + "examples/test_fab41.result/test_fab41_predicted_aligned_error_v1.json" }, + { "examples/AlphaFold/AF-A0A1U8FD60-F1-predicted_aligned_error_v4.json" }, + { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4.json" }, + { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4_2023.json" } , + { "examples/AlphaFold/AF-Q5VSL9-F1-predicted_aligned_error_v4B.json" } }; + } + + @Test(groups = { "Functional" }, dataProvider = "getExamplePAEfiles") + public void checkPAEimport(String paeFile) throws Exception + { + PAEContactMatrix cm = new PAEContactMatrix( + new Sequence("Dummy/1-2000", "ASDASDA"), + EBIAlfaFold.parseJSONtoPAEContactMatrix( + new FileInputStream(paeFile))); + Assert.assertNotEquals("No data from " + paeFile, cm.getMax(), 0); + } +}