X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2FDBRefFetcher.java;h=1fd9f1c1078b210f835dab27133f9745e558d8c6;hb=cb37b13542829ad0406c5f0ff8349334f83c31ae;hp=825b0f9075bbd08ba2acfe888bcc16d91fa4c7ba;hpb=da730577512f3497148dea04506c2e936bdd7fcc;p=jalview.git diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index 825b0f9..1fd9f1c 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -1,6 +1,6 @@ /* - * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4) - * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * 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 * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,18 +18,29 @@ */ package jalview.ws; -import java.io.*; -import java.util.*; +import jalview.analysis.AlignSeq; +import jalview.bin.Cache; +import jalview.datamodel.AlignmentI; +import jalview.datamodel.DBRefEntry; +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.IProgressIndicator; +import jalview.gui.OOMWarning; + +import java.lang.reflect.Array; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.StringTokenizer; +import java.util.Vector; import org.biojava.dasobert.dasregistry.DasSource; -import org.exolab.castor.mapping.*; -import org.exolab.castor.xml.*; -import jalview.analysis.*; -import jalview.datamodel.*; -import jalview.datamodel.Mapping; -import jalview.gui.*; -import jalview.ws.dbsources.Uniprot; -import jalview.ws.ebi.EBIFetchClient; + +import uk.ac.ebi.picr.model.UPEntry; /** * Implements a runnable for validating a sequence against external databases @@ -50,6 +61,11 @@ public class DBRefFetcher implements Runnable boolean running = false; + /** + * picr client instance + */ + uk.ac.ebi.www.picr.AccessionMappingService.AccessionMapperInterface picrClient = null; + // /This will be a collection of Vectors of sequenceI refs. // The key will be the seq name or accession id of the seq Hashtable seqRefs; @@ -63,27 +79,29 @@ public class DBRefFetcher implements Runnable } /** - * 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) { @@ -99,11 +117,13 @@ 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() + 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(); while (en.hasMoreElements()) @@ -112,12 +132,14 @@ public class DBRefFetcher implements Runnable selsources.addElement(src.getNickname()); } int osel = 0; - for (int o=0;otherdb!=null && o0) + String[] otherdb = sfetcher + .getDbInstances(jalview.ws.dbsources.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); + 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); 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) { @@ -195,9 +228,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) { @@ -237,9 +270,21 @@ public class DBRefFetcher implements Runnable { throw new Error("Implementation error. Must initialise dbSources"); } + running = true; long startTime = System.currentTimeMillis(); af.setProgressBar("Fetching db refs", startTime); - running = true; + 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"); + e.printStackTrace(); + } int db = 0; Vector sdataset = new Vector(); for (int s = 0; s < dataset.length; s++) @@ -283,10 +328,10 @@ public class DBRefFetcher implements Runnable { // 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) + 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)) @@ -305,7 +350,9 @@ public class DBRefFetcher implements Runnable { if (jalview.bin.Cache.log.isDebugEnabled()) { - jalview.bin.Cache.log.debug("Querying "+dbsource.getDbName()+" with : '"+queryString.toString()+"'"); + jalview.bin.Cache.log.debug("Querying " + + dbsource.getDbName() + " with : '" + + queryString.toString() + "'"); } retrieved = dbsource.getSequenceRecords(queryString.toString()); } catch (Exception ex) @@ -332,7 +379,7 @@ public class DBRefFetcher implements Runnable { dbSources[db] }); // jalview.datamodel.DBRefSource.UNIPROT // }); // check for existing dbrefs to use - if (uprefs != null && uprefs.length>0) + if (uprefs != null && uprefs.length > 0) { for (int j = 0; j < uprefs.length; j++) { @@ -350,8 +397,43 @@ public class DBRefFetcher implements Runnable while (st.hasMoreTokens()) { String token = st.nextToken(); - addSeqId(sequence, token); - queries.addElement(token.toUpperCase()); + UPEntry[] presp = null; + if (picrClient != null) + { + // resolve the string against PICR to recover valid IDs + try + { + presp = picrClient + .getUPIForAccession(token, null, picrClient + .getMappedDatabaseNames(), null, true); + } catch (Exception e) + { + System.err.println("Exception with Picr for '" + token + + "'\n"); + e.printStackTrace(); + } + } + if (presp != null && presp.length > 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 + { + // if () + // System.out.println("Not querying source with token="+token+"\n"); + addSeqId(sequence, token); + queries.addElement(token.toUpperCase()); + } } } } @@ -389,13 +471,15 @@ public class DBRefFetcher implements Runnable AlignmentI retrievedAl) // File // file) { - if (retrievedAl == null || retrievedAl.getHeight() == 0) { return; } - SequenceI[] retrieved = retrievedAl.getSequencesArray(); + SequenceI[] retrieved = recoverDbSequences(retrievedAl + .getSequencesArray()); SequenceI sequence = null; + boolean transferred = false; + StringBuffer messages = new StringBuffer(); // Vector entries = new Uniprot().getUniprotEntries(file); @@ -488,11 +572,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"); // @@ -512,6 +596,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 @@ -557,8 +642,47 @@ public class DBRefFetcher implements Runnable // 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 && i < sequencesArray.length; i++) + { + nseq.addElement(sequencesArray[i]); + DBRefEntry dbr[] = sequencesArray[i].getDBRef(); + jalview.datamodel.Mapping map = null; + for (int r = 0; (dbr != null) && r < dbr.length; r++) + { + if ((map = dbr[r].getMap()) != null) + { + if (map.getTo() != null && !nseq.contains(map.getTo())) + { + nseq.addElement(map.getTo()); + } + } + } + } + if (nseq.size() > 0) + { + sequencesArray = new SequenceI[nseq.size()]; + nseq.toArray(sequencesArray); + } + return sequencesArray; } }