X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=d3aeead362ece755be01e131ececf30ed3aee6df;hb=e7e569d85f161d6f508851d861ab3e76e2b4bbf9;hp=524311192bff927d2568d1d29f71fb59744e73c2;hpb=6b406c397d41a0f2d84b75f13e7ab478932bf57d;p=jalview.git diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index 5243111..d3aeead 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -1,169 +1,104 @@ -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.seqfetcher.ASequenceFetcher; -import jalview.ws.seqfetcher.DbSourceProxy; - -/** - * prototype of abstract sequence retrieval interface - * - */ -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() - { - 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()); - }; - - public static void main(String[] argv) - { - AlignmentI ds = null; - Vector noProds = new Vector(); - if (argv != null && argv.length > 0) - { - System.out - .println("Ignoring arguments. Future Usage = dbname:query1;query2;..."); - } - SequenceFetcher sfetcher = new SequenceFetcher(); - Enumeration e = sfetcher.FETCHABLEDBS.keys(); - while (e.hasMoreElements()) - { - String db = (String) e.nextElement(); - // skip me - if (db.equals(DBRefSource.PDB)) - continue; - DbSourceProxy sp = sfetcher.getSourceProxy(db); - System.out - .println("" + db + ": retrieving test:" + sp.getTestQuery()); - AlignmentI al = null; - try - { - al = sp.getSequenceRecords(sp.getTestQuery()); - if (al != null && al.getHeight() > 0) - { - 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; p0) - { - 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[] 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("Found " - + ((prod == null) ? "no" : "" + prod.length) - + " products"); - if (prod!=null) - { - for (int p=0; p. + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ +package jalview.ws; + +import jalview.ext.ensembl.EnsemblGene; +import jalview.ws.dbsources.EmblCdsSource; +import jalview.ws.dbsources.EmblSource; +import jalview.ws.dbsources.Pdb; +import jalview.ws.dbsources.PfamFull; +import jalview.ws.dbsources.PfamSeed; +import jalview.ws.dbsources.RfamSeed; +import jalview.ws.dbsources.Uniprot; +import jalview.ws.seqfetcher.ASequenceFetcher; +import jalview.ws.seqfetcher.DbSourceProxy; + +import java.util.ArrayList; + +/** + * This implements the run-time discovery of sequence database clients. + * + */ +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() + { + addDBRefSourceImpl(EnsemblGene.class); + // addDBRefSourceImpl(EnsemblGenomes.class); + addDBRefSourceImpl(EmblSource.class); + addDBRefSourceImpl(EmblCdsSource.class); + addDBRefSourceImpl(Uniprot.class); + addDBRefSourceImpl(Pdb.class); + addDBRefSourceImpl(PfamFull.class); + addDBRefSourceImpl(PfamSeed.class); + addDBRefSourceImpl(RfamSeed.class); + } + + /** + * return an ordered list of database sources excluding alignment only databases + */ + public String[] getOrderedSupportedSources() + { + String[] srcs = this.getSupportedDb(); + ArrayList src = new ArrayList<>(); + + for (int i = 0; i < srcs.length; i++) + { + boolean skip = false; + 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.isAlignmentSource()) + { + skip = true; + } + } + if (skip) + { + continue; + } + { + src.add(srcs[i]); + } + } + String[] tosort = src.toArray(new String[0]), + sorted = src.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 + int i = 0; + for (int j = sorted.length - 1; j >= 0; j--, i++) + { + tosort[i] = sorted[j]; + } + return tosort; + } +}