X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FDBRefFetcher.java;h=ca403c55b629c3dfef451ca028d3c5f1c32e29b6;hb=3f12f4932226512316ec113e600695150431fd0a;hp=17c1bc9a68b94ca698a2392abeee79da3531d4f6;hpb=67bb04bf601a6f5bc2bf2d568a1bd73a8656072a;p=jalview.git
diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java
index 17c1bc9..ca403c5 100644
--- a/src/jalview/ws/DBRefFetcher.java
+++ b/src/jalview/ws/DBRefFetcher.java
@@ -1,19 +1,22 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
*
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.ws;
@@ -25,11 +28,12 @@ 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;
import jalview.ws.dbsources.das.api.jalviewSourceI;
import jalview.ws.seqfetcher.DbSourceProxy;
@@ -51,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();
@@ -76,59 +87,61 @@ public class DBRefFetcher implements Runnable
private SequenceI[] alseqs;
- public DBRefFetcher()
- {
- }
-
/**
- * 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.
+ * when true - retrieved sequences will be trimmed to cover longest derived
+ * alignment sequence
*/
- public DBRefFetcher(SequenceI[] seqs, AlignFrame af)
- {
- this(seqs, af, null);
- }
+ private boolean trimDsSeqs = true;
/**
- * 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.
+ * 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++)
{
alseqs[i] = seqs[i];
if (seqs[i].getDatasetSequence() != null)
+ {
ds[i] = seqs[i].getDatasetSequence();
+ }
else
+ {
ds[i] = seqs[i];
+ }
}
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);
if (sources == null)
{
// af.featureSettings_actionPerformed(null);
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();
@@ -146,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;
}
@@ -163,6 +176,9 @@ public class DBRefFetcher implements Runnable
srces.addAll(srcesfordb);
}
}
+ // append the PDB data source, since it is 'special', catering for both
+ // nucleotide and protein
+ srces.addAll(sfetcher.getSourceProxy(DBRefSource.PDB));
// append the selected sequence sources to the default dbs
srces.addAll(selsources);
@@ -177,6 +193,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
*/
@@ -266,15 +302,23 @@ public class DBRefFetcher implements Runnable
/**
* DOCUMENT ME!
*/
+ @Override
public void run()
{
if (dbSources == null)
{
- throw new Error("Implementation error. Must initialise dbSources");
+ throw new Error(
+ MessageManager
+ .getString("error.implementation_error_must_init_dbsources"));
}
running = true;
long startTime = System.currentTimeMillis();
- af.setProgressBar("Fetching db refs", startTime);
+ if (progressWindow != null)
+ {
+ progressWindow.setProgressBar(
+ MessageManager.getString("status.fetching_db_refs"),
+ startTime);
+ }
try
{
if (Cache.getDefault("DBREFFETCH_USEPICR", false))
@@ -315,16 +359,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)
@@ -370,7 +406,7 @@ public class DBRefFetcher implements Runnable
if (retrieved != null)
{
transferReferences(sdataset, dbsource.getDbSource(),
- retrieved);
+ retrieved, trimDsSeqs);
}
}
else
@@ -380,8 +416,8 @@ public class DBRefFetcher implements Runnable
{
SequenceI sequence = dataset[seqIndex];
DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(
- sequence.getDBRef(), new String[]
- { dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT
+ sequence.getDBRefs(),
+ new String[] { dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT
// });
// check for existing dbrefs to use
if (uprefs != null && uprefs.length > 0)
@@ -449,32 +485,42 @@ public class DBRefFetcher implements Runnable
} // all databases have been queries.
if (sbuffer.length() > 0)
{
- output.setText("Your sequences have been verified against known sequence databases. Some of the ids have been\n"
- + "altered, most likely the start/end residue will have been updated.\n"
- + "Save your alignment to maintain the updated id.\n\n"
+ output.setText(MessageManager
+ .getString("label.your_sequences_have_been_verified")
+ sbuffer.toString());
- Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300);
+ Desktop.addInternalFrame(output,
+ MessageManager.getString("label.sequence_names_updated"),
+ 600, 300);
// The above is the dataset, we must now find out the index
// of the viewed sequence
}
+ if (progressWindow != null)
+ {
+ progressWindow.setProgressBar(
+ MessageManager.getString("label.dbref_search_completed"),
+ startTime);
+ }
- af.setProgressBar("DBRef search completed", startTime);
- // promptBeforeBlast();
-
+ for (FetchFinishedListenerI listener : listeners)
+ {
+ listener.finished();
+ }
running = false;
-
}
/**
* Verify local sequences in seqRefs against the retrieved sequence database
* records.
*
+ * @param trimDatasetSeqs
+ *
*/
void transferReferences(Vector sdataset, String dbSource,
- AlignmentI retrievedAl) // File
+ AlignmentI retrievedAl, boolean trimDatasetSeqs) // File
// file)
{
+ System.out.println("trimming ? " + trimDatasetSeqs);
if (retrievedAl == null || retrievedAl.getHeight() == 0)
{
return;
@@ -498,8 +544,7 @@ public class DBRefFetcher implements Runnable
Vector sequenceMatches = new Vector();
// look for corresponding accession ids
DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(
- entry.getDBRef(), new String[]
- { dbSource });
+ entry.getDBRefs(), new String[] { dbSource });
if (entryRefs == null)
{
System.err
@@ -566,48 +611,57 @@ public class DBRefFetcher implements Runnable
// no existing references
// TODO: test for legacy where uniprot or EMBL refs exist but no
// mappings are made (but content matches retrieved set)
- boolean updateRefFrame = sequence.getDBRef() == null
- || sequence.getDBRef().length == 0;
+ boolean updateRefFrame = sequence.getDBRefs() == null
+ || sequence.getDBRefs().length == 0;
+ // TODO:
// verify sequence against the entry sequence
String nonGapped = AlignSeq.extractGaps("-. ",
sequence.getSequenceAsString()).toUpperCase();
int absStart = entrySeq.indexOf(nonGapped);
- int mapStart = entry.getStart();
- jalview.datamodel.Mapping mp;
+ Mapping mp;
+ final int sequenceStart = sequence.getStart();
if (absStart == -1)
{
- // Is local sequence contained in dataset sequence?
+ // couldn't find local sequence in sequence from database, so check if
+ // the database sequence is a subsequence of local sequence
absStart = nonGapped.indexOf(entrySeq);
if (absStart == -1)
- { // verification failed.
+ {
+ // verification failed. couldn't find any relationship between
+ // entrySeq and local sequence
messages.append(sequence.getName()
+ " SEQUENCE NOT %100 MATCH \n");
continue;
}
+ /*
+ * found match for the whole of the database sequence within the local
+ * sequence's reference frame.
+ */
transferred = true;
sbuffer.append(sequence.getName() + " HAS " + absStart
+ " PREFIXED RESIDUES COMPARED TO " + dbSource + "\n");
- //
- // + " - ANY SEQUENCE FEATURES"
- // + " HAVE BEEN ADJUSTED ACCORDINGLY \n");
- // absStart = 0;
- // create valid mapping between matching region of local sequence and
- // the mapped sequence
- mp = new Mapping(null, new int[]
- { sequence.getStart() + absStart,
- sequence.getStart() + absStart + entrySeq.length() - 1 },
- new int[]
- { entry.getStart(),
- entry.getStart() + entrySeq.length() - 1 }, 1, 1);
- updateRefFrame = false; // mapping is based on current start/end so
- // don't modify start and end
+
+ /*
+ * So create a mapping to the external entry from the matching region of
+ * the local sequence, and leave local start/end untouched.
+ */
+ mp = new Mapping(null, new int[] { sequenceStart + absStart,
+ sequenceStart + absStart + entrySeq.length() - 1 }, new int[]
+ { entry.getStart(), entry.getStart() + entrySeq.length() - 1 },
+ 1, 1);
+ updateRefFrame = false;
}
else
{
+ /*
+ * found a match for the local sequence within sequence from
+ * the external database
+ */
transferred = true;
+
// update start and end of local sequence to place it in entry's
// reference frame.
// apply identity map map from whole of local sequence to matching
@@ -619,12 +673,16 @@ public class DBRefFetcher implements Runnable
// absStart+sequence.getStart()+entrySeq.length()-1},
// new int[] { entry.getStart(), entry.getEnd() }, 1, 1);
// relocate local features for updated start
+
if (updateRefFrame)
{
if (sequence.getSequenceFeatures() != null)
{
+ /*
+ * relocate existing sequence features by offset
+ */
SequenceFeature[] sf = sequence.getSequenceFeatures();
- int start = sequence.getStart();
+ int start = sequenceStart;
int end = sequence.getEnd();
int startShift = 1 - absStart - start; // how much the features
// are
@@ -645,14 +703,24 @@ public class DBRefFetcher implements Runnable
System.out.println("Adding dbrefs to " + sequence.getName()
+ " from " + dbSource + " sequence : " + entry.getName());
sequence.transferAnnotation(entry, mp);
- // unknownSequences.remove(sequence);
- int absEnd = absStart + nonGapped.length();
- absStart += 1;
+
+ absStart += entry.getStart();
+ int absEnd = absStart + nonGapped.length() - 1;
+ if (!trimDatasetSeqs)
+ {
+ // insert full length sequence from record
+ sequence.setSequence(entry.getSequenceAsString());
+ sequence.setStart(entry.getStart());
+ }
if (updateRefFrame)
{
// finally, update local sequence reference frame if we're allowed
- sequence.setStart(absStart);
- sequence.setEnd(absEnd);
+ if (trimDatasetSeqs)
+ {
+ // just fix start/end
+ sequence.setStart(absStart);
+ sequence.setEnd(absEnd);
+ }
// search for alignment sequences to update coordinate frame for
for (int alsq = 0; alsq < alseqs.length; alsq++)
{
@@ -703,7 +771,7 @@ public class DBRefFetcher implements Runnable
for (int i = 0; sequencesArray != null && i < sequencesArray.length; i++)
{
nseq.addElement(sequencesArray[i]);
- DBRefEntry dbr[] = sequencesArray[i].getDBRef();
+ DBRefEntry dbr[] = sequencesArray[i].getDBRefs();
jalview.datamodel.Mapping map = null;
for (int r = 0; (dbr != null) && r < dbr.length; r++)
{