From a3dae2a49b205b6700dd478739905f9ae7dc38d8 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Sat, 15 Oct 2022 11:09:52 +0100 Subject: [PATCH] JAL-3855 pAE v2 import --- .../ws/datamodel/alphafold/PAEContactMatrix.java | 52 +++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java index af8dfc3..8b6771e 100644 --- a/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java +++ b/src/jalview/ws/datamodel/alphafold/PAEContactMatrix.java @@ -15,6 +15,11 @@ public class PAEContactMatrix implements ContactMatrixI SequenceI refSeq = null; + /** + * the length that refSeq is expected to be (excluding gaps, of course) + */ + int length; + int maxrow = 0, maxcol = 0; int[] indices1, indices2; @@ -33,8 +38,53 @@ public class PAEContactMatrix implements ContactMatrixI refSeq = refSeq.getDatasetSequence(); } // convert the lists to primitive arrays and store - int length = _refSeq.getEnd() - _refSeq.getStart() + 1; + length = _refSeq.getEnd() - _refSeq.getStart() + 1; + + if (!pae_obj.containsKey("predicted_aligned_error")) + { + parse_version_1_pAE(pae_obj); + return; + } + else + { + parse_version_2_pAE(pae_obj); + } + } + + /** + * parse a sane JSON representation of the pAE + * + * @param pae_obj + */ + 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) pae_obj.get("max_predicted_aligned_error")) + .floatValue(); + Iterator> scoreRows = ((List>) pae_obj + .get("predicted_aligned_error")).iterator(); + int row = 0, col = 0; + while (scoreRows.hasNext()) + { + Iterator scores = scoreRows.next().iterator(); + while (scores.hasNext()) + { + elements[row][col++] = scores.next(); + } + row++; + col = 0; + } + } + /** + * v1 format got ditched 28th July 2022 see + * https://alphafold.ebi.ac.uk/faq#:~:text=We%20updated%20the%20PAE%20JSON%20file%20format%20on%2028th%20July%202022 + * + * @param pae_obj + */ + private void parse_version_1_pAE(Map pae_obj) + { // assume indices are with respect to range defined by _refSeq on the // dataset refSeq Iterator rows = ((List) pae_obj.get("residue1")).iterator(); -- 1.7.10.2