-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)\r
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle\r
- * \r
- * This file is part of Jalview.\r
- * \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
- * 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
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
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
*/\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
// alignment is\r
// 'default' for\r
// PFAM\r
- registerDasSequenceSources();\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 suitable for using in a GUI\r
- * element\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 dassrc = new ArrayList(), nondas = new ArrayList();\r
+ ArrayList<String> dassrc = new ArrayList<String>(), nondas = new ArrayList<String>();\r
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
+ boolean das = false, skip = false;\r
+ String nm;\r
+ for (DbSourceProxy dbs : getSourceProxy(srcs[i]))\r
{\r
- if (nm.startsWith("das:"))\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 = nm.substring(4);\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
- dassrc.add(new String[]\r
- { srcs[i], nm.toUpperCase() });\r
+ }\r
+ if (skip)\r
+ {\r
+ continue;\r
+ }\r
+ if (das)\r
+ {\r
+ dassrc.add(srcs[i]);\r
}\r
else\r
{\r
- nondas.add(new String[]\r
- { srcs[i], nm.toUpperCase() });\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
}\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
{\r
AlignmentI ds = null;\r
Vector noProds = new Vector();\r
- String usage = "SequenceFetcher.main [<DBNAME> <ACCNO>]\n"\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
- + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.";\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
- DbSourceProxy sp = new SequenceFetcher().getSourceProxy(argv[0]);\r
- if (sp != null)\r
+ List<DbSourceProxy> sps = new SequenceFetcher(withDas)\r
+ .getSourceProxy(argv[0]);\r
+\r
+ if (sps != null)\r
{\r
- AlignmentI al = null;\r
- try\r
- {\r
- al = sp.getSequenceRecords(argv[1]);\r
- } catch (Exception e)\r
+ for (DbSourceProxy sp : sps)\r
{\r
- e.printStackTrace();\r
- System.err.println("Error when retrieving " + argv[1] + " from "\r
- + 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
+ AlignmentI al = null;\r
+ try\r
{\r
- System.out.println("Prod " + p + ": "\r
- + prod[p].getDisplayId(true) + " : "\r
- + prod[p].getDescription());\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
+ new SequenceFetcher().getSupportedDb());\r
}\r
System.out.println(usage);\r
+ return;\r
}\r
- ASequenceFetcher sfetcher = new SequenceFetcher();\r
+ ASequenceFetcher sfetcher = new SequenceFetcher(withDas);\r
String[] dbSources = sfetcher.getSupportedDb();\r
for (int dbsource = 0; dbsource < dbSources.length; dbsource++)\r
{\r
// skip me\r
if (db.equals(DBRefSource.PDB))\r
continue;\r
- DbSourceProxy sp = sfetcher.getSourceProxy(db);\r
- System.out.println("Source: " + sp.getDbName() + " (" + db\r
- + "): retrieving test:" + sp.getTestQuery());\r
- AlignmentI al = null;\r
- try\r
+ for (DbSourceProxy sp : sfetcher.getSourceProxy(db))\r
{\r
- al = sp.getSequenceRecords(sp.getTestQuery());\r
- if (al != null && al.getHeight() > 0\r
- && sp.getDbSourceProperties() != null)\r
+ System.out.println("Source: " + sp.getDbName() + " (" + db\r
+ + "): retrieving test:" + sp.getTestQuery());\r
+ AlignmentI al = null;\r
+ try\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.findSequenceXrefTypes(\r
- dna, al.getSequencesArray());\r
- if (types != null)\r
+ al = sp.getSequenceRecords(sp.getTestQuery());\r
+ if (al != null && al.getHeight() > 0\r
+ && sp.getDbSourceProperties() != null)\r
{\r
- System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));\r
- for (int t = 0; t < types.length; t++)\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("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
+ System.out.println("Xref Types for: "\r
+ + (dna ? "dna" : "prot"));\r
+ for (int t = 0; t < types.length; t++)\r
{\r
- for (int p = 0; p < prod.length; p++)\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
- System.out.println("Prod " + p + ": "\r
- + prod[p].getDisplayId(true));\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
- else\r
- {\r
- noProds.addElement((dna ? new Object[]\r
- { al, al } : new Object[]\r
- { al }));\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
- } catch (Exception ex)\r
- {\r
- System.out.println("ERROR:Failed to retrieve test query.");\r
- ex.printStackTrace(System.out);\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
+ System.out.println("Retrieved " + al.getHeight() + " sequences.");\r
+ for (int s = 0; s < al.getHeight(); s++)\r
{\r
- sq = sq.getDatasetSequence();\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
+ if (ds == null)\r
+ {\r
+ ds = new Alignment(new SequenceI[]\r
+ { sq });\r
\r
- }\r
- else\r
- {\r
- ds.addSequence(sq);\r
+ }\r
+ else\r
+ {\r
+ ds.addSequence(sq);\r
+ }\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
+ System.out.flush();\r
+ System.err.flush();\r
\r
+ }\r
+ if (noProds.size() > 0)\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: " + (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
+ Enumeration ts = noProds.elements();\r
+ while (ts.hasMoreElements())\r
+\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
+ 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
- System.out.println("Prod " + p + ": "\r
- + prod[p].getDisplayId(true));\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
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
- /**\r
- * Try to create and add a DasSequenceSource to the list of sources.\r
- * \r
- * @param source\r
- * @return null if no source was added, or the new DasSequenceSource created\r
- */\r
- DasSequenceSource addDasSequenceSource(DasSource source)\r
- {\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()\r
+ .getSources())\r
{\r
- if (source instanceof Das2Source)\r
+ if (source.isSequenceSource())\r
{\r
- if (((Das2Source) source).hasDas1Capabilities())\r
+ List<DbSourceProxy> dassources = source.getSequenceSourceProxies();\r
+ for (DbSourceProxy seqsrc : dassources)\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
- {\r
- if (source instanceof Das1Source)\r
- {\r
- d1s = (Das1Source) source;\r
+ addDbRefSourceImpl(seqsrc);\r
}\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[]\r
- { 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("das:"\r
- + 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 " + d1s.getNickname()\r
- + "- threw exception when constructing fetcher.\n");\r
- e.printStackTrace();\r
- }\r
- }\r
- }\r
- return ds;\r
}\r
+\r
}\r