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.ArrayList;
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
29 Vector noProds = new Vector();
30 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
31 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
32 + "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"
33 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.\n"
34 + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use.";
35 boolean withDas = true;
36 if (argv != null && argv.length > 0
37 && argv[0].toLowerCase().startsWith("-nodas"))
40 String targs[] = new String[argv.length - 1];
41 System.arraycopy(argv, 1, targs, 0, targs.length);
44 if (argv != null && argv.length > 0)
46 List<DbSourceProxy> sps = new SequenceFetcher(withDas)
47 .getSourceProxy(argv[0]);
51 for (DbSourceProxy sp : sps)
56 al = sp.getSequenceRecords(argv.length > 1 ? argv[1] : sp
61 System.err.println("Error when retrieving "
62 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
63 + " from " + argv[0] + "\nUsage: " + usage);
65 SequenceI[] prod = al.getSequencesArray();
68 for (int p = 0; p < prod.length; p++)
70 System.out.println("Prod " + p + ": "
71 + prod[p].getDisplayId(true) + " : "
72 + prod[p].getDescription());
80 System.err.println("Can't resolve " + argv[0]
81 + " as a database name. Allowed values are :\n"
82 + new SequenceFetcher().getSupportedDb());
84 System.out.println(usage);
87 ASequenceFetcher sfetcher = new SequenceFetcher(withDas);
88 String[] dbSources = sfetcher.getSupportedDb();
89 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
91 String db = dbSources[dbsource];
93 if (db.equals(DBRefSource.PDB))
97 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
99 System.out.println("Source: " + sp.getDbName() + " (" + db
100 + "): retrieving test:" + sp.getTestQuery());
101 AlignmentI al = null;
104 al = sp.getSequenceRecords(sp.getTestQuery());
105 if (al != null && al.getHeight() > 0)
107 boolean dna = sp.isDnaCoding();
108 // try and find products
109 String types[] = jalview.analysis.CrossRef
110 .findSequenceXrefTypes(dna, al.getSequencesArray());
113 System.out.println("Xref Types for: "
114 + (dna ? "dna" : "prot"));
115 for (int t = 0; t < types.length; t++)
117 System.out.println("Type: " + types[t]);
118 SequenceI[] prod = jalview.analysis.CrossRef
119 .findXrefSequences(al.getSequencesArray(), dna,
120 types[t], null, new ArrayList<SequenceI>())
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.");
164 for (int s = 0; s < al.getHeight(); s++)
166 SequenceI sq = al.getSequenceAt(s);
167 while (sq.getDatasetSequence() != null)
169 sq = sq.getDatasetSequence();
174 ds = new Alignment(new SequenceI[] { sq });
187 if (noProds.size() > 0)
189 Enumeration ts = noProds.elements();
190 while (ts.hasMoreElements())
193 Object[] typeSq = (Object[]) ts.nextElement();
194 boolean dna = (typeSq.length > 1);
195 AlignmentI al = (AlignmentI) typeSq[0];
196 System.out.println("Trying getProducts for "
197 + al.getSequenceAt(0).getDisplayId(true));
198 System.out.println("Search DS Xref for: "
199 + (dna ? "dna" : "prot"));
200 // have a bash at finding the products amongst all the retrieved
202 SequenceI[] seqs = al.getSequencesArray();
203 Alignment prodal = jalview.analysis.CrossRef.findXrefSequences(
204 seqs, dna, null, ds, new ArrayList<SequenceI>());
205 System.out.println("Found "
206 + ((prodal == null) ? "no" : "" + prodal.getHeight())
210 SequenceI[] prod = prodal.getSequencesArray(); // note
221 for (int p = 0; p < prod.length; p++)
223 System.out.println("Prod " + p + ": "
224 + prod[p].getDisplayId(true));