2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.analysis.CrossRef;
24 import jalview.datamodel.Alignment;
25 import jalview.datamodel.AlignmentI;
26 import jalview.datamodel.DBRefSource;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.JvOptionPane;
29 import jalview.ws.seqfetcher.ASequenceFetcher;
30 import jalview.ws.seqfetcher.DbSourceProxy;
32 import java.util.Enumeration;
33 import java.util.List;
34 import java.util.Vector;
36 import org.testng.annotations.BeforeClass;
38 public class SequenceFetcherTest
41 @BeforeClass(alwaysRun = true)
42 public void setUpJvOptionPane()
44 JvOptionPane.setInteractiveMode(false);
45 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
49 * simple run method to test dbsources.
53 public static void main(String[] argv)
55 // TODO: extracted from SequenceFetcher - convert to network dependent
56 // functional integration test with
59 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
60 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
61 + "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"
62 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.";
64 if (argv != null && argv.length > 0)
66 String targs[] = new String[argv.length - 1];
67 System.arraycopy(argv, 1, targs, 0, targs.length);
70 if (argv != null && argv.length > 0)
72 List<DbSourceProxy> sps = new SequenceFetcher()
73 .getSourceProxy(argv[0]);
77 for (DbSourceProxy sp : sps)
82 testRetrieval(argv[0], sp,
83 argv.length > 1 ? argv[1] : sp.getTestQuery());
87 System.err.println("Error when retrieving "
88 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
89 + " from " + argv[0] + "\nUsage: " + usage);
96 System.err.println("Can't resolve " + argv[0]
97 + " as a database name. Allowed values are :\n"
98 + new SequenceFetcher().getSupportedDb());
100 System.out.println(usage);
103 ASequenceFetcher sfetcher = new SequenceFetcher();
104 String[] dbSources = sfetcher.getSupportedDb();
105 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
107 String db = dbSources[dbsource];
109 if (db.equals(DBRefSource.PDB))
113 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
115 testRetrieval(db, sp, sp.getTestQuery());
121 private static void testRetrieval(String db, DbSourceProxy sp,
124 AlignmentI ds = null;
125 Vector<Object[]> noProds = new Vector<>();
126 System.out.println("Source: " + sp.getDbName() + " (" + db
127 + "): retrieving test:" + sp.getTestQuery());
129 AlignmentI al = null;
132 al = sp.getSequenceRecords(testQuery);
133 if (al != null && al.getHeight() > 0)
135 boolean dna = sp.isDnaCoding();
137 AlignmentI alds = al.getDataset();
138 // try and find products
139 CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds);
140 List<String> types = crossRef.findXrefSourcesForSequences(dna);
143 System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
144 for (String source : types)
146 System.out.println("Type: " + source);
147 SequenceI[] prod = crossRef.findXrefSequences(source, dna)
148 .getSequencesArray();
149 System.out.println("Found "
150 + ((prod == null) ? "no" : "" + prod.length)
154 for (int p = 0; p < prod.length; p++)
156 System.out.println("Prod " + p + ": "
157 + prod[p].getDisplayId(true));
164 noProds.addElement((dna ? new Object[] { al, al }
165 : new Object[] { al }));
169 } catch (Exception ex)
171 System.out.println("ERROR:Failed to retrieve test query.");
172 ex.printStackTrace(System.out);
177 System.out.println("ERROR:No alignment retrieved.");
178 StringBuffer raw = sp.getRawRecords();
181 System.out.println(raw.toString());
185 System.out.println("ERROR:No Raw results.");
190 System.out.println("Retrieved " + al.getHeight() + " sequences.");
193 ds = al.getDataset();
197 ds.append(al.getDataset());
204 if (noProds.size() > 0)
206 Enumeration<Object[]> ts = noProds.elements();
207 while (ts.hasMoreElements())
210 Object[] typeSq = ts.nextElement();
211 boolean dna = (typeSq.length > 1);
212 AlignmentI al = (AlignmentI) typeSq[0];
213 System.out.println("Trying getProducts for "
214 + al.getSequenceAt(0).getDisplayId(true));
215 System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot"));
216 // have a bash at finding the products amongst all the retrieved
218 SequenceI[] seqs = al.getSequencesArray();
219 Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
221 System.out.println("Found "
222 + ((prodal == null) ? "no" : "" + prodal.getHeight())
226 SequenceI[] prod = prodal.getSequencesArray(); // note
237 for (int p = 0; p < prod.length; p++)
239 System.out.println("Prod " + p + ": "
240 + prod[p].getDisplayId(true));