refactored das sequence source creation code to the implementor of the das source...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 29 Feb 2012 16:16:58 +0000 (16:16 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 29 Feb 2012 16:16:58 +0000 (16:16 +0000)
src/jalview/ws/SequenceFetcher.java

index 4f9e0ab..8c9e08f 100644 (file)
  */\r
 package jalview.ws;\r
 \r
-import java.util.ArrayList;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\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
-\r
 import jalview.datamodel.Alignment;\r
 import jalview.datamodel.AlignmentI;\r
 import jalview.datamodel.DBRefSource;\r
 import jalview.datamodel.SequenceI;\r
-import jalview.ws.dbsources.DasSequenceSource;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
 import jalview.ws.seqfetcher.ASequenceFetcher;\r
 import jalview.ws.seqfetcher.DbSourceProxy;\r
 \r
+import java.util.ArrayList;\r
+import java.util.Enumeration;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
 /**\r
  * This is the the concrete implementation of the sequence retrieval interface\r
  * and abstract class in jalview.ws.seqfetcher. This implements the run-time\r
@@ -75,7 +71,7 @@ public class SequenceFetcher extends ASequenceFetcher
     for (int i = 0; i < srcs.length; i++)\r
     {\r
       String nm = getSourceProxy(srcs[i]).getDbName();\r
-      if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.DasSequenceSource)\r
+      if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)\r
       {\r
         if (nm.startsWith("das:"))\r
         {\r
@@ -317,91 +313,18 @@ public class SequenceFetcher extends ASequenceFetcher
    */\r
   public void registerDasSequenceSources()\r
   {\r
-    DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher\r
-            .getDASSources();\r
-    if (sources != null)\r
-    {\r
-      for (int s = 0; sources != null && s < sources.length; s++)\r
-      {\r
-        addDasSequenceSource(sources[s]);\r
-      }\r
-    }\r
-\r
-    Vector localsources = jalview.bin.Cache.getLocalDasSources();\r
-    if (localsources != null)\r
-    {\r
-      for (Enumeration ls = localsources.elements(); ls.hasMoreElements();)\r
-      {\r
-        addDasSequenceSource((DasSource) ls.nextElement());\r
-      }\r
-    }\r
-  }\r
-\r
-  /**\r
-   * Try to create and add a DasSequenceSource to the list of sources.\r
-   * \r
-   * @param source\r
-   * @return null if no source was added, or the new DasSequenceSource created\r
-   */\r
-  DasSequenceSource addDasSequenceSource(DasSource source)\r
-  {\r
-    DasSequenceSource ds = null;\r
-    Das1Source d1s = null;\r
-    if (source.hasCapability("sequence"))\r
-    {\r
-      if (source instanceof Das2Source)\r
-      {\r
-        if (((Das2Source) source).hasDas1Capabilities())\r
-        {\r
-          try\r
-          {\r
-            d1s = org.biojava.dasobert.das2.DasSourceConverter\r
-                    .toDas1Source((Das2Source) source);\r
-          } catch (Exception e)\r
-          {\r
-            System.err.println("Ignoring DAS2 sequence source "\r
-                    + source.getNickname()\r
-                    + " - couldn't map to Das1Source.\n");\r
-            e.printStackTrace();\r
-          }\r
-        }\r
-      }\r
-      else\r
-      {\r
-        if (source instanceof Das1Source)\r
-        {\r
-          d1s = (Das1Source) source;\r
-        }\r
-      }\r
-    }\r
-    if (d1s != null)\r
+    // TODO: define a context as a registry provider (either desktop,\r
+    // jalview.bin.cache, or something else).\r
+    for (jalviewSourceI source : jalview.bin.Cache.getDasSourceRegistry().getSources())\r
     {\r
-      DasCoordinateSystem[] css = d1s.getCoordinateSystem();\r
-      if (css == null || css.length == 0)\r
+      if (source.isSequenceSource())\r
       {\r
-        // TODO: query das source directly to identify coordinate system... or\r
-        // have to make up a coordinate system\r
-        css = new DasCoordinateSystem[]\r
-        { new DasCoordinateSystem() };\r
-        css[0].setName(d1s.getNickname());\r
-        css[0].setUniqueId(d1s.getNickname());\r
-      }\r
-      for (int c = 0; c < css.length; c++)\r
-      {\r
-        try\r
+        List<DbSourceProxy> dassources = source.getSequenceSourceProxies();\r
+        for (DbSourceProxy seqsrc : dassources)\r
         {\r
-          addDbRefSourceImpl(ds = new DasSequenceSource("das:"\r
-                  + d1s.getNickname() + " (" + css[c].getName() + ")",\r
-                  css[c].getName(), d1s, css[c]));\r
-        } catch (Exception e)\r
-        {\r
-          System.err.println("Ignoring sequence coord system " + c + " ("\r
-                  + css[c].getName() + ") for source " + d1s.getNickname()\r
-                  + "- threw exception when constructing fetcher.\n");\r
-          e.printStackTrace();\r
+          addDbRefSourceImpl(seqsrc);\r
         }\r
       }\r
     }\r
-    return ds;\r
   }\r
 }\r