X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FDasSequenceFeatureFetcher.java;h=30fe7253f1ee69f5490ce771217d0d0ac8d07b15;hb=3bd894ddb06a8d9a1efd29c1705235031174e391;hp=d3c20ba3c15ef8fe0800a52cd47a874f29800a6b;hpb=2de8acfae59aced665e4c37ad0f7dcc2ed68818e;p=jalview.git diff --git a/src/jalview/ws/DasSequenceFeatureFetcher.java b/src/jalview/ws/DasSequenceFeatureFetcher.java index d3c20ba..30fe725 100644 --- a/src/jalview/ws/DasSequenceFeatureFetcher.java +++ b/src/jalview/ws/DasSequenceFeatureFetcher.java @@ -1,20 +1,19 @@ /* - * 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, 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; @@ -23,6 +22,9 @@ import java.util.*; import javax.swing.*; +import org.biodas.jdas.client.SourcesClient; +import org.biodas.jdas.schema.sources.SOURCE; +import org.biodas.jdas.schema.sources.SOURCES; import org.biojava.dasobert.das.*; import org.biojava.dasobert.das2.*; import org.biojava.dasobert.das2.io.*; @@ -80,9 +82,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) @@ -94,18 +96,20 @@ public class DasSequenceFeatureFetcher FeatureSettings fsettings, Vector ourselectedSources, boolean checkDbrefs, boolean promptFetchDbrefs) { - this.selectedSources = new Vector(); + 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); - }; + if (!selectedSources.contains(src)) + { + selectedSources.addElement(src); + } + ; } Vector sqs = new Vector(); - for (int i=0; i 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 @@ -609,8 +617,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 @@ -648,20 +656,20 @@ public class DasSequenceFeatureFetcher * simple sequence feature. * * @param seq - * the sequence to annotate + * the sequence to annotate * @param f - * the jalview sequence feature generated from the DAS feature + * the jalview sequence feature generated from the DAS feature * @param map - * the sequence feature attributes + * the sequence feature attributes * @param source - * the source that emitted the feature + * 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) { SequenceI mseq = seq; - while (seq.getDatasetSequence()!=null) + while (seq.getDatasetSequence() != null) { seq = seq.getDatasetSequence(); } @@ -671,14 +679,18 @@ public class DasSequenceFeatureFetcher if (type.equalsIgnoreCase("protein_name")) { // parse name onto the alignment sequence or the dataset sequence. - if (seq.getDescription()==null || seq.getDescription().trim().length() == 0) + 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 + // 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) + 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 + // 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; @@ -700,29 +712,36 @@ public class DasSequenceFeatureFetcher 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. + // 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.setDescription(); f.setValue("linkonly", Boolean.TRUE); - //f.setDescription(""); + // 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 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); + } + else + { + // couldn't parse the link properly. Keep it anyway - just in + // case. + debug("couldn't parse link string - " + elm); newlinks.addElement(elm); } } @@ -788,8 +807,9 @@ public class DasSequenceFeatureFetcher { } - 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")) { @@ -823,7 +843,7 @@ public class DasSequenceFeatureFetcher * * @return list of sources */ - public static DasSource[] getDASSources() + public static SOURCE[] getDASSources() { String registryURL = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL", @@ -835,42 +855,25 @@ 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) + public static SOURCE[] getDASSources(String registryURL) { - DasSourceReaderImpl reader = new DasSourceReaderImpl(); - + try { URL url = new URL(registryURL); + org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient(); + + SOURCES sources = client.fetchData(registryURL); - DasSource[] sources = reader.readDasSource(url); - - List das1sources = new ArrayList(); - for (int i = 0; i < sources.length; i++) - { - DasSource ds = sources[i]; - if (ds instanceof Das2Source) - { - Das2Source d2s = (Das2Source) ds; - if (d2s.hasDas1Capabilities()) - { - Das1Source d1s = DasSourceConverter.toDas1Source(d2s); - das1sources.add(d1s); - } - - } - else if (ds instanceof Das1Source) - { - das1sources.add((Das1Source) ds); - } - } + List dassources = sources.getSOURCE(); - return (Das1Source[]) das1sources.toArray(new Das1Source[das1sources - .size()]); + return dassources.toArray(new SOURCE[dassources.size()]); } catch (Exception ex) { + System.err.println("Failed to contact DAS1 registry at " + + registryURL); ex.printStackTrace(); return null; }