1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ws; |
22 |
|
|
23 |
|
import java.util.Locale; |
24 |
|
|
25 |
|
import java.util.ArrayList; |
26 |
|
import java.util.Arrays; |
27 |
|
import java.util.Enumeration; |
28 |
|
import java.util.HashMap; |
29 |
|
import java.util.Hashtable; |
30 |
|
import java.util.List; |
31 |
|
import java.util.Map; |
32 |
|
import java.util.StringTokenizer; |
33 |
|
import java.util.Vector; |
34 |
|
import java.util.regex.Matcher; |
35 |
|
import java.util.regex.Pattern; |
36 |
|
|
37 |
|
import jalview.analysis.AlignSeq; |
38 |
|
import jalview.api.FeatureSettingsModelI; |
39 |
|
import jalview.bin.Cache; |
40 |
|
import jalview.bin.Console; |
41 |
|
import jalview.datamodel.AlignmentI; |
42 |
|
import jalview.datamodel.DBRefEntry; |
43 |
|
import jalview.datamodel.DBRefSource; |
44 |
|
import jalview.datamodel.Mapping; |
45 |
|
import jalview.datamodel.SequenceI; |
46 |
|
import jalview.gui.CutAndPasteTransfer; |
47 |
|
import jalview.gui.Desktop; |
48 |
|
import jalview.gui.FeatureSettings; |
49 |
|
import jalview.gui.IProgressIndicator; |
50 |
|
import jalview.gui.OOMWarning; |
51 |
|
import jalview.util.DBRefUtils; |
52 |
|
import jalview.util.MessageManager; |
53 |
|
import jalview.ws.seqfetcher.DbSourceProxy; |
54 |
|
import uk.ac.ebi.picr.model.UPEntry; |
55 |
|
import uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@author |
62 |
|
@version |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 388 (388) |
Complexity: 97 |
Complexity Density: 0.4 |
|
64 |
|
public class DBRefFetcher implements Runnable |
65 |
|
{ |
66 |
|
private static final String NEWLINE = System.lineSeparator(); |
67 |
|
|
68 |
|
public static final String TRIM_RETRIEVED_SEQUENCES = "TRIM_FETCHED_DATASET_SEQS"; |
69 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 0 |
Complexity Density: - |
|
70 |
|
public interface FetchFinishedListenerI |
71 |
|
{ |
72 |
|
void finished(); |
73 |
|
} |
74 |
|
|
75 |
|
SequenceI[] dataset; |
76 |
|
|
77 |
|
IProgressIndicator progressWindow; |
78 |
|
|
79 |
|
CutAndPasteTransfer output = new CutAndPasteTransfer(); |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperInterface picrClient = null; |
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
Hashtable<String, Vector<SequenceI>> seqRefs; |
89 |
|
|
90 |
|
DbSourceProxy[] dbSources; |
91 |
|
|
92 |
|
SequenceFetcher sfetcher; |
93 |
|
|
94 |
|
private List<FetchFinishedListenerI> listeners; |
95 |
|
|
96 |
|
private SequenceI[] alseqs; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
private boolean trimDsSeqs = true; |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
@param |
109 |
|
|
110 |
|
@param |
111 |
|
|
112 |
|
@param |
113 |
|
|
114 |
|
@param |
115 |
|
|
116 |
|
@param |
117 |
|
|
118 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 4 |
Complexity Density: 0.27 |
|
119 |
0 |
public DBRefFetcher(SequenceI[] seqs,... |
120 |
|
IProgressIndicator progressIndicatorFrame, |
121 |
|
DbSourceProxy[] sources, FeatureSettings featureSettings, |
122 |
|
boolean isNucleotide) |
123 |
|
{ |
124 |
0 |
listeners = new ArrayList<>(); |
125 |
0 |
this.progressWindow = progressIndicatorFrame; |
126 |
0 |
alseqs = new SequenceI[seqs.length]; |
127 |
0 |
SequenceI[] ds = new SequenceI[seqs.length]; |
128 |
0 |
for (int i = 0; i < seqs.length; i++) |
129 |
|
{ |
130 |
0 |
alseqs[i] = seqs[i]; |
131 |
0 |
if (seqs[i].getDatasetSequence() != null) |
132 |
|
{ |
133 |
0 |
ds[i] = seqs[i].getDatasetSequence(); |
134 |
|
} |
135 |
|
else |
136 |
|
{ |
137 |
0 |
ds[i] = seqs[i]; |
138 |
|
} |
139 |
|
} |
140 |
0 |
this.dataset = ds; |
141 |
|
|
142 |
0 |
sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(); |
143 |
|
|
144 |
|
|
145 |
0 |
trimDsSeqs = Cache.getDefault(TRIM_RETRIEVED_SEQUENCES, true); |
146 |
0 |
if (sources == null) |
147 |
|
{ |
148 |
0 |
setDatabaseSources(featureSettings, isNucleotide); |
149 |
|
} |
150 |
|
else |
151 |
|
{ |
152 |
|
|
153 |
|
|
154 |
0 |
dbSources = sources; |
155 |
|
} |
156 |
|
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
@param |
162 |
|
@param |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
164 |
0 |
void setDatabaseSources(FeatureSettings featureSettings,... |
165 |
|
boolean forNucleotide) |
166 |
|
{ |
167 |
|
|
168 |
0 |
String[] defdb = null; |
169 |
0 |
List<DbSourceProxy> selsources = new ArrayList<>(); |
170 |
|
|
171 |
0 |
if (forNucleotide) |
172 |
|
{ |
173 |
0 |
defdb = DBRefSource.DNACODINGDBS; |
174 |
|
} |
175 |
|
else |
176 |
|
{ |
177 |
0 |
defdb = DBRefSource.PROTEINDBS; |
178 |
|
} |
179 |
0 |
List<DbSourceProxy> srces = new ArrayList<>(); |
180 |
0 |
for (String ddb : defdb) |
181 |
|
{ |
182 |
0 |
List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb); |
183 |
0 |
if (srcesfordb != null) |
184 |
|
{ |
185 |
0 |
for (DbSourceProxy src : srcesfordb) |
186 |
|
{ |
187 |
0 |
if (!srces.contains(src)) |
188 |
|
{ |
189 |
0 |
srces.addAll(srcesfordb); |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
|
|
198 |
0 |
srces.addAll(selsources); |
199 |
0 |
dbSources = srces.toArray(new DbSourceProxy[srces.size()]); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
|
205 |
|
@param |
206 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
207 |
0 |
public DBRefFetcher(SequenceI[] sequences)... |
208 |
|
{ |
209 |
0 |
this(sequences, null, null, null, false); |
210 |
|
} |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
@param |
216 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
217 |
0 |
public void addListener(FetchFinishedListenerI l)... |
218 |
|
{ |
219 |
0 |
listeners.add(l); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@param |
226 |
|
|
227 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
228 |
0 |
public void fetchDBRefs(boolean waitTillFinished)... |
229 |
|
{ |
230 |
0 |
if (waitTillFinished) |
231 |
|
{ |
232 |
0 |
run(); |
233 |
|
} |
234 |
|
else |
235 |
|
{ |
236 |
0 |
new Thread(this).start(); |
237 |
|
} |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
|
246 |
|
@param |
247 |
|
|
248 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
249 |
0 |
void addSeqId(SequenceI seq, String key)... |
250 |
|
{ |
251 |
0 |
key = key.toUpperCase(Locale.ROOT); |
252 |
|
|
253 |
0 |
Vector<SequenceI> seqs; |
254 |
0 |
if (seqRefs.containsKey(key)) |
255 |
|
{ |
256 |
0 |
seqs = seqRefs.get(key); |
257 |
|
|
258 |
0 |
if (seqs != null && !seqs.contains(seq)) |
259 |
|
{ |
260 |
0 |
seqs.addElement(seq); |
261 |
|
} |
262 |
0 |
else if (seqs == null) |
263 |
|
{ |
264 |
0 |
seqs = new Vector<>(); |
265 |
0 |
seqs.addElement(seq); |
266 |
|
} |
267 |
|
|
268 |
|
} |
269 |
|
else |
270 |
|
{ |
271 |
0 |
seqs = new Vector<>(); |
272 |
0 |
seqs.addElement(seq); |
273 |
|
} |
274 |
|
|
275 |
0 |
seqRefs.put(key, seqs); |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
|
|
| 0% |
Uncovered Elements: 126 (126) |
Complexity: 32 |
Complexity Density: 0.38 |
|
281 |
0 |
@Override... |
282 |
|
public void run() |
283 |
|
{ |
284 |
0 |
if (dbSources == null) |
285 |
|
{ |
286 |
0 |
throw new Error(MessageManager |
287 |
|
.getString("error.implementation_error_must_init_dbsources")); |
288 |
|
} |
289 |
0 |
long startTime = System.currentTimeMillis(); |
290 |
0 |
if (progressWindow != null) |
291 |
|
{ |
292 |
0 |
progressWindow.setProgressBar( |
293 |
|
MessageManager.getString("status.fetching_db_refs"), |
294 |
|
startTime); |
295 |
|
} |
296 |
0 |
try |
297 |
|
{ |
298 |
0 |
if (Cache.getDefault("DBREFFETCH_USEPICR", false)) |
299 |
|
{ |
300 |
0 |
picrClient = new AccessionMapperServiceLocator() |
301 |
|
.getAccessionMapperPort(); |
302 |
|
} |
303 |
|
} catch (Exception e) |
304 |
|
{ |
305 |
0 |
jalview.bin.Console |
306 |
|
.errPrintln("Couldn't locate PICR service instance.\n"); |
307 |
0 |
e.printStackTrace(); |
308 |
|
} |
309 |
|
|
310 |
0 |
Vector<SequenceI> sdataset = new Vector<>(Arrays.asList(dataset)); |
311 |
0 |
List<String> warningMessages = new ArrayList<>(); |
312 |
|
|
313 |
|
|
314 |
0 |
featureDisplaySettings = null; |
315 |
|
|
316 |
0 |
int db = 0; |
317 |
0 |
while (sdataset.size() > 0 && db < dbSources.length) |
318 |
|
{ |
319 |
0 |
int maxqlen = 1; |
320 |
0 |
jalview.bin.Console |
321 |
|
.outPrintln("Verifying against " + dbSources[db].getDbName()); |
322 |
|
|
323 |
|
|
324 |
0 |
SequenceI[] currSeqs = new SequenceI[sdataset.size()]; |
325 |
0 |
sdataset.copyInto(currSeqs); |
326 |
|
|
327 |
0 |
Vector<String> queries = new Vector<>(); |
328 |
0 |
seqRefs = new Hashtable<>(); |
329 |
|
|
330 |
0 |
int seqIndex = 0; |
331 |
|
|
332 |
0 |
DbSourceProxy dbsource = dbSources[db]; |
333 |
|
|
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
0 |
maxqlen = dbsource.getMaximumQueryCount(); |
339 |
|
|
340 |
0 |
while (queries.size() > 0 || seqIndex < currSeqs.length) |
341 |
|
{ |
342 |
0 |
if (queries.size() > 0) |
343 |
|
{ |
344 |
|
|
345 |
0 |
StringBuffer queryString = new StringBuffer(""); |
346 |
0 |
int numq = 0; |
347 |
0 |
int nqSize = (maxqlen > queries.size()) ? queries.size() |
348 |
|
: maxqlen; |
349 |
|
|
350 |
0 |
while (queries.size() > 0 && numq < nqSize) |
351 |
|
{ |
352 |
0 |
String query = queries.elementAt(0); |
353 |
0 |
if (dbsource.isValidReference(query)) |
354 |
|
{ |
355 |
0 |
queryString.append( |
356 |
0 |
(numq == 0) ? "" : dbsource.getAccessionSeparator()); |
357 |
0 |
queryString.append(query); |
358 |
0 |
numq++; |
359 |
|
} |
360 |
|
|
361 |
0 |
queries.removeElementAt(0); |
362 |
|
} |
363 |
|
|
364 |
0 |
AlignmentI retrieved = null; |
365 |
0 |
try |
366 |
|
{ |
367 |
0 |
if (Console.isDebugEnabled()) |
368 |
|
{ |
369 |
0 |
Console.debug("Querying " + dbsource.getDbName() + " with : '" |
370 |
|
+ queryString.toString() + "'"); |
371 |
|
} |
372 |
0 |
retrieved = dbsource.getSequenceRecords(queryString.toString()); |
373 |
|
} catch (Exception ex) |
374 |
|
{ |
375 |
0 |
ex.printStackTrace(); |
376 |
|
} catch (OutOfMemoryError err) |
377 |
|
{ |
378 |
0 |
new OOMWarning("retrieving database references (" |
379 |
|
+ queryString.toString() + ")", err); |
380 |
|
} |
381 |
0 |
if (retrieved != null) |
382 |
|
{ |
383 |
0 |
transferReferences(sdataset, dbsource, retrieved, trimDsSeqs, |
384 |
|
warningMessages); |
385 |
|
} |
386 |
|
} |
387 |
|
else |
388 |
|
{ |
389 |
|
|
390 |
0 |
for (int i = 0; (seqIndex < dataset.length) |
391 |
|
&& (i < 50); seqIndex++, i++) |
392 |
|
{ |
393 |
0 |
SequenceI sequence = dataset[seqIndex]; |
394 |
0 |
List<DBRefEntry> uprefs = DBRefUtils |
395 |
|
.selectRefs(sequence.getDBRefs(), new String[] |
396 |
|
{ dbsource.getDbSource() }); |
397 |
|
|
398 |
|
|
399 |
0 |
if (uprefs != null && uprefs.size() > 0) |
400 |
|
{ |
401 |
0 |
for (int j = 0, n = uprefs.size(); j < n; j++) |
402 |
|
{ |
403 |
0 |
DBRefEntry upref = uprefs.get(j); |
404 |
0 |
addSeqId(sequence, upref.getAccessionId()); |
405 |
0 |
queries.addElement( |
406 |
|
upref.getAccessionId().toUpperCase(Locale.ROOT)); |
407 |
|
} |
408 |
|
} |
409 |
|
else |
410 |
|
{ |
411 |
0 |
Pattern possibleIds = Pattern.compile("[A-Za-z0-9_]+"); |
412 |
|
|
413 |
0 |
Matcher tokens = possibleIds.matcher(sequence.getName()); |
414 |
0 |
int p = 0; |
415 |
0 |
while (tokens.find(p)) |
416 |
|
{ |
417 |
0 |
String token = tokens.group(); |
418 |
0 |
p = tokens.end(); |
419 |
0 |
UPEntry[] presp = null; |
420 |
0 |
if (picrClient != null) |
421 |
|
{ |
422 |
|
|
423 |
0 |
try |
424 |
|
{ |
425 |
0 |
presp = picrClient.getUPIForAccession(token, null, |
426 |
|
picrClient.getMappedDatabaseNames(), null, |
427 |
|
true); |
428 |
|
} catch (Exception e) |
429 |
|
{ |
430 |
0 |
jalview.bin.Console.errPrintln( |
431 |
|
"Exception with Picr for '" + token + "'\n"); |
432 |
0 |
e.printStackTrace(); |
433 |
|
} |
434 |
|
} |
435 |
0 |
if (presp != null && presp.length > 0) |
436 |
|
{ |
437 |
0 |
for (int id = 0; id < presp.length; id++) |
438 |
|
{ |
439 |
|
|
440 |
|
|
441 |
|
|
442 |
|
} |
443 |
0 |
jalview.bin.Console.outPrintln( |
444 |
|
"Validated ID against PICR... (for what its worth):" |
445 |
|
+ token); |
446 |
0 |
addSeqId(sequence, token); |
447 |
0 |
queries.addElement(token.toUpperCase(Locale.ROOT)); |
448 |
|
} |
449 |
|
else |
450 |
|
{ |
451 |
|
|
452 |
|
|
453 |
|
|
454 |
0 |
addSeqId(sequence, token); |
455 |
0 |
queries.addElement(token.toUpperCase(Locale.ROOT)); |
456 |
|
} |
457 |
|
} |
458 |
|
} |
459 |
|
} |
460 |
|
} |
461 |
|
} |
462 |
|
|
463 |
0 |
db++; |
464 |
|
} |
465 |
0 |
if (!warningMessages.isEmpty()) |
466 |
|
{ |
467 |
0 |
StringBuilder sb = new StringBuilder(warningMessages.size() * 30); |
468 |
0 |
sb.append(MessageManager |
469 |
|
.getString("label.your_sequences_have_been_verified")); |
470 |
0 |
for (String msg : warningMessages) |
471 |
|
{ |
472 |
0 |
sb.append(msg).append(NEWLINE); |
473 |
|
} |
474 |
0 |
output.setText(sb.toString()); |
475 |
|
|
476 |
0 |
Desktop.addInternalFrame(output, |
477 |
|
MessageManager.getString("label.sequences_updated"), 600, |
478 |
|
300); |
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
} |
483 |
0 |
if (progressWindow != null) |
484 |
|
{ |
485 |
0 |
progressWindow.setProgressBar( |
486 |
|
MessageManager.getString("label.dbref_search_completed"), |
487 |
|
startTime); |
488 |
|
} |
489 |
|
|
490 |
0 |
for (FetchFinishedListenerI listener : listeners) |
491 |
|
{ |
492 |
0 |
listener.finished(); |
493 |
|
} |
494 |
|
} |
495 |
|
|
496 |
|
|
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@param |
502 |
|
|
503 |
|
@param |
504 |
|
|
505 |
|
@param |
506 |
|
|
507 |
|
@param |
508 |
|
|
509 |
|
|
510 |
|
@param |
511 |
|
|
512 |
|
|
|
|
| 0% |
Uncovered Elements: 138 (138) |
Complexity: 31 |
Complexity Density: 0.36 |
|
513 |
0 |
boolean transferReferences(Vector<SequenceI> sdataset,... |
514 |
|
DbSourceProxy dbSourceProxy, AlignmentI retrievedAl, |
515 |
|
boolean trimDatasetSeqs, List<String> warningMessages) |
516 |
|
{ |
517 |
|
|
518 |
0 |
if (retrievedAl == null || retrievedAl.getHeight() == 0) |
519 |
|
{ |
520 |
0 |
return false; |
521 |
|
} |
522 |
|
|
523 |
0 |
String dbSource = dbSourceProxy.getDbName(); |
524 |
0 |
boolean modified = false; |
525 |
0 |
SequenceI[] retrieved = recoverDbSequences( |
526 |
|
retrievedAl.getSequencesArray()); |
527 |
0 |
SequenceI sequence = null; |
528 |
|
|
529 |
0 |
for (SequenceI retrievedSeq : retrieved) |
530 |
|
{ |
531 |
|
|
532 |
|
|
533 |
0 |
Vector<SequenceI> sequenceMatches = new Vector<>(); |
534 |
|
|
535 |
0 |
List<DBRefEntry> entryRefs = DBRefUtils |
536 |
|
.selectRefs(retrievedSeq.getDBRefs(), new String[] |
537 |
|
{ dbSource }); |
538 |
0 |
if (entryRefs == null) |
539 |
|
{ |
540 |
0 |
System.err |
541 |
|
.println("Dud dbSource string ? no entryrefs selected for " |
542 |
|
+ dbSource + " on " + retrievedSeq.getName()); |
543 |
0 |
continue; |
544 |
|
} |
545 |
0 |
for (int j = 0, n = entryRefs.size(); j < n; j++) |
546 |
|
{ |
547 |
0 |
DBRefEntry ref = entryRefs.get(j); |
548 |
0 |
String accessionId = ref.getAccessionId(); |
549 |
|
|
550 |
0 |
if (seqRefs.containsKey(accessionId.toUpperCase(Locale.ROOT))) |
551 |
|
{ |
552 |
0 |
Vector<SequenceI> seqs = seqRefs.get(accessionId); |
553 |
0 |
for (int jj = 0; jj < seqs.size(); jj++) |
554 |
|
{ |
555 |
0 |
sequence = seqs.elementAt(jj); |
556 |
0 |
if (!sequenceMatches.contains(sequence)) |
557 |
|
{ |
558 |
0 |
sequenceMatches.addElement(sequence); |
559 |
|
} |
560 |
|
} |
561 |
|
} |
562 |
|
} |
563 |
0 |
if (sequenceMatches.isEmpty()) |
564 |
|
{ |
565 |
|
|
566 |
|
|
567 |
0 |
Enumeration<String> e = seqRefs.keys(); |
568 |
0 |
while (e.hasMoreElements()) |
569 |
|
{ |
570 |
0 |
Vector<SequenceI> sqs = seqRefs.get(e.nextElement()); |
571 |
0 |
if (sqs != null && sqs.size() > 0) |
572 |
|
{ |
573 |
0 |
Enumeration<SequenceI> sqe = sqs.elements(); |
574 |
0 |
while (sqe.hasMoreElements()) |
575 |
|
{ |
576 |
0 |
sequenceMatches.addElement(sqe.nextElement()); |
577 |
|
} |
578 |
|
} |
579 |
|
} |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
|
587 |
|
|
588 |
|
|
589 |
|
|
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
0 |
if (sequenceMatches.size() > 0) |
596 |
|
{ |
597 |
0 |
addFeatureSettings(dbSourceProxy); |
598 |
|
} |
599 |
|
|
600 |
|
|
601 |
0 |
final String retrievedSeqString = retrievedSeq.getSequenceAsString(); |
602 |
0 |
String entrySeq = retrievedSeqString.toUpperCase(Locale.ROOT); |
603 |
0 |
for (int m = 0; m < sequenceMatches.size(); m++) |
604 |
|
{ |
605 |
0 |
sequence = sequenceMatches.elementAt(m); |
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
0 |
boolean updateRefFrame = sequence.getDBRefs() == null |
611 |
|
|| sequence.getDBRefs().size() == 0; |
612 |
|
|
613 |
|
|
614 |
|
|
615 |
0 |
Mapping mp; |
616 |
0 |
final int sequenceStart = sequence.getStart(); |
617 |
|
|
618 |
0 |
boolean remoteEnclosesLocal = false; |
619 |
0 |
String nonGapped = AlignSeq |
620 |
|
.extractGaps("-. ", sequence.getSequenceAsString()) |
621 |
|
.toUpperCase(Locale.ROOT); |
622 |
0 |
int absStart = entrySeq.indexOf(nonGapped); |
623 |
0 |
if (absStart == -1) |
624 |
|
{ |
625 |
|
|
626 |
|
|
627 |
0 |
absStart = nonGapped.indexOf(entrySeq); |
628 |
0 |
if (absStart == -1) |
629 |
|
{ |
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
0 |
continue; |
638 |
|
} |
639 |
|
|
640 |
|
|
641 |
|
|
642 |
0 |
String msg = sequence.getName() + " has " + absStart |
643 |
|
+ " prefixed residues compared to " |
644 |
|
+ retrievedSeq.getName(); |
645 |
0 |
addWarningMessage(warningMessages, msg); |
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
0 |
mp = new Mapping(null, |
652 |
|
new int[] |
653 |
|
{ sequenceStart + absStart, |
654 |
|
sequenceStart + absStart + entrySeq.length() - 1 }, |
655 |
|
new int[] |
656 |
|
{ retrievedSeq.getStart(), |
657 |
|
retrievedSeq.getStart() + entrySeq.length() - 1 }, |
658 |
|
1, 1); |
659 |
0 |
updateRefFrame = false; |
660 |
|
} |
661 |
|
else |
662 |
|
{ |
663 |
|
|
664 |
|
|
665 |
|
|
666 |
0 |
remoteEnclosesLocal = true; |
667 |
0 |
mp = null; |
668 |
|
|
669 |
0 |
if (updateRefFrame) |
670 |
|
{ |
671 |
|
|
672 |
|
|
673 |
|
|
674 |
0 |
int startShift = absStart - sequenceStart + 1; |
675 |
0 |
if (startShift != 0) |
676 |
|
{ |
677 |
0 |
modified |= sequence.getFeatures().shiftFeatures(1, |
678 |
|
startShift); |
679 |
|
} |
680 |
|
} |
681 |
|
} |
682 |
|
|
683 |
0 |
jalview.bin.Console.outPrintln("Adding dbrefs to " |
684 |
|
+ sequence.getName() + " from " + dbSource + " sequence : " |
685 |
|
+ retrievedSeq.getName()); |
686 |
0 |
sequence.transferAnnotation(retrievedSeq, mp); |
687 |
|
|
688 |
0 |
absStart += retrievedSeq.getStart(); |
689 |
0 |
int absEnd = absStart + nonGapped.length() - 1; |
690 |
0 |
if (!trimDatasetSeqs) |
691 |
|
{ |
692 |
|
|
693 |
|
|
694 |
|
|
695 |
0 |
if (!retrievedSeqString.equals(sequence.getSequenceAsString()) |
696 |
|
&& remoteEnclosesLocal) |
697 |
|
{ |
698 |
0 |
sequence.setSequence(retrievedSeqString); |
699 |
0 |
modified = true; |
700 |
0 |
addWarningMessage(warningMessages, |
701 |
|
"Sequence for " + sequence.getName() + " expanded from " |
702 |
|
+ retrievedSeq.getName()); |
703 |
|
} |
704 |
0 |
if (sequence.getStart() != retrievedSeq.getStart()) |
705 |
|
{ |
706 |
0 |
sequence.setStart(retrievedSeq.getStart()); |
707 |
0 |
modified = true; |
708 |
0 |
if (absStart != sequenceStart) |
709 |
|
{ |
710 |
0 |
addWarningMessage(warningMessages, |
711 |
|
"Start/end position for " + sequence.getName() |
712 |
|
+ " updated from " + retrievedSeq.getName()); |
713 |
|
} |
714 |
|
} |
715 |
|
} |
716 |
0 |
if (updateRefFrame) |
717 |
|
{ |
718 |
|
|
719 |
0 |
if (trimDatasetSeqs) |
720 |
|
{ |
721 |
|
|
722 |
0 |
if (sequence.getStart() != absStart |
723 |
|
|| sequence.getEnd() != absEnd) |
724 |
|
{ |
725 |
0 |
sequence.setStart(absStart); |
726 |
0 |
sequence.setEnd(absEnd); |
727 |
0 |
modified = true; |
728 |
0 |
addWarningMessage(warningMessages, |
729 |
|
"Start/end for " + sequence.getName() |
730 |
|
+ " updated from " + retrievedSeq.getName()); |
731 |
|
} |
732 |
|
} |
733 |
|
|
734 |
0 |
for (int alsq = 0; alsq < alseqs.length; alsq++) |
735 |
|
{ |
736 |
0 |
if (alseqs[alsq].getDatasetSequence() == sequence) |
737 |
|
{ |
738 |
0 |
String ngAlsq = AlignSeq |
739 |
|
.extractGaps("-. ", |
740 |
|
alseqs[alsq].getSequenceAsString()) |
741 |
|
.toUpperCase(Locale.ROOT); |
742 |
0 |
int oldstrt = alseqs[alsq].getStart(); |
743 |
0 |
alseqs[alsq].setStart(sequence.getSequenceAsString() |
744 |
|
.toUpperCase(Locale.ROOT).indexOf(ngAlsq) |
745 |
|
+ sequence.getStart()); |
746 |
0 |
if (oldstrt != alseqs[alsq].getStart()) |
747 |
|
{ |
748 |
0 |
alseqs[alsq].setEnd( |
749 |
|
ngAlsq.length() + alseqs[alsq].getStart() - 1); |
750 |
0 |
modified = true; |
751 |
|
} |
752 |
|
} |
753 |
|
} |
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
|
758 |
|
|
759 |
|
} |
760 |
|
|
761 |
|
|
762 |
0 |
sdataset.remove(sequence); |
763 |
|
} |
764 |
|
} |
765 |
0 |
return modified; |
766 |
|
} |
767 |
|
|
768 |
|
Map<String, FeatureSettingsModelI> featureDisplaySettings = null; |
769 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
770 |
0 |
private void addFeatureSettings(DbSourceProxy dbSourceProxy)... |
771 |
|
{ |
772 |
0 |
FeatureSettingsModelI fsettings = dbSourceProxy |
773 |
|
.getFeatureColourScheme(); |
774 |
0 |
if (fsettings != null) |
775 |
|
{ |
776 |
0 |
if (featureDisplaySettings == null) |
777 |
|
{ |
778 |
0 |
featureDisplaySettings = new HashMap<>(); |
779 |
|
} |
780 |
0 |
featureDisplaySettings.put(dbSourceProxy.getDbName(), fsettings); |
781 |
|
} |
782 |
|
} |
783 |
|
|
784 |
|
|
785 |
|
|
786 |
|
@return |
787 |
|
|
788 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
789 |
0 |
public List<FeatureSettingsModelI> getFeatureSettingsModels()... |
790 |
|
{ |
791 |
0 |
return featureDisplaySettings == null |
792 |
|
? Arrays.asList(new FeatureSettingsModelI[0]) |
793 |
|
: Arrays.asList(featureDisplaySettings.values() |
794 |
|
.toArray(new FeatureSettingsModelI[1])); |
795 |
|
} |
796 |
|
|
797 |
|
|
798 |
|
|
799 |
|
|
800 |
|
@param |
801 |
|
@param |
802 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
803 |
0 |
void addWarningMessage(List<String> messageList, String msg)... |
804 |
|
{ |
805 |
0 |
if (!messageList.contains(msg)) |
806 |
|
{ |
807 |
0 |
messageList.add(msg); |
808 |
|
} |
809 |
|
} |
810 |
|
|
811 |
|
|
812 |
|
|
813 |
|
|
814 |
|
@param |
815 |
|
@return |
816 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 10 |
Complexity Density: 0.62 |
|
817 |
0 |
private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray)... |
818 |
|
{ |
819 |
0 |
int n; |
820 |
0 |
if (sequencesArray == null || (n = sequencesArray.length) == 0) |
821 |
0 |
return sequencesArray; |
822 |
0 |
ArrayList<SequenceI> nseq = new ArrayList<>(); |
823 |
0 |
for (int i = 0; i < n; i++) |
824 |
|
{ |
825 |
0 |
nseq.add(sequencesArray[i]); |
826 |
0 |
List<DBRefEntry> dbr = sequencesArray[i].getDBRefs(); |
827 |
0 |
Mapping map = null; |
828 |
0 |
if (dbr != null) |
829 |
|
{ |
830 |
0 |
for (int r = 0, rn = dbr.size(); r < rn; r++) |
831 |
|
{ |
832 |
0 |
if ((map = dbr.get(r).getMap()) != null) |
833 |
|
{ |
834 |
0 |
if (map.getTo() != null && !nseq.contains(map.getTo())) |
835 |
|
{ |
836 |
0 |
nseq.add(map.getTo()); |
837 |
|
} |
838 |
|
} |
839 |
|
} |
840 |
|
} |
841 |
|
} |
842 |
|
|
843 |
|
|
844 |
0 |
if (nseq.size() > 0) |
845 |
|
{ |
846 |
0 |
return nseq.toArray(new SequenceI[nseq.size()]); |
847 |
|
} |
848 |
0 |
return sequencesArray; |
849 |
|
} |
850 |
|
} |