remove dead imports
[jalview.git] / src / jalview / ws / dbsources / DasSequenceSource.java
1 /*\r
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
4  * \r
5  * This file is part of Jalview.\r
6  * \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
10  * \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
15  * \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
17  */\r
18 package jalview.ws.dbsources;\r
19 \r
20 import java.util.Hashtable;\r
21 \r
22 import com.stevesoft.pat.Regex;\r
23 \r
24 import jalview.ws.dbsources.das.DasSequenceSourceListener;\r
25 import jalview.ws.seqfetcher.*;\r
26 import jalview.datamodel.AlignmentI;\r
27 \r
28 /**\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
31  * \r
32  * @author JimP\r
33  * \r
34  */\r
35 public class DasSequenceSource extends DbSourceProxyImpl implements\r
36         DbSourceProxy\r
37 {\r
38   protected Das1Source source = null;\r
39 \r
40   protected String dbname = "DASCS";\r
41 \r
42   protected String dbrefname = "das:source";\r
43 \r
44   protected DasCoordinateSystem coordsys = null;\r
45 \r
46   /**\r
47    * create a new DbSource proxy for a DAS 1 source\r
48    * \r
49    * @param dbnbame\r
50    *          Human Readable Name to use when fetching from this source\r
51    * @param dbrefname\r
52    *          DbRefName for DbRefs attached to sequences retrieved from this\r
53    *          source\r
54    * @param source\r
55    *          Das1Source\r
56    * @param coordsys\r
57    *          specific coordinate system to use for this source\r
58    * @throws Exception\r
59    *           if source is not capable of the 'sequence' command\r
60    */\r
61   public DasSequenceSource(String dbname, String dbrefname,\r
62           Das1Source source, DasCoordinateSystem coordsys) throws Exception\r
63   {\r
64     if (!source.hasCapability("sequence"))\r
65     {\r
66       throw new Exception("Source " + source.getNickname()\r
67               + " does not support the sequence command.");\r
68     }\r
69     this.source = source;\r
70     this.dbname = dbname;\r
71     this.dbrefname = dbrefname;\r
72     this.coordsys = coordsys;\r
73   }\r
74 \r
75   public String getAccessionSeparator()\r
76   {\r
77     // cope with single sequences only\r
78     return null;\r
79   }\r
80 \r
81   public Regex getAccessionValidator()\r
82   {\r
83     /** ? * */\r
84     return Regex.perlCode("\\S+");\r
85   }\r
86 \r
87   public String getDbName()\r
88   {\r
89     // TODO: map to\r
90     return dbname + " (DAS)";\r
91   }\r
92 \r
93   public String getDbSource()\r
94   {\r
95     return dbrefname;\r
96   }\r
97 \r
98   public String getDbVersion()\r
99   {\r
100     return coordsys.getVersion();\r
101   }\r
102 \r
103   public AlignmentI getSequenceRecords(String queries) throws Exception\r
104   {\r
105     SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(\r
106             queries, source);\r
107     DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(\r
108             this, queries);\r
109     seqfetcher.addSequenceListener(ourlistener);\r
110     seqfetcher.start();\r
111     try\r
112     {\r
113       Thread.sleep(5);\r
114     } catch (Exception e)\r
115     {\r
116     }\r
117     ;\r
118     while (ourlistener.isNotCalled() && seqfetcher.isAlive())\r
119     {\r
120       try\r
121       {\r
122         Thread.sleep(5);\r
123       } catch (Exception e)\r
124       {\r
125       }\r
126       ;\r
127     }\r
128     if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())\r
129     {\r
130       System.err.println("Sequence Query to " + source.getNickname()\r
131               + " with '" + queries + "' returned no sequences.");\r
132       return null;\r
133     }\r
134     else\r
135     {\r
136       return ourlistener.getSequences();\r
137     }\r
138   }\r
139 \r
140   public String getTestQuery()\r
141   {\r
142     return coordsys.getTestCode();\r
143   }\r
144 \r
145   public boolean isValidReference(String accession)\r
146   {\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
149 \r
150     return true;\r
151   }\r
152 \r
153   /**\r
154    * @return the source\r
155    */\r
156   public Das1Source getSource()\r
157   {\r
158     return source;\r
159   }\r
160 \r
161   /**\r
162    * @return the coordsys\r
163    */\r
164   public DasCoordinateSystem getCoordsys()\r
165   {\r
166     return coordsys;\r
167   }\r
168 }\r