X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fws%2FSequenceFetcher.java;h=d3aeead362ece755be01e131ececf30ed3aee6df;hb=e7e569d85f161d6f508851d861ab3e76e2b4bbf9;hp=208eb887dc787bb41085a2bc598989d2bc8fc840;hpb=063ed867eb33b87f48b4d1520f6069b60ccd1abd;p=jalview.git diff --git a/src/jalview/ws/SequenceFetcher.java b/src/jalview/ws/SequenceFetcher.java index 208eb88..d3aeead 100644 --- a/src/jalview/ws/SequenceFetcher.java +++ b/src/jalview/ws/SequenceFetcher.java @@ -1,185 +1,104 @@ -package jalview.ws; - -import java.util.Enumeration; -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; - -/** - * 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 -{ - /** - * 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(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.Pfam.class); - }; - - 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;..."); - } - ASequenceFetcher sfetcher = new SequenceFetcher(); - String[] dbSources = sfetcher.getSupportedDb(); - for (int dbsource=0; dbsource 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; p < prod.length; p++) - { - System.out.println("Prod " + p + ": " - + prod[p].getDisplayId(true)); - } - } - } - } - 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."); - } - 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) - { - sq = sq.getDatasetSequence(); - - } - if (ds == null) - { - ds = new Alignment(new SequenceI[] - { sq }); - - } - else - { - ds.addSequence(sq); - } - } - } - System.out.flush(); - System.err.flush(); - - } - if (noProds.size() > 0) - { - 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[] 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) - { - 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)); - } - } - } - - } - } -} +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * 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 . + * 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; + } +}