| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.ws.datamodel.alphafold; |
| 22 |
|
|
| 23 |
|
import java.io.File; |
| 24 |
|
import java.io.FileInputStream; |
| 25 |
|
import java.io.IOException; |
| 26 |
|
import java.util.Iterator; |
| 27 |
|
import java.util.List; |
| 28 |
|
import java.util.Map; |
| 29 |
|
|
| 30 |
|
import org.json.simple.JSONObject; |
| 31 |
|
|
| 32 |
|
import jalview.datamodel.ContactListI; |
| 33 |
|
import jalview.datamodel.ContactListImpl; |
| 34 |
|
import jalview.datamodel.ContactListProviderI; |
| 35 |
|
import jalview.datamodel.ContactMatrixI; |
| 36 |
|
import jalview.datamodel.FloatContactMatrix; |
| 37 |
|
import jalview.datamodel.GroupSet; |
| 38 |
|
import jalview.datamodel.SequenceDummy; |
| 39 |
|
import jalview.datamodel.SequenceI; |
| 40 |
|
import jalview.io.FileFormatException; |
| 41 |
|
import jalview.util.MapList; |
| 42 |
|
import jalview.util.MapUtils; |
| 43 |
|
import jalview.ws.dbsources.EBIAlfaFold; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
@author |
| 58 |
|
|
| 59 |
|
|
| |
|
| 81.4% |
Uncovered Elements: 21 (113) |
Complexity: 29 |
Complexity Density: 0.39 |
|
| 60 |
|
public class PAEContactMatrix extends |
| 61 |
|
MappableContactMatrix<PAEContactMatrix> implements ContactMatrixI |
| 62 |
|
{ |
| 63 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 64 |
70 |
@SuppressWarnings("unchecked")... |
| 65 |
|
public PAEContactMatrix(SequenceI _refSeq, Map<String, Object> pae_obj) |
| 66 |
|
throws FileFormatException |
| 67 |
|
{ |
| 68 |
70 |
setRefSeq(_refSeq); |
| 69 |
|
|
| 70 |
|
|
| 71 |
70 |
if (!MapUtils.containsAKey(pae_obj, "predicted_aligned_error", "pae")) |
| 72 |
|
{ |
| 73 |
2 |
parse_version_1_pAE(pae_obj); |
| 74 |
2 |
return; |
| 75 |
|
} |
| 76 |
|
else |
| 77 |
|
{ |
| 78 |
68 |
parse_version_2_pAE(pae_obj); |
| 79 |
|
} |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
|
| 83 |
|
|
| 84 |
|
|
| 85 |
|
@param |
| 86 |
|
@param |
| 87 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 88 |
6 |
public PAEContactMatrix(SequenceI _refSeq, float[][] matrix)... |
| 89 |
|
{ |
| 90 |
6 |
mappedMatrix = new FloatContactMatrix(matrix); |
| 91 |
6 |
setRefSeq(_refSeq); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
|
| 95 |
|
|
| 96 |
|
|
| 97 |
|
@param |
| 98 |
|
@param |
| 99 |
|
@param |
| 100 |
|
@param |
| 101 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 102 |
1 |
public PAEContactMatrix(SequenceI newRefSeq, MapList newFromMapList,... |
| 103 |
|
float[][] elements2, GroupSet grps2) |
| 104 |
|
{ |
| 105 |
1 |
this(newRefSeq, new FloatContactMatrix(elements2, grps2)); |
| 106 |
1 |
toSeq = newFromMapList; |
| 107 |
|
} |
| 108 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 109 |
1 |
public PAEContactMatrix(SequenceI _refSeq,... |
| 110 |
|
ContactMatrixI floatContactMatrix) |
| 111 |
|
{ |
| 112 |
1 |
mappedMatrix = floatContactMatrix; |
| 113 |
1 |
setRefSeq(_refSeq); |
| 114 |
|
} |
| 115 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 116 |
81 |
public PAEContactMatrix(SequenceI _refSeq, MapList newFromMapList,... |
| 117 |
|
ContactMatrixI floatContactMatrix) |
| 118 |
|
{ |
| 119 |
81 |
mappedMatrix = floatContactMatrix; |
| 120 |
81 |
setRefSeq(_refSeq); |
| 121 |
81 |
toSeq = newFromMapList; |
| 122 |
|
} |
| 123 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 124 |
42 |
@Override... |
| 125 |
|
protected PAEContactMatrix newMappableContactMatrix(SequenceI newRefSeq, |
| 126 |
|
MapList newFromMapList) |
| 127 |
|
{ |
| 128 |
42 |
return new PAEContactMatrix(newRefSeq, newFromMapList, mappedMatrix); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@param |
| 135 |
|
|
| |
|
| 92% |
Uncovered Elements: 2 (25) |
Complexity: 5 |
Complexity Density: 0.26 |
|
| 136 |
68 |
@SuppressWarnings("unchecked")... |
| 137 |
|
private void parse_version_2_pAE(Map<String, Object> pae_obj) |
| 138 |
|
{ |
| 139 |
68 |
float maxscore = -1; |
| 140 |
|
|
| 141 |
68 |
try |
| 142 |
|
{ |
| 143 |
|
|
| 144 |
68 |
maxscore = ((Double) MapUtils.getFirst(pae_obj, |
| 145 |
|
"max_predicted_aligned_error", "max_pae")).floatValue(); |
| 146 |
|
} catch (Throwable t) |
| 147 |
|
{ |
| 148 |
|
|
| 149 |
|
} |
| 150 |
68 |
List<List<Long>> scoreRows = ((List<List<Long>>) MapUtils |
| 151 |
|
.getFirst(pae_obj, "predicted_aligned_error", "pae")); |
| 152 |
68 |
float[][] elements = new float[scoreRows.size()][scoreRows.size()]; |
| 153 |
68 |
int row = 0, col = 0; |
| 154 |
68 |
for (List<Long> scoreRow : scoreRows) |
| 155 |
|
{ |
| 156 |
11236 |
Iterator<Long> scores = scoreRow.iterator(); |
| 157 |
4264488 |
while (scores.hasNext()) |
| 158 |
|
{ |
| 159 |
4253252 |
Object d = scores.next(); |
| 160 |
4253252 |
if (d instanceof Double) |
| 161 |
|
{ |
| 162 |
69620 |
elements[col][row] = ((Double) d).longValue(); |
| 163 |
|
} |
| 164 |
|
else |
| 165 |
|
{ |
| 166 |
4183632 |
elements[col][row] = (float) ((Long) d).longValue(); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
4253252 |
if (maxscore < elements[col][row]) |
| 170 |
|
{ |
| 171 |
0 |
maxscore = elements[col][row]; |
| 172 |
|
} |
| 173 |
4253252 |
col++; |
| 174 |
|
} |
| 175 |
11236 |
row++; |
| 176 |
11236 |
col = 0; |
| 177 |
|
} |
| 178 |
68 |
mappedMatrix = new FloatContactMatrix(elements); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
@param |
| 186 |
|
|
| |
|
| 88.9% |
Uncovered Elements: 4 (36) |
Complexity: 7 |
Complexity Density: 0.29 |
|
| 187 |
2 |
@SuppressWarnings("unchecked")... |
| 188 |
|
private void parse_version_1_pAE(Map<String, Object> pae_obj) |
| 189 |
|
{ |
| 190 |
|
|
| 191 |
|
|
| 192 |
2 |
Iterator<Long> rows = ((List<Long>) pae_obj.get("residue1")).iterator(); |
| 193 |
2 |
Iterator<Long> cols = ((List<Long>) pae_obj.get("residue2")).iterator(); |
| 194 |
|
|
| 195 |
|
|
| 196 |
2 |
int maxrow = -1, maxcol = -1; |
| 197 |
6964 |
while (rows.hasNext()) |
| 198 |
|
{ |
| 199 |
6962 |
int row = rows.next().intValue(); |
| 200 |
6962 |
int col = cols.next().intValue(); |
| 201 |
6962 |
if (maxrow < row) |
| 202 |
|
{ |
| 203 |
118 |
maxrow = row; |
| 204 |
|
} |
| 205 |
6962 |
if (maxcol < col) |
| 206 |
|
{ |
| 207 |
118 |
maxcol = col; |
| 208 |
|
} |
| 209 |
|
|
| 210 |
|
} |
| 211 |
2 |
rows = ((List<Long>) pae_obj.get("residue1")).iterator(); |
| 212 |
2 |
cols = ((List<Long>) pae_obj.get("residue2")).iterator(); |
| 213 |
2 |
Iterator<Double> scores = ((List<Double>) pae_obj.get("distance")) |
| 214 |
|
.iterator(); |
| 215 |
2 |
float[][] elements = new float[maxcol][maxrow]; |
| 216 |
6964 |
while (scores.hasNext()) |
| 217 |
|
{ |
| 218 |
6962 |
float escore = scores.next().floatValue(); |
| 219 |
6962 |
int row = rows.next().intValue(); |
| 220 |
6962 |
int col = cols.next().intValue(); |
| 221 |
6962 |
if (maxrow < row) |
| 222 |
|
{ |
| 223 |
0 |
maxrow = row; |
| 224 |
|
} |
| 225 |
6962 |
if (maxcol < col) |
| 226 |
|
{ |
| 227 |
0 |
maxcol = col; |
| 228 |
|
} |
| 229 |
6962 |
elements[col - 1][row - 1] = escore; |
| 230 |
|
} |
| 231 |
|
|
| 232 |
2 |
mappedMatrix = new FloatContactMatrix(elements); |
| 233 |
|
} |
| 234 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 235 |
76 |
@Override... |
| 236 |
|
public String getAnnotDescr() |
| 237 |
|
{ |
| 238 |
76 |
return "Predicted Alignment Error" |
| 239 |
76 |
+ ((refSeq == null) ? "" : (" for " + refSeq.getName())); |
| 240 |
|
} |
| 241 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 242 |
76 |
@Override... |
| 243 |
|
public String getAnnotLabel() |
| 244 |
|
{ |
| 245 |
76 |
StringBuilder label = new StringBuilder("PAE Matrix"); |
| 246 |
|
|
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
76 |
return label.toString(); |
| 251 |
|
} |
| 252 |
|
|
| 253 |
|
public static final String PAEMATRIX = "PAE_MATRIX"; |
| 254 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 255 |
194 |
@Override... |
| 256 |
|
public String getType() |
| 257 |
|
{ |
| 258 |
194 |
return PAEMATRIX; |
| 259 |
|
} |
| 260 |
|
|
| |
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.36 |
|
| 261 |
0 |
public static void validateContactMatrixFile(String fileName)... |
| 262 |
|
throws FileFormatException, IOException |
| 263 |
|
{ |
| 264 |
0 |
FileInputStream infile = null; |
| 265 |
0 |
try |
| 266 |
|
{ |
| 267 |
0 |
infile = new FileInputStream(new File(fileName)); |
| 268 |
|
} catch (Throwable t) |
| 269 |
|
{ |
| 270 |
0 |
new IOException("Couldn't open " + fileName, t); |
| 271 |
|
} |
| 272 |
0 |
JSONObject paeDict = null; |
| 273 |
0 |
try |
| 274 |
|
{ |
| 275 |
0 |
paeDict = EBIAlfaFold.parseJSONtoPAEContactMatrix(infile); |
| 276 |
|
} catch (Throwable t) |
| 277 |
|
{ |
| 278 |
0 |
new FileFormatException("Couldn't parse " + fileName |
| 279 |
|
+ " as a JSON dict or array containing a dict"); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
0 |
PAEContactMatrix matrix = new PAEContactMatrix( |
| 283 |
|
new SequenceDummy("Predicted"), (Map<String, Object>) paeDict); |
| 284 |
0 |
if (matrix.getWidth() <= 0) |
| 285 |
|
{ |
| 286 |
0 |
throw new FileFormatException( |
| 287 |
|
"No data in PAE matrix read from '" + fileName + "'"); |
| 288 |
|
} |
| 289 |
|
} |
| 290 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 291 |
28 |
@Override... |
| 292 |
|
public boolean equals(Object obj) |
| 293 |
|
{ |
| 294 |
28 |
return super.equals(obj); |
| 295 |
|
} |
| 296 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 297 |
96 |
@Override... |
| 298 |
|
public int hashCode() |
| 299 |
|
{ |
| 300 |
96 |
return super.hashCode(); |
| 301 |
|
} |
| 302 |
|
} |