Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.ws

File DBRefFetcher.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

126
228
10
2
811
543
92
0.4
22.8
5
9.2

Classes

Class Line # Actions
DBRefFetcher 57 228 92 364
0.00%
DBRefFetcher.FetchFinishedListenerI 63 0 0 0
-1.0 -
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.ws;
22   
23    import jalview.analysis.AlignSeq;
24    import jalview.bin.Cache;
25    import jalview.datamodel.AlignmentI;
26    import jalview.datamodel.DBRefEntry;
27    import jalview.datamodel.DBRefSource;
28    import jalview.datamodel.Mapping;
29    import jalview.datamodel.SequenceI;
30    import jalview.gui.CutAndPasteTransfer;
31    import jalview.gui.Desktop;
32    import jalview.gui.FeatureSettings;
33    import jalview.gui.IProgressIndicator;
34    import jalview.gui.OOMWarning;
35    import jalview.util.DBRefUtils;
36    import jalview.util.MessageManager;
37    import jalview.ws.seqfetcher.DbSourceProxy;
38   
39    import java.util.ArrayList;
40    import java.util.Arrays;
41    import java.util.Enumeration;
42    import java.util.Hashtable;
43    import java.util.List;
44    import java.util.StringTokenizer;
45    import java.util.Vector;
46   
47    import uk.ac.ebi.picr.model.UPEntry;
48    import uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator;
49   
50    /**
51    * Implements a runnable for validating a sequence against external databases
52    * and then propagating references and features onto the sequence(s)
53    *
54    * @author $author$
55    * @version $Revision$
56    */
 
57    public class DBRefFetcher implements Runnable
58    {
59    private static final String NEWLINE = System.lineSeparator();
60   
61    public static final String TRIM_RETRIEVED_SEQUENCES = "TRIM_FETCHED_DATASET_SEQS";
62   
 
63    public interface FetchFinishedListenerI
64    {
65    void finished();
66    }
67   
68    SequenceI[] dataset;
69   
70    IProgressIndicator progressWindow;
71   
72    CutAndPasteTransfer output = new CutAndPasteTransfer();
73   
74    boolean running = false;
75   
76    /**
77    * picr client instance
78    */
79    uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperInterface picrClient = null;
80   
81    // This will be a collection of Vectors of sequenceI refs.
82    // The key will be the seq name or accession id of the seq
83    Hashtable<String, Vector<SequenceI>> seqRefs;
84   
85    DbSourceProxy[] dbSources;
86   
87    SequenceFetcher sfetcher;
88   
89    private List<FetchFinishedListenerI> listeners;
90   
91    private SequenceI[] alseqs;
92   
93    /*
94    * when true - retrieved sequences will be trimmed to cover longest derived
95    * alignment sequence
96    */
97    private boolean trimDsSeqs = true;
98   
99    /**
100    * Creates a new DBRefFetcher object and fetches from the currently selected
101    * set of databases, if this is null then it fetches based on feature settings
102    *
103    * @param seqs
104    * fetch references for these SequenceI array
105    * @param progressIndicatorFrame
106    * the frame for progress bar monitoring
107    * @param sources
108    * array of DbSourceProxy to query references form
109    * @param featureSettings
110    * FeatureSettings to get alternative DbSourceProxy from
111    * @param isNucleotide
112    * indicates if the array of SequenceI are Nucleotides or not
113    */
 
114  0 toggle public DBRefFetcher(SequenceI[] seqs,
115    IProgressIndicator progressIndicatorFrame,
116    DbSourceProxy[] sources, FeatureSettings featureSettings,
117    boolean isNucleotide)
118    {
119  0 listeners = new ArrayList<>();
120  0 this.progressWindow = progressIndicatorFrame;
121  0 alseqs = new SequenceI[seqs.length];
122  0 SequenceI[] ds = new SequenceI[seqs.length];
123  0 for (int i = 0; i < seqs.length; i++)
124    {
125  0 alseqs[i] = seqs[i];
126  0 if (seqs[i].getDatasetSequence() != null)
127    {
128  0 ds[i] = seqs[i].getDatasetSequence();
129    }
130    else
131    {
132  0 ds[i] = seqs[i];
133    }
134    }
135  0 this.dataset = ds;
136    // TODO Jalview 2.5 lots of this code should be in the gui package!
137  0 sfetcher = jalview.gui.SequenceFetcher
138    .getSequenceFetcherSingleton(progressIndicatorFrame);
139    // set default behaviour for transferring excess sequence data to the
140    // dataset
141  0 trimDsSeqs = Cache.getDefault(TRIM_RETRIEVED_SEQUENCES, true);
142  0 if (sources == null)
143    {
144  0 setDatabaseSources(featureSettings, isNucleotide);
145    }
146    else
147    {
148    // we assume the caller knows what they're doing and ensured that all the
149    // db source names are valid
150  0 dbSources = sources;
151    }
152    }
153   
154    /**
155    * Helper method to configure the list of database sources to query
156    *
157    * @param featureSettings
158    * @param forNucleotide
159    */
 
160  0 toggle void setDatabaseSources(FeatureSettings featureSettings,
161    boolean forNucleotide)
162    {
163    // af.featureSettings_actionPerformed(null);
164  0 String[] defdb = null;
165  0 List<DbSourceProxy> selsources = new ArrayList<>();
166    // select appropriate databases based on alignFrame context.
167  0 if (forNucleotide)
168    {
169  0 defdb = DBRefSource.DNACODINGDBS;
170    }
171    else
172    {
173  0 defdb = DBRefSource.PROTEINDBS;
174    }
175  0 List<DbSourceProxy> srces = new ArrayList<>();
176  0 for (String ddb : defdb)
177    {
178  0 List<DbSourceProxy> srcesfordb = sfetcher.getSourceProxy(ddb);
179  0 if (srcesfordb != null)
180    {
181  0 for (DbSourceProxy src : srcesfordb)
182    {
183  0 if (!srces.contains(src))
184    {
185  0 srces.addAll(srcesfordb);
186    }
187    }
188    }
189    }
190    // append the PDB data source, since it is 'special', catering for both
191    // nucleotide and protein
192    // srces.addAll(sfetcher.getSourceProxy(DBRefSource.PDB));
193   
194  0 srces.addAll(selsources);
195  0 dbSources = srces.toArray(new DbSourceProxy[srces.size()]);
196    }
197   
198    /**
199    * Constructor with only sequences provided
200    *
201    * @param sequences
202    */
 
203  0 toggle public DBRefFetcher(SequenceI[] sequences)
204    {
205  0 this(sequences, null, null, null, false);
206    }
207   
208    /**
209    * Add a listener to be notified when sequence fetching is complete
210    *
211    * @param l
212    */
 
213  0 toggle public void addListener(FetchFinishedListenerI l)
214    {
215  0 listeners.add(l);
216    }
217   
218    /**
219    * start the fetcher thread
220    *
221    * @param waitTillFinished
222    * true to block until the fetcher has finished
223    */
 
224  0 toggle public void fetchDBRefs(boolean waitTillFinished)
225    {
226    // TODO can we not simply write
227    // if (waitTillFinished) { run(); } else { new Thread(this).start(); }
228   
229  0 Thread thread = new Thread(this);
230  0 thread.start();
231  0 running = true;
232   
233  0 if (waitTillFinished)
234    {
235  0 while (running)
236    {
237  0 try
238    {
239  0 Thread.sleep(500);
240    } catch (Exception ex)
241    {
242    }
243    }
244    }
245    }
246   
247    /**
248    * The sequence will be added to a vector of sequences belonging to key which
249    * could be either seq name or dbref id
250    *
251    * @param seq
252    * SequenceI
253    * @param key
254    * String
255    */
 
256  0 toggle void addSeqId(SequenceI seq, String key)
257    {
258  0 key = key.toUpperCase();
259   
260  0 Vector<SequenceI> seqs;
261  0 if (seqRefs.containsKey(key))
262    {
263  0 seqs = seqRefs.get(key);
264   
265  0 if (seqs != null && !seqs.contains(seq))
266    {
267  0 seqs.addElement(seq);
268    }
269  0 else if (seqs == null)
270    {
271  0 seqs = new Vector<>();
272  0 seqs.addElement(seq);
273    }
274   
275    }
276    else
277    {
278  0 seqs = new Vector<>();
279  0 seqs.addElement(seq);
280    }
281   
282  0 seqRefs.put(key, seqs);
283    }
284   
285    /**
286    * DOCUMENT ME!
287    */
 
288  0 toggle @Override
289    public void run()
290    {
291  0 if (dbSources == null)
292    {
293  0 throw new Error(MessageManager
294    .getString("error.implementation_error_must_init_dbsources"));
295    }
296  0 running = true;
297  0 long startTime = System.currentTimeMillis();
298  0 if (progressWindow != null)
299    {
300  0 progressWindow.setProgressBar(
301    MessageManager.getString("status.fetching_db_refs"),
302    startTime);
303    }
304  0 try
305    {
306  0 if (Cache.getDefault("DBREFFETCH_USEPICR", false))
307    {
308  0 picrClient = new AccessionMapperServiceLocator()
309    .getAccessionMapperPort();
310    }
311    } catch (Exception e)
312    {
313  0 System.err.println("Couldn't locate PICR service instance.\n");
314  0 e.printStackTrace();
315    }
316   
317  0 Vector<SequenceI> sdataset = new Vector<>(
318    Arrays.asList(dataset));
319  0 List<String> warningMessages = new ArrayList<>();
320   
321  0 int db = 0;
322  0 while (sdataset.size() > 0 && db < dbSources.length)
323    {
324  0 int maxqlen = 1; // default number of queries made at one time
325  0 System.out.println("Verifying against " + dbSources[db].getDbName());
326   
327    // iterate through db for each remaining un-verified sequence
328  0 SequenceI[] currSeqs = new SequenceI[sdataset.size()];
329  0 sdataset.copyInto(currSeqs);// seqs that are to be validated against
330    // dbSources[db]
331  0 Vector<String> queries = new Vector<>(); // generated queries curSeq
332  0 seqRefs = new Hashtable<>();
333   
334  0 int seqIndex = 0;
335   
336  0 DbSourceProxy dbsource = dbSources[db];
337    // for moment, we dumbly iterate over all retrieval sources for a
338    // particular database
339    // TODO: introduce multithread multisource queries and logic to remove a
340    // query from other sources if any source for a database returns a
341    // record
342  0 maxqlen = dbsource.getMaximumQueryCount();
343   
344  0 while (queries.size() > 0 || seqIndex < currSeqs.length)
345    {
346  0 if (queries.size() > 0)
347    {
348    // Still queries to make for current seqIndex
349  0 StringBuffer queryString = new StringBuffer("");
350  0 int numq = 0;
351  0 int nqSize = (maxqlen > queries.size()) ? queries.size()
352    : maxqlen;
353   
354  0 while (queries.size() > 0 && numq < nqSize)
355    {
356  0 String query = queries.elementAt(0);
357  0 if (dbsource.isValidReference(query))
358    {
359  0 queryString.append(
360  0 (numq == 0) ? "" : dbsource.getAccessionSeparator());
361  0 queryString.append(query);
362  0 numq++;
363    }
364    // remove the extracted query string
365  0 queries.removeElementAt(0);
366    }
367    // make the queries and process the response
368  0 AlignmentI retrieved = null;
369  0 try
370    {
371  0 if (Cache.log.isDebugEnabled())
372    {
373  0 Cache.log.debug("Querying " + dbsource.getDbName()
374    + " with : '" + queryString.toString() + "'");
375    }
376  0 retrieved = dbsource.getSequenceRecords(queryString.toString());
377    } catch (Exception ex)
378    {
379  0 ex.printStackTrace();
380    } catch (OutOfMemoryError err)
381    {
382  0 new OOMWarning("retrieving database references ("
383    + queryString.toString() + ")", err);
384    }
385  0 if (retrieved != null)
386    {
387  0 transferReferences(sdataset, dbsource.getDbSource(), retrieved,
388    trimDsSeqs, warningMessages);
389    }
390    }
391    else
392    {
393    // make some more strings for use as queries
394  0 for (int i = 0; (seqIndex < dataset.length)
395    && (i < 50); seqIndex++, i++)
396    {
397  0 SequenceI sequence = dataset[seqIndex];
398  0 DBRefEntry[] uprefs = DBRefUtils
399    .selectRefs(sequence.getDBRefs(), new String[]
400    { dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT
401    // });
402    // check for existing dbrefs to use
403  0 if (uprefs != null && uprefs.length > 0)
404    {
405  0 for (int j = 0; j < uprefs.length; j++)
406    {
407  0 addSeqId(sequence, uprefs[j].getAccessionId());
408  0 queries.addElement(
409    uprefs[j].getAccessionId().toUpperCase());
410    }
411    }
412    else
413    {
414    // generate queries from sequence ID string
415  0 StringTokenizer st = new StringTokenizer(sequence.getName(),
416    "|");
417  0 while (st.hasMoreTokens())
418    {
419  0 String token = st.nextToken();
420  0 UPEntry[] presp = null;
421  0 if (picrClient != null)
422    {
423    // resolve the string against PICR to recover valid IDs
424  0 try
425    {
426  0 presp = picrClient.getUPIForAccession(token, null,
427    picrClient.getMappedDatabaseNames(), null,
428    true);
429    } catch (Exception e)
430    {
431  0 System.err.println(
432    "Exception with Picr for '" + token + "'\n");
433  0 e.printStackTrace();
434    }
435    }
436  0 if (presp != null && presp.length > 0)
437    {
438  0 for (int id = 0; id < presp.length; id++)
439    {
440    // construct sequences from response if sequences are
441    // present, and do a transferReferences
442    // otherwise transfer non sequence x-references directly.
443    }
444  0 System.out.println(
445    "Validated ID against PICR... (for what its worth):"
446    + token);
447  0 addSeqId(sequence, token);
448  0 queries.addElement(token.toUpperCase());
449    }
450    else
451    {
452    // if ()
453    // System.out.println("Not querying source with
454    // token="+token+"\n");
455  0 addSeqId(sequence, token);
456  0 queries.addElement(token.toUpperCase());
457    }
458    }
459    }
460    }
461    }
462    }
463    // advance to next database
464  0 db++;
465    } // all databases have been queried
466  0 if (!warningMessages.isEmpty())
467    {
468  0 StringBuilder sb = new StringBuilder(warningMessages.size() * 30);
469  0 sb.append(MessageManager
470    .getString("label.your_sequences_have_been_verified"));
471  0 for (String msg : warningMessages)
472    {
473  0 sb.append(msg).append(NEWLINE);
474    }
475  0 output.setText(sb.toString());
476   
477  0 Desktop.addInternalFrame(output,
478    MessageManager.getString("label.sequences_updated"), 600,
479    300);
480    // The above is the dataset, we must now find out the index
481    // of the viewed sequence
482   
483    }
484  0 if (progressWindow != null)
485    {
486  0 progressWindow.setProgressBar(
487    MessageManager.getString("label.dbref_search_completed"),
488    startTime);
489    }
490   
491  0 for (FetchFinishedListenerI listener : listeners)
492    {
493  0 listener.finished();
494    }
495  0 running = false;
496    }
497   
498    /**
499    * Verify local sequences in seqRefs against the retrieved sequence database
500    * records. Returns true if any sequence was modified as a result (start/end
501    * changed and/or sequence enlarged), else false.
502    *
503    * @param sdataset
504    * dataset sequences we are retrieving for
505    * @param dbSource
506    * database source we are retrieving from
507    * @param retrievedAl
508    * retrieved sequences as alignment
509    * @param trimDatasetSeqs
510    * if true, sequences will not be enlarged to match longer retrieved
511    * sequences, only their start/end adjusted
512    * @param warningMessages
513    * a list of messages to add to
514    */
 
515  0 toggle boolean transferReferences(Vector<SequenceI> sdataset, String dbSource,
516    AlignmentI retrievedAl, boolean trimDatasetSeqs,
517    List<String> warningMessages)
518    {
519    // System.out.println("trimming ? " + trimDatasetSeqs);
520  0 if (retrievedAl == null || retrievedAl.getHeight() == 0)
521    {
522  0 return false;
523    }
524   
525  0 boolean modified = false;
526  0 SequenceI[] retrieved = recoverDbSequences(
527    retrievedAl.getSequencesArray());
528  0 SequenceI sequence = null;
529   
530  0 for (SequenceI retrievedSeq : retrieved)
531    {
532    // Work out which sequences this sequence matches,
533    // taking into account all accessionIds and names in the file
534  0 Vector<SequenceI> sequenceMatches = new Vector<>();
535    // look for corresponding accession ids
536  0 DBRefEntry[] entryRefs = DBRefUtils
537    .selectRefs(retrievedSeq.getDBRefs(), new String[]
538    { dbSource });
539  0 if (entryRefs == null)
540    {
541  0 System.err
542    .println("Dud dbSource string ? no entryrefs selected for "
543    + dbSource + " on " + retrievedSeq.getName());
544  0 continue;
545    }
546  0 for (int j = 0; j < entryRefs.length; j++)
547    {
548  0 String accessionId = entryRefs[j].getAccessionId();
549    // match up on accessionId
550  0 if (seqRefs.containsKey(accessionId.toUpperCase()))
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    // failed to match directly on accessionId==query so just compare all
566    // sequences to entry
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    // look for corresponding names
582    // this is uniprot specific ?
583    // could be useful to extend this so we try to find any 'significant'
584    // information in common between two sequence objects.
585    /*
586    * DBRefEntry[] entryRefs =
587    * jalview.util.DBRefUtils.selectRefs(entry.getDBRef(), new String[] {
588    * dbSource }); for (int j = 0; j < entry.getName().size(); j++) { String
589    * name = entry.getName().elementAt(j).toString(); if
590    * (seqRefs.containsKey(name)) { Vector seqs = (Vector) seqRefs.get(name);
591    * for (int jj = 0; jj < seqs.size(); jj++) { sequence = (SequenceI)
592    * seqs.elementAt(jj); if (!sequenceMatches.contains(sequence)) {
593    * sequenceMatches.addElement(sequence); } } } }
594    */
595    // sequenceMatches now contains the set of all sequences associated with
596    // the returned db record
597  0 final String retrievedSeqString = retrievedSeq.getSequenceAsString();
598  0 String entrySeq = retrievedSeqString.toUpperCase();
599  0 for (int m = 0; m < sequenceMatches.size(); m++)
600    {
601  0 sequence = sequenceMatches.elementAt(m);
602    // only update start and end positions and shift features if there are
603    // no existing references
604    // TODO: test for legacy where uniprot or EMBL refs exist but no
605    // mappings are made (but content matches retrieved set)
606  0 boolean updateRefFrame = sequence.getDBRefs() == null
607    || sequence.getDBRefs().length == 0;
608    // TODO:
609    // verify sequence against the entry sequence
610   
611  0 Mapping mp;
612  0 final int sequenceStart = sequence.getStart();
613   
614  0 boolean remoteEnclosesLocal = false;
615  0 String nonGapped = AlignSeq
616    .extractGaps("-. ", sequence.getSequenceAsString())
617    .toUpperCase();
618  0 int absStart = entrySeq.indexOf(nonGapped);
619  0 if (absStart == -1)
620    {
621    // couldn't find local sequence in sequence from database, so check if
622    // the database sequence is a subsequence of local sequence
623  0 absStart = nonGapped.indexOf(entrySeq);
624  0 if (absStart == -1)
625    {
626    // verification failed. couldn't find any relationship between
627    // entrySeq and local sequence
628    // messages suppressed as many-to-many matches are confusing
629    // String msg = sequence.getName()
630    // + " Sequence not 100% match with "
631    // + retrievedSeq.getName();
632    // addWarningMessage(warningMessages, msg);
633  0 continue;
634    }
635    /*
636    * retrieved sequence is a proper subsequence of local sequence
637    */
638  0 String msg = sequence.getName() + " has " + absStart
639    + " prefixed residues compared to "
640    + retrievedSeq.getName();
641  0 addWarningMessage(warningMessages, msg);
642   
643    /*
644    * So create a mapping to the external entry from the matching region of
645    * the local sequence, and leave local start/end untouched.
646    */
647  0 mp = new Mapping(null,
648    new int[]
649    { sequenceStart + absStart,
650    sequenceStart + absStart + entrySeq.length() - 1 },
651    new int[]
652    { retrievedSeq.getStart(),
653    retrievedSeq.getStart() + entrySeq.length() - 1 },
654    1, 1);
655  0 updateRefFrame = false;
656    }
657    else
658    {
659    /*
660    * local sequence is a subsequence of (or matches) retrieved sequence
661    */
662  0 remoteEnclosesLocal = true;
663  0 mp = null;
664   
665  0 if (updateRefFrame)
666    {
667    /*
668    * relocate existing sequence features by offset
669    */
670  0 int startShift = absStart - sequenceStart + 1;
671  0 if (startShift != 0)
672    {
673  0 modified |= sequence.getFeatures().shiftFeatures(startShift);
674    }
675    }
676    }
677   
678  0 System.out.println("Adding dbrefs to " + sequence.getName()
679    + " from " + dbSource + " sequence : "
680    + retrievedSeq.getName());
681  0 sequence.transferAnnotation(retrievedSeq, mp);
682   
683  0 absStart += retrievedSeq.getStart();
684  0 int absEnd = absStart + nonGapped.length() - 1;
685  0 if (!trimDatasetSeqs)
686    {
687    /*
688    * update start position and/or expand to longer retrieved sequence
689    */
690  0 if (!retrievedSeqString.equals(sequence.getSequenceAsString())
691    && remoteEnclosesLocal)
692    {
693  0 sequence.setSequence(retrievedSeqString);
694  0 modified = true;
695  0 addWarningMessage(warningMessages,
696    "Sequence for " + sequence.getName() + " expanded from "
697    + retrievedSeq.getName());
698    }
699  0 if (sequence.getStart() != retrievedSeq.getStart())
700    {
701  0 sequence.setStart(retrievedSeq.getStart());
702  0 modified = true;
703  0 if (absStart != sequenceStart)
704    {
705  0 addWarningMessage(warningMessages,
706    "Start/end position for " + sequence.getName()
707    + " updated from " + retrievedSeq.getName());
708    }
709    }
710    }
711  0 if (updateRefFrame)
712    {
713    // finally, update local sequence reference frame if we're allowed
714  0 if (trimDatasetSeqs)
715    {
716    // just fix start/end
717  0 if (sequence.getStart() != absStart
718    || sequence.getEnd() != absEnd)
719    {
720  0 sequence.setStart(absStart);
721  0 sequence.setEnd(absEnd);
722  0 modified = true;
723  0 addWarningMessage(warningMessages,
724    "Start/end for " + sequence.getName()
725    + " updated from " + retrievedSeq.getName());
726    }
727    }
728    // search for alignment sequences to update coordinate frame for
729  0 for (int alsq = 0; alsq < alseqs.length; alsq++)
730    {
731  0 if (alseqs[alsq].getDatasetSequence() == sequence)
732    {
733  0 String ngAlsq = AlignSeq
734    .extractGaps("-. ",
735    alseqs[alsq].getSequenceAsString())
736    .toUpperCase();
737  0 int oldstrt = alseqs[alsq].getStart();
738  0 alseqs[alsq].setStart(sequence.getSequenceAsString()
739    .toUpperCase().indexOf(ngAlsq) + sequence.getStart());
740  0 if (oldstrt != alseqs[alsq].getStart())
741    {
742  0 alseqs[alsq].setEnd(
743    ngAlsq.length() + alseqs[alsq].getStart() - 1);
744  0 modified = true;
745    }
746    }
747    }
748    // TODO: search for all other references to this dataset sequence, and
749    // update start/end
750    // TODO: update all AlCodonMappings which involve this alignment
751    // sequence (e.g. Q30167 cdna translation from exon2 product (vamsas
752    // demo)
753    }
754    // and remove it from the rest
755    // TODO: decide if we should remove annotated sequence from set
756  0 sdataset.remove(sequence);
757    // TODO: should we make a note of sequences that have received new DB
758    // ids, so we can query all enabled DAS servers for them ?
759    }
760    }
761  0 return modified;
762    }
763   
764    /**
765    * Adds the message to the list unless it already contains it
766    *
767    * @param messageList
768    * @param msg
769    */
 
770  0 toggle void addWarningMessage(List<String> messageList, String msg)
771    {
772  0 if (!messageList.contains(msg))
773    {
774  0 messageList.add(msg);
775    }
776    }
777   
778    /**
779    * loop thru and collect additional sequences in Map.
780    *
781    * @param sequencesArray
782    * @return
783    */
 
784  0 toggle private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray)
785    {
786  0 Vector<SequenceI> nseq = new Vector<>();
787  0 for (int i = 0; sequencesArray != null
788    && i < sequencesArray.length; i++)
789    {
790  0 nseq.addElement(sequencesArray[i]);
791  0 DBRefEntry[] dbr = sequencesArray[i].getDBRefs();
792  0 Mapping map = null;
793  0 for (int r = 0; (dbr != null) && r < dbr.length; r++)
794    {
795  0 if ((map = dbr[r].getMap()) != null)
796    {
797  0 if (map.getTo() != null && !nseq.contains(map.getTo()))
798    {
799  0 nseq.addElement(map.getTo());
800    }
801    }
802    }
803    }
804  0 if (nseq.size() > 0)
805    {
806  0 sequencesArray = new SequenceI[nseq.size()];
807  0 nseq.toArray(sequencesArray);
808    }
809  0 return sequencesArray;
810    }
811    }