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 noProds = new Vector();
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,
119 types[t]).getSequencesArray();
120 System.out.println("Found "
121 + ((prod == null) ? "no" : "" + prod.length)
125 for (int p = 0; p < prod.length; p++)
127 System.out.println("Prod " + p + ": "
128 + prod[p].getDisplayId(true));
135 noProds.addElement((dna ? new Object[] { al, al }
136 : new Object[] { al }));
140 } catch (Exception ex)
142 System.out.println("ERROR:Failed to retrieve test query.");
143 ex.printStackTrace(System.out);
148 System.out.println("ERROR:No alignment retrieved.");
149 StringBuffer raw = sp.getRawRecords();
152 System.out.println(raw.toString());
156 System.out.println("ERROR:No Raw results.");
161 System.out.println("Retrieved " + al.getHeight() + " sequences.");
162 for (int s = 0; s < al.getHeight(); s++)
164 SequenceI sq = al.getSequenceAt(s);
165 while (sq.getDatasetSequence() != null)
167 sq = sq.getDatasetSequence();
172 ds = new Alignment(new SequenceI[] { sq });
185 if (noProds.size() > 0)
187 Enumeration ts = noProds.elements();
188 while (ts.hasMoreElements())
191 Object[] typeSq = (Object[]) ts.nextElement();
192 boolean dna = (typeSq.length > 1);
193 AlignmentI al = (AlignmentI) typeSq[0];
194 System.out.println("Trying getProducts for "
195 + al.getSequenceAt(0).getDisplayId(true));
196 System.out.println("Search DS Xref for: "
197 + (dna ? "dna" : "prot"));
198 // have a bash at finding the products amongst all the retrieved
200 SequenceI[] seqs = al.getSequencesArray();
201 Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(
202 seqs, dna, null, ds);
203 System.out.println("Found "
204 + ((prodal == null) ? "no" : "" + prodal.getHeight())
208 SequenceI[] prod = prodal.getSequencesArray(); // note
219 for (int p = 0; p < prod.length; p++)
221 System.out.println("Prod " + p + ": "
222 + prod[p].getDisplayId(true));