2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.CrossRef;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefSource;
27 import jalview.datamodel.SequenceI;
28 import jalview.ws.seqfetcher.ASequenceFetcher;
29 import jalview.ws.seqfetcher.DbSourceProxy;
31 import java.util.Enumeration;
32 import java.util.List;
33 import java.util.Vector;
35 public class SequenceFetcherTest
39 * simple run method to test dbsources.
43 public static void main(String[] argv)
45 // TODO: extracted from SequenceFetcher - convert to proper unit test with
48 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
49 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
50 + "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"
51 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
52 + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
53 boolean withDas = true;
54 if (argv != null && argv.length > 0
55 && argv[0].toLowerCase().startsWith("-nodas"))
58 String targs[] = new String[argv.length - 1];
59 System.arraycopy(argv, 1, targs, 0, targs.length);
62 if (argv != null && argv.length > 0)
64 List<DbSourceProxy> sps = new SequenceFetcher(withDas)
65 .getSourceProxy(argv[0]);
69 for (DbSourceProxy sp : sps)
74 testRetrieval(argv[0], sp,
75 argv.length > 1 ? argv[1] : sp.getTestQuery());
79 System.err.println("Error when retrieving "
80 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
81 + " from " + argv[0] + "\nUsage: " + usage);
88 System.err.println("Can't resolve " + argv[0]
89 + " as a database name. Allowed values are :\n"
90 + new SequenceFetcher().getSupportedDb());
92 System.out.println(usage);
95 ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
96 String[] dbSources = sfetcher.getSupportedDb();
97 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
99 String db = dbSources[dbsource];
101 if (db.equals(DBRefSource.PDB))
105 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
107 testRetrieval(db, sp, sp.getTestQuery());
113 private static void testRetrieval(String db, DbSourceProxy sp,
116 AlignmentI ds = null;
117 Vector<Object[]> noProds = new Vector<Object[]>();
118 System.out.println("Source: " + sp.getDbName() + " (" + db
119 + "): retrieving test:" + sp.getTestQuery());
121 AlignmentI al = null;
124 al = sp.getSequenceRecords(testQuery);
125 if (al != null && al.getHeight() > 0)
127 boolean dna = sp.isDnaCoding();
129 AlignmentI alds = al.getDataset();
130 // try and find products
131 CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds);
132 List<String> types = crossRef.findXrefSourcesForSequences(dna);
135 System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
136 for (String source : types)
138 System.out.println("Type: " + source);
139 SequenceI[] prod = crossRef.findXrefSequences(source, dna)
140 .getSequencesArray();
141 System.out.println("Found "
142 + ((prod == null) ? "no" : "" + prod.length)
146 for (int p = 0; p < prod.length; p++)
148 System.out.println("Prod " + p + ": "
149 + prod[p].getDisplayId(true));
156 noProds.addElement((dna ? new Object[] { al, al }
157 : new Object[] { al }));
161 } catch (Exception ex)
163 System.out.println("ERROR:Failed to retrieve test query.");
164 ex.printStackTrace(System.out);
169 System.out.println("ERROR:No alignment retrieved.");
170 StringBuffer raw = sp.getRawRecords();
173 System.out.println(raw.toString());
177 System.out.println("ERROR:No Raw results.");
182 System.out.println("Retrieved " + al.getHeight() + " sequences.");
185 ds = al.getDataset();
189 ds.append(al.getDataset());
196 if (noProds.size() > 0)
198 Enumeration<Object[]> ts = noProds.elements();
199 while (ts.hasMoreElements())
202 Object[] typeSq = ts.nextElement();
203 boolean dna = (typeSq.length > 1);
204 AlignmentI al = (AlignmentI) typeSq[0];
205 System.out.println("Trying getProducts for "
206 + al.getSequenceAt(0).getDisplayId(true));
207 System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot"));
208 // have a bash at finding the products amongst all the retrieved
210 SequenceI[] seqs = al.getSequencesArray();
211 Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
213 System.out.println("Found "
214 + ((prodal == null) ? "no" : "" + prodal.getHeight())
218 SequenceI[] prod = prodal.getSequencesArray(); // note
229 for (int p = 0; p < prod.length; p++)
231 System.out.println("Prod " + p + ": "
232 + prod[p].getDisplayId(true));