1 package jalview.ws.datamodel.alphafold;
3 import java.util.Iterator;
7 import jalview.datamodel.ContactListI;
8 import jalview.datamodel.ContactListImpl;
9 import jalview.datamodel.ContactListProviderI;
10 import jalview.datamodel.ContactMatrixI;
11 import jalview.datamodel.SequenceI;
13 public class PAEContactMatrix implements ContactMatrixI
16 SequenceI refSeq = null;
19 * the length that refSeq is expected to be (excluding gaps, of course)
23 int maxrow = 0, maxcol = 0;
25 int[] indices1, indices2;
31 @SuppressWarnings("unchecked")
32 public PAEContactMatrix(SequenceI _refSeq, Map<String, Object> pae_obj)
35 while (refSeq.getDatasetSequence() != null)
37 refSeq = refSeq.getDatasetSequence();
39 // convert the lists to primitive arrays and store
40 length = _refSeq.getEnd() - _refSeq.getStart() + 1;
42 if (!pae_obj.containsKey("predicted_aligned_error"))
44 parse_version_1_pAE(pae_obj);
49 parse_version_2_pAE(pae_obj);
54 * parse a sane JSON representation of the pAE
58 private void parse_version_2_pAE(Map<String, Object> pae_obj)
60 elements = new float[length][length];
61 // this is never going to be reached by the integer rounding.. or is it ?
62 maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
64 Iterator<List<Long>> scoreRows = ((List<List<Long>>) pae_obj
65 .get("predicted_aligned_error")).iterator();
67 while (scoreRows.hasNext())
69 Iterator<Long> scores = scoreRows.next().iterator();
70 while (scores.hasNext())
72 elements[row][col++] = scores.next();
82 * v1 format got ditched 28th July 2022 see
83 * https://alphafold.ebi.ac.uk/faq#:~:text=We%20updated%20the%20PAE%20JSON%20file%20format%20on%2028th%20July%202022
87 private void parse_version_1_pAE(Map<String, Object> pae_obj)
89 // assume indices are with respect to range defined by _refSeq on the
91 Iterator<Long> rows = ((List<Long>) pae_obj.get("residue1")).iterator();
92 Iterator<Long> cols = ((List<Long>) pae_obj.get("residue2")).iterator();
93 Iterator<Double> scores = ((List<Double>) pae_obj.get("distance"))
96 elements = new float[length][length];
97 while (scores.hasNext())
99 float escore = scores.next().floatValue();
100 int row = rows.next().intValue();
101 int col = cols.next().intValue();
110 elements[row - 1][col - 1] = escore;
113 maxscore = ((Double) pae_obj.get("max_predicted_aligned_error"))
118 public ContactListI getContactList(final int _column)
120 if (_column < 0 || _column >= elements.length)
125 return new ContactListImpl(new ContactListProviderI()
128 public int getPosition()
134 public int getContactHeight()
140 public double getContactAt(int column)
142 if (column < 0 || column >= elements[_column].length)
146 // TODO Auto-generated method stub
147 return elements[_column][column];
153 public float getMin()
159 public float getMax()
165 public boolean hasReferenceSeq()
167 return (refSeq != null);
171 public SequenceI getReferenceSeq()
177 public String getAnnotDescr()
179 return "Predicted Alignment Error for " + refSeq.getName();
183 public String getAnnotLabel()