@SuppressWarnings("unchecked")
private void parse_version_2_pAE(Map<String, Object> 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<List<Long>> scoreRows = ((List<List<Long>>) MapUtils
+ List<List<Long>> scoreRows = ((List<List<Long>>) 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<Long> scoreRow:scoreRows)
{
- Iterator<Long> scores = scoreRows.next().iterator();
+ Iterator<Long> 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;
Iterator<Long> cols = ((List<Long>) pae_obj.get("residue2")).iterator();
Iterator<Double> scores = ((List<Double>) pae_obj.get("distance"))
.iterator();
-
+ // assume square matrix
elements = new float[length][length];
while (scores.hasNext())
{
}
}
+ JSONObject paeDict = parseJSONtoPAEContactMatrix(pae_input);
+ if (paeDict == null)
+ {
+ Console.debug("JSON file did not parse properly.");
+ return false;
+ }
+ ContactMatrixI matrix = new PAEContactMatrix(sequence,
+ (Map<String, Object>) 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");
paeDict = (JSONObject) jsonArray.get(0);
}
- if (paeDict == null)
- {
- Console.debug("JSON file did not parse properly.");
- return false;
- }
- ContactMatrixI matrix = new PAEContactMatrix(sequence,
- (Map<String, Object>) paeDict);
-
- AlignmentAnnotation cmannot = sequence.addContactList(matrix);
- pdbAlignment.addAnnotation(cmannot);
-
- return true;
+ return paeDict;
}
public static boolean importPaeJSONAsContactMatrixToStructure(
throws IOException, ParseException
{
- List<Object> pae_obj = (List<Object>) Platform.parseJSON(paeInput);
+ JSONObject pae_obj = parseJSONtoPAEContactMatrix(paeInput);
if (pae_obj == null)
{
Console.debug("JSON file did not parse properly.");
}
ContactMatrixI matrix = new PAEContactMatrix(sm.getSequence(),
- (Map<String, Object>) pae_obj.get(0));
+ (Map<String, Object>) pae_obj);
AlignmentAnnotation cmannot = sm.getSequence().addContactList(matrix);
// sm.getSequence().addAlignmentAnnotation(cmannot);
--- /dev/null
+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);
+ }
+}