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.HashMap;
34 import java.util.List;
36 import java.util.Vector;
38 import org.testng.Assert;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 public class SequenceFetcherTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @Test(groups = "Functional")
53 public void testNoDuplicatesInFetchDbRefs()
55 Map<String, List<DbSourceProxy>> seen = new HashMap<>();
56 jalview.ws.SequenceFetcher sfetcher = new jalview.ws.SequenceFetcher();
58 // for (String src : sfetcher.getOrderedSupportedSources())
59 for (String src : sfetcher.getNonAlignmentSources())
61 List<DbSourceProxy> seenitem = seen.get(src);
64 dupes += (dupes.length() > 0 ? "," : "") + src;
68 seen.put(src, sfetcher.getSourceProxy(src));
71 if (dupes.length() > 0)
73 Assert.fail("Duplicate sources : " + dupes);
78 * simple run method to test dbsources.
83 public static void main(String[] argv)
85 // TODO: extracted from SequenceFetcher - convert to network dependent
86 // functional integration test with
89 String usage = "SequenceFetcher.main [-nodas] [<DBNAME> [<ACCNO>]]\n"
90 + "With no arguments, all DbSources will be queried with their test Accession number.\n"
91 + "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"
92 + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to <DBNAME> and retrieve <ACCNO> from it.";
94 if (argv != null && argv.length > 0)
96 String targs[] = new String[argv.length - 1];
97 System.arraycopy(argv, 1, targs, 0, targs.length);
100 if (argv != null && argv.length > 0)
102 List<DbSourceProxy> sps = new SequenceFetcher()
103 .getSourceProxy(argv[0]);
107 for (DbSourceProxy sp : sps)
109 AlignmentI al = null;
112 testRetrieval(argv[0], sp,
113 argv.length > 1 ? argv[1] : sp.getTestQuery());
114 } catch (Exception e)
117 System.err.println("Error when retrieving "
118 + (argv.length > 1 ? argv[1] : sp.getTestQuery())
119 + " from " + argv[0] + "\nUsage: " + usage);
126 System.err.println("Can't resolve " + argv[0]
127 + " as a database name. Allowed values are :\n"
128 + new SequenceFetcher().getSupportedDb());
130 System.out.println(usage);
133 ASequenceFetcher sfetcher = new SequenceFetcher();
134 String[] dbSources = sfetcher.getSupportedDb();
135 for (int dbsource = 0; dbsource < dbSources.length; dbsource++)
137 String db = dbSources[dbsource];
139 if (db.equals(DBRefSource.PDB))
143 for (DbSourceProxy sp : sfetcher.getSourceProxy(db))
145 testRetrieval(db, sp, sp.getTestQuery());
151 private static void testRetrieval(String db, DbSourceProxy sp,
154 AlignmentI ds = null;
155 Vector<Object[]> noProds = new Vector<>();
156 System.out.println("Source: " + sp.getDbName() + " (" + db
157 + "): retrieving test:" + sp.getTestQuery());
159 AlignmentI al = null;
162 al = sp.getSequenceRecords(testQuery);
163 if (al != null && al.getHeight() > 0)
165 boolean dna = sp.isDnaCoding();
167 AlignmentI alds = al.getDataset();
168 // try and find products
169 CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds);
170 List<String> types = crossRef.findXrefSourcesForSequences(dna);
173 System.out.println("Xref Types for: " + (dna ? "dna" : "prot"));
174 for (String source : types)
176 System.out.println("Type: " + source);
177 SequenceI[] prod = crossRef.findXrefSequences(source, dna)
178 .getSequencesArray();
179 System.out.println("Found "
180 + ((prod == null) ? "no" : "" + prod.length)
184 for (int p = 0; p < prod.length; p++)
186 System.out.println("Prod " + p + ": "
187 + prod[p].getDisplayId(true));
194 noProds.addElement((dna ? new Object[] { al, al }
195 : new Object[] { al }));
199 } catch (Exception ex)
201 System.out.println("ERROR:Failed to retrieve test query.");
202 ex.printStackTrace(System.out);
207 System.out.println("ERROR:No alignment retrieved.");
208 StringBuffer raw = sp.getRawRecords();
211 System.out.println(raw.toString());
215 System.out.println("ERROR:No Raw results.");
220 System.out.println("Retrieved " + al.getHeight() + " sequences.");
223 ds = al.getDataset();
227 ds.append(al.getDataset());
234 if (noProds.size() > 0)
236 Enumeration<Object[]> ts = noProds.elements();
237 while (ts.hasMoreElements())
240 Object[] typeSq = ts.nextElement();
241 boolean dna = (typeSq.length > 1);
242 AlignmentI al = (AlignmentI) typeSq[0];
243 System.out.println("Trying getProducts for "
244 + al.getSequenceAt(0).getDisplayId(true));
245 System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot"));
246 // have a bash at finding the products amongst all the retrieved
248 SequenceI[] seqs = al.getSequencesArray();
249 Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null,
251 System.out.println("Found "
252 + ((prodal == null) ? "no" : "" + prodal.getHeight())
256 SequenceI[] prod = prodal.getSequencesArray(); // note
267 for (int p = 0; p < prod.length; p++)
269 System.out.println("Prod " + p + ": "
270 + prod[p].getDisplayId(true));