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 @SuppressWarnings("unchecked")
33 public PAEContactMatrix(SequenceI _refSeq, Map<String, Object> pae_obj)
36 while (refSeq.getDatasetSequence() != null)
38 refSeq = refSeq.getDatasetSequence();
40 // convert the lists to primitive arrays and store
41 length = _refSeq.getEnd() - _refSeq.getStart() + 1;
43 if (!MapUtils.containsAKey(pae_obj, "predicted_aligned_error", "pae"))
45 parse_version_1_pAE(pae_obj);
50 parse_version_2_pAE(pae_obj);
55 * parse a sane JSON representation of the pAE
59 private void parse_version_2_pAE(Map<String, Object> pae_obj)
61 elements = new float[length][length];
62 // this is never going to be reached by the integer rounding.. or is it ?
63 maxscore = ((Double) MapUtils.getFirst(pae_obj,
64 "max_predicted_aligned_error", "max_pae")).floatValue();
65 Iterator<List<Long>> scoreRows = ((List<List<Long>>) MapUtils
66 .getFirst(pae_obj, "predicted_aligned_error", "pae"))
69 while (scoreRows.hasNext())
71 Iterator<Long> scores = scoreRows.next().iterator();
72 while (scores.hasNext())
74 elements[row][col++] = scores.next();
84 * v1 format got ditched 28th July 2022 see
85 * https://alphafold.ebi.ac.uk/faq#:~:text=We%20updated%20the%20PAE%20JSON%20file%20format%20on%2028th%20July%202022
89 private void parse_version_1_pAE(Map<String, Object> pae_obj)
91 // assume indices are with respect to range defined by _refSeq on the
93 Iterator<Long> rows = ((List<Long>) pae_obj.get("residue1")).iterator();
94 Iterator<Long> cols = ((List<Long>) pae_obj.get("residue2")).iterator();
95 Iterator<Double> scores = ((List<Double>) pae_obj.get("distance"))
98 elements = new float[length][length];
99 while (scores.hasNext())
101 float escore = scores.next().floatValue();
102 int row = rows.next().intValue();
103 int col = cols.next().intValue();
112 elements[row - 1][col - 1] = escore;
115 maxscore = ((Double) MapUtils.getFirst(pae_obj,
116 "max_predicted_aligned_error", "max_pae")).floatValue();
120 public ContactListI getContactList(final int _column)
122 if (_column < 0 || _column >= elements.length)
127 return new ContactListImpl(new ContactListProviderI()
130 public int getPosition()
136 public int getContactHeight()
142 public double getContactAt(int column)
144 if (column < 0 || column >= elements[_column].length)
148 // TODO Auto-generated method stub
149 return elements[_column][column];
155 public float getMin()
161 public float getMax()
167 public boolean hasReferenceSeq()
169 return (refSeq != null);
173 public SequenceI getReferenceSeq()
179 public String getAnnotDescr()
181 return "Predicted Alignment Error for " + refSeq.getName();
185 public String getAnnotLabel()
190 public static final String PAEMATRIX="PAE_MATRIX";
192 public String getType()