2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
\r
3 * Copyright (C) 2010 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 org.biojava.dasobert.das.SequenceThread;
\r
23 import org.biojava.dasobert.das2.Das2Source;
\r
24 import org.biojava.dasobert.dasregistry.Das1Source;
\r
25 import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
\r
26 import org.biojava.dasobert.dasregistry.DasSource;
\r
27 import org.biojava.dasobert.eventmodel.SequenceEvent;
\r
28 import org.biojava.dasobert.eventmodel.SequenceListener;
\r
30 import com.stevesoft.pat.Regex;
\r
32 import jalview.ws.dbsources.das.DasSequenceSourceListener;
\r
33 import jalview.ws.seqfetcher.*;
\r
34 import jalview.datamodel.AlignmentI;
\r
37 * an instance of this class is created for each unique DAS Sequence source (ie
\r
38 * one capable of handling the 'sequence' for a particular MapMaster)
\r
43 public class DasSequenceSource extends DbSourceProxyImpl implements
\r
46 protected Das1Source source = null;
\r
48 protected String dbname = "DASCS";
\r
50 protected String dbrefname = "das:source";
\r
52 protected DasCoordinateSystem coordsys = null;
\r
55 * create a new DbSource proxy for a DAS 1 source
\r
58 * Human Readable Name to use when fetching from this source
\r
60 * DbRefName for DbRefs attached to sequences retrieved from this
\r
65 * specific coordinate system to use for this source
\r
67 * if source is not capable of the 'sequence' command
\r
69 public DasSequenceSource(String dbname, String dbrefname,
\r
70 Das1Source source, DasCoordinateSystem coordsys) throws Exception
\r
72 if (!source.hasCapability("sequence"))
\r
74 throw new Exception("Source " + source.getNickname()
\r
75 + " does not support the sequence command.");
\r
77 this.source = source;
\r
78 this.dbname = dbname;
\r
79 this.dbrefname = dbrefname;
\r
80 this.coordsys = coordsys;
\r
83 public String getAccessionSeparator()
\r
85 // cope with single sequences only
\r
89 public Regex getAccessionValidator()
\r
92 return Regex.perlCode("\\S+");
\r
95 public String getDbName()
\r
98 return dbname + " (DAS)";
\r
101 public String getDbSource()
\r
106 public String getDbVersion()
\r
108 return coordsys.getVersion();
\r
111 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
113 SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(
\r
115 DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(
\r
117 seqfetcher.addSequenceListener(ourlistener);
\r
118 seqfetcher.start();
\r
122 } catch (Exception e)
\r
126 while (ourlistener.isNotCalled() && seqfetcher.isAlive())
\r
131 } catch (Exception e)
\r
136 if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())
\r
138 System.err.println("Sequence Query to " + source.getNickname()
\r
139 + " with '" + queries + "' returned no sequences.");
\r
144 return ourlistener.getSequences();
\r
148 public String getTestQuery()
\r
150 return coordsys.getTestCode();
\r
153 public boolean isValidReference(String accession)
\r
155 // TODO try to validate an accession against source
\r
156 // We don't really know how to do this without querying source
\r
162 * @return the source
\r
164 public Das1Source getSource()
\r
170 * @return the coordsys
\r
172 public DasCoordinateSystem getCoordsys()
\r