X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FDBRefFetcher.java;h=1886172f12c27f172661e5eb8c183ad823df09f9;hb=0d6fdcd9c4597475c09fd96da43ddcadccf78fa1;hp=4b7c07e6d1b0dcd72ab01909a98a0c732fdd0a39;hpb=37c97b109c3a03f4640bce3855069f8ad8e17123;p=jalview.git
diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java
index 4b7c07e..1886172 100644
--- a/src/jalview/ws/DBRefFetcher.java
+++ b/src/jalview/ws/DBRefFetcher.java
@@ -1,24 +1,24 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
*
- * This program 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 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
*
- * This program 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.
+ * 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.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * 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 .
*/
package jalview.ws;
import jalview.analysis.AlignSeq;
+import jalview.bin.Cache;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefEntry;
import jalview.datamodel.DBRefSource;
@@ -30,15 +30,17 @@ import jalview.gui.CutAndPasteTransfer;
import jalview.gui.Desktop;
import jalview.gui.IProgressIndicator;
import jalview.gui.OOMWarning;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+import jalview.ws.seqfetcher.DbSourceProxy;
import java.lang.reflect.Array;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import java.util.StringTokenizer;
import java.util.Vector;
-import org.biojava.dasobert.dasregistry.DasSource;
-
import uk.ac.ebi.picr.model.UPEntry;
/**
@@ -59,6 +61,7 @@ public class DBRefFetcher implements Runnable
StringBuffer sbuffer = new StringBuffer();
boolean running = false;
+
/**
* picr client instance
*/
@@ -68,43 +71,49 @@ public class DBRefFetcher implements Runnable
// The key will be the seq name or accession id of the seq
Hashtable seqRefs;
- String[] dbSources;
+ DbSourceProxy[] dbSources;
SequenceFetcher sfetcher;
+ private SequenceI[] alseqs;
+
public DBRefFetcher()
{
}
/**
- * Creates a new SequenceFeatureFetcher object and fetches from the
- * currently selected set of databases.
+ * Creates a new SequenceFeatureFetcher object and fetches from the currently
+ * selected set of databases.
*
* @param seqs
- * fetch references for these sequences
+ * fetch references for these sequences
* @param af
- * the parent alignframe for progress bar monitoring.
+ * 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.
+ * Creates a new SequenceFeatureFetcher object and fetches from the currently
+ * selected set of databases.
*
* @param seqs
- * fetch references for these sequences
+ * fetch references for these sequences
* @param af
- * the parent alignframe for progress bar monitoring.
- * @param sources array of database source strings to query references from
+ * the parent alignframe for progress bar monitoring.
+ * @param sources
+ * array of database source strings to query references from
*/
- public DBRefFetcher(SequenceI[] seqs, AlignFrame af, String[] sources)
+ public DBRefFetcher(SequenceI[] seqs, AlignFrame af, DbSourceProxy[] sources)
{
this.af = af;
+ 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
@@ -113,26 +122,24 @@ 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);
- if (sources==null)
+ if (sources == null)
{
// af.featureSettings_actionPerformed(null);
- String[] defdb=null,otherdb = sfetcher.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
- Vector selsources = new Vector(), dasselsrc= (af.featureSettings!=null) ? af.featureSettings.getSelectedSources()
- : new jalview.gui.DasSourceBrowser().getSelectedSources();
- Enumeration en = dasselsrc.elements();
+ String[] defdb = null, otherdb = sfetcher
+ .getDbInstances(jalview.ws.dbsources.das.datamodel.DasSequenceSource.class);
+ List selsources = new ArrayList();
+ Vector dasselsrc = (af.featureSettings != null) ? af.featureSettings
+ .getSelectedSources() : new jalview.gui.DasSourceBrowser()
+ .getSelectedSources();
+ Enumeration en = dasselsrc.elements();
while (en.hasMoreElements())
{
- DasSource src = (DasSource) en.nextElement();
- selsources.addElement(src.getNickname());
- }
- int osel = 0;
- for (int o=0;otherdb!=null && o sp=src.getSequenceSourceProxies();
+ selsources.addAll(sp);
+ if (sp.size()>1)
{
- otherdb[o] = null;
- } else {
- osel++;
+ Cache.log.debug("Added many Db Sources for :"+src.getTitle());
}
}
// select appropriate databases based on alignFrame context.
@@ -144,45 +151,50 @@ public class DBRefFetcher implements Runnable
{
defdb = DBRefSource.PROTEINDBS;
}
- // append the selected sequence sources to the default dbs
- dbSources = new String[defdb.length+osel];
- System.arraycopy(defdb, 0, dbSources, 0, defdb.length);
- for (int o=0,op=defdb.length; otherdb!=null && o srces=new ArrayList();
+ for (String ddb:defdb) {
+ srces.addAll(sfetcher.getSourceProxy(ddb));
}
- } else {
- // we assume the caller knows what they're doing and ensured that all the db source names are valid
+
+ // append the selected sequence sources to the default dbs
+ srces.addAll(selsources);
+ dbSources = srces.toArray(new DbSourceProxy[0]);
+ }
+ else
+ {
+ // we assume the caller knows what they're doing and ensured that all the
+ // db source names are valid
dbSources = sources;
}
}
+
/**
- * retrieve all the das sequence sources and add them to the list of db sources to retrieve from
+ * retrieve all the das sequence sources and add them to the list of db
+ * sources to retrieve from
*/
public void appendAllDasSources()
{
if (dbSources == null)
{
- dbSources = new String[] {};
+ dbSources = new DbSourceProxy[0];
}
// append additional sources
- String[] otherdb = sfetcher.getDbInstances(jalview.ws.dbsources.DasSequenceSource.class);
- if (otherdb!=null && otherdb.length>0)
+ DbSourceProxy[] otherdb=sfetcher
+ .getDbSourceProxyInstances(jalview.ws.dbsources.das.datamodel.DasSequenceSource.class);
+ if (otherdb != null && otherdb.length > 0)
{
- String[] newsrc = new String[dbSources.length+otherdb.length];
- System.arraycopy(dbSources, 0, newsrc,0,dbSources.length);
- System.arraycopy(otherdb, 0, newsrc,dbSources.length, otherdb.length);
+ DbSourceProxy[] newsrc = new DbSourceProxy[dbSources.length + otherdb.length];
+ System.arraycopy(dbSources, 0, newsrc, 0, dbSources.length);
+ System.arraycopy(otherdb, 0, newsrc, dbSources.length, otherdb.length);
dbSources = newsrc;
}
}
+
/**
* start the fetcher thread
*
* @param waitTillFinished
- * true to block until the fetcher has finished
+ * true to block until the fetcher has finished
*/
public void fetchDBRefs(boolean waitTillFinished)
{
@@ -209,9 +221,9 @@ public class DBRefFetcher implements Runnable
* could be either seq name or dbref id
*
* @param seq
- * SequenceI
+ * SequenceI
* @param key
- * String
+ * String
*/
void addSeqId(SequenceI seq, String key)
{
@@ -254,8 +266,13 @@ public class DBRefFetcher implements Runnable
running = true;
long startTime = System.currentTimeMillis();
af.setProgressBar("Fetching db refs", startTime);
- try {
- picrClient = new uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator().getAccessionMapperPort();
+ try
+ {
+ if (Cache.getDefault("DBREFFETCH_USEPICR", false))
+ {
+ picrClient = new uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperServiceLocator()
+ .getAccessionMapperPort();
+ }
} catch (Exception e)
{
System.err.println("Couldn't locate PICR service instance.\n");
@@ -270,25 +287,9 @@ public class DBRefFetcher implements Runnable
while (sdataset.size() > 0 && db < dbSources.length)
{
int maxqlen = 1; // default number of queries made to at one time
- System.err.println("Verifying against " + dbSources[db]);
- jalview.ws.seqfetcher.DbSourceProxy dbsource = sfetcher
- .getSourceProxy(dbSources[db]);
- if (dbsource == null)
- {
- System.err.println("No proxy for " + dbSources[db]);
- db++;
- continue;
- }
- if (dbsource.getDbSourceProperties()
- .containsKey(DBRefSource.MULTIACC))
- {
- maxqlen = ((Integer) dbsource.getDbSourceProperties().get(
- DBRefSource.MULTIACC)).intValue();
- }
- else
- {
- maxqlen = 1;
- }
+ System.err.println("Verifying against " + dbSources[db].getDbName());
+ boolean dn = false;
+
// iterate through db for each remaining un-verified sequence
SequenceI[] currSeqs = new SequenceI[sdataset.size()];
sdataset.copyInto(currSeqs);// seqs that are to be validated against
@@ -298,101 +299,132 @@ public class DBRefFetcher implements Runnable
int seqIndex = 0;
- while (queries.size() > 0 || seqIndex < currSeqs.length)
+ jalview.ws.seqfetcher.DbSourceProxy dbsource = dbSources[db];
{
- if (queries.size() > 0)
+ // for moment, we dumbly iterate over all retrieval sources for a particular database
+ // 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))
{
- // Still queries to make for current seqIndex
- StringBuffer queryString = new StringBuffer("");
- int numq=0,nqSize = (maxqlen > queries.size()) ? queries.size()
- : maxqlen;
-
- while (queries.size()>0 && numq < nqSize)
- {
- String query = (String) queries.elementAt(0);
- if (dbsource.isValidReference(query))
- {
- queryString.append((numq == 0) ? "" : dbsource
- .getAccessionSeparator());
- queryString.append(query);
- numq++;
- }
- // remove the extracted query string
- queries.removeElementAt(0);
- }
- // make the queries and process the response
- AlignmentI retrieved = null;
- try
- {
- if (jalview.bin.Cache.log.isDebugEnabled())
- {
- jalview.bin.Cache.log.debug("Querying "+dbsource.getDbName()+" with : '"+queryString.toString()+"'");
- }
- retrieved = dbsource.getSequenceRecords(queryString.toString());
- } catch (Exception ex)
- {
- ex.printStackTrace();
- } catch (OutOfMemoryError err)
- {
- new OOMWarning("retrieving database references ("
- + queryString.toString() + ")", err);
- }
- if (retrieved != null)
- {
- transferReferences(sdataset, dbSources[db], retrieved);
- }
+ maxqlen = ((Integer) dbsource.getDbSourceProperties().get(
+ DBRefSource.MULTIACC)).intValue();
}
else
{
- // make some more strings for use as queries
- for (int i = 0; (seqIndex < dataset.length) && (i < 50); seqIndex++, i++)
+ maxqlen = 1;
+ }
+ while (queries.size() > 0 || seqIndex < currSeqs.length)
+ {
+ if (queries.size() > 0)
{
- SequenceI sequence = dataset[seqIndex];
- DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(
- sequence.getDBRef(), new String[]
- { dbSources[db] }); // jalview.datamodel.DBRefSource.UNIPROT
- // });
- // check for existing dbrefs to use
- if (uprefs != null && uprefs.length>0)
+ // Still queries to make for current seqIndex
+ StringBuffer queryString = new StringBuffer("");
+ int numq = 0, nqSize = (maxqlen > queries.size()) ? queries
+ .size() : maxqlen;
+
+ while (queries.size() > 0 && numq < nqSize)
{
- for (int j = 0; j < uprefs.length; j++)
+ String query = (String) queries.elementAt(0);
+ if (dbsource.isValidReference(query))
{
- addSeqId(sequence, uprefs[j].getAccessionId());
- queries
- .addElement(uprefs[j].getAccessionId()
- .toUpperCase());
+ queryString.append((numq == 0) ? "" : dbsource
+ .getAccessionSeparator());
+ queryString.append(query);
+ numq++;
}
+ // remove the extracted query string
+ queries.removeElementAt(0);
}
- else
+ // make the queries and process the response
+ AlignmentI retrieved = null;
+ try
{
- // generate queries from sequence ID string
- StringTokenizer st = new StringTokenizer(sequence.getName(),
- "|");
- while (st.hasMoreTokens())
+ if (jalview.bin.Cache.log.isDebugEnabled())
{
- String token = st.nextToken();
- UPEntry[] presp = null;
- try {
- presp=picrClient.getUPIForAccession(token, null, picrClient.getMappedDatabaseNames(), null, true);
- } catch (Exception e) {
- System.err.println("Exception with Picr for '"+token+"'\n");
- e.printStackTrace();
+ jalview.bin.Cache.log.debug("Querying "
+ + dbsource.getDbName() + " with : '"
+ + queryString.toString() + "'");
+ }
+ retrieved = dbsource.getSequenceRecords(queryString
+ .toString());
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ } catch (OutOfMemoryError err)
+ {
+ new OOMWarning("retrieving database references ("
+ + queryString.toString() + ")", err);
+ }
+ if (retrieved != null)
+ {
+ transferReferences(sdataset, dbsource.getDbSource(), retrieved);
+ }
+ }
+ else
+ {
+ // make some more strings for use as queries
+ for (int i = 0; (seqIndex < dataset.length) && (i < 50); seqIndex++, i++)
+ {
+ SequenceI sequence = dataset[seqIndex];
+ DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(
+ sequence.getDBRef(), new String[]
+ { dbsource.getDbSource() }); // jalview.datamodel.DBRefSource.UNIPROT
+ // });
+ // check for existing dbrefs to use
+ if (uprefs != null && uprefs.length > 0)
+ {
+ for (int j = 0; j < uprefs.length; j++)
+ {
+ addSeqId(sequence, uprefs[j].getAccessionId());
+ queries.addElement(uprefs[j].getAccessionId()
+ .toUpperCase());
}
- if (presp!=null && presp.length>0)
+ }
+ else
+ {
+ // generate queries from sequence ID string
+ StringTokenizer st = new StringTokenizer(
+ sequence.getName(), "|");
+ while (st.hasMoreTokens())
{
- for (int id=0;id 0)
+ {
+ for (int id = 0; id < presp.length; id++)
+ {
+ // construct sequences from response if sequences are
+ // present, and do a transferReferences
+ // otherwise transfer non sequence x-references directly.
+ }
+ System.out
+ .println("Validated ID against PICR... (for what its worth):"
+ + token);
+ addSeqId(sequence, token);
+ queries.addElement(token.toUpperCase());
+ }
+ else
{
- // construct sequences from response if sequences are present, and do a transferReferences
- // otherwise transfer non sequence x-references directly.
+ // if ()
+ // System.out.println("Not querying source with token="+token+"\n");
+ addSeqId(sequence, token);
+ queries.addElement(token.toUpperCase());
}
- System.out.println("Validated ID against PICR... (for what its worth):"+token);
- addSeqId(sequence, token);
- queries.addElement(token.toUpperCase());
- } else {
- //if ()
- //System.out.println("Not querying source with token="+token+"\n");
- addSeqId(sequence, token);
- queries.addElement(token.toUpperCase());
}
}
}
@@ -404,11 +436,10 @@ 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"
- + sbuffer.toString());
+ 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"
+ + sbuffer.toString());
Desktop.addInternalFrame(output, "Sequence names updated ", 600, 300);
// The above is the dataset, we must now find out the index
// of the viewed sequence
@@ -431,13 +462,15 @@ public class DBRefFetcher implements Runnable
AlignmentI retrievedAl) // File
// file)
{
-
if (retrievedAl == null || retrievedAl.getHeight() == 0)
{
return;
}
- SequenceI[] retrieved = recoverDbSequences(retrievedAl.getSequencesArray());
+ SequenceI[] retrieved = recoverDbSequences(retrievedAl
+ .getSequencesArray());
SequenceI sequence = null;
+ boolean transferred = false;
+ StringBuffer messages = new StringBuffer();
// Vector entries = new Uniprot().getUniprotEntries(file);
@@ -451,9 +484,16 @@ public class DBRefFetcher implements Runnable
// taking into account all accessionIds and names in the file
Vector sequenceMatches = new Vector();
// look for corresponding accession ids
- DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(entry
- .getDBRef(), new String[]
- { dbSource });
+ DBRefEntry[] entryRefs = jalview.util.DBRefUtils.selectRefs(
+ entry.getDBRef(), new String[]
+ { dbSource });
+ if (entryRefs == null)
+ {
+ System.err
+ .println("Dud dbSource string ? no entryrefs selected for "
+ + dbSource + " on " + entry.getName());
+ continue;
+ }
for (int j = 0; j < entryRefs.length; j++)
{
String accessionId = entryRefs[j].getAccessionId(); // .getAccession().elementAt(j).toString();
@@ -530,11 +570,11 @@ public class DBRefFetcher implements Runnable
absStart = nonGapped.indexOf(entrySeq);
if (absStart == -1)
{ // verification failed.
- sbuffer.append(sequence.getName()
+ messages.append(sequence.getName()
+ " SEQUENCE NOT %100 MATCH \n");
continue;
}
-
+ transferred = true;
sbuffer.append(sequence.getName() + " HAS " + absStart
+ " PREFIXED RESIDUES COMPARED TO " + dbSource + "\n");
//
@@ -554,6 +594,7 @@ public class DBRefFetcher implements Runnable
}
else
{
+ 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
@@ -565,20 +606,24 @@ 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 && sequence.getSequenceFeatures() != null)
+ if (updateRefFrame)
{
- SequenceFeature[] sf = sequence.getSequenceFeatures();
- int start = sequence.getStart();
- int end = sequence.getEnd();
- int startShift = 1 - absStart - start; // how much the features are
- // to be shifted by
- for (int sfi = 0; sfi < sf.length; sfi++)
+ if (sequence.getSequenceFeatures() != null)
{
- if (sf[sfi].getBegin() >= start && sf[sfi].getEnd() <= end)
+ SequenceFeature[] sf = sequence.getSequenceFeatures();
+ int start = sequence.getStart();
+ int end = sequence.getEnd();
+ int startShift = 1 - absStart - start; // how much the features
+ // are
+ // to be shifted by
+ for (int sfi = 0; sfi < sf.length; sfi++)
{
- // shift feature along by absstart
- sf[sfi].setBegin(sf[sfi].getBegin() + startShift);
- sf[sfi].setEnd(sf[sfi].getEnd() + startShift);
+ if (sf[sfi].getBegin() >= start && sf[sfi].getEnd() <= end)
+ {
+ // shift feature along by absstart
+ sf[sfi].setBegin(sf[sfi].getBegin() + startShift);
+ sf[sfi].setEnd(sf[sfi].getEnd() + startShift);
+ }
}
}
}
@@ -595,39 +640,71 @@ public class DBRefFetcher implements Runnable
// finally, update local sequence reference frame if we're allowed
sequence.setStart(absStart);
sequence.setEnd(absEnd);
+ // search for alignment sequences to update coordinate frame for
+ for (int alsq = 0; alsq < alseqs.length; alsq++)
+ {
+ if (alseqs[alsq].getDatasetSequence() == sequence)
+ {
+ String ngAlsq = AlignSeq.extractGaps("-. ",
+ alseqs[alsq].getSequenceAsString()).toUpperCase();
+ int oldstrt = alseqs[alsq].getStart();
+ alseqs[alsq].setStart(sequence.getSequenceAsString()
+ .toUpperCase().indexOf(ngAlsq)
+ + sequence.getStart());
+ if (oldstrt != alseqs[alsq].getStart())
+ {
+ alseqs[alsq].setEnd(ngAlsq.length()
+ + alseqs[alsq].getStart() - 1);
+ }
+ }
+ }
+ // TODO: search for all other references to this dataset sequence, and
+ // update start/end
+ // TODO: update all AlCodonMappings which involve this alignment
+ // sequence (e.g. Q30167 cdna translation from exon2 product (vamsas
+ // demo)
}
// and remove it from the rest
// TODO: decide if we should remove annotated sequence from set
sdataset.remove(sequence);
- // TODO: should we make a note of sequences that have received new DB ids, so we can query all enabled DAS servers for them ?
+ // TODO: should we make a note of sequences that have received new DB
+ // ids, so we can query all enabled DAS servers for them ?
}
}
+ if (!transferred)
+ {
+ // report the ID/sequence mismatches
+ sbuffer.append(messages);
+ }
}
/**
* loop thru and collect additional sequences in Map.
+ *
* @param sequencesArray
* @return
*/
private SequenceI[] recoverDbSequences(SequenceI[] sequencesArray)
{
Vector nseq = new Vector();
- for (int i=0;sequencesArray!=null && i0) {
+ if (nseq.size() > 0)
+ {
sequencesArray = new SequenceI[nseq.size()];
nseq.toArray(sequencesArray);
}