sequence fetchers generated for local das sequence sources
authorjprocter <Jim Procter>
Thu, 4 Dec 2008 10:27:03 +0000 (10:27 +0000)
committerjprocter <Jim Procter>
Thu, 4 Dec 2008 10:27:03 +0000 (10:27 +0000)
src/jalview/ws/SequenceFetcher.java

index b20ebbb..2be142a 100644 (file)
@@ -31,6 +31,7 @@ import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentI;\r
 import jalview.datamodel.DBRefSource;\r
 import jalview.datamodel.SequenceI;\r
+import jalview.ws.dbsources.DasSequenceSource;\r
 import jalview.ws.seqfetcher.ASequenceFetcher;\r
 import jalview.ws.seqfetcher.DbSourceProxy;\r
 \r
@@ -319,23 +320,45 @@ public class SequenceFetcher extends ASequenceFetcher
   {\r
     DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher\r
             .getDASSources();\r
-    for (int s = 0; s < sources.length; s++)\r
+    if (sources!=null)\r
     {\r
-      Das1Source d1s = null;\r
-      if (sources[s].hasCapability("sequence"))\r
+      for (int s=0; sources!=null && s<sources.length; s++)\r
       {\r
-        if (sources[s] instanceof Das2Source)\r
-        {\r
-          if (((Das2Source) sources[s]).hasDas1Capabilities())\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
+   * Try to create and add a DasSequenceSource to the list of sources.\r
+   * @param source\r
+   * @return null if no source was added, or the new DasSequenceSource created\r
+   */\r
+  DasSequenceSource addDasSequenceSource(DasSource source) {\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) sources[s]);\r
+                      .toDas1Source((Das2Source) source);\r
             } catch (Exception e)\r
             {\r
               System.err.println("Ignoring DAS2 sequence source "\r
-                      + sources[s].getNickname()\r
+                      + source.getNickname()\r
                       + " - couldn't map to Das1Source.\n");\r
               e.printStackTrace();\r
             }\r
@@ -343,20 +366,28 @@ public class SequenceFetcher extends ASequenceFetcher
         }\r
         else\r
         {\r
-          if (sources[s] instanceof Das1Source)\r
+          if (source instanceof Das1Source)\r
           {\r
-            d1s = (Das1Source) sources[s];\r
+            d1s = (Das1Source) source;\r
           }\r
         }\r
       }\r
       if (d1s != null)\r
       {\r
         DasCoordinateSystem[] css = d1s.getCoordinateSystem();\r
+        if (css==null || css.length==0)\r
+        {\r
+          // TODO: query das source directly to identify coordinate system... or\r
+          // have to make up a coordinate system\r
+          css = new DasCoordinateSystem[] { 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
           {\r
-            addDbRefSourceImpl(new jalview.ws.dbsources.DasSequenceSource(\r
+            addDbRefSourceImpl(ds=new DasSequenceSource(\r
                     "das:" + d1s.getNickname() + " (" + css[c].getName()\r
                             + ")", css[c].getName(), d1s, css[c]));\r
           } catch (Exception e)\r
@@ -369,8 +400,6 @@ public class SequenceFetcher extends ASequenceFetcher
           }\r
         }\r
       }\r
-\r
-    }\r
+      return ds;\r
   }\r
-\r
 }\r