3 import jalview.analysis.CrossRef;
4 import jalview.datamodel.Alignment;
5 import jalview.datamodel.AlignmentI;
6 import jalview.datamodel.DBRefSource;
7 import jalview.datamodel.SequenceI;
8 import jalview.ws.seqfetcher.ASequenceFetcher;
9 import jalview.ws.seqfetcher.DbSourceProxy;
11 import java.util.Enumeration;
12 import java.util.List;
13 import java.util.Vector;
15 public class SequenceFetcherTest
19 * simple run method to test dbsources.
23 public static void main(String[] argv)
25 // TODO: extracted from SequenceFetcher - convert to proper unit test with
28 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
29 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
30 + "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"
31 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
32 + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
33 boolean withDas = true;
34 if (argv != null && argv.length > 0
35 && argv[0].toLowerCase().startsWith("-nodas"))
38 String targs[] = new String[argv.length - 1];
39 System.arraycopy(argv, 1, targs, 0, targs.length);
42 if (argv != null && argv.length > 0)
44 List<DbSourceProxy> sps = new SequenceFetcher(withDas)
45 .getSourceProxy(argv[0]);
49 for (DbSourceProxy sp : sps)
54 testRetrieval(argv[0], sp,
55 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);
69 System.err.println("Can't resolve " + argv[0]
70 + " as a database name. Allowed values are :\n"
71 + new SequenceFetcher().getSupportedDb());
73 System.out.println(usage);
76 ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
77 String[] dbSources = sfetcher.getSupportedDb();
78 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
80 String db = dbSources[dbsource];
82 if (db.equals(DBRefSource.PDB))
86 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
88 testRetrieval(db, sp, sp.getTestQuery());
94 private static void testRetrieval(String db, DbSourceProxy sp,
98 Vector<Object[]> noProds = new Vector<Object[]>();
99 System.out.println("Source: " + sp.getDbName() + " (" + db
100 + "): retrieving test:" + sp.getTestQuery());
102 AlignmentI al = null;
105 al = sp.getSequenceRecords(testQuery);
106 if (al != null && al.getHeight() > 0)
108 boolean dna = sp.isDnaCoding();
110 AlignmentI alds = al.getDataset();
111 // try and find products
112 CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds);
113 List<String> types = crossRef.findXrefSourcesForSequences(dna);
116 System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
117 for (String source : types)
119 System.out.println("Type: " + source);
120 SequenceI[] prod = crossRef.findXrefSequences(source, dna)
121 .getSequencesArray();
122 System.out.println("Found "
123 + ((prod == null) ? "no" : "" + prod.length)
127 for (int p = 0; p < prod.length; p++)
129 System.out.println("Prod " + p + ": "
130 + prod[p].getDisplayId(true));
137 noProds.addElement((dna ? new Object[] { al, al }
138 : new Object[] { al }));
142 } catch (Exception ex)
144 System.out.println("ERROR:Failed to retrieve test query.");
145 ex.printStackTrace(System.out);
150 System.out.println("ERROR:No alignment retrieved.");
151 StringBuffer raw = sp.getRawRecords();
154 System.out.println(raw.toString());
158 System.out.println("ERROR:No Raw results.");
163 System.out.println("Retrieved " + al.getHeight() + " sequences.");
166 ds = al.getDataset();
170 ds.append(al.getDataset());
177 if (noProds.size() > 0)
179 Enumeration<Object[]> ts = noProds.elements();
180 while (ts.hasMoreElements())
183 Object[] typeSq = ts.nextElement();
184 boolean dna = (typeSq.length > 1);
185 AlignmentI al = (AlignmentI) typeSq[0];
186 System.out.println("Trying getProducts for "
187 + al.getSequenceAt(0).getDisplayId(true));
188 System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot"));
189 // have a bash at finding the products amongst all the retrieved
191 SequenceI[] seqs = al.getSequencesArray();
192 Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
194 System.out.println("Found "
195 + ((prodal == null) ? "no" : "" + prodal.getHeight())
199 SequenceI[] prod = prodal.getSequencesArray(); // note
210 for (int p = 0; p < prod.length; p++)
212 System.out.println("Prod " + p + ": "
213 + prod[p].getDisplayId(true));