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
\r
/**\r
* This is the the concrete implementation of the sequence retrieval interface\r
- * and abstract class in jalview.ws.seqfetcher. This implements the discovery \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 testing all registered handlers. \r
* \r
*/\r
public class SequenceFetcher extends ASequenceFetcher\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.Pfam.class);\r
- };\r
+ addDBRefSourceImpl(jalview.ws.dbsources.PfamFull.class);\r
+ addDBRefSourceImpl(jalview.ws.dbsources.PfamSeed.class); // ensures Seed alignment is 'default' for PFAM\r
+ registerDasSequenceSources();\r
+ }\r
+ /**\r
+ * return an ordered list of database sources suitable for using in a GUI element\r
+ */\r
+ public String[] getOrderedSupportedSources() {\r
+ String[] srcs = this.getSupportedDb();\r
+ ArrayList dassrc = new ArrayList(),\r
+ nondas=new ArrayList();\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
+ {\r
+ if (nm.startsWith("das:"))\r
+ {\r
+ nm = nm.substring(4);\r
+ }\r
+ dassrc.add(new String[] { srcs[i], nm.toUpperCase()} );\r
+ } else {\r
+ nondas.add(new String[] { srcs[i], nm.toUpperCase()} );\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
+ 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
+ * simple run method to test dbsources.\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 [<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
if (argv != null && argv.length > 0)\r
{\r
+ DbSourceProxy sp = new SequenceFetcher().getSourceProxy(argv[0]);\r
+ if (sp!=null)\r
+ {\r
+ AlignmentI al = null;\r
+ try\r
+ {\r
+ al = sp.getSequenceRecords(argv[1]);\r
+ } catch (Exception e)\r
+ {\r
+ e.printStackTrace();\r
+ System.err.println("Error when retrieving "+argv[1]+" 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) + " : "+prod[p].getDescription());\r
+ }\r
+ }\r
+ return;\r
+ } else {\r
+ System.err.println("Can't resolve "+argv[0]+" as a database name. Allowed values are :\n"+new SequenceFetcher().getSupportedDb());\r
+ }\r
System.out\r
- .println("Ignoring arguments. Future Usage = dbname:query1;query2;...");\r
+ .println(usage);\r
}\r
ASequenceFetcher sfetcher = new SequenceFetcher();\r
String[] dbSources = sfetcher.getSupportedDb();\r
continue;\r
DbSourceProxy sp = sfetcher.getSourceProxy(db);\r
System.out\r
- .println("" + db + ": retrieving test:" + sp.getTestQuery());\r
+ .println("Source: "+sp.getDbName()+" (" + db + "): 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
+ if (al != null && al.getHeight() > 0 && sp.getDbSourceProperties()!=null)\r
{\r
boolean dna = sp.getDbSourceProperties().containsKey(\r
DBRefSource.DNACODINGSEQDB)\r
\r
}\r
}\r
+ /**\r
+ * query the currently defined DAS source registry for sequence sources and add a DasSequenceSource instance for each source to the SequenceFetcher source list.\r
+ */\r
+ public void registerDasSequenceSources() {\r
+ DasSource[] sources = jalview.ws.DasSequenceFeatureFetcher.getDASSources();\r
+ for (int s=0;s<sources.length; s++)\r
+ {\r
+ Das1Source d1s=null;\r
+ if (sources[s].hasCapability("sequence"))\r
+ {\r
+ if (sources[s] instanceof Das2Source)\r
+ {\r
+ if (((Das2Source)sources[s]).hasDas1Capabilities()) {\r
+ try {\r
+ d1s = org.biojava.dasobert.das2.DasSourceConverter.toDas1Source((Das2Source) sources[s]);\r
+ } catch (Exception e)\r
+ {\r
+ System.err.println("Ignoring DAS2 sequence source "+sources[s].getNickname()+" - couldn't map to Das1Source.\n");\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ } else {\r
+ if (sources[s] instanceof Das1Source)\r
+ { \r
+ d1s = (Das1Source) sources[s];\r
+ }\r
+ }\r
+ }\r
+ if (d1s!=null)\r
+ {\r
+ DasCoordinateSystem[] css = d1s.getCoordinateSystem();\r
+ for (int c=0;c<css.length;c++)\r
+ {\r
+ try {\r
+ addDbRefSourceImpl(\r
+ new jalview.ws.dbsources.DasSequenceSource("das:"+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
+ \r
+ }\r
+ }\r
+\r
}\r