Merge branch 'JAL-972-dasobert-to-jdas' into JAL-972-jdas
[jalview.git] / src / jalview / ws / SequenceFetcher.java
index adf386c..d5b3d11 100644 (file)
@@ -1,40 +1,35 @@
 /*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)\r
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)\r
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle\r
  * \r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
+ * This file is part of Jalview.\r
  * \r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * Jalview is free software: you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License \r
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\r
  * \r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ * Jalview is distributed in the hope that it will be useful, but \r
+ * WITHOUT ANY WARRANTY; without even the implied warranty \r
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR \r
+ * PURPOSE.  See the GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.\r
  */\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
@@ -59,9 +54,11 @@ public class SequenceFetcher extends ASequenceFetcher
     addDBRefSourceImpl(jalview.ws.dbsources.Pdb.class);\r
     addDBRefSourceImpl(jalview.ws.dbsources.PfamFull.class);\r
     addDBRefSourceImpl(jalview.ws.dbsources.PfamSeed.class); // ensures Seed\r
-                                                              // alignment is\r
-                                                              // 'default' for\r
-                                                              // PFAM\r
+    // alignment is\r
+    // 'default' for\r
+    // PFAM\r
+    addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class);\r
+    addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class);\r
     registerDasSequenceSources();\r
   }\r
 \r
@@ -76,7 +73,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
@@ -318,88 +315,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
-   * 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
+    // 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
-      if (source instanceof Das2Source)\r
+      if (source.isSequenceSource())\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
+        List<DbSourceProxy> dassources = source.getSequenceSourceProxies();\r
+        for (DbSourceProxy seqsrc : dassources)\r
         {\r
-          if (source instanceof Das1Source)\r
-          {\r
-            d1s = (Das1Source) source;\r
-          }\r
+          addDbRefSourceImpl(seqsrc);\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(ds=new DasSequenceSource(\r
-                    "das:" + 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 "\r
-                    + d1s.getNickname()\r
-                    + "- threw exception when constructing fetcher.\n");\r
-            e.printStackTrace();\r
-          }\r
-        }\r
-      }\r
-      return ds;\r
+    }\r
   }\r
 }\r