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 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
47 protected String dbname="DASCS";
\r
48 protected String dbrefname="das:source";
\r
49 protected DasCoordinateSystem coordsys = null;
\r
51 * create a new DbSource proxy for a DAS 1 source
\r
52 * @param dbnbame Human Readable Name to use when fetching from this source
\r
53 * @param dbrefname DbRefName for DbRefs attached to sequences retrieved from this source
\r
54 * @param source Das1Source
\r
55 * @param coordsys specific coordinate system to use for this source
\r
56 * @throws Exception if source is not capable of the 'sequence' command
\r
58 public DasSequenceSource(String dbname, String dbrefname, Das1Source source,
\r
59 DasCoordinateSystem coordsys) throws Exception
\r
61 if (!source.hasCapability("sequence"))
\r
63 throw new Exception("Source "+source.getNickname()+" does not support the sequence command.");
\r
65 this.source = source;
\r
66 this.dbname = dbname;
\r
67 this.dbrefname=dbrefname;
\r
68 this.coordsys = coordsys;
\r
70 public String getAccessionSeparator()
\r
72 // cope with single sequences only
\r
76 public Regex getAccessionValidator()
\r
79 return Regex.perlCode("\\S+");
\r
82 public String getDbName()
\r
85 return dbname+" (DAS)";
\r
88 public String getDbSource()
\r
93 public String getDbVersion()
\r
95 return coordsys.getVersion();
\r
98 public AlignmentI getSequenceRecords(String queries) throws Exception
\r
100 SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(queries, source);
\r
101 DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(this, queries);
\r
102 seqfetcher.addSequenceListener(ourlistener);
\r
103 seqfetcher.start();
\r
104 try { Thread.sleep(5); } catch (Exception e) {};
\r
105 while (ourlistener.isNotCalled() && seqfetcher.isAlive())
\r
107 try { Thread.sleep(5); } catch (Exception e) { };
\r
109 if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())
\r
111 System.err.println("Sequence Query to "+source.getNickname()+" with '"+queries+"' returned no sequences.");
\r
114 return ourlistener.getSequences();
\r
118 public String getTestQuery()
\r
120 return coordsys.getTestCode();
\r
122 public boolean isValidReference(String accession)
\r
124 // TODO try to validate an accession against source
\r
125 // We don't really know how to do this without querying source
\r
130 * @return the source
\r
132 public Das1Source getSource()
\r
137 * @return the coordsys
\r
139 public DasCoordinateSystem getCoordsys()
\r