2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
\r
3 * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
\r
5 * This file is part of Jalview.
\r
7 * Jalview is free software: you can redistribute it and/or
\r
8 * modify it under the terms of the GNU General Public License
\r
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
\r
11 * Jalview is distributed in the hope that it will be useful, but
\r
12 * WITHOUT ANY WARRANTY; without even the implied warranty
\r
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
\r
14 * PURPOSE. See the GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
\r
18 package jalview.ws.dbsources;
\r
20 import java.util.Hashtable;
\r
22 import com.stevesoft.pat.Regex;
\r
24 import jalview.ws.dbsources.das.DasSequenceSourceListener;
\r
25 import jalview.ws.seqfetcher.*;
\r
26 import jalview.datamodel.AlignmentI;
\r
29 * an instance of this class is created for each unique DAS Sequence source (ie
\r
30 * one capable of handling the 'sequence' for a particular MapMaster)
\r
35 public class DasSequenceSource extends DbSourceProxyImpl implements
\r
38 protected Das1Source source = null;
\r
40 protected String dbname = "DASCS";
\r
42 protected String dbrefname = "das:source";
\r
44 protected DasCoordinateSystem coordsys = null;
\r
47 * create a new DbSource proxy for a DAS 1 source
\r
50 * Human Readable Name to use when fetching from this source
\r
52 * DbRefName for DbRefs attached to sequences retrieved from this
\r
57 * specific coordinate system to use for this source
\r
59 * if source is not capable of the 'sequence' command
\r
61 public DasSequenceSource(String dbname, String dbrefname,
\r
62 Das1Source source, DasCoordinateSystem coordsys) throws Exception
\r
64 if (!source.hasCapability("sequence"))
\r
66 throw new Exception("Source " + source.getNickname()
\r
67 + " does not support the sequence command.");
\r
69 this.source = source;
\r
70 this.dbname = dbname;
\r
71 this.dbrefname = dbrefname;
\r
72 this.coordsys = coordsys;
\r
75 public String getAccessionSeparator()
\r
77 // cope with single sequences only
\r
81 public Regex getAccessionValidator()
\r
84 return Regex.perlCode("\\S+");
\r
87 public String getDbName()
\r
90 return dbname + " (DAS)";
\r
93 public String getDbSource()
\r
98 public String getDbVersion()
\r
100 return coordsys.getVersion();
\r
103 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
105 SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(
\r
107 DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(
\r
109 seqfetcher.addSequenceListener(ourlistener);
\r
110 seqfetcher.start();
\r
114 } catch (Exception e)
\r
118 while (ourlistener.isNotCalled() && seqfetcher.isAlive())
\r
123 } catch (Exception e)
\r
128 if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())
\r
130 System.err.println("Sequence Query to " + source.getNickname()
\r
131 + " with '" + queries + "' returned no sequences.");
\r
136 return ourlistener.getSequences();
\r
140 public String getTestQuery()
\r
142 return coordsys.getTestCode();
\r
145 public boolean isValidReference(String accession)
\r
147 // TODO try to validate an accession against source
\r
148 // We don't really know how to do this without querying source
\r
154 * @return the source
\r
156 public Das1Source getSource()
\r
162 * @return the coordsys
\r
164 public DasCoordinateSystem getCoordsys()
\r