X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FDasSequenceFeatureFetcher.java;h=fd4d09230a9a13880692e056038cede8d9184adc;hb=8c2e72fec911f86333cbc82aaed4d29fadac542c;hp=56ca9ea61bfad24a6c81999ceb0d9fb1ecd52bf6;hpb=0ae6f43a167ee4219a60e51b1b39672b54860cd0;p=jalview.git diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index 56ca9ea..fd4d092 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -1,20 +1,19 @@ /* - * 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 (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; @@ -31,6 +30,7 @@ import org.biojava.dasobert.eventmodel.*; import jalview.bin.Cache; import jalview.datamodel.*; import jalview.gui.*; +import jalview.util.UrlLink; /** * DOCUMENT ME! @@ -79,9 +79,9 @@ public class DasSequenceFeatureFetcher * Creates a new SequenceFeatureFetcher object. Uses default * * @param align - * DOCUMENT ME! + * DOCUMENT ME! * @param ap - * DOCUMENT ME! + * DOCUMENT ME! */ public DasSequenceFeatureFetcher(SequenceI[] sequences, FeatureSettings fsettings, Vector selectedSources) @@ -89,12 +89,35 @@ public class DasSequenceFeatureFetcher this(sequences, fsettings, selectedSources, true, true); } - public DasSequenceFeatureFetcher(SequenceI[] sequences, - FeatureSettings fsettings, Vector selectedSources, + public DasSequenceFeatureFetcher(SequenceI[] oursequences, + FeatureSettings fsettings, Vector ourselectedSources, boolean checkDbrefs, boolean promptFetchDbrefs) { - this.selectedSources = selectedSources; - this.sequences = sequences; + this.selectedSources = new Vector(); + Enumeration sources = ourselectedSources.elements(); + // filter both sequences and sources to eliminate duplicates + while (sources.hasMoreElements()) + { + Object src = sources.nextElement(); + if (!selectedSources.contains(src)) + { + selectedSources.addElement(src); + } + ; + } + Vector sqs = new Vector(); + for (int i = 0; i < oursequences.length; i++) + { + if (!sqs.contains(oursequences[i])) + { + sqs.addElement(oursequences[i]); + } + } + sequences = new SequenceI[sqs.size()]; + for (int i = 0; i < sequences.length; i++) + { + sequences[i] = (SequenceI) sqs.elementAt(i); + } if (fsettings != null) { this.fsettings = fsettings; @@ -191,26 +214,34 @@ public class DasSequenceFeatureFetcher 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()) + try { - token = st.nextToken(); - for (int i = 0; i < sources.length; i++) + DasSource[] sources = new jalview.gui.DasSourceBrowser() + .getDASSource(); + + String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE", + "uniprot"); + StringTokenizer st = new StringTokenizer(active, "\t"); + selectedSources = new Vector(); + String token; + while (st.hasMoreTokens()) { - if (sources[i].getNickname().equals(token)) + token = st.nextToken(); + for (int i = 0; i < sources.length; i++) { - selectedSources.addElement(sources[i]); - break; + if (sources[i].getNickname().equals(token)) + { + selectedSources.addElement(sources[i]); + break; + } } } + } catch (Exception ex) + { + debug("Exception whilst setting default feature sources from registry and local preferences.", + ex); } } @@ -303,8 +334,9 @@ public class DasSequenceFeatureFetcher private void setGuiFetchComplete() { - if (af != null) + if (!cancelled && af != null) { + // only update the progress bar if we've completed the fetch normally af.setProgressBar("DAS Feature Fetching Complete", startTime); } @@ -478,8 +510,8 @@ public class DasSequenceFeatureFetcher for (int i = 0; i < features.length; i++) { // standard DAS feature-> jalview sequence feature transformation - SequenceFeature f = newSequenceFeature(features[i], source - .getNickname()); + SequenceFeature f = newSequenceFeature(features[i], + source.getNickname()); if (!parseSeqFeature(seq, f, features[i], source)) { if (dbref.getMap() != null && f.getBegin() > 0 @@ -582,8 +614,8 @@ public class DasSequenceFeatureFetcher for (int i = 0; i < features.length; i++) { // standard DAS feature-> jalview sequence feature transformation - SequenceFeature f = newSequenceFeature(features[i], source - .getNickname()); + SequenceFeature f = newSequenceFeature(features[i], + source.getNickname()); if (!parseSeqFeature(seq, f, features[i], source)) { // just add as a simple sequence feature @@ -616,37 +648,105 @@ public class DasSequenceFeatureFetcher } /** - * examine the given sequence feature to determine if it should actually - * be turned into sequence annotation or database cross references rather - * than a simple sequence feature. - * @param seq the sequence to annotate - * @param f the jalview sequence feature generated from the DAS feature - * @param map the sequence feature attributes - * @param source the source that emitted the feature + * examine the given sequence feature to determine if it should actually be + * turned into sequence annotation or database cross references rather than a + * simple sequence feature. + * + * @param seq + * the sequence to annotate + * @param f + * the jalview sequence feature generated from the DAS feature + * @param map + * the sequence feature attributes + * @param source + * the source that emitted the feature * @return true if feature was consumed as another kind of annotation. */ - protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f, Map map, - Das1Source source) + protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f, + Map map, Das1Source source) { - // check if source has biosapiens or other sequence ontology label - if (f.getType()!=null && (f.getType().equalsIgnoreCase("DBXREF") - || f.getType().equalsIgnoreCase("DBREF"))) - { - // try to parse the accession out - - DBRefEntry dbr = new DBRefEntry(); - dbr.setVersion(source.getNickname()); - StringTokenizer st = new StringTokenizer(f.getDescription(),":"); - if (st.hasMoreTokens()) + SequenceI mseq = seq; + while (seq.getDatasetSequence() != null) + { + seq = seq.getDatasetSequence(); + } + if (f.getType() != null) + { + String type = f.getType(); + if (type.equalsIgnoreCase("protein_name")) { - dbr.setSource(st.nextToken()); + // parse name onto the alignment sequence or the dataset sequence. + if (seq.getDescription() == null + || seq.getDescription().trim().length() == 0) + { + // could look at the note series to pick out the first long name, for + // the moment just use the whole description string + seq.setDescription(f.getDescription()); + } + if (mseq.getDescription() == null + || mseq.getDescription().trim().length() == 0) + { + // could look at the note series to pick out the first long name, for + // the moment just use the whole description string + mseq.setDescription(f.getDescription()); + } + return true; } - if (st.hasMoreTokens()) + // check if source has biosapiens or other sequence ontology label + if (type.equalsIgnoreCase("DBXREF") || type.equalsIgnoreCase("DBREF")) { - dbr.setAccessionId(st.nextToken()); + // try to parse the accession out + + DBRefEntry dbr = new DBRefEntry(); + dbr.setVersion(source.getNickname()); + StringTokenizer st = new StringTokenizer(f.getDescription(), ":"); + if (st.hasMoreTokens()) + { + dbr.setSource(st.nextToken()); + } + if (st.hasMoreTokens()) + { + dbr.setAccessionId(st.nextToken()); + } + seq.addDBRef(dbr); + + if (f.links != null && f.links.size() > 0) + { + // feature is also appended to enable links to be seen. + // TODO: consider extending dbrefs to have their own links ? + // TODO: new feature: extract dbref links from DAS servers and add the + // URL pattern to the list of DB name associated links in the user's + // preferences ? + // for the moment - just fix up the existing feature so it displays + // correctly. + // f.setType(dbr.getSource()); + // f.setDescription(); + f.setValue("linkonly", Boolean.TRUE); + // f.setDescription(""); + Vector newlinks = new Vector(); + Enumeration it = f.links.elements(); + while (it.hasMoreElements()) + { + String elm; + UrlLink urllink = new UrlLink(elm = (String) it.nextElement()); + if (urllink.isValid()) + { + urllink.setLabel(f.getDescription()); + newlinks.addElement(urllink.toString()); + } + else + { + // couldn't parse the link properly. Keep it anyway - just in + // case. + debug("couldn't parse link string - " + elm); + newlinks.addElement(elm); + } + } + f.links = newlinks; + seq.addSequenceFeature(f); + } + return true; } - seq.addDBRef(dbr); - return true; } return false; } @@ -695,16 +795,18 @@ public class DasSequenceFeatureFetcher try { Object scr = dasfeature.get("SCORE"); - if (scr!=null) - {score = (float) Double.parseDouble(scr.toString()); - - } + if (scr != null) + { + score = (float) Double.parseDouble(scr.toString()); + + } } catch (Exception ex) { } - SequenceFeature f = new SequenceFeature((String) dasfeature - .get("TYPE"), desc, start, end, score, nickname); + SequenceFeature f = new SequenceFeature( + (String) dasfeature.get("TYPE"), desc, start, end, score, + nickname); if (dasfeature.containsKey("LINK")) { @@ -750,7 +852,7 @@ public class DasSequenceFeatureFetcher * query the given URL for DasSources. * * @param registryURL - * return sources from registryURL + * return sources from registryURL */ public static DasSource[] getDASSources(String registryURL) { @@ -786,6 +888,8 @@ public class DasSequenceFeatureFetcher .size()]); } catch (Exception ex) { + System.err.println("Failed to contact DAS1 registry at " + + registryURL); ex.printStackTrace(); return null; }