--- /dev/null
+package jalview.ws.dbsources;\r
+\r
+import java.util.Hashtable;\r
+\r
+import org.biojava.dasobert.das.SequenceThread;\r
+import org.biojava.dasobert.das2.Das2Source;\r
+import org.biojava.dasobert.dasregistry.Das1Source;\r
+import org.biojava.dasobert.dasregistry.DasCoordinateSystem;\r
+import org.biojava.dasobert.dasregistry.DasSource;\r
+import org.biojava.dasobert.eventmodel.SequenceEvent;\r
+import org.biojava.dasobert.eventmodel.SequenceListener;\r
+\r
+import com.stevesoft.pat.Regex;\r
+\r
+import jalview.ws.dbsources.das.DasSequenceSourceListener;\r
+import jalview.ws.seqfetcher.*;\r
+import jalview.datamodel.AlignmentI;\r
+\r
+/**\r
+ * 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
+ * \r
+ * @author JimP\r
+ *\r
+ */\r
+public class DasSequenceSource extends DbSourceProxyImpl implements\r
+ DbSourceProxy\r
+{\r
+ protected Das1Source source=null;\r
+ protected String dbname="DASCS";\r
+ protected String dbrefname="das:source";\r
+ protected DasCoordinateSystem coordsys = null;\r
+ /**\r
+ * create a new DbSource proxy for a DAS 1 source\r
+ * @param dbnbame Human Readable Name to use when fetching from this source\r
+ * @param dbrefname DbRefName for DbRefs attached to sequences retrieved from this source\r
+ * @param source Das1Source\r
+ * @param coordsys specific coordinate system to use for this source\r
+ * @throws Exception if source is not capable of the 'sequence' command\r
+ */\r
+ public DasSequenceSource(String dbname, String dbrefname, Das1Source source,\r
+ DasCoordinateSystem coordsys) throws Exception\r
+ {\r
+ if (!source.hasCapability("sequence"))\r
+ {\r
+ throw new Exception("Source "+source.getNickname()+" does not support the sequence command.");\r
+ }\r
+ this.source = source;\r
+ this.dbname = dbname;\r
+ this.dbrefname=dbrefname;\r
+ this.coordsys = coordsys;\r
+ }\r
+ public String getAccessionSeparator()\r
+ {\r
+ // cope with single sequences only\r
+ return null;\r
+ }\r
+\r
+ public Regex getAccessionValidator()\r
+ {\r
+ /** ? **/\r
+ return Regex.perlCode("\\S+");\r
+ }\r
+\r
+ public String getDbName()\r
+ {\r
+ // TODO: map to\r
+ return dbname+" (DAS)";\r
+ }\r
+\r
+ public String getDbSource()\r
+ {\r
+ return dbrefname;\r
+ }\r
+\r
+ public String getDbVersion()\r
+ {\r
+ return coordsys.getVersion();\r
+ }\r
+\r
+ public AlignmentI getSequenceRecords(String queries) throws Exception\r
+ {\r
+ SequenceThread seqfetcher = new org.biojava.dasobert.das.SequenceThread(queries, source);\r
+ DasSequenceSourceListener ourlistener = new DasSequenceSourceListener(this, queries);\r
+ seqfetcher.addSequenceListener(ourlistener);\r
+ seqfetcher.start();\r
+ try { Thread.sleep(5); } catch (Exception e) {};\r
+ while (ourlistener.isNotCalled() && seqfetcher.isAlive())\r
+ {\r
+ try { Thread.sleep(5); } catch (Exception e) { };\r
+ }\r
+ if (ourlistener.isNotCalled() || ourlistener.hasNoSequences())\r
+ {\r
+ System.err.println("Sequence Query to "+source.getNickname()+" with '"+queries+"' returned no sequences.");\r
+ return null;\r
+ } else {\r
+ return ourlistener.getSequences();\r
+ }\r
+ }\r
+\r
+ public String getTestQuery()\r
+ {\r
+ return coordsys.getTestCode();\r
+ }\r
+ public boolean isValidReference(String accession)\r
+ {\r
+ // TODO try to validate an accession against source\r
+ // We don't really know how to do this without querying source\r
+ \r
+ return true;\r
+ }\r
+ /**\r
+ * @return the source\r
+ */\r
+ public Das1Source getSource()\r
+ {\r
+ return source;\r
+ }\r
+ /**\r
+ * @return the coordsys\r
+ */\r
+ public DasCoordinateSystem getCoordsys()\r
+ {\r
+ return coordsys;\r
+ }\r
+}\r