1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.fts.service.alphafold; |
22 |
|
|
23 |
|
import java.net.URL; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Collection; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Objects; |
28 |
|
|
29 |
|
import jalview.bin.Console; |
30 |
|
import jalview.datamodel.DBRefEntry; |
31 |
|
import jalview.datamodel.DBRefSource; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.fts.api.FTSData; |
34 |
|
import jalview.fts.api.FTSDataColumnI; |
35 |
|
import jalview.fts.core.FTSRestRequest; |
36 |
|
import jalview.util.DBRefUtils; |
37 |
|
import jalview.util.HttpUtils; |
38 |
|
import jalview.ws.dbsources.EBIAlfaFold; |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 66 (66) |
Complexity: 17 |
Complexity Density: 0.39 |
|
40 |
|
public class AlphafoldRestClient |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
@return |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 11 |
Complexity Density: 0.31 |
|
50 |
0 |
public static List<FTSData> getFTSData(... |
51 |
|
FTSRestRequest request) |
52 |
|
{ |
53 |
0 |
List<FTSData> records = new ArrayList<FTSData>(); |
54 |
0 |
String primaryKey = null; |
55 |
|
|
56 |
0 |
Object[] summaryRowData; |
57 |
|
|
58 |
0 |
SequenceI associatedSequence; |
59 |
|
|
60 |
0 |
Collection<FTSDataColumnI> diplayFields = request.getWantedFields(); |
61 |
0 |
SequenceI associatedSeq = request.getAssociatedSequence(); |
62 |
|
|
63 |
0 |
for (DBRefEntry upref : DBRefUtils |
64 |
|
.selectRefs(associatedSeq.getPrimaryDBRefs(), new String[] |
65 |
|
{ DBRefSource.UNIPROT })) |
66 |
|
{ |
67 |
0 |
String alphaFoldId = "AF-" + upref.getAccessionId() + "-F1"; |
68 |
0 |
try |
69 |
|
{ |
70 |
0 |
String urls = EBIAlfaFold.getAlphaFoldCifDownloadUrl(alphaFoldId, |
71 |
|
null); |
72 |
0 |
URL url = new URL(urls); |
73 |
0 |
if (!HttpUtils.checkUrlAvailable(url, 50)) |
74 |
|
{ |
75 |
0 |
continue; |
76 |
|
} |
77 |
|
} catch (Exception mfe) |
78 |
|
{ |
79 |
0 |
Console.debug("Exception accessing urls", mfe); |
80 |
0 |
continue; |
81 |
|
} |
82 |
0 |
int colCounter = 0; |
83 |
0 |
summaryRowData = new Object[(associatedSeq != null) |
84 |
|
? diplayFields.size() + 1 |
85 |
|
: diplayFields.size()]; |
86 |
0 |
if (associatedSeq != null) |
87 |
|
{ |
88 |
0 |
associatedSequence = associatedSeq; |
89 |
0 |
summaryRowData[0] = associatedSequence; |
90 |
0 |
colCounter = 1; |
91 |
|
} |
92 |
|
|
93 |
0 |
for (FTSDataColumnI field : diplayFields) |
94 |
|
{ |
95 |
0 |
String fieldData = "alphafold"; |
96 |
|
|
97 |
|
|
98 |
0 |
if (field.isPrimaryKeyColumn()) |
99 |
|
{ |
100 |
0 |
primaryKey = alphaFoldId; |
101 |
0 |
summaryRowData[colCounter++] = alphaFoldId; |
102 |
|
} |
103 |
0 |
else if (fieldData == null || fieldData.isEmpty()) |
104 |
|
{ |
105 |
0 |
summaryRowData[colCounter++] = null; |
106 |
|
} |
107 |
|
else |
108 |
|
{ |
109 |
0 |
try |
110 |
|
{ |
111 |
0 |
summaryRowData[colCounter++] = (field.getDataType() |
112 |
|
.getDataTypeClass() == Integer.class) |
113 |
|
? 1 |
114 |
0 |
: (field.getDataType() |
115 |
|
.getDataTypeClass() == Double.class) |
116 |
|
? 1.3131313 |
117 |
|
: "AlphaFold clarity"; |
118 |
|
} catch (Exception e) |
119 |
|
{ |
120 |
0 |
e.printStackTrace(); |
121 |
0 |
jalview.bin.Console.outPrintln("offending value:" + fieldData); |
122 |
|
} |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
0 |
final String primaryKey1 = primaryKey; |
127 |
|
|
128 |
0 |
final Object[] summaryRowData1 = summaryRowData; |
129 |
0 |
records.add(new FTSData() |
130 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
131 |
0 |
@Override... |
132 |
|
public Object[] getSummaryData() |
133 |
|
{ |
134 |
0 |
return summaryRowData1; |
135 |
|
} |
136 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
137 |
0 |
@Override... |
138 |
|
public Object getPrimaryKey() |
139 |
|
{ |
140 |
0 |
return primaryKey1; |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
146 |
0 |
@Override... |
147 |
|
public String toString() |
148 |
|
{ |
149 |
0 |
StringBuilder summaryFieldValues = new StringBuilder(); |
150 |
0 |
for (Object summaryField : summaryRowData1) |
151 |
|
{ |
152 |
0 |
summaryFieldValues.append( |
153 |
0 |
summaryField == null ? " " : summaryField.toString()) |
154 |
|
.append("\t"); |
155 |
|
} |
156 |
0 |
return summaryFieldValues.toString(); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
0 |
@Override... |
163 |
|
public int hashCode() |
164 |
|
{ |
165 |
0 |
return Objects.hash(primaryKey1, this.toString()); |
166 |
|
} |
167 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
168 |
0 |
@Override... |
169 |
|
public boolean equals(Object that) |
170 |
|
{ |
171 |
0 |
return this.toString().equals(that.toString()); |
172 |
|
} |
173 |
|
}); |
174 |
|
} |
175 |
0 |
return records; |
176 |
|
} |
177 |
|
} |