X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=d5b3d11e8ce5816d6c92d6708c64643745ac4fc6;hb=2a5cbe264ec842c1a0f93e6bd78294607a94e686;hp=524311192bff927d2568d1d29f71fb59744e73c2;hpb=6b406c397d41a0f2d84b75f13e7ab478932bf57d;p=jalview.git
diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java
index 5243111..d5b3d11 100644
--- a/src/jalview/ws/SequenceFetcher.java
+++ b/src/jalview/ws/SequenceFetcher.java
@@ -1,18 +1,40 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * 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 .
+ */
package jalview.ws;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Vector;
-
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;
+
/**
- * prototype of abstract sequence retrieval interface
+ * 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
@@ -25,44 +47,142 @@ public class SequenceFetcher extends ASequenceFetcher
*/
public SequenceFetcher()
{
- FETCHABLEDBS = new Hashtable();
- FETCHABLEDBS.put(DBRefSource.EMBL,
- new jalview.ws.dbsources.EmblSource());
- FETCHABLEDBS.put(DBRefSource.EMBLCDS,
- new jalview.ws.dbsources.EmblCdsSouce());
- FETCHABLEDBS.put(DBRefSource.UNIPROT,
- new jalview.ws.dbsources.Uniprot());
- FETCHABLEDBS.put(DBRefSource.UP_NAME,
- new jalview.ws.dbsources.Uniprot());
- FETCHABLEDBS.put(DBRefSource.PDB, new jalview.ws.dbsources.Pdb());
- FETCHABLEDBS.put(DBRefSource.PFAM, new jalview.ws.dbsources.Pfam());
- };
-
+ 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);
+ registerDasSequenceSources();
+ }
+
+ /**
+ * return an ordered list of database sources 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++)
+ {
+ String nm = getSourceProxy(srcs[i]).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;
+ 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 [ ]\n"
+ + "With no arguments, all DbSources will be queried with their test Accession number.\n"
+ + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it.";
if (argv != null && argv.length > 0)
{
- System.out
- .println("Ignoring arguments. Future Usage = dbname:query1;query2;...");
+ DbSourceProxy sp = new SequenceFetcher().getSourceProxy(argv[0]);
+ if (sp != null)
+ {
+ AlignmentI al = null;
+ try
+ {
+ al = sp.getSequenceRecords(argv[1]);
+ } catch (Exception e)
+ {
+ e.printStackTrace();
+ System.err.println("Error when retrieving " + argv[1] + " 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);
}
- SequenceFetcher sfetcher = new SequenceFetcher();
- Enumeration e = sfetcher.FETCHABLEDBS.keys();
- while (e.hasMoreElements())
+ ASequenceFetcher sfetcher = new SequenceFetcher();
+ String[] dbSources = sfetcher.getSupportedDb();
+ for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
{
- String db = (String) e.nextElement();
+ String db = dbSources[dbsource];
// skip me
if (db.equals(DBRefSource.PDB))
continue;
DbSourceProxy sp = sfetcher.getSourceProxy(db);
- System.out
- .println("" + db + ": retrieving test:" + sp.getTestQuery());
+ 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)
+ if (al != null && al.getHeight() > 0
+ && sp.getDbSourceProperties() != null)
{
boolean dna = sp.getDbSourceProperties().containsKey(
DBRefSource.DNACODINGSEQDB)
@@ -75,25 +195,31 @@ public class SequenceFetcher extends ASequenceFetcher
dna, al.getSequencesArray());
if (types != null)
{
- System.out.println("Xref Types for: "+(dna ? "dna" : "prot"));
+ 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();
+ 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)
+ if (prod != null)
{
- for (int p=0; p0)
+ if (noProds.size() > 0)
{
Enumeration ts = noProds.elements();
while (ts.hasMoreElements())
-
+
{
Object[] typeSq = (Object[]) ts.nextElement();
- boolean dna = (typeSq.length>1);
+ 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[] prod = jalview.analysis.CrossRef.findXrefSequences(al
- .getSequencesArray(), dna, null, ds).getSequencesArray(); // note should test rather than throw away codon mapping (if present)
+ 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 "
- + ((prod == null) ? "no" : "" + prod.length)
+ + ((prodal == null) ? "no" : "" + prodal.getHeight())
+ " products");
- if (prod!=null)
+ if (prodal != null)
{
- for (int p=0; p dassources = source.getSequenceSourceProxies();
+ for (DbSourceProxy seqsrc : dassources)
+ {
+ addDbRefSourceImpl(seqsrc);
+ }
+ }
+ }
+ }
}