move from dasobert to jdas multithreaded feature fetching - and use jalview das api...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 29 Feb 2012 16:24:50 +0000 (16:24 +0000)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Wed, 29 Feb 2012 16:36:31 +0000 (16:36 +0000)
src/jalview/ws/DasSequenceFeatureFetcher.java

index 30fe725..1220df7 100644 (file)
  */\r
 package jalview.ws;\r
 \r
-import java.net.*;\r
-import java.util.*;\r
-\r
-import javax.swing.*;\r
-\r
-import org.biodas.jdas.client.SourcesClient;\r
-import org.biodas.jdas.schema.sources.SOURCE;\r
-import org.biodas.jdas.schema.sources.SOURCES;\r
-import org.biojava.dasobert.das.*;\r
-import org.biojava.dasobert.das2.*;\r
-import org.biojava.dasobert.das2.io.*;\r
-import org.biojava.dasobert.dasregistry.*;\r
-import org.biojava.dasobert.eventmodel.*;\r
 import jalview.bin.Cache;\r
-import jalview.datamodel.*;\r
-import jalview.gui.*;\r
+import jalview.datamodel.DBRefEntry;\r
+import jalview.datamodel.SequenceFeature;\r
+import jalview.datamodel.SequenceI;\r
+import jalview.gui.AlignFrame;\r
+import jalview.gui.Desktop;\r
+import jalview.gui.FeatureSettings;\r
 import jalview.util.UrlLink;\r
+import jalview.ws.dbsources.das.api.DasSourceRegistryI;\r
+import jalview.ws.dbsources.das.api.jalviewSourceI;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Enumeration;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.StringTokenizer;\r
+import java.util.Vector;\r
+\r
+import javax.swing.JOptionPane;\r
+\r
+import org.biodas.jdas.client.adapters.features.DasGFFAdapter;\r
+import org.biodas.jdas.client.adapters.features.DasGFFAdapter.GFFAdapter;\r
+import org.biodas.jdas.client.threads.FeaturesClientMultipleSources;\r
+import org.biodas.jdas.schema.features.ERRORSEGMENT;\r
+import org.biodas.jdas.schema.features.FEATURE;\r
+import org.biodas.jdas.schema.features.LINK;\r
+import org.biodas.jdas.schema.features.SEGMENT;\r
+import org.biodas.jdas.schema.features.TYPE;\r
+import org.biodas.jdas.schema.features.UNKNOWNFEATURE;\r
+import org.biodas.jdas.schema.features.UNKNOWNSEGMENT;\r
+import org.biodas.jdas.schema.sources.COORDINATES;\r
 \r
 /**\r
  * DOCUMENT ME!\r
@@ -51,7 +69,7 @@ public class DasSequenceFeatureFetcher
 \r
   StringBuffer sbuffer = new StringBuffer();\r
 \r
-  Vector selectedSources;\r
+  List<jalviewSourceI> selectedSources;\r
 \r
   boolean cancelled = false;\r
 \r
@@ -78,6 +96,8 @@ public class DasSequenceFeatureFetcher
 \r
   long startTime;\r
 \r
+  private DasSourceRegistryI sourceRegistry;\r
+\r
   /**\r
    * Creates a new SequenceFeatureFetcher object. Uses default\r
    * \r
@@ -93,18 +113,16 @@ public class DasSequenceFeatureFetcher
   }\r
 \r
   public DasSequenceFeatureFetcher(SequenceI[] oursequences,\r
-          FeatureSettings fsettings, Vector ourselectedSources,\r
+          FeatureSettings fsettings, List<jalviewSourceI> selectedSources2,\r
           boolean checkDbrefs, boolean promptFetchDbrefs)\r
   {\r
-    this.selectedSources = new Vector();\r
-    Enumeration sources = ourselectedSources.elements();\r
+    this.selectedSources = new ArrayList<jalviewSourceI>();\r
     // filter both sequences and sources to eliminate duplicates\r
-    while (sources.hasMoreElements())\r
+    for (jalviewSourceI src : selectedSources2)\r
     {\r
-      Object src = sources.nextElement();\r
       if (!selectedSources.contains(src))\r
       {\r
-        selectedSources.addElement(src);\r
+        selectedSources.add(src);\r
       }\r
       ;\r
     }\r
@@ -128,15 +146,13 @@ public class DasSequenceFeatureFetcher
       af.setShowSeqFeatures(true);\r
     }\r
     int uniprotCount = 0;\r
-    for (int i = 0; i < selectedSources.size(); i++)\r
+    for (jalviewSourceI source : selectedSources)\r
     {\r
-      DasSource source = (DasSource) selectedSources.elementAt(i);\r
-      DasCoordinateSystem[] coords = source.getCoordinateSystem();\r
-      for (int c = 0; c < coords.length; c++)\r
+      for (COORDINATES coords : source.getVersion().getCOORDINATES())\r
       {\r
         // TODO: match UniProt coord system canonically (?) - does\r
         // UniProt==uniprot==UNIPROT ?\r
-        if (coords[c].getName().indexOf("UniProt") > -1)\r
+        if (coords.getAuthority().toLowerCase().equals("uniprot"))\r
         {\r
           uniprotCount++;\r
           break;\r
@@ -185,28 +201,39 @@ public class DasSequenceFeatureFetcher
       }\r
       else\r
       {\r
-        startFetching();\r
+        _startFetching();\r
       }\r
     }\r
     else\r
     {\r
-      startFetching();\r
+      _startFetching();\r
     }\r
 \r
   }\r
-\r
+  private void _startFetching()\r
+  {\r
+    new Thread(new FetchSeqFeatures()).start();\r
+  }\r
+  class FetchSeqFeatures implements Runnable\r
+  {\r
+    public void run()\r
+    {\r
+      startFetching();\r
+      setGuiFetchComplete();\r
+    }\r
+  }\r
   class FetchDBRefs implements Runnable\r
   {\r
     public void run()\r
     {\r
       new DBRefFetcher(sequences, af).fetchDBRefs(true);\r
       startFetching();\r
+      setGuiFetchComplete();\r
     }\r
   }\r
 \r
   /**\r
-   * Spawns a number of dasobert Fetcher threads to add features to sequences in\r
-   * the dataset\r
+   * Spawns Fetcher threads to add features to sequences in the dataset\r
    */\r
   void startFetching()\r
   {\r
@@ -216,14 +243,16 @@ public class DasSequenceFeatureFetcher
     {\r
       af.setProgressBar("Fetching DAS Sequence Features", startTime);\r
     }\r
-\r
+    if (sourceRegistry == null)\r
+    {\r
+      sourceRegistry = Cache.getDasSourceRegistry();\r
+    }\r
     if (selectedSources == null || selectedSources.size() == 0)\r
     {\r
       try\r
       {\r
-        DasSource[] sources = new jalview.gui.DasSourceBrowser()\r
-                .getDASSource();\r
-\r
+        jalviewSourceI[] sources = sourceRegistry.getSources().toArray(\r
+                new jalviewSourceI[0]);\r
         String active = jalview.bin.Cache.getDefault("DAS_ACTIVE_SOURCE",\r
                 "uniprot");\r
         StringTokenizer st = new StringTokenizer(active, "\t");\r
@@ -234,9 +263,9 @@ public class DasSequenceFeatureFetcher
           token = st.nextToken();\r
           for (int i = 0; i < sources.length; i++)\r
           {\r
-            if (sources[i].getNickname().equals(token))\r
+            if (sources[i].getTitle().equals(token))\r
             {\r
-              selectedSources.addElement(sources[i]);\r
+              selectedSources.add(sources[i]);\r
               break;\r
             }\r
           }\r
@@ -257,14 +286,180 @@ public class DasSequenceFeatureFetcher
     }\r
 \r
     sourcesRemaining = selectedSources.size();\r
+    FeaturesClientMultipleSources fc = new FeaturesClientMultipleSources();\r
+    fc.setConnProps(sourceRegistry.getSessionHandler());\r
     // Now sending requests one at a time to each server\r
-    for (int sourceIndex = 0; sourceIndex < selectedSources.size()\r
-            && !cancelled; sourceIndex++)\r
+    ArrayList<jalviewSourceI> srcobj = new ArrayList<jalviewSourceI>();\r
+    ArrayList<String> src = new ArrayList<String>();\r
+    List<List<String>> ids = new ArrayList<List<String>>();\r
+    List<List<DBRefEntry>> idobj = new ArrayList<List<DBRefEntry>>();\r
+    List<Map<String, SequenceI>> sqset = new ArrayList<Map<String, SequenceI>>();\r
+    for (jalviewSourceI _sr : selectedSources)\r
     {\r
-      DasSource dasSource = (DasSource) selectedSources\r
-              .elementAt(sourceIndex);\r
 \r
-      nextSequence(dasSource, sequences[0]);\r
+      Map<String, SequenceI> slist = new HashMap<String, SequenceI>();\r
+      List<DBRefEntry> idob = new ArrayList<DBRefEntry>();\r
+      List<String> qset = new ArrayList<String>();\r
+\r
+      for (SequenceI seq : sequences)\r
+      {\r
+        Object[] idset = nextSequence(_sr, seq);\r
+        if (idset != null)\r
+        {\r
+          List<DBRefEntry> _idob = (List<DBRefEntry>) idset[0];\r
+          List<String> _qset = (List<String>) idset[1];\r
+          if (_idob.size() > 0)\r
+          {\r
+            // add sequence's ref for each id derived from it\r
+            // (space inefficient, but most unambiguous)\r
+            // could replace with hash with _qset values as keys.\r
+            Iterator<DBRefEntry> dbobj = _idob.iterator();\r
+            for (String q : _qset)\r
+            {\r
+              SequenceI osq = slist.get(q);\r
+              DBRefEntry dr = dbobj.next();\r
+              if (osq != null && osq != seq)\r
+              {\r
+                // skip - non-canonical query\r
+              }\r
+              else\r
+              {\r
+                idob.add(dr);\r
+                qset.add(q);\r
+                slist.put(q, seq);\r
+              }\r
+            }\r
+          }\r
+        }\r
+      }\r
+      if (idob.size() > 0)\r
+      {\r
+        srcobj.add(_sr);\r
+        src.add(_sr.getSourceURL());\r
+        ids.add(qset);\r
+        idobj.add(idob);\r
+        sqset.add(slist);\r
+      }\r
+    }\r
+    Map<String, Map<List<String>, Exception>> errors = new HashMap<String, Map<List<String>, Exception>>();\r
+    Map<String, Map<List<String>, DasGFFAdapter>> results = new HashMap<String, Map<List<String>, DasGFFAdapter>>();\r
+    fc.fetchData(src, ids, false, results, errors);\r
+    fc.shutDown();\r
+    while (!fc.isTerminated())\r
+    {\r
+      try\r
+      {\r
+        Thread.sleep(200);\r
+      } catch (InterruptedException x)\r
+      {\r
+\r
+      }\r
+    }\r
+    Iterator<List<String>> idset = ids.iterator();\r
+    Iterator<List<DBRefEntry>> idobjset = idobj.iterator();\r
+    Iterator<Map<String, SequenceI>> seqset = sqset.iterator();\r
+    for (jalviewSourceI source : srcobj)\r
+    {\r
+      processResponse(seqset.next(), source, idset.next(), idobjset.next(),\r
+              results.get(source.getSourceURL()),\r
+              errors.get(source.getSourceURL()));\r
+    }\r
+  }\r
+\r
+  private void processResponse(Map<String, SequenceI> sequencemap,\r
+          jalviewSourceI jvsource, List<String> ids,\r
+          List<DBRefEntry> idobj, Map<List<String>, DasGFFAdapter> results,\r
+          Map<List<String>, Exception> errors)\r
+  {\r
+    Set<SequenceI> sequences = new HashSet<SequenceI>();\r
+    String source = jvsource.getSourceURL();\r
+    // process features\r
+    DasGFFAdapter result = (results == null) ? null : results.get(ids);\r
+    Exception error = (errors == null) ? null : errors.get(ids);\r
+    if (result == null)\r
+    {\r
+      debug("das source " + source + " could not be contacted. "\r
+              + (error == null ? "" : error.toString()));\r
+    }\r
+    else\r
+    {\r
+\r
+      GFFAdapter gff = result.getGFF();\r
+      List<SEGMENT> segments = gff.getSegments();\r
+      List<ERRORSEGMENT> errorsegs = gff.getErrorSegments();\r
+      List<UNKNOWNFEATURE> unkfeats = gff.getUnknownFeatures();\r
+      List<UNKNOWNSEGMENT> unksegs = gff.getUnknownSegments();\r
+      debug("das source " + source + " returned " + gff.getTotal()\r
+              + " responses. " + (errorsegs != null ? errorsegs.size() : 0)\r
+              + " were incorrect segment queries, "\r
+              + (unkfeats != null ? unkfeats.size() : 0)\r
+              + " were unknown features "\r
+              + (unksegs != null ? unksegs.size() : 0)\r
+              + " were unknown segments and "\r
+              + (segments != null ? segments.size() : 0)\r
+              + " were segment responses.");\r
+      Iterator<DBRefEntry> dbr = idobj.iterator();\r
+      if (segments != null)\r
+      {\r
+        for (SEGMENT seg : segments)\r
+        {\r
+          String id = seg.getId();\r
+          DBRefEntry dbref = idobj.get(ids.indexOf(id));\r
+          SequenceI sequence = sequencemap.get(id);\r
+          boolean added = false;\r
+          sequences.add(sequence);\r
+\r
+          for (FEATURE feat : seg.getFEATURE())\r
+          {\r
+            // standard DAS feature-> jalview sequence feature transformation\r
+            SequenceFeature f = newSequenceFeature(feat, jvsource.getTitle());\r
+            if (!parseSeqFeature(sequence, f, feat, jvsource))\r
+            {\r
+              if (dbref.getMap() != null && f.getBegin() > 0\r
+                      && f.getEnd() > 0)\r
+              {\r
+                debug("mapping from " + f.getBegin() + " - " + f.getEnd());\r
+                SequenceFeature vf[] = null;\r
+\r
+                try\r
+                {\r
+                  vf = dbref.getMap().locateFeature(f);\r
+                } catch (Exception ex)\r
+                {\r
+                  Cache.log\r
+                          .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");\r
+                  Cache.log.info("Mapping feature from " + f.getBegin()\r
+                          + " to " + f.getEnd() + " in dbref "\r
+                          + dbref.getAccessionId() + " in "\r
+                          + dbref.getSource());\r
+                  Cache.log.info("using das Source " + source);\r
+                  Cache.log.info("Exception", ex);\r
+                }\r
+\r
+                if (vf != null)\r
+                {\r
+                  for (int v = 0; v < vf.length; v++)\r
+                  {\r
+                    debug("mapping to " + v + ": " + vf[v].getBegin()\r
+                            + " - " + vf[v].getEnd());\r
+                    sequence.addSequenceFeature(vf[v]);\r
+                  }\r
+                }\r
+              }\r
+              else\r
+              {\r
+                sequence.addSequenceFeature(f);\r
+              }\r
+            }\r
+          }\r
+        }\r
+        featuresAdded(sequences);\r
+      }\r
+      else\r
+      {\r
+        // System.out.println("No features found for " + seq.getName()\r
+        // + " from: " + e.getDasSource().getNickname());\r
+      }\r
     }\r
   }\r
 \r
@@ -310,30 +505,6 @@ public class DasSequenceFeatureFetcher
 \r
   int sourcesRemaining = 0;\r
 \r
-  void responseComplete(DasSource dasSource, SequenceI seq)\r
-  {\r
-    if (seq != null)\r
-    {\r
-      for (int seqIndex = 0; seqIndex < sequences.length - 1 && !cancelled; seqIndex++)\r
-      {\r
-        if (sequences[seqIndex] == seq)\r
-        {\r
-          nextSequence(dasSource, sequences[++seqIndex]);\r
-          return;\r
-        }\r
-      }\r
-    }\r
-\r
-    sourcesRemaining--;\r
-\r
-    if (sourcesRemaining == 0)\r
-    {\r
-      System.err.println("Fetching Complete.");\r
-      setGuiFetchComplete();\r
-    }\r
-\r
-  }\r
-\r
   private void setGuiFetchComplete()\r
   {\r
 \r
@@ -354,7 +525,7 @@ public class DasSequenceFeatureFetcher
     }\r
   }\r
 \r
-  void featuresAdded(SequenceI seq)\r
+  void featuresAdded(Set<SequenceI> seqs)\r
   {\r
     if (af == null)\r
     {\r
@@ -368,19 +539,23 @@ public class DasSequenceFeatureFetcher
     int index;\r
     for (index = start; index < end; index++)\r
     {\r
-      if (seq == af.getViewport().getAlignment().getSequenceAt(index)\r
-              .getDatasetSequence())\r
+      for (SequenceI seq : seqs)\r
       {\r
-        af.alignPanel.paintAlignment(true);\r
-        break;\r
+        if (seq == af.getViewport().getAlignment().getSequenceAt(index)\r
+                .getDatasetSequence())\r
+        {\r
+          af.alignPanel.paintAlignment(true);\r
+          index = end;\r
+          break;\r
+        }\r
       }\r
     }\r
   }\r
 \r
-  void nextSequence(DasSource dasSource, SequenceI seq)\r
+  Object[] nextSequence(jalviewSourceI dasSource, SequenceI seq)\r
   {\r
     if (cancelled)\r
-      return;\r
+      return null;\r
     DBRefEntry[] uprefs = jalview.util.DBRefUtils.selectRefs(\r
             seq.getDBRef(), new String[]\r
             {\r
@@ -392,6 +567,8 @@ public class DasSequenceFeatureFetcher
     // TODO: minimal list of DAS queries to make by querying with untyped ID if\r
     // distinct from any typed IDs\r
 \r
+    List<DBRefEntry> ids = new ArrayList<DBRefEntry>();\r
+    List<String> qstring = new ArrayList<String>();\r
     boolean dasCoordSysFound = false;\r
 \r
     if (uprefs != null)\r
@@ -399,29 +576,28 @@ public class DasSequenceFeatureFetcher
       // do any of these ids match the source's coordinate system ?\r
       for (int j = 0; !dasCoordSysFound && j < uprefs.length; j++)\r
       {\r
-        DasCoordinateSystem cs[] = dasSource.getCoordinateSystem();\r
 \r
-        for (int csIndex = 0; csIndex < cs.length && !dasCoordSysFound; csIndex++)\r
+        for (COORDINATES csys : dasSource.getVersion().getCOORDINATES())\r
         {\r
-          if (cs.length > 0\r
-                  && jalview.util.DBRefUtils.isDasCoordinateSystem(\r
-                          cs[csIndex].getName(), uprefs[j]))\r
+          if (jalview.util.DBRefUtils.isDasCoordinateSystem(\r
+                  csys.getAuthority(), uprefs[j]))\r
           {\r
             debug("Launched fetcher for coordinate system "\r
-                    + cs[0].getName());\r
+                    + csys.getAuthority());\r
             // Will have to pass any mapping information to the fetcher\r
             // - the start/end for the DBRefEntry may not be the same as the\r
             // sequence's start/end\r
 \r
             System.out.println(seq.getName() + " "\r
                     + (seq.getDatasetSequence() == null) + " "\r
-                    + dasSource.getUrl());\r
+                    + csys.getUri());\r
 \r
             dasCoordSysFound = true; // break's out of the loop\r
-            createFeatureFetcher(seq, dasSource, uprefs[j]);\r
+            ids.add(uprefs[j]);\r
+            qstring.add(uprefs[j].getAccessionId());\r
           }\r
           else\r
-            System.out.println("IGNORE " + cs[csIndex].getName());\r
+            System.out.println("IGNORE " + csys.getAuthority());\r
         }\r
       }\r
     }\r
@@ -450,204 +626,17 @@ public class DasSequenceFeatureFetcher
       }\r
       if (id != null)\r
       {\r
+        DBRefEntry dbre = new DBRefEntry();\r
+        dbre.setAccessionId(id);\r
         // Should try to call a general feature fetcher that\r
         // queries many sources with name to discover applicable ID references\r
-        createFeatureFetcher(seq, dasSource, id);\r
+        ids.add(dbre);\r
+        qstring.add(dbre.getAccessionId());\r
       }\r
     }\r
 \r
-  }\r
-\r
-  /**\r
-   * fetch and add das features to a sequence using the given source URL and\r
-   * compatible DbRef id. new features are mapped using the DbRef mapping to the\r
-   * local coordinate system.\r
-   * \r
-   * @param seq\r
-   * @param SourceUrl\r
-   * @param dbref\r
-   */\r
-  protected void createFeatureFetcher(final SequenceI seq,\r
-          final DasSource dasSource, final DBRefEntry dbref)\r
-  {\r
-\r
-    // ////////////\r
-    // / fetch DAS features\r
-    final Das1Source source = new Das1Source();\r
-    source.setUrl(dasSource.getUrl());\r
-    source.setNickname(dasSource.getNickname());\r
-    if (dbref == null || dbref.getAccessionId() == null\r
-            || dbref.getAccessionId().length() < 1)\r
-    {\r
-      responseComplete(dasSource, seq); // reduce thread count anyhow\r
-      return;\r
-    }\r
-    debug("new Das Feature Fetcher for " + dbref.getSource() + ":"\r
-            + dbref.getAccessionId() + " querying " + dasSource.getUrl());\r
-    FeatureThread fetcher = new FeatureThread(dbref.getAccessionId()\r
-    // + ":" + start + "," + end,\r
-            , source);\r
-\r
-    fetcher.addFeatureListener(new FeatureListener()\r
-    {\r
-      public void comeBackLater(FeatureEvent e)\r
-      {\r
-        responseComplete(dasSource, seq);\r
-        debug("das source " + e.getSource().getNickname()\r
-                + " asked us to come back in " + e.getComeBackLater()\r
-                + " secs.");\r
-      }\r
-\r
-      public void newFeatures(FeatureEvent e)\r
-      {\r
-\r
-        Das1Source ds = e.getSource();\r
-\r
-        Map[] features = e.getFeatures();\r
-        // add features to sequence\r
-        debug("das source " + ds.getUrl() + " returned " + features.length\r
-                + " features");\r
-\r
-        if (features.length > 0)\r
-        {\r
-          for (int i = 0; i < features.length; i++)\r
-          {\r
-            // standard DAS feature-> jalview sequence feature transformation\r
-            SequenceFeature f = newSequenceFeature(features[i],\r
-                    source.getNickname());\r
-            if (!parseSeqFeature(seq, f, features[i], source))\r
-            {\r
-              if (dbref.getMap() != null && f.getBegin() > 0\r
-                      && f.getEnd() > 0)\r
-              {\r
-                debug("mapping from " + f.getBegin() + " - " + f.getEnd());\r
-                SequenceFeature vf[] = null;\r
-\r
-                try\r
-                {\r
-                  vf = dbref.getMap().locateFeature(f);\r
-                } catch (Exception ex)\r
-                {\r
-                  Cache.log\r
-                          .info("Error in 'experimental' mapping of features. Please try to reproduce and then report info to jalview-discuss@jalview.org.");\r
-                  Cache.log.info("Mapping feature from " + f.getBegin()\r
-                          + " to " + f.getEnd() + " in dbref "\r
-                          + dbref.getAccessionId() + " in "\r
-                          + dbref.getSource());\r
-                  Cache.log.info("using das Source " + ds.getUrl());\r
-                  Cache.log.info("Exception", ex);\r
-                }\r
-\r
-                if (vf != null)\r
-                {\r
-                  for (int v = 0; v < vf.length; v++)\r
-                  {\r
-                    debug("mapping to " + v + ": " + vf[v].getBegin()\r
-                            + " - " + vf[v].getEnd());\r
-                    seq.addSequenceFeature(vf[v]);\r
-                  }\r
-                }\r
-              }\r
-              else\r
-              {\r
-                seq.addSequenceFeature(f);\r
-              }\r
-            }\r
-          }\r
-          featuresAdded(seq);\r
-        }\r
-        else\r
-        {\r
-          // System.out.println("No features found for " + seq.getName()\r
-          // + " from: " + e.getDasSource().getNickname());\r
-        }\r
-        responseComplete(dasSource, seq);\r
-\r
-      }\r
-    }\r
-\r
-    );\r
-\r
-    fetcher.start();\r
-  }\r
-\r
-  protected void createFeatureFetcher(final SequenceI seq,\r
-          final DasSource dasSource, String id)\r
-  {\r
-    // ////////////\r
-    // / fetch DAS features\r
-    final Das1Source source = new Das1Source();\r
-    source.setUrl(dasSource.getUrl());\r
-    source.setNickname(dasSource.getNickname());\r
-\r
-    if (id != null)\r
-    {\r
-      id = id.trim();\r
-    }\r
-    if (id != null && id.length() > 0)\r
-    {\r
-      debug("new Das Feature Fetcher for " + id + " querying "\r
-              + dasSource.getUrl());\r
-      FeatureThread fetcher = new FeatureThread(id\r
-      // + ":" + start + "," + end,\r
-              , source);\r
-\r
-      fetcher.addFeatureListener(new FeatureListener()\r
-      {\r
-        public void comeBackLater(FeatureEvent e)\r
-        {\r
-          responseComplete(dasSource, seq);\r
-          debug("das source " + e.getSource().getNickname()\r
-                  + " asked us to come back in " + e.getComeBackLater()\r
-                  + " secs.");\r
-        }\r
-\r
-        public void newFeatures(FeatureEvent e)\r
-        {\r
-\r
-          Das1Source ds = e.getSource();\r
-\r
-          Map[] features = e.getFeatures();\r
-          // add features to sequence\r
-          debug("das source " + ds.getUrl() + " returned "\r
-                  + features.length + " features");\r
-\r
-          if (features.length > 0)\r
-          {\r
-            for (int i = 0; i < features.length; i++)\r
-            {\r
-              // standard DAS feature-> jalview sequence feature transformation\r
-              SequenceFeature f = newSequenceFeature(features[i],\r
-                      source.getNickname());\r
-              if (!parseSeqFeature(seq, f, features[i], source))\r
-              {\r
-                // just add as a simple sequence feature\r
-                seq.addSequenceFeature(f);\r
-              }\r
-            }\r
-\r
-            featuresAdded(seq);\r
-          }\r
-          else\r
-          {\r
-            // System.out.println("No features found for " + seq.getName()\r
-            // + " from: " + e.getDasSource().getNickname());\r
-          }\r
-          responseComplete(dasSource, seq);\r
-\r
-        }\r
-      }\r
-\r
-      );\r
-\r
-      fetcher.start();\r
-    }\r
-    else\r
-    {\r
-      // invalid fetch - indicate it is finished.\r
-      debug("Skipping empty ID for querying " + dasSource.getUrl());\r
-      responseComplete(dasSource, seq);\r
-    }\r
+    return new Object[]\r
+    { ids, qstring };\r
   }\r
 \r
   /**\r
@@ -666,7 +655,7 @@ public class DasSequenceFeatureFetcher
    * @return true if feature was consumed as another kind of annotation.\r
    */\r
   protected boolean parseSeqFeature(SequenceI seq, SequenceFeature f,\r
-          Map map, Das1Source source)\r
+          FEATURE feature, jalviewSourceI source)\r
   {\r
     SequenceI mseq = seq;\r
     while (seq.getDatasetSequence() != null)\r
@@ -701,7 +690,7 @@ public class DasSequenceFeatureFetcher
         // try to parse the accession out\r
 \r
         DBRefEntry dbr = new DBRefEntry();\r
-        dbr.setVersion(source.getNickname());\r
+        dbr.setVersion(source.getTitle());\r
         StringTokenizer st = new StringTokenizer(f.getDescription(), ":");\r
         if (st.hasMoreTokens())\r
         {\r
@@ -757,12 +746,12 @@ public class DasSequenceFeatureFetcher
   /**\r
    * creates a jalview sequence feature from a das feature document\r
    * \r
-   * @param dasfeature\r
+   * @param feat\r
    * @return sequence feature object created using dasfeature information\r
    */\r
-  SequenceFeature newSequenceFeature(Map dasfeature, String nickname)\r
+  SequenceFeature newSequenceFeature(FEATURE feat, String nickname)\r
   {\r
-    if (dasfeature == null)\r
+    if (feat == null)\r
     {\r
       return null;\r
     }\r
@@ -775,9 +764,12 @@ public class DasSequenceFeatureFetcher
        * qName.equals("SCORE")\r
        */\r
       String desc = new String();\r
-      if (dasfeature.containsKey("NOTE"))\r
+      if (feat.getNOTE() != null)\r
       {\r
-        desc += (String) dasfeature.get("NOTE");\r
+        for (String note : feat.getNOTE())\r
+        {\r
+          desc += (String) note;\r
+        }\r
       }\r
 \r
       int start = 0, end = 0;\r
@@ -785,19 +777,19 @@ public class DasSequenceFeatureFetcher
 \r
       try\r
       {\r
-        start = Integer.parseInt(dasfeature.get("START").toString());\r
+        start = Integer.parseInt(feat.getSTART().toString());\r
       } catch (Exception ex)\r
       {\r
       }\r
       try\r
       {\r
-        end = Integer.parseInt(dasfeature.get("END").toString());\r
+        end = Integer.parseInt(feat.getEND().toString());\r
       } catch (Exception ex)\r
       {\r
       }\r
       try\r
       {\r
-        Object scr = dasfeature.get("SCORE");\r
+        Object scr = feat.getSCORE();\r
         if (scr != null)\r
         {\r
           score = (float) Double.parseDouble(scr.toString());\r
@@ -808,20 +800,24 @@ public class DasSequenceFeatureFetcher
       }\r
 \r
       SequenceFeature f = new SequenceFeature(\r
-              (String) dasfeature.get("TYPE"), desc, start, end, score,\r
+              getTypeString(feat.getTYPE()), desc, start, end, score,\r
               nickname);\r
 \r
-      if (dasfeature.containsKey("LINK"))\r
+      if (feat.getLINK() != null)\r
       {\r
-        // Do not put feature extent in link text for non-positional features\r
-        if (f.begin == 0 && f.end == 0)\r
-        {\r
-          f.addLink(f.getType() + "|" + dasfeature.get("LINK"));\r
-        }\r
-        else\r
+        for (LINK link : feat.getLINK())\r
         {\r
-          f.addLink(f.getType() + " " + f.begin + "_" + f.end + "|"\r
-                  + dasfeature.get("LINK"));\r
+          // Do not put feature extent in link text for non-positional features\r
+          if (f.begin == 0 && f.end == 0)\r
+          {\r
+            f.addLink(f.getType() + " " + link.getContent() + "|"\r
+                    + link.getHref());\r
+          }\r
+          else\r
+          {\r
+            f.addLink(f.getType() + " " + f.begin + "_" + f.end + " "\r
+                    + link.getContent() + "|" + link.getHref());\r
+          }\r
         }\r
       }\r
 \r
@@ -831,52 +827,14 @@ public class DasSequenceFeatureFetcher
       System.out.println("ERRR " + e);\r
       e.printStackTrace();\r
       System.out.println("############");\r
-      debug("Failed to parse " + dasfeature.toString(), e);\r
+      debug("Failed to parse " + feat.toString(), e);\r
       return null;\r
     }\r
   }\r
 \r
-  /**\r
-   * query the default DAS Source Registry for sources. Uses value of jalview\r
-   * property DAS_REGISTRY_URL and the DasSourceBrowser.DEFAULT_REGISTRY if that\r
-   * doesn't exist.\r
-   * \r
-   * @return list of sources\r
-   */\r
-  public static SOURCE[] getDASSources()\r
-  {\r
-\r
-    String registryURL = jalview.bin.Cache.getDefault("DAS_REGISTRY_URL",\r
-            DasSourceBrowser.DEFAULT_REGISTRY);\r
-    return getDASSources(registryURL);\r
-  }\r
-\r
-  /**\r
-   * query the given URL for DasSources.\r
-   * \r
-   * @param registryURL\r
-   *          return sources from registryURL\r
-   */\r
-  public static SOURCE[] getDASSources(String registryURL)\r
+  private String getTypeString(TYPE type)\r
   {\r
-    \r
-    try\r
-    {\r
-      URL url = new URL(registryURL);\r
-      org.biodas.jdas.client.SourcesClientInterface client = new SourcesClient();\r
-      \r
-      SOURCES sources = client.fetchData(registryURL);\r
-\r
-      List<SOURCE> dassources = sources.getSOURCE();\r
-\r
-      return dassources.toArray(new SOURCE[dassources.size()]);\r
-    } catch (Exception ex)\r
-    {\r
-      System.err.println("Failed to contact DAS1 registry at "\r
-              + registryURL);\r
-      ex.printStackTrace();\r
-      return null;\r
-    }\r
+    return type.getContent();\r
   }\r
 \r
 }\r