X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fws%2FSequenceFetcherTest.java;h=0b501ee841f35a44dc3283c02f4c05ef893a9040;hb=60134d1200ccd43a13205159cc10bb3695a55499;hp=7a9b5532ac96e1cbb7d2d14de407971acabfbab3;hpb=409fd993c6e32e999b24082aae107a043a590f8f;p=jalview.git diff --git a/test/jalview/ws/SequenceFetcherTest.java b/test/jalview/ws/SequenceFetcherTest.java index 7a9b553..0b501ee 100644 --- a/test/jalview/ws/SequenceFetcherTest.java +++ b/test/jalview/ws/SequenceFetcherTest.java @@ -1,9 +1,31 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.ws; +import jalview.analysis.CrossRef; import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; import jalview.datamodel.DBRefSource; import jalview.datamodel.SequenceI; +import jalview.gui.JvOptionPane; import jalview.ws.seqfetcher.ASequenceFetcher; import jalview.ws.seqfetcher.DbSourceProxy; @@ -11,9 +33,18 @@ import java.util.Enumeration; import java.util.List; import java.util.Vector; +import org.testng.annotations.BeforeClass; + public class SequenceFetcherTest { + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + /** * simple run method to test dbsources. * @@ -21,30 +52,26 @@ public class SequenceFetcherTest */ public static void main(String[] argv) { - // TODO: extracted from SequenceFetcher - convert to proper unit test with + // TODO: extracted from SequenceFetcher - convert to network dependent + // functional integration test with // assertions - AlignmentI ds = null; - Vector noProds = new Vector(); String usage = "SequenceFetcher.main [-nodas] [ []]\n" + "With no arguments, all DbSources will be queried with their test Accession number.\n" + "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" - + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it.\n" - + "The -nodas option will exclude DAS sources from the database fetchers Jalview will try to use."; - boolean withDas = true; - if (argv != null && argv.length > 0 - && argv[0].toLowerCase().startsWith("-nodas")) + + "If given two arguments, SequenceFetcher will try to find the DbFetcher corresponding to and retrieve from it."; + + if (argv != null && argv.length > 0) { - withDas = false; String targs[] = new String[argv.length - 1]; System.arraycopy(argv, 1, targs, 0, targs.length); argv = targs; } if (argv != null && argv.length > 0) { - List sps = new SequenceFetcher(withDas) + List sps = new SequenceFetcher() .getSourceProxy(argv[0]); - + if (sps != null) { for (DbSourceProxy sp : sps) @@ -52,8 +79,8 @@ public class SequenceFetcherTest AlignmentI al = null; try { - al = sp.getSequenceRecords(argv.length > 1 ? argv[1] : sp - .getTestQuery()); + testRetrieval(argv[0], sp, + argv.length > 1 ? argv[1] : sp.getTestQuery()); } catch (Exception e) { e.printStackTrace(); @@ -61,16 +88,6 @@ public class SequenceFetcherTest + (argv.length > 1 ? argv[1] : sp.getTestQuery()) + " from " + argv[0] + "\nUsage: " + usage); } - SequenceI[] prod = al.getSequencesArray(); - if (al != null) - { - for (int p = 0; p < prod.length; p++) - { - System.out.println("Prod " + p + ": " - + prod[p].getDisplayId(true) + " : " - + prod[p].getDescription()); - } - } } return; } @@ -83,7 +100,7 @@ public class SequenceFetcherTest System.out.println(usage); return; } - ASequenceFetcher sfetcher = new SequenceFetcher(withDas); + ASequenceFetcher sfetcher = new SequenceFetcher(); String[] dbSources = sfetcher.getSupportedDb(); for (int dbsource = 0; dbsource < dbSources.length; dbsource++) { @@ -95,138 +112,135 @@ public class SequenceFetcherTest } for (DbSourceProxy sp : sfetcher.getSourceProxy(db)) { - System.out.println("Source: " + sp.getDbName() + " (" + db - + "): retrieving test:" + sp.getTestQuery()); - AlignmentI al = null; - try + testRetrieval(db, sp, sp.getTestQuery()); + } + } + + } + + private static void testRetrieval(String db, DbSourceProxy sp, + String testQuery) + { + AlignmentI ds = null; + Vector noProds = new Vector<>(); + System.out.println("Source: " + sp.getDbName() + " (" + db + + "): retrieving test:" + sp.getTestQuery()); + { + AlignmentI al = null; + try + { + al = sp.getSequenceRecords(testQuery); + if (al != null && al.getHeight() > 0) { - al = sp.getSequenceRecords(sp.getTestQuery()); - if (al != null && al.getHeight() > 0) + boolean dna = sp.isDnaCoding(); + al.setDataset(null); + AlignmentI alds = al.getDataset(); + // try and find products + CrossRef crossRef = new CrossRef(al.getSequencesArray(), alds); + List types = crossRef.findXrefSourcesForSequences(dna); + if (types != null) { - boolean dna = sp.isDnaCoding(); - // try and find products - String types[] = jalview.analysis.CrossRef - .findSequenceXrefTypes(dna, al.getSequencesArray()); - if (types != null) + System.out.println("Xref Types for: " + (dna ? "dna" : "prot")); + for (String source : types) { - System.out.println("Xref Types for: " - + (dna ? "dna" : "prot")); - for (int t = 0; t < types.length; t++) + System.out.println("Type: " + source); + SequenceI[] prod = crossRef.findXrefSequences(source, dna) + .getSequencesArray(); + System.out.println("Found " + + ((prod == null) ? "no" : "" + prod.length) + + " products"); + if (prod != null) { - System.out.println("Type: " + types[t]); - SequenceI[] prod = jalview.analysis.CrossRef - .findXrefSequences(al.getSequencesArray(), dna, - types[t]).getSequencesArray(); - System.out.println("Found " - + ((prod == null) ? "no" : "" + prod.length) - + " products"); - if (prod != null) + for (int p = 0; p < prod.length; p++) { - for (int p = 0; p < prod.length; p++) - { - System.out.println("Prod " + p + ": " - + prod[p].getDisplayId(true)); - } + System.out.println("Prod " + p + ": " + + prod[p].getDisplayId(true)); } } } - else - { - noProds.addElement((dna ? new Object[] { al, al } - : new Object[] { al })); - } - - } - } catch (Exception ex) - { - System.out.println("ERROR:Failed to retrieve test query."); - ex.printStackTrace(System.out); - } - - if (al == null) - { - System.out.println("ERROR:No alignment retrieved."); - StringBuffer raw = sp.getRawRecords(); - if (raw != null) - { - System.out.println(raw.toString()); } else { - System.out.println("ERROR:No Raw results."); + noProds.addElement((dna ? new Object[] { al, al } + : new Object[] { al })); } + + } + } catch (Exception ex) + { + System.out.println("ERROR:Failed to retrieve test query."); + ex.printStackTrace(System.out); + } + + if (al == null) + { + System.out.println("ERROR:No alignment retrieved."); + StringBuffer raw = sp.getRawRecords(); + if (raw != null) + { + System.out.println(raw.toString()); } else { - System.out.println("Retrieved " + al.getHeight() + " sequences."); - for (int s = 0; s < al.getHeight(); s++) - { - SequenceI sq = al.getSequenceAt(s); - while (sq.getDatasetSequence() != null) - { - sq = sq.getDatasetSequence(); - - } - if (ds == null) - { - ds = new Alignment(new SequenceI[] { sq }); - - } - else - { - ds.addSequence(sq); - } - } + System.out.println("ERROR:No Raw results."); } - System.out.flush(); - System.err.flush(); - } - if (noProds.size() > 0) + else + { + System.out.println("Retrieved " + al.getHeight() + " sequences."); + if (ds == null) + { + ds = al.getDataset(); + } + else + { + ds.append(al.getDataset()); + al.setDataset(ds); + } + } + System.out.flush(); + System.err.flush(); + } + if (noProds.size() > 0) + { + Enumeration ts = noProds.elements(); + while (ts.hasMoreElements()) + { - Enumeration ts = noProds.elements(); - while (ts.hasMoreElements()) - + Object[] typeSq = ts.nextElement(); + boolean dna = (typeSq.length > 1); + AlignmentI al = (AlignmentI) typeSq[0]; + System.out.println("Trying getProducts for " + + al.getSequenceAt(0).getDisplayId(true)); + System.out.println("Search DS Xref for: " + (dna ? "dna" : "prot")); + // have a bash at finding the products amongst all the retrieved + // sequences. + SequenceI[] seqs = al.getSequencesArray(); + Alignment prodal = new CrossRef(seqs, ds).findXrefSequences(null, + dna); + System.out.println("Found " + + ((prodal == null) ? "no" : "" + prodal.getHeight()) + + " products"); + if (prodal != null) { - Object[] typeSq = (Object[]) ts.nextElement(); - boolean dna = (typeSq.length > 1); - AlignmentI al = (AlignmentI) typeSq[0]; - System.out.println("Trying getProducts for " - + al.getSequenceAt(0).getDisplayId(true)); - System.out.println("Search DS Xref for: " - + (dna ? "dna" : "prot")); - // have a bash at finding the products amongst all the retrieved - // sequences. - SequenceI[] seqs = al.getSequencesArray(); - Alignment prodal = jalview.analysis.CrossRef.findXrefSequences( - seqs, dna, null, ds); - System.out.println("Found " - + ((prodal == null) ? "no" : "" + prodal.getHeight()) - + " products"); - if (prodal != null) + SequenceI[] prod = prodal.getSequencesArray(); // note + // should + // test + // rather + // than + // throw + // away + // codon + // mapping + // (if + // present) + for (int p = 0; p < prod.length; p++) { - SequenceI[] prod = prodal.getSequencesArray(); // note - // should - // test - // rather - // than - // throw - // away - // codon - // mapping - // (if - // present) - for (int p = 0; p < prod.length; p++) - { - System.out.println("Prod " + p + ": " - + prod[p].getDisplayId(true)); - } + System.out.println("Prod " + p + ": " + + prod[p].getDisplayId(true)); } } - } - } } - }