3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.AlignmentI;
5 import jalview.datamodel.DBRefSource;
6 import jalview.datamodel.SequenceI;
7 import jalview.ws.seqfetcher.ASequenceFetcher;
8 import jalview.ws.seqfetcher.DbSourceProxy;
10 import java.util.Enumeration;
11 import java.util.List;
12 import java.util.Vector;
14 public class SequenceFetcherTest
18 * simple run method to test dbsources.
22 public static void main(String[] argv)
24 // TODO: extracted from SequenceFetcher - convert to proper unit test with
28 Vector<Object[]> noProds = new Vector<Object[]>();
29 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
30 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
31 + "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"
32 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
33 + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
34 boolean withDas = true;
35 if (argv != null && argv.length > 0
36 && argv[0].toLowerCase().startsWith("-nodas"))
39 String targs[] = new String[argv.length - 1];
40 System.arraycopy(argv, 1, targs, 0, targs.length);
43 if (argv != null && argv.length > 0)
45 List<DbSourceProxy> sps = new SequenceFetcher(withDas)
46 .getSourceProxy(argv[0]);
50 for (DbSourceProxy sp : sps)
55 al = sp.getSequenceRecords(argv.length > 1 ? argv[1] : sp
60 System.err.println("Error when retrieving "
61 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
62 + " from " + argv[0] + "\nUsage: " + usage);
64 SequenceI[] prod = al.getSequencesArray();
67 for (int p = 0; p < prod.length; p++)
69 System.out.println("Prod " + p + ": "
70 + prod[p].getDisplayId(true) + " : "
71 + prod[p].getDescription());
79 System.err.println("Can't resolve " + argv[0]
80 + " as a database name. Allowed values are :\n"
81 + new SequenceFetcher().getSupportedDb());
83 System.out.println(usage);
86 ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
87 String[] dbSources = sfetcher.getSupportedDb();
88 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
90 String db = dbSources[dbsource];
92 if (db.equals(DBRefSource.PDB))
96 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
98 System.out.println("Source: " + sp.getDbName() + " (" + db
99 + "): retrieving test:" + sp.getTestQuery());
100 AlignmentI al = null;
103 al = sp.getSequenceRecords(sp.getTestQuery());
104 if (al != null && al.getHeight() > 0)
106 boolean dna = sp.isDnaCoding();
107 // try and find products
108 String types[] = jalview.analysis.CrossRef
109 .findSequenceXrefTypes(dna, al.getSequencesArray());
112 System.out.println("Xref Types for: "
113 + (dna ? "dna" : "prot"));
114 for (int t = 0; t < types.length; t++)
116 System.out.println("Type: " + types[t]);
117 SequenceI[] prod = jalview.analysis.CrossRef
118 .findXrefSequences(al.getSequencesArray(), dna,
120 .getSequencesArray();
121 System.out.println("Found "
122 + ((prod == null) ? "no" : "" + prod.length)
126 for (int p = 0; p < prod.length; p++)
128 System.out.println("Prod " + p + ": "
129 + prod[p].getDisplayId(true));
136 noProds.addElement((dna ? new Object[] { al, al }
137 : new Object[] { al }));
141 } catch (Exception ex)
143 System.out.println("ERROR:Failed to retrieve test query.");
144 ex.printStackTrace(System.out);
149 System.out.println("ERROR:No alignment retrieved.");
150 StringBuffer raw = sp.getRawRecords();
153 System.out.println(raw.toString());
157 System.out.println("ERROR:No Raw results.");
162 System.out.println("Retrieved " + al.getHeight() + " sequences.");
163 for (int s = 0; s < al.getHeight(); s++)
165 SequenceI sq = al.getSequenceAt(s);
166 while (sq.getDatasetSequence() != null)
168 sq = sq.getDatasetSequence();
173 ds = new Alignment(new SequenceI[] { sq });
186 if (noProds.size() > 0)
188 Enumeration<Object[]> ts = noProds.elements();
189 while (ts.hasMoreElements())
192 Object[] typeSq = ts.nextElement();
193 boolean dna = (typeSq.length > 1);
194 AlignmentI al = (AlignmentI) typeSq[0];
195 System.out.println("Trying getProducts for "
196 + al.getSequenceAt(0).getDisplayId(true));
197 System.out.println("Search DS Xref for: "
198 + (dna ? "dna" : "prot"));
199 // have a bash at finding the products amongst all the retrieved
201 SequenceI[] seqs = al.getSequencesArray();
202 Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(
203 seqs, dna, null, ds);
204 System.out.println("Found "
205 + ((prodal == null) ? "no" : "" + prodal.getHeight())
209 SequenceI[] prod = prodal.getSequencesArray(); // note
220 for (int p = 0; p < prod.length; p++)
222 System.out.println("Prod " + p + ": "
223 + prod[p].getDisplayId(true));