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;
12 import jalview.util.MapUtils;
14 public class PAEContactMatrix implements ContactMatrixI
17 SequenceI refSeq = null;
20 * the length that refSeq is expected to be (excluding gaps, of course)
24 int maxrow = 0, maxcol = 0;
26 int[] indices1, indices2;
32 private void setRefSeq(SequenceI _refSeq)
35 while (refSeq.getDatasetSequence() != null)
37 refSeq = refSeq.getDatasetSequence();
39 length = _refSeq.getEnd() - _refSeq.getStart() + 1;
41 @SuppressWarnings("unchecked")
42 public PAEContactMatrix(SequenceI _refSeq, Map<String, Object> pae_obj)
45 // convert the lists to primitive arrays and store
47 if (!MapUtils.containsAKey(pae_obj, "predicted_aligned_error", "pae"))
49 parse_version_1_pAE(pae_obj);
54 parse_version_2_pAE(pae_obj);
58 * construct a sequence associated PAE matrix directly from a float array
62 public PAEContactMatrix(SequenceI _refSeq, float[][] matrix)
66 for (float[] row:matrix)
68 if (row.length>maxcol)
85 * parse a sane JSON representation of the pAE
89 @SuppressWarnings("unchecked")
90 private void parse_version_2_pAE(Map<String, Object> pae_obj)
92 elements = new float[length][length];
93 // this is never going to be reached by the integer rounding.. or is it ?
94 maxscore = ((Double) MapUtils.getFirst(pae_obj,
95 "max_predicted_aligned_error", "max_pae")).floatValue();
96 Iterator<List<Long>> scoreRows = ((List<List<Long>>) MapUtils
97 .getFirst(pae_obj, "predicted_aligned_error", "pae"))
100 while (scoreRows.hasNext())
102 Iterator<Long> scores = scoreRows.next().iterator();
103 while (scores.hasNext())
105 elements[row][col++] = scores.next();
115 * v1 format got ditched 28th July 2022 see
116 * https://alphafold.ebi.ac.uk/faq#:~:text=We%20updated%20the%20PAE%20JSON%20file%20format%20on%2028th%20July%202022
120 @SuppressWarnings("unchecked")
121 private void parse_version_1_pAE(Map<String, Object> pae_obj)
123 // assume indices are with respect to range defined by _refSeq on the
125 Iterator<Long> rows = ((List<Long>) pae_obj.get("residue1")).iterator();
126 Iterator<Long> cols = ((List<Long>) pae_obj.get("residue2")).iterator();
127 Iterator<Double> scores = ((List<Double>) pae_obj.get("distance"))
130 elements = new float[length][length];
131 while (scores.hasNext())
133 float escore = scores.next().floatValue();
134 int row = rows.next().intValue();
135 int col = cols.next().intValue();
144 elements[row - 1][col - 1] = escore;
147 maxscore = ((Double) MapUtils.getFirst(pae_obj,
148 "max_predicted_aligned_error", "max_pae")).floatValue();
152 public ContactListI getContactList(final int _column)
154 if (_column < 0 || _column >= elements.length)
159 return new ContactListImpl(new ContactListProviderI()
162 public int getPosition()
168 public int getContactHeight()
174 public double getContactAt(int column)
176 if (column < 0 || column >= elements[_column].length)
180 return elements[_column][column];
186 public float getMin()
192 public float getMax()
198 public boolean hasReferenceSeq()
200 return (refSeq != null);
204 public SequenceI getReferenceSeq()
210 public String getAnnotDescr()
212 return "Predicted Alignment Error for " + refSeq.getName();
216 public String getAnnotLabel()
221 public static final String PAEMATRIX="PAE_MATRIX";
223 public String getType()