From: jprocter Date: Mon, 19 Mar 2007 15:48:12 +0000 (+0000) Subject: DAS features mapped to local reference frame X-Git-Tag: Release_2_3~320 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=fae5909561b434d5fa0043584ace268c545dad9b;p=jalview.git DAS features mapped to local reference frame --- diff --git a/src/jalview/io/DasSequenceFeatureFetcher.java b/src/jalview/io/DasSequenceFeatureFetcher.java index ca11852..a4dc777 100755 --- a/src/jalview/io/DasSequenceFeatureFetcher.java +++ b/src/jalview/io/DasSequenceFeatureFetcher.java @@ -116,14 +116,14 @@ public class DasSequenceFeatureFetcher else { startFetching(); - } + } } else { startFetching(); } - } + } class FetchDBRefs implements Runnable @@ -136,183 +136,258 @@ public class DasSequenceFeatureFetcher } } - /** - * Spawns a number of dasobert Fetcher threads to add features to sequences in the dataset - */ - void startFetching() - { - cancelled = false; - startTime = System.currentTimeMillis(); - af.setProgressBar("Fetching DAS Sequence Features", startTime); - DasSource[] sources = new jalview.gui.DasSourceBrowser().getDASSource(); - - if (selectedSources == null || selectedSources.size() == 0) - { - String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", - "uniprot"); - StringTokenizer st = new StringTokenizer(active, "\t"); - Vector selectedSources = new Vector(); - String token; - while (st.hasMoreTokens()) + /** + * Spawns a number of dasobert Fetcher threads to add features to sequences in the dataset + */ + void startFetching() + { + cancelled = false; + startTime = System.currentTimeMillis(); + af.setProgressBar("Fetching DAS Sequence Features", startTime); + + DasSource[] sources = new jalview.gui.DasSourceBrowser().getDASSource(); + + if (selectedSources == null || selectedSources.size() == 0) + { + String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", + "uniprot"); + StringTokenizer st = new StringTokenizer(active, "\t"); + Vector selectedSources = new Vector(); + String token; + while (st.hasMoreTokens()) + { + token = st.nextToken(); + for (int i = 0; i < sources.length; i++) + { + if (sources[i].getNickname().equals(token)) + { + selectedSources.addElement(sources[i]); + break; + } + } + } + } + + if (selectedSources == null || selectedSources.size() == 0) + { + System.out.println("No DAS Sources active"); + af.setProgressBar("No DAS Sources Active", startTime); + return; + } + + sourcesRemaining = selectedSources.size(); + //Now sending requests one at a time to each server + for (int sourceIndex = 0; + sourceIndex < selectedSources.size() + && !cancelled; + sourceIndex++) + { + DasSource dasSource = (DasSource) selectedSources.elementAt( + sourceIndex); + + nextSequence(dasSource, sequences[0]); + } + } + + public void cancel() + { + af.setProgressBar("DAS Feature Fetching Cancelled", startTime); + cancelled = true; + } + + int sourcesRemaining=0; + void responseComplete(DasSource dasSource, SequenceI seq) + { + if (seq != null) + { + for (int seqIndex = 0; + seqIndex < sequences.length-1 + && !cancelled; seqIndex++) + { + if (sequences[seqIndex] == seq) + { + nextSequence(dasSource, sequences[++seqIndex]); + return; + } + } + } + + sourcesRemaining --; + + if(sourcesRemaining==0) + { + af.setProgressBar("DAS Feature Fetching Complete", startTime); + + if(af.featureSettings!=null) { - token = st.nextToken(); - for (int i = 0; i < sources.length; i++) - { - if (sources[i].getNickname().equals(token)) - { - selectedSources.addElement(sources[i]); - break; - } - } + af.featureSettings.setTableData(); } - } - if (selectedSources == null || selectedSources.size() == 0) - { - System.out.println("No DAS Sources active"); - af.setProgressBar("No DAS Sources Active", startTime); - return; - } - - sourcesRemaining = selectedSources.size(); - //Now sending requests one at a time to each server - for (int sourceIndex = 0; - sourceIndex < selectedSources.size() - && !cancelled; - sourceIndex++) - { - DasSource dasSource = (DasSource) selectedSources.elementAt( - sourceIndex); - - nextSequence(dasSource, sequences[0]); - } - } - - public void cancel() - { - af.setProgressBar("DAS Feature Fetching Cancelled", startTime); - cancelled = true; - } + fsettings.complete(); + } - int sourcesRemaining = 0; - void responseComplete(DasSource dasSource, SequenceI seq) - { - if (seq != null) - { - for (int seqIndex = 0; - seqIndex < sequences.length - 1 - && !cancelled; seqIndex++) - { - if (sequences[seqIndex] == seq) - { - nextSequence(dasSource, sequences[++seqIndex]); - return; - } - } - } + } - sourcesRemaining--; + void featuresAdded(SequenceI seq) + { + af.getFeatureRenderer().featuresAdded(); - if (sourcesRemaining == 0) - { - af.setProgressBar("DAS Feature Fetching Complete", startTime); - - if (af.featureSettings != null) - { - af.featureSettings.setTableData(); - } - - fsettings.complete(); - } - - } - - void featuresAdded(SequenceI seq) - { - af.getFeatureRenderer().featuresAdded(); - - int start = af.getViewport().getStartSeq(); - int end = af.getViewport().getEndSeq(); - int index; - for (index = start; index < end; index++) - { + int start = af.getViewport().getStartSeq(); + int end = af.getViewport().getEndSeq(); + int index; + for(index=start; index 0) + jalview.datamodel.DBRefSource.UNIPROT, + // jalview.datamodel.DBRefSource.EMBL - not tested on any EMBL coord sys sources + }); +// TODO: minimal list of DAS queries to make by querying with untyped ID if distinct from any typed IDs + if (uprefs != null) { - // for (int l = 0; l < cs.length; l++) + // do any of these ids match the source's coordinate system ? + for (int j = 0; j < uprefs.length; j++) { - // - if (jalview.util.DBRefUtils - .isDasCoordinateSystem(cs[0].getName(), uprefs[0])) + DasCoordinateSystem cs[] = dasSource.getCoordinateSystem(); + + if(cs.length>0 && jalview.util.DBRefUtils + .isDasCoordinateSystem(cs[0].getName(), uprefs[j])) { Cache.log.debug("Launched fetcher for coordinate system " + - cs[0].getName()); - + cs[0].getName()); + // Will have to pass any mapping information to the fetcher + //- the start/end for the DBRefEntry may not be the same as the sequence's start/end + createFeatureFetcher(seq, - dasSource, - uprefs[0].getAccessionId()); + dasSource, + uprefs[j]); + break; // only do this for one reference - assume same source will send same features for all IDs } } } - } - } - else + else + { + String id = null; + // try and use the name as the sequence id + if (seq.getName().indexOf("|") > -1) + { + id = seq.getName().substring( + seq.getName().lastIndexOf("|") + 1); + } + else + { + id = seq.getName(); + } + if (id != null) + { + // Should try to call a general feature fetcher that + // queries many sources with name to discover applicable ID references + createFeatureFetcher(seq, + dasSource, + id); + } + } + + } + + +/** + * fetch and add das features to a sequence using the given source URL and compatible DbRef id. + * new features are mapped using the DbRef mapping to the local coordinate system. + * @param seq + * @param SourceUrl + * @param dbref + */ + protected void createFeatureFetcher(final SequenceI seq, final DasSource dasSource, + final DBRefEntry dbref) { + + ////////////// + /// fetch DAS features + final Das1Source source = new Das1Source(); + source.setUrl(dasSource.getUrl()); + source.setNickname(dasSource.getNickname()); + if (dbref==null || dbref.getAccessionId()==null || dbref.getAccessionId().length()<1) { - String id = null; - // try and use the name as the sequence id - if (seq.getName().indexOf("|") > -1) - { - id = seq.getName().substring( - seq.getName().lastIndexOf("|") + 1); - } - else - { - id = seq.getName(); - } - if (id != null) + return; + } + Cache.log.debug("new Das Feature Fetcher for " + dbref.getSource()+":"+dbref.getAccessionId() + " querying " + + dasSource.getUrl()); + FeatureThread fetcher = new FeatureThread(dbref.getAccessionId() + // + ":" + start + "," + end, + , source); + + fetcher.addFeatureListener(new FeatureListener() { - // Should try to call a general feature fetcher that - // queries many sources with name to discover applicable ID references - createFeatureFetcher(seq, - dasSource, - id); + public void comeBackLater(FeatureEvent e) + { + responseComplete(dasSource, seq); + Cache.log.debug("das source " + e.getDasSource().getNickname() + + " asked us to come back in " + e.getComeBackLater() + + " secs."); + } + + public void newFeatures(FeatureEvent e) + { + + Das1Source ds = e.getDasSource(); + + Map[] features = e.getFeatures(); + // add features to sequence + Cache.log.debug("das source " + ds.getUrl() + " returned " + + features.length + " features"); + + if (features.length > 0) + { + for (int i = 0; i < features.length; i++) + { + SequenceFeature f = newSequenceFeature(features[i], + source.getNickname()); + if (dbref.getMap()!=null && f.getBegin()>0 && f.getEnd()>0) { + Cache.log.debug("mapping from "+f.getBegin()+" - "+f.getEnd()); + SequenceFeature vf[] = dbref.getMap().locateFeature(f); + if (vf!=null) { + for (int v=0;v