2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
\r
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.ws.dbsources;
\r
21 import java.util.Hashtable;
\r
23 import org.biojava.dasobert.das.SequenceThread;
\r
24 import org.biojava.dasobert.das2.Das2Source;
\r
25 import org.biojava.dasobert.dasregistry.Das1Source;
\r
26 import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
\r
27 import org.biojava.dasobert.dasregistry.DasSource;
\r
28 import org.biojava.dasobert.eventmodel.SequenceEvent;
\r
29 import org.biojava.dasobert.eventmodel.SequenceListener;
\r
31 import com.stevesoft.pat.Regex;
\r
33 import jalview.ws.dbsources.das.DasSequenceSourceListener;
\r
34 import jalview.ws.seqfetcher.*;
\r
35 import jalview.datamodel.AlignmentI;
\r
38 * an instance of this class is created for each unique DAS Sequence source (ie
\r
39 * one capable of handling the 'sequence' for a particular MapMaster)
\r
44 public class DasSequenceSource extends DbSourceProxyImpl implements
\r
47 protected Das1Source source = null;
\r
49 protected String dbname = "DASCS";
\r
51 protected String dbrefname = "das:source";
\r
53 protected DasCoordinateSystem coordsys = null;
\r
56 * create a new DbSource proxy for a DAS 1 source
\r
59 * Human Readable Name to use when fetching from this source
\r
61 * DbRefName for DbRefs attached to sequences retrieved from
\r
66 * specific coordinate system to use for this source
\r
68 * if source is not capable of the 'sequence' command
\r
70 public DasSequenceSource(String dbname, String dbrefname,
\r
71 Das1Source source, DasCoordinateSystem coordsys) throws Exception
\r
73 if (!source.hasCapability("sequence"))
\r
75 throw new Exception("Source " + source.getNickname()
\r
76 + " does not support the sequence command.");
\r
78 this.source = source;
\r
79 this.dbname = dbname;
\r
80 this.dbrefname = dbrefname;
\r
81 this.coordsys = coordsys;
\r
84 public String getAccessionSeparator()
\r
86 // cope with single sequences only
\r
90 public Regex getAccessionValidator()
\r
93 return Regex.perlCode("\\S+");
\r
96 public String getDbName()
\r
99 return dbname + " (DAS)";
\r
102 public String getDbSource()
\r
107 public String getDbVersion()
\r
109 return coordsys.getVersion();
\r
112 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
114 SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(
\r
116 DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(
\r
118 seqfetcher.addSequenceListener(ourlistener);
\r
119 seqfetcher.start();
\r
123 } catch (Exception e)
\r
127 while (ourlistener.isNotCalled() && seqfetcher.isAlive())
\r
132 } catch (Exception e)
\r
137 if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())
\r
139 System.err.println("Sequence Query to " + source.getNickname()
\r
140 + " with '" + queries + "' returned no sequences.");
\r
145 return ourlistener.getSequences();
\r
149 public String getTestQuery()
\r
151 return coordsys.getTestCode();
\r
154 public boolean isValidReference(String accession)
\r
156 // TODO try to validate an accession against source
\r
157 // We don't really know how to do this without querying source
\r
163 * @return the source
\r
165 public Das1Source getSource()
\r
171 * @return the coordsys
\r
173 public DasCoordinateSystem getCoordsys()
\r