From cb37b13542829ad0406c5f0ff8349334f83c31ae Mon Sep 17 00:00:00 2001 From: jprocter Date: Fri, 19 Jun 2009 10:01:09 +0000 Subject: [PATCH] bugfix mapped reference transfer and made picr ID retrieval optional --- src/jalview/ws/DBRefFetcher.java | 172 +++++++++++++++++++++++++------------- 1 file changed, 112 insertions(+), 60 deletions(-) diff --git a/src/jalview/ws/DBRefFetcher.java b/src/jalview/ws/DBRefFetcher.java index 4b7c07e..1fd9f1c 100644 --- a/src/jalview/ws/DBRefFetcher.java +++ b/src/jalview/ws/DBRefFetcher.java @@ -19,6 +19,7 @@ package jalview.ws; import jalview.analysis.AlignSeq; +import jalview.bin.Cache; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefEntry; import jalview.datamodel.DBRefSource; @@ -59,6 +60,7 @@ public class DBRefFetcher implements Runnable StringBuffer sbuffer = new StringBuffer(); boolean running = false; + /** * picr client instance */ @@ -77,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) { @@ -113,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()) @@ -126,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) { @@ -209,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) { @@ -254,8 +273,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"); @@ -304,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)) @@ -326,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) @@ -353,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++) { @@ -372,25 +398,39 @@ public class DBRefFetcher implements Runnable { 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(); + 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) + if (presp != null && presp.length > 0) { - for (int id=0;id0) { + if (nseq.size() > 0) + { sequencesArray = new SequenceI[nseq.size()]; nseq.toArray(sequencesArray); } -- 1.7.10.2