JAL-1432 updated copyright notices
[jalview.git] / src / jalview / ws / SequenceFetcher.java
index 14b6997..ce3e952 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
- * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
+ * Copyright (C) 2014 The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
  * PURPOSE.  See the GNU General Public License for more details.
  * 
  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
  */
-package jalview.ws;\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.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
- * discovery of sequence database clients, and provides a hardwired main for\r
- * testing all registered handlers.\r
- * \r
- */\r
-public class SequenceFetcher extends ASequenceFetcher\r
-{\r
-  /**\r
-   * Thread safe construction of database proxies TODO: extend to a configurable\r
-   * database plugin mechanism where classes are instantiated by reflection and\r
-   * queried for their DbRefSource and version association.\r
-   * \r
-   */\r
-  public SequenceFetcher()\r
-  {\r
-    this(true);\r
-  }\r
-  public SequenceFetcher(boolean addDas)\r
-  {\r
-    addDBRefSourceImpl(jalview.ws.dbsources.EmblSource.class);\r
-    addDBRefSourceImpl(jalview.ws.dbsources.EmblCdsSouce.class);\r
-    addDBRefSourceImpl(jalview.ws.dbsources.Uniprot.class);\r
-    addDBRefSourceImpl(jalview.ws.dbsources.UnprotName.class);\r
-    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
-    addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class);\r
-    addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class);\r
-    if (addDas) {\r
-      registerDasSequenceSources();\r
-    }\r
-  }\r
-\r
-  /**\r
-   * return an ordered list of database sources where non-das database classes\r
-   * appear before das database classes\r
-   */\r
-  public String[] getOrderedSupportedSources()\r
-  {\r
-    String[] srcs = this.getSupportedDb();\r
-    ArrayList<String> dassrc = new ArrayList<String>(), nondas = new ArrayList<String>();\r
-    for (int i = 0; i < srcs.length; i++)\r
-    {\r
-      boolean das = false, skip = false;\r
-      String nm;\r
-      for (DbSourceProxy dbs : getSourceProxy(srcs[i]))\r
-      {\r
-        // Skip the alignment databases for the moment - they're not useful for\r
-        // verifying a single sequence against its reference source\r
-        if (dbs.isA(DBRefSource.ALIGNMENTDB))\r
-        {\r
-          skip = true;\r
-        }\r
-        else\r
-        {\r
-          nm = dbs.getDbName();\r
-          if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)\r
-          {\r
-            if (nm.startsWith("das:"))\r
-            {\r
-              nm = nm.substring(4);\r
-              das = true;\r
-            }\r
-            break;\r
-          }\r
-        }\r
-      }\r
-      if (skip)\r
-      {\r
-        continue;\r
-      }\r
-      if (das)\r
-      {\r
-        dassrc.add(srcs[i]);\r
-      }\r
-      else\r
-      {\r
-        nondas.add(srcs[i]);\r
-      }\r
-    }\r
-    String[] tosort = nondas.toArray(new String[0]), sorted = nondas\r
-            .toArray(new String[0]);\r
-    for (int j = 0, jSize = sorted.length; j < jSize; j++)\r
-    {\r
-      tosort[j] = tosort[j].toLowerCase();\r
-    }\r
-    jalview.util.QuickSort.sort(tosort, sorted);\r
-    // construct array with all sources listed\r
-\r
-    srcs = new String[sorted.length + dassrc.size()];\r
-    int i = 0;\r
-    for (int j = sorted.length - 1; j >= 0; j--, i++)\r
-    {\r
-      srcs[i] = sorted[j];\r
-      sorted[j] = null;\r
-    }\r
-\r
-    sorted = dassrc.toArray(new String[0]);\r
-    tosort = dassrc.toArray(new String[0]);\r
-    for (int j = 0, jSize = sorted.length; j < jSize; j++)\r
-    {\r
-      tosort[j] = tosort[j].toLowerCase();\r
-    }\r
-    jalview.util.QuickSort.sort(tosort, sorted);\r
-    for (int j = sorted.length - 1; j >= 0; j--, i++)\r
-    {\r
-      srcs[i] = sorted[j];\r
-    }\r
-    return srcs;\r
-  }\r
-\r
-  /**\r
-   * return plaintext databse list suitable for using in a GUI element\r
-   */\r
-  public String[] _getOrderedSupportedSources()\r
-  {\r
-    String[] srcs = this.getSupportedDb();\r
-    ArrayList dassrc = new ArrayList(), nondas = new ArrayList();\r
-    for (int i = 0; i < srcs.length; i++)\r
-    {\r
-      for (DbSourceProxy dbs : getSourceProxy(srcs[i]))\r
-      {\r
-        String nm = dbs.getDbName();\r
-        if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)\r
-        {\r
-          if (nm.startsWith("das:"))\r
-          {\r
-            nm = nm.substring(4);\r
-          }\r
-          dassrc.add(new String[]\r
-          { srcs[i], nm.toUpperCase() });\r
-        }\r
-        else\r
-        {\r
-          nondas.add(new String[]\r
-          { srcs[i], nm.toUpperCase() });\r
-        }\r
-      }\r
-    }\r
-    Object[] sorted = nondas.toArray();\r
-    String[] tosort = new String[sorted.length];\r
-    nondas.clear();\r
-    for (int j = 0; j < sorted.length; j++)\r
-    {\r
-      tosort[j] = ((String[]) sorted[j])[1];\r
-    }\r
-    jalview.util.QuickSort.sort(tosort, sorted);\r
-    int i = 0;\r
-    // construct array with all sources listed\r
-    srcs = new String[sorted.length + dassrc.size()];\r
-    for (int j = sorted.length - 1; j >= 0; j--, i++)\r
-    {\r
-      srcs[i] = ((String[]) sorted[j])[0];\r
-      sorted[j] = null;\r
-    }\r
-\r
-    sorted = dassrc.toArray();\r
-    tosort = new String[sorted.length];\r
-    dassrc.clear();\r
-    for (int j = 0; j < sorted.length; j++)\r
-    {\r
-      tosort[j] = ((String[]) sorted[j])[1];\r
-    }\r
-    jalview.util.QuickSort.sort(tosort, sorted);\r
-    for (int j = sorted.length - 1; j >= 0; j--, i++)\r
-    {\r
-      srcs[i] = ((String[]) sorted[j])[0];\r
-      sorted[j] = null;\r
-    }\r
-    return srcs;\r
-  }\r
-\r
-  /**\r
-   * simple run method to test dbsources.\r
-   * \r
-   * @param argv\r
-   */\r
-  public static void main(String[] argv)\r
-  {\r
-    AlignmentI ds = null;\r
-    Vector noProds = new Vector();\r
-    String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"\r
-            + "With no arguments, all DbSources will be queried with their test Accession number.\n"\r
-            + "With one argument, the argument will be resolved to one or more db sources and each will be queried with their test accession only.\n"\r
-            + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"\r
-            + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";\r
-    boolean withDas=true;\r
-    if (argv!=null && argv.length>0 && argv[0].toLowerCase().startsWith("-nodas"))\r
-    {\r
-      withDas=false;\r
-      String targs[] = new String[argv.length-1];\r
-      System.arraycopy(argv, 1, targs, 0, targs.length);\r
-      argv=targs;\r
-    }\r
-    if (argv != null && argv.length > 0)\r
-    {\r
-      List<DbSourceProxy> sps = new SequenceFetcher(withDas)\r
-              .getSourceProxy(argv[0]);\r
-\r
-      if (sps != null)\r
-      {\r
-        for (DbSourceProxy sp : sps)\r
-        {\r
-          AlignmentI al = null;\r
-          try\r
-          {\r
-            al = sp.getSequenceRecords(argv.length>1 ? argv[1] : sp.getTestQuery());\r
-          } catch (Exception e)\r
-          {\r
-            e.printStackTrace();\r
-            System.err.println("Error when retrieving " + (argv.length>1 ? argv[1] : sp.getTestQuery())\r
-                    + " from " + argv[0] + "\nUsage: " + usage);\r
-          }\r
-          SequenceI[] prod = al.getSequencesArray();\r
-          if (al != null)\r
-          {\r
-            for (int p = 0; p < prod.length; p++)\r
-            {\r
-              System.out.println("Prod " + p + ": "\r
-                      + prod[p].getDisplayId(true) + " : "\r
-                      + prod[p].getDescription());\r
-            }\r
-          }\r
-        }\r
-        return;\r
-      }\r
-      else\r
-      {\r
-        System.err.println("Can't resolve " + argv[0]\r
-                + " as a database name. Allowed values are :\n"\r
-                + new SequenceFetcher().getSupportedDb());\r
-      }\r
-      System.out.println(usage);\r
-      return;\r
-    }\r
-    ASequenceFetcher sfetcher = new SequenceFetcher(withDas);\r
-    String[] dbSources = sfetcher.getSupportedDb();\r
-    for (int dbsource = 0; dbsource < dbSources.length; dbsource++)\r
-    {\r
-      String db = dbSources[dbsource];\r
-      // skip me\r
-      if (db.equals(DBRefSource.PDB))\r
-        continue;\r
-      for (DbSourceProxy sp : sfetcher.getSourceProxy(db))\r
-      {\r
-        System.out.println("Source: " + sp.getDbName() + " (" + db\r
-                + "): retrieving test:" + sp.getTestQuery());\r
-        AlignmentI al = null;\r
-        try\r
-        {\r
-          al = sp.getSequenceRecords(sp.getTestQuery());\r
-          if (al != null && al.getHeight() > 0\r
-                  && sp.getDbSourceProperties() != null)\r
-          {\r
-            boolean dna = sp.getDbSourceProperties().containsKey(\r
-                    DBRefSource.DNACODINGSEQDB)\r
-                    || sp.getDbSourceProperties().containsKey(\r
-                            DBRefSource.DNASEQDB)\r
-                    || sp.getDbSourceProperties().containsKey(\r
-                            DBRefSource.CODINGSEQDB);\r
-            // try and find products\r
-            String types[] = jalview.analysis.CrossRef\r
-                    .findSequenceXrefTypes(dna, al.getSequencesArray());\r
-            if (types != null)\r
-            {\r
-              System.out.println("Xref Types for: "\r
-                      + (dna ? "dna" : "prot"));\r
-              for (int t = 0; t < types.length; t++)\r
-              {\r
-                System.out.println("Type: " + types[t]);\r
-                SequenceI[] prod = jalview.analysis.CrossRef\r
-                        .findXrefSequences(al.getSequencesArray(), dna,\r
-                                types[t]).getSequencesArray();\r
-                System.out.println("Found "\r
-                        + ((prod == null) ? "no" : "" + prod.length)\r
-                        + " products");\r
-                if (prod != null)\r
-                {\r
-                  for (int p = 0; p < prod.length; p++)\r
-                  {\r
-                    System.out.println("Prod " + p + ": "\r
-                            + prod[p].getDisplayId(true));\r
-                  }\r
-                }\r
-              }\r
-            }\r
-            else\r
-            {\r
-              noProds.addElement((dna ? new Object[]\r
-              { al, al } : new Object[]\r
-              { al }));\r
-            }\r
-\r
-          }\r
-        } catch (Exception ex)\r
-        {\r
-          System.out.println("ERROR:Failed to retrieve test query.");\r
-          ex.printStackTrace(System.out);\r
-        }\r
-\r
-        if (al == null)\r
-        {\r
-          System.out.println("ERROR:No alignment retrieved.");\r
-          StringBuffer raw = sp.getRawRecords();\r
-          if (raw != null)\r
-            System.out.println(raw.toString());\r
-          else\r
-            System.out.println("ERROR:No Raw results.");\r
-        }\r
-        else\r
-        {\r
-          System.out.println("Retrieved " + al.getHeight() + " sequences.");\r
-          for (int s = 0; s < al.getHeight(); s++)\r
-          {\r
-            SequenceI sq = al.getSequenceAt(s);\r
-            while (sq.getDatasetSequence() != null)\r
-            {\r
-              sq = sq.getDatasetSequence();\r
-\r
-            }\r
-            if (ds == null)\r
-            {\r
-              ds = new Alignment(new SequenceI[]\r
-              { sq });\r
-\r
-            }\r
-            else\r
-            {\r
-              ds.addSequence(sq);\r
-            }\r
-          }\r
-        }\r
-        System.out.flush();\r
-        System.err.flush();\r
-\r
-      }\r
-      if (noProds.size() > 0)\r
-      {\r
-        Enumeration ts = noProds.elements();\r
-        while (ts.hasMoreElements())\r
-\r
-        {\r
-          Object[] typeSq = (Object[]) ts.nextElement();\r
-          boolean dna = (typeSq.length > 1);\r
-          AlignmentI al = (AlignmentI) typeSq[0];\r
-          System.out.println("Trying getProducts for "\r
-                  + al.getSequenceAt(0).getDisplayId(true));\r
-          System.out.println("Search DS Xref for: "\r
-                  + (dna ? "dna" : "prot"));\r
-          // have a bash at finding the products amongst all the retrieved\r
-          // sequences.\r
-          SequenceI[] seqs = al.getSequencesArray();\r
-          Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(\r
-                  seqs, dna, null, ds);\r
-          System.out.println("Found "\r
-                  + ((prodal == null) ? "no" : "" + prodal.getHeight())\r
-                  + " products");\r
-          if (prodal != null)\r
-          {\r
-            SequenceI[] prod = prodal.getSequencesArray(); // note\r
-            // should\r
-            // test\r
-            // rather\r
-            // than\r
-            // throw\r
-            // away\r
-            // codon\r
-            // mapping\r
-            // (if\r
-            // present)\r
-            for (int p = 0; p < prod.length; p++)\r
-            {\r
-              System.out.println("Prod " + p + ": "\r
-                      + prod[p].getDisplayId(true));\r
-            }\r
-          }\r
-        }\r
-\r
-      }\r
-\r
-    }\r
-  }\r
-\r
-  /**\r
-   * query the currently defined DAS source registry for sequence sources and\r
-   * add a DasSequenceSource instance for each source to the SequenceFetcher\r
-   * source list.\r
-   */\r
-  public void registerDasSequenceSources()\r
-  {\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()\r
-            .getSources())\r
-    {\r
-      if (source.isSequenceSource())\r
-      {\r
-        List<DbSourceProxy> dassources = source.getSequenceSourceProxies();\r
-        for (DbSourceProxy seqsrc : dassources)\r
-        {\r
-          addDbRefSourceImpl(seqsrc);\r
-        }\r
-      }\r
-    }\r
-  }\r
-\r
-}\r
+package jalview.ws;
+
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.DBRefSource;
+import jalview.datamodel.SequenceI;
+import jalview.ws.dbsources.das.api.jalviewSourceI;
+import jalview.ws.seqfetcher.ASequenceFetcher;
+import jalview.ws.seqfetcher.DbSourceProxy;
+
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * This is the the concrete implementation of the sequence retrieval interface
+ * and abstract class in jalview.ws.seqfetcher. This implements the run-time
+ * discovery of sequence database clients, and provides a hardwired main for
+ * testing all registered handlers.
+ * 
+ */
+public class SequenceFetcher extends ASequenceFetcher
+{
+  /**
+   * Thread safe construction of database proxies TODO: extend to a configurable
+   * database plugin mechanism where classes are instantiated by reflection and
+   * queried for their DbRefSource and version association.
+   * 
+   */
+  public SequenceFetcher()
+  {
+    this(true);
+  }
+  public SequenceFetcher(boolean addDas)
+  {
+    addDBRefSourceImpl(jalview.ws.dbsources.EmblSource.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.EmblCdsSouce.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.Uniprot.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.UnprotName.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.Pdb.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.PfamFull.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.PfamSeed.class); // ensures Seed
+    // alignment is
+    // 'default' for
+    // PFAM
+    addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class);
+    addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class);
+    if (addDas) {
+      registerDasSequenceSources();
+    }
+  }
+
+  /**
+   * return an ordered list of database sources where non-das database classes
+   * appear before das database classes
+   */
+  public String[] getOrderedSupportedSources()
+  {
+    String[] srcs = this.getSupportedDb();
+    ArrayList<String> dassrc = new ArrayList<String>(), nondas = new ArrayList<String>();
+    for (int i = 0; i < srcs.length; i++)
+    {
+      boolean das = false, skip = false;
+      String nm;
+      for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
+      {
+        // Skip the alignment databases for the moment - they're not useful for
+        // verifying a single sequence against its reference source
+        if (dbs.isA(DBRefSource.ALIGNMENTDB))
+        {
+          skip = true;
+        }
+        else
+        {
+          nm = dbs.getDbName();
+          if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
+          {
+            if (nm.startsWith("das:"))
+            {
+              nm = nm.substring(4);
+              das = true;
+            }
+            break;
+          }
+        }
+      }
+      if (skip)
+      {
+        continue;
+      }
+      if (das)
+      {
+        dassrc.add(srcs[i]);
+      }
+      else
+      {
+        nondas.add(srcs[i]);
+      }
+    }
+    String[] tosort = nondas.toArray(new String[0]), sorted = nondas
+            .toArray(new String[0]);
+    for (int j = 0, jSize = sorted.length; j < jSize; j++)
+    {
+      tosort[j] = tosort[j].toLowerCase();
+    }
+    jalview.util.QuickSort.sort(tosort, sorted);
+    // construct array with all sources listed
+
+    srcs = new String[sorted.length + dassrc.size()];
+    int i = 0;
+    for (int j = sorted.length - 1; j >= 0; j--, i++)
+    {
+      srcs[i] = sorted[j];
+      sorted[j] = null;
+    }
+
+    sorted = dassrc.toArray(new String[0]);
+    tosort = dassrc.toArray(new String[0]);
+    for (int j = 0, jSize = sorted.length; j < jSize; j++)
+    {
+      tosort[j] = tosort[j].toLowerCase();
+    }
+    jalview.util.QuickSort.sort(tosort, sorted);
+    for (int j = sorted.length - 1; j >= 0; j--, i++)
+    {
+      srcs[i] = sorted[j];
+    }
+    return srcs;
+  }
+
+  /**
+   * return plaintext databse list suitable for using in a GUI element
+   */
+  public String[] _getOrderedSupportedSources()
+  {
+    String[] srcs = this.getSupportedDb();
+    ArrayList dassrc = new ArrayList(), nondas = new ArrayList();
+    for (int i = 0; i < srcs.length; i++)
+    {
+      for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
+      {
+        String nm = dbs.getDbName();
+        if (getSourceProxy(srcs[i]) instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource)
+        {
+          if (nm.startsWith("das:"))
+          {
+            nm = nm.substring(4);
+          }
+          dassrc.add(new String[]
+          { srcs[i], nm.toUpperCase() });
+        }
+        else
+        {
+          nondas.add(new String[]
+          { srcs[i], nm.toUpperCase() });
+        }
+      }
+    }
+    Object[] sorted = nondas.toArray();
+    String[] tosort = new String[sorted.length];
+    nondas.clear();
+    for (int j = 0; j < sorted.length; j++)
+    {
+      tosort[j] = ((String[]) sorted[j])[1];
+    }
+    jalview.util.QuickSort.sort(tosort, sorted);
+    int i = 0;
+    // construct array with all sources listed
+    srcs = new String[sorted.length + dassrc.size()];
+    for (int j = sorted.length - 1; j >= 0; j--, i++)
+    {
+      srcs[i] = ((String[]) sorted[j])[0];
+      sorted[j] = null;
+    }
+
+    sorted = dassrc.toArray();
+    tosort = new String[sorted.length];
+    dassrc.clear();
+    for (int j = 0; j < sorted.length; j++)
+    {
+      tosort[j] = ((String[]) sorted[j])[1];
+    }
+    jalview.util.QuickSort.sort(tosort, sorted);
+    for (int j = sorted.length - 1; j >= 0; j--, i++)
+    {
+      srcs[i] = ((String[]) sorted[j])[0];
+      sorted[j] = null;
+    }
+    return srcs;
+  }
+
+  /**
+   * simple run method to test dbsources.
+   * 
+   * @param argv
+   */
+  public static void main(String[] argv)
+  {
+    AlignmentI ds = null;
+    Vector noProds = new Vector();
+    String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
+            + "With no arguments, all DbSources will be queried with their test Accession number.\n"
+            + "With one argument, the argument will be resolved to one or more db sources and each will be queried with their test accession only.\n"
+            + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
+            + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
+    boolean withDas=true;
+    if (argv!=null && argv.length>0 && argv[0].toLowerCase().startsWith("-nodas"))
+    {
+      withDas=false;
+      String targs[] = new String[argv.length-1];
+      System.arraycopy(argv, 1, targs, 0, targs.length);
+      argv=targs;
+    }
+    if (argv != null && argv.length > 0)
+    {
+      List<DbSourceProxy> sps = new SequenceFetcher(withDas)
+              .getSourceProxy(argv[0]);
+
+      if (sps != null)
+      {
+        for (DbSourceProxy sp : sps)
+        {
+          AlignmentI al = null;
+          try
+          {
+            al = sp.getSequenceRecords(argv.length>1 ? argv[1] : sp.getTestQuery());
+          } catch (Exception e)
+          {
+            e.printStackTrace();
+            System.err.println("Error when retrieving " + (argv.length>1 ? argv[1] : sp.getTestQuery())
+                    + " from " + argv[0] + "\nUsage: " + usage);
+          }
+          SequenceI[] prod = al.getSequencesArray();
+          if (al != null)
+          {
+            for (int p = 0; p < prod.length; p++)
+            {
+              System.out.println("Prod " + p + ": "
+                      + prod[p].getDisplayId(true) + " : "
+                      + prod[p].getDescription());
+            }
+          }
+        }
+        return;
+      }
+      else
+      {
+        System.err.println("Can't resolve " + argv[0]
+                + " as a database name. Allowed values are :\n"
+                + new SequenceFetcher().getSupportedDb());
+      }
+      System.out.println(usage);
+      return;
+    }
+    ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
+    String[] dbSources = sfetcher.getSupportedDb();
+    for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
+    {
+      String db = dbSources[dbsource];
+      // skip me
+      if (db.equals(DBRefSource.PDB))
+        continue;
+      for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
+      {
+        System.out.println("Source: " + sp.getDbName() + " (" + db
+                + "): retrieving test:" + sp.getTestQuery());
+        AlignmentI al = null;
+        try
+        {
+          al = sp.getSequenceRecords(sp.getTestQuery());
+          if (al != null && al.getHeight() > 0
+                  && sp.getDbSourceProperties() != null)
+          {
+            boolean dna = sp.getDbSourceProperties().containsKey(
+                    DBRefSource.DNACODINGSEQDB)
+                    || sp.getDbSourceProperties().containsKey(
+                            DBRefSource.DNASEQDB)
+                    || sp.getDbSourceProperties().containsKey(
+                            DBRefSource.CODINGSEQDB);
+            // try and find products
+            String types[] = jalview.analysis.CrossRef
+                    .findSequenceXrefTypes(dna, al.getSequencesArray());
+            if (types != null)
+            {
+              System.out.println("Xref Types for: "
+                      + (dna ? "dna" : "prot"));
+              for (int t = 0; t < types.length; t++)
+              {
+                System.out.println("Type: " + types[t]);
+                SequenceI[] prod = jalview.analysis.CrossRef
+                        .findXrefSequences(al.getSequencesArray(), dna,
+                                types[t]).getSequencesArray();
+                System.out.println("Found "
+                        + ((prod == null) ? "no" : "" + prod.length)
+                        + " products");
+                if (prod != null)
+                {
+                  for (int p = 0; p < prod.length; p++)
+                  {
+                    System.out.println("Prod " + p + ": "
+                            + prod[p].getDisplayId(true));
+                  }
+                }
+              }
+            }
+            else
+            {
+              noProds.addElement((dna ? new Object[]
+              { al, al } : new Object[]
+              { al }));
+            }
+
+          }
+        } catch (Exception ex)
+        {
+          System.out.println("ERROR:Failed to retrieve test query.");
+          ex.printStackTrace(System.out);
+        }
+
+        if (al == null)
+        {
+          System.out.println("ERROR:No alignment retrieved.");
+          StringBuffer raw = sp.getRawRecords();
+          if (raw != null)
+            System.out.println(raw.toString());
+          else
+            System.out.println("ERROR:No Raw results.");
+        }
+        else
+        {
+          System.out.println("Retrieved " + al.getHeight() + " sequences.");
+          for (int s = 0; s < al.getHeight(); s++)
+          {
+            SequenceI sq = al.getSequenceAt(s);
+            while (sq.getDatasetSequence() != null)
+            {
+              sq = sq.getDatasetSequence();
+
+            }
+            if (ds == null)
+            {
+              ds = new Alignment(new SequenceI[]
+              { sq });
+
+            }
+            else
+            {
+              ds.addSequence(sq);
+            }
+          }
+        }
+        System.out.flush();
+        System.err.flush();
+
+      }
+      if (noProds.size() > 0)
+      {
+        Enumeration ts = noProds.elements();
+        while (ts.hasMoreElements())
+
+        {
+          Object[] typeSq = (Object[]) ts.nextElement();
+          boolean dna = (typeSq.length > 1);
+          AlignmentI al = (AlignmentI) typeSq[0];
+          System.out.println("Trying getProducts for "
+                  + al.getSequenceAt(0).getDisplayId(true));
+          System.out.println("Search DS Xref for: "
+                  + (dna ? "dna" : "prot"));
+          // have a bash at finding the products amongst all the retrieved
+          // sequences.
+          SequenceI[] seqs = al.getSequencesArray();
+          Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(
+                  seqs, dna, null, ds);
+          System.out.println("Found "
+                  + ((prodal == null) ? "no" : "" + prodal.getHeight())
+                  + " products");
+          if (prodal != null)
+          {
+            SequenceI[] prod = prodal.getSequencesArray(); // note
+            // should
+            // test
+            // rather
+            // than
+            // throw
+            // away
+            // codon
+            // mapping
+            // (if
+            // present)
+            for (int p = 0; p < prod.length; p++)
+            {
+              System.out.println("Prod " + p + ": "
+                      + prod[p].getDisplayId(true));
+            }
+          }
+        }
+
+      }
+
+    }
+  }
+
+  /**
+   * query the currently defined DAS source registry for sequence sources and
+   * add a DasSequenceSource instance for each source to the SequenceFetcher
+   * source list.
+   */
+  public void registerDasSequenceSources()
+  {
+    // TODO: define a context as a registry provider (either desktop,
+    // jalview.bin.cache, or something else).
+    for (jalviewSourceI source : jalview.bin.Cache.getDasSourceRegistry()
+            .getSources())
+    {
+      if (source.isSequenceSource())
+      {
+        List<DbSourceProxy> dassources = source.getSequenceSourceProxies();
+        for (DbSourceProxy seqsrc : dassources)
+        {
+          addDbRefSourceImpl(seqsrc);
+        }
+      }
+    }
+  }
+
+}