X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=14b69972a1276bd20bff2ac2425acb3c1103549f;hb=02e9934037787599aefda03a6af9b7501e867dc3;hp=fa58a2ca0dc69b091892c3aef1aa3868352a0abb;hpb=153dd62dc91da13ae732600e6ea55ddbe15eab39;p=jalview.git
diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java
index fa58a2c..14b6997 100644
--- a/src/jalview/ws/SequenceFetcher.java
+++ b/src/jalview/ws/SequenceFetcher.java
@@ -1,39 +1,35 @@
-/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, 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 .
- */
+/*
+ * 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
+ *
+ * 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.ArrayList;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.biojava.dasobert.das2.Das2Source;
-import org.biojava.dasobert.dasregistry.Das1Source;
-import org.biojava.dasobert.dasregistry.DasCoordinateSystem;
-import org.biojava.dasobert.dasregistry.DasSource;
-
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.DBRefSource;
import jalview.datamodel.SequenceI;
-import jalview.ws.dbsources.DasSequenceSource;
+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
@@ -51,6 +47,10 @@ public class SequenceFetcher extends ASequenceFetcher
*/
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);
@@ -61,33 +61,117 @@ public class SequenceFetcher extends ASequenceFetcher
// alignment is
// 'default' for
// PFAM
- registerDasSequenceSources();
+ addDBRefSourceImpl(jalview.ws.dbsources.RfamFull.class);
+ addDBRefSourceImpl(jalview.ws.dbsources.RfamSeed.class);
+ if (addDas) {
+ registerDasSequenceSources();
+ }
}
/**
- * return an ordered list of database sources suitable for using in a GUI
- * element
+ * 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 dassrc = new ArrayList(), nondas = new ArrayList();
+ 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.DasSequenceSource)
+ boolean das = false, skip = false;
+ String nm;
+ for (DbSourceProxy dbs : getSourceProxy(srcs[i]))
{
- if (nm.startsWith("das:"))
+ // 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 = nm.substring(4);
+ 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;
+ }
}
- dassrc.add(new String[]
- { srcs[i], nm.toUpperCase() });
+ }
+ if (skip)
+ {
+ continue;
+ }
+ if (das)
+ {
+ dassrc.add(srcs[i]);
}
else
{
- nondas.add(new String[]
- { srcs[i], nm.toUpperCase() });
+ 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();
@@ -99,6 +183,8 @@ public class SequenceFetcher extends ASequenceFetcher
}
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];
@@ -130,32 +216,47 @@ public class SequenceFetcher extends ASequenceFetcher
{
AlignmentI ds = null;
Vector noProds = new Vector();
- String usage = "SequenceFetcher.main [ ]\n"
+ String usage = "SequenceFetcher.main [-nodas] [ []]\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.";
+ + "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 and retrieve 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)
{
- DbSourceProxy sp = new SequenceFetcher().getSourceProxy(argv[0]);
- if (sp != null)
+ List sps = new SequenceFetcher(withDas)
+ .getSourceProxy(argv[0]);
+
+ if (sps != null)
{
- AlignmentI al = null;
- try
- {
- al = sp.getSequenceRecords(argv[1]);
- } catch (Exception e)
+ for (DbSourceProxy sp : sps)
{
- 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++)
+ AlignmentI al = null;
+ try
{
- System.out.println("Prod " + p + ": "
- + prod[p].getDisplayId(true) + " : "
- + prod[p].getDescription());
+ 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;
@@ -167,8 +268,9 @@ public class SequenceFetcher extends ASequenceFetcher
+ new SequenceFetcher().getSupportedDb());
}
System.out.println(usage);
+ return;
}
- ASequenceFetcher sfetcher = new SequenceFetcher();
+ ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
String[] dbSources = sfetcher.getSupportedDb();
for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
{
@@ -176,135 +278,141 @@ public class SequenceFetcher extends ASequenceFetcher
// skip me
if (db.equals(DBRefSource.PDB))
continue;
- DbSourceProxy sp = sfetcher.getSourceProxy(db);
- System.out.println("Source: " + sp.getDbName() + " (" + db
- + "): retrieving test:" + sp.getTestQuery());
- AlignmentI al = null;
- try
+ for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
{
- al = sp.getSequenceRecords(sp.getTestQuery());
- if (al != null && al.getHeight() > 0
- && sp.getDbSourceProperties() != null)
+ System.out.println("Source: " + sp.getDbName() + " (" + db
+ + "): retrieving test:" + sp.getTestQuery());
+ AlignmentI al = null;
+ try
{
- 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)
+ al = sp.getSequenceRecords(sp.getTestQuery());
+ if (al != null && al.getHeight() > 0
+ && sp.getDbSourceProperties() != null)
{
- System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
- for (int t = 0; t < types.length; t++)
+ 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("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)
+ System.out.println("Xref Types for: "
+ + (dna ? "dna" : "prot"));
+ for (int t = 0; t < types.length; t++)
{
- for (int p = 0; p < prod.length; p++)
+ 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)
{
- System.out.println("Prod " + p + ": "
- + prod[p].getDisplayId(true));
+ 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 }));
+ }
+
}
- 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.");
}
- } 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)
+ System.out.println("Retrieved " + al.getHeight() + " sequences.");
+ for (int s = 0; s < al.getHeight(); s++)
{
- sq = sq.getDatasetSequence();
+ SequenceI sq = al.getSequenceAt(s);
+ while (sq.getDatasetSequence() != null)
+ {
+ sq = sq.getDatasetSequence();
- }
- if (ds == null)
- {
- ds = new Alignment(new SequenceI[]
- { sq });
+ }
+ if (ds == null)
+ {
+ ds = new Alignment(new SequenceI[]
+ { sq });
- }
- else
- {
- ds.addSequence(sq);
+ }
+ else
+ {
+ ds.addSequence(sq);
+ }
}
}
- }
- System.out.flush();
- System.err.flush();
-
- }
- if (noProds.size() > 0)
- {
- Enumeration ts = noProds.elements();
- while (ts.hasMoreElements())
+ System.out.flush();
+ System.err.flush();
+ }
+ if (noProds.size() > 0)
{
- 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)
+ Enumeration ts = noProds.elements();
+ while (ts.hasMoreElements())
+
{
- SequenceI[] prod = prodal.getSequencesArray(); // note
- // should
- // test
- // rather
- // than
- // throw
- // away
- // codon
- // mapping
- // (if
- // present)
- for (int p = 0; p < prod.length; p++)
+ 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)
{
- System.out.println("Prod " + p + ": "
- + prod[p].getDisplayId(true));
+ 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));
+ }
}
}
+
}
}
@@ -317,91 +425,20 @@ public class SequenceFetcher extends ASequenceFetcher
*/
public void registerDasSequenceSources()
{
- DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher
- .getDASSources();
- if (sources != null)
- {
- for (int s = 0; sources != null && s < sources.length; s++)
- {
- addDasSequenceSource(sources[s]);
- }
- }
-
- Vector localsources = jalview.bin.Cache.getLocalDasSources();
- if (localsources != null)
- {
- for (Enumeration ls = localsources.elements(); ls.hasMoreElements();)
- {
- addDasSequenceSource((DasSource) ls.nextElement());
- }
- }
- }
-
- /**
- * Try to create and add a DasSequenceSource to the list of sources.
- *
- * @param source
- * @return null if no source was added, or the new DasSequenceSource created
- */
- DasSequenceSource addDasSequenceSource(DasSource source)
- {
- DasSequenceSource ds = null;
- Das1Source d1s = null;
- if (source.hasCapability("sequence"))
+ // 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 instanceof Das2Source)
+ if (source.isSequenceSource())
{
- if (((Das2Source) source).hasDas1Capabilities())
+ List dassources = source.getSequenceSourceProxies();
+ for (DbSourceProxy seqsrc : dassources)
{
- try
- {
- d1s = org.biojava.dasobert.das2.DasSourceConverter
- .toDas1Source((Das2Source) source);
- } catch (Exception e)
- {
- System.err.println("Ignoring DAS2 sequence source "
- + source.getNickname()
- + " - couldn't map to Das1Source.\n");
- e.printStackTrace();
- }
- }
- }
- else
- {
- if (source instanceof Das1Source)
- {
- d1s = (Das1Source) source;
+ addDbRefSourceImpl(seqsrc);
}
}
}
- if (d1s != null)
- {
- DasCoordinateSystem[] css = d1s.getCoordinateSystem();
- if (css == null || css.length == 0)
- {
- // TODO: query das source directly to identify coordinate system... or
- // have to make up a coordinate system
- css = new DasCoordinateSystem[]
- { new DasCoordinateSystem() };
- css[0].setName(d1s.getNickname());
- css[0].setUniqueId(d1s.getNickname());
- }
- for (int c = 0; c < css.length; c++)
- {
- try
- {
- addDbRefSourceImpl(ds = new DasSequenceSource("das:"
- + d1s.getNickname() + " (" + css[c].getName() + ")",
- css[c].getName(), d1s, css[c]));
- } catch (Exception e)
- {
- System.err.println("Ignoring sequence coord system " + c + " ("
- + css[c].getName() + ") for source " + d1s.getNickname()
- + "- threw exception when constructing fetcher.\n");
- e.printStackTrace();
- }
- }
- }
- return ds;
}
+
}