X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2FDBRefFetcher.java;h=3ba0e3454db16f5357a25e3498ba20e5c236fb3d;hb=36dceb54710feb97a81f4bd69ad051f316141dc3;hp=b708ec1a0479ca6bc626f48ba6a00eaa2a6b9baf;hpb=a21b84a669a9620f6943b9b5054e8756cb6f0687;p=jalview.git diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index b708ec1..3ba0e34 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -28,9 +28,9 @@ import jalview.datamodel.DBRefSource; import jalview.datamodel.Mapping; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; -import jalview.gui.AlignFrame; import jalview.gui.CutAndPasteTransfer; import jalview.gui.Desktop; +import jalview.gui.FeatureSettings; import jalview.gui.IProgressIndicator; import jalview.gui.OOMWarning; import jalview.util.MessageManager; @@ -55,9 +55,16 @@ import uk.ac.ebi.picr.model.UPEntry; */ public class DBRefFetcher implements Runnable { + public interface FetchFinishedListenerI + { + void finished(); + } + + private List listeners; + SequenceI[] dataset; - IProgressIndicator af; + IProgressIndicator progressWindow; CutAndPasteTransfer output = new CutAndPasteTransfer(); @@ -86,39 +93,27 @@ public class DBRefFetcher implements Runnable */ private boolean trimDsSeqs = true; - public DBRefFetcher() - { - } - /** - * Creates a new SequenceFeatureFetcher object and fetches from the currently - * selected set of databases. + * Creates a new DBRefFetcher object and fetches from the currently selected + * set of databases, if this is null then it fetches based on feature settings * * @param seqs - * fetch references for these sequences - * @param af - * the parent alignframe for progress bar monitoring. - */ - public DBRefFetcher(SequenceI[] seqs, AlignFrame af) - { - this(seqs, af, null); - } - - /** - * Creates a new SequenceFeatureFetcher object and fetches from the currently - * selected set of databases. - * - * @param seqs - * fetch references for these sequences - * @param af - * the parent alignframe for progress bar monitoring. + * fetch references for these SequenceI array + * @param progressIndicatorFrame + * the frame for progress bar monitoring * @param sources - * array of database source strings to query references from + * array of DbSourceProxy to query references form + * @param featureSettings + * FeatureSettings to get alternative DbSourceProxy from + * @param isNucleotide + * indicates if the array of SequenceI are Nucleotides or not */ - public DBRefFetcher(SequenceI[] seqs, AlignFrame af, - DbSourceProxy[] sources) + public DBRefFetcher(SequenceI[] seqs, + IProgressIndicator progressIndicatorFrame, + DbSourceProxy[] sources, FeatureSettings featureSettings, boolean isNucleotide) { - this.af = af; + listeners = new ArrayList(); + this.progressWindow = progressIndicatorFrame; alseqs = new SequenceI[seqs.length]; SequenceI[] ds = new SequenceI[seqs.length]; for (int i = 0; i < seqs.length; i++) @@ -135,7 +130,8 @@ public class DBRefFetcher implements Runnable } this.dataset = ds; // TODO Jalview 2.5 lots of this code should be in the gui package! - sfetcher = jalview.gui.SequenceFetcher.getSequenceFetcherSingleton(af); + sfetcher = jalview.gui.SequenceFetcher + .getSequenceFetcherSingleton(progressIndicatorFrame); // set default behaviour for transferring excess sequence data to the // dataset trimDsSeqs = Cache.getDefault("TRIM_FETCHED_DATASET_SEQS", true); @@ -145,7 +141,7 @@ public class DBRefFetcher implements Runnable String[] defdb = null, otherdb = sfetcher .getDbInstances(jalview.ws.dbsources.das.datamodel.DasSequenceSource.class); List selsources = new ArrayList(); - Vector dasselsrc = (af.featureSettings != null) ? af.featureSettings + Vector dasselsrc = (featureSettings != null) ? featureSettings .getSelectedSources() : new jalview.gui.DasSourceBrowser() .getSelectedSources(); Enumeration en = dasselsrc.elements(); @@ -163,7 +159,7 @@ public class DBRefFetcher implements Runnable } } // select appropriate databases based on alignFrame context. - if (af.getViewport().getAlignment().isNucleotide()) + if (isNucleotide) { defdb = DBRefSource.DNACODINGDBS; } @@ -194,6 +190,26 @@ public class DBRefFetcher implements Runnable } /** + * Constructor with only sequences provided + * + * @param sequences + */ + public DBRefFetcher(SequenceI[] sequences) + { + this(sequences, null, null, null, false); + } + + /** + * Add a listener to be notified when sequence fetching is complete + * + * @param l + */ + public void addListener(FetchFinishedListenerI l) + { + listeners.add(l); + } + + /** * retrieve all the das sequence sources and add them to the list of db * sources to retrieve from */ @@ -283,6 +299,7 @@ public class DBRefFetcher implements Runnable /** * DOCUMENT ME! */ + @Override public void run() { if (dbSources == null) @@ -293,8 +310,12 @@ public class DBRefFetcher implements Runnable } running = true; long startTime = System.currentTimeMillis(); - af.setProgressBar(MessageManager.getString("status.fetching_db_refs"), + if (progressWindow != null) + { + progressWindow.setProgressBar( + MessageManager.getString("status.fetching_db_refs"), startTime); + } try { if (Cache.getDefault("DBREFFETCH_USEPICR", false)) @@ -335,16 +356,8 @@ public class DBRefFetcher implements Runnable // TODO: introduce multithread multisource queries and logic to remove a // query from other sources if any source for a database returns a // record - if (dbsource.getDbSourceProperties().containsKey( - DBRefSource.MULTIACC)) - { - maxqlen = ((Integer) dbsource.getDbSourceProperties().get( - DBRefSource.MULTIACC)).intValue(); - } - else - { - maxqlen = 1; - } + maxqlen = dbsource.getMaximumQueryCount(); + while (queries.size() > 0 || seqIndex < currSeqs.length) { if (queries.size() > 0) @@ -479,14 +492,18 @@ public class DBRefFetcher implements Runnable // of the viewed sequence } + if (progressWindow != null) + { + progressWindow.setProgressBar( + MessageManager.getString("label.dbref_search_completed"), + startTime); + } - af.setProgressBar( - MessageManager.getString("label.dbref_search_completed"), - startTime); - // promptBeforeBlast(); - + for (FetchFinishedListenerI listener : listeners) + { + listener.finished(); + } running = false; - } /**