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.getTestQuery());
59 System.err.println("Error when retrieving "
60 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
61 + " from " + argv[0] + "\nUsage: " + usage);
68 System.err.println("Can't resolve " + argv[0]
69 + " as a database name. Allowed values are :\n"
70 + new SequenceFetcher().getSupportedDb());
72 System.out.println(usage);
75 ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
76 String[] dbSources = sfetcher.getSupportedDb();
77 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
79 String db = dbSources[dbsource];
81 if (db.equals(DBRefSource.PDB))
85 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
87 testRetrieval(db, sp, sp.getTestQuery());
93 private static void testRetrieval(String db, DbSourceProxy sp,
97 Vector<Object[]> noProds = new Vector<Object[]>();
98 System.out.println("Source: " + sp.getDbName() + " (" + db
99 + "): retrieving test:" + sp.getTestQuery());
101 AlignmentI al = null;
104 al = sp.getSequenceRecords(testQuery);
105 if (al != null && al.getHeight() > 0)
107 boolean dna = sp.isDnaCoding();
109 AlignmentI alds = al.getDataset();
110 // try and find products
111 CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds);
112 List<String> types = crossRef.findXrefSourcesForSequences(dna);
115 System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
116 for (String source : types)
118 System.out.println("Type: " + source);
119 SequenceI[] prod = crossRef.findXrefSequences(source, 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.");
165 ds = al.getDataset();
169 ds.append(al.getDataset());
176 if (noProds.size() > 0)
178 Enumeration<Object[]> ts = noProds.elements();
179 while (ts.hasMoreElements())
182 Object[] typeSq = ts.nextElement();
183 boolean dna = (typeSq.length > 1);
184 AlignmentI al = (AlignmentI) typeSq[0];
185 System.out.println("Trying getProducts for "
186 + al.getSequenceAt(0).getDisplayId(true));
187 System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot"));
188 // have a bash at finding the products amongst all the retrieved
190 SequenceI[] seqs = al.getSequencesArray();
191 Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
193 System.out.println("Found "
194 + ((prodal == null) ? "no" : "" + prodal.getHeight())
198 SequenceI[] prod = prodal.getSequencesArray(); // note
209 for (int p = 0; p < prod.length; p++)
211 System.out.println("Prod " + p + ": "
212 + prod[p].getDisplayId(true));