X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Fensembl%2FEnsemblSeqProxyTest.java;h=a4d6d92b98964e6ab8afc925a1b9e5b9f8dee7e1;hb=6200addf078b7f7ace90597dc056dafc7fc602c1;hp=978316bf2cc8f118c3aa21cb975531f87477d52b;hpb=58c6b8248851792fa37db90c54d55f419a439cad;p=jalview.git diff --git a/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java b/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java index 978316b..a4d6d92 100644 --- a/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java +++ b/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java @@ -1,53 +1,57 @@ +/* + * 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.ext.ensembl; -import jalview.datamodel.Alignment; +import static org.testng.AssertJUnit.assertEquals; + +import jalview.datamodel.AlignmentI; +import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; -import jalview.ext.ensembl.SeqFetcher.EnsemblSeqType; -import jalview.io.AppletFormatAdapter; +import jalview.gui.JvOptionPane; +import jalview.io.DataSourceType; import jalview.io.FastaFile; -import jalview.io.FileParse; -import jalview.util.DBRefUtils; +import jalview.io.gff.SequenceOntologyFactory; +import jalview.io.gff.SequenceOntologyLite; import java.lang.reflect.Method; -import java.util.Arrays; import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; public class EnsemblSeqProxyTest { - @Test - public void testCheckEnsembl() - { - SeqFetcher sf = new SeqFetcher(); - sf.setTestEnsemblStatus(true); - sf.setTesting(true); - Assert.assertTrue(sf.isEnsemblAvailable()); - sf.setTestEnsemblStatus(false); - Assert.assertFalse(sf.isEnsemblAvailable()); - } - - @Test(suiteName = "live") - public void testLiveCheckEnsembl() - { - SeqFetcher sf = new SeqFetcher(); - boolean isAvailable = sf.isEnsemblAvailable(); - System.out.println("Ensembl is " - + (isAvailable ? "UP!" : "DOWN ******************* BAD!")); - } - @DataProvider(name = "ens_seqs") - public Object[][] createData(Method m) + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() { - System.out.println(m.getName()); - return allSeqs; + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } - public static Object[][] allSeqs = new Object[][] - { + private static final Object[][] allSeqs = new Object[][] { { - EnsemblSeqType.PROTEIN, + new EnsemblProtein(), "CCDS5863.1", ">CCDS5863.1\n" + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n" @@ -64,7 +68,7 @@ public class EnsemblSeqProxyTest + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n" + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH\n" }, { - EnsemblSeqType.TRANSCRIPT, + new EnsemblCdna(), "CCDS5863.1", ">CCDS5863.1\n" + "ATGGCGGCGCTGAGCGGTGGCGGTGGTGGCGGCGCGGAGCCGGGCCAGGCTCTGTTCAAC\n" @@ -107,7 +111,7 @@ public class EnsemblSeqProxyTest + "GAGGATTTTAGTCTATATGCTTGTGCTTCTCCAAAAACACCCATCCAGGCAGGGGGATAT\n" + "GGTGCGTTTCCTGTCCACTGA\n" }, { - EnsemblSeqType.PROTEIN, + new EnsemblProtein(), "ENSP00000288602", ">ENSP00000288602\n" + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n" @@ -116,7 +120,11 @@ public class EnsemblSeqProxyTest + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n" + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n" + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n" - + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n" + + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDG\n" + // ? insertion added in ENSP00000288602.11, not in P15056 + + "APLNQLMRCLRKYQSRTPSPLLHSVPSEIVFDFEPGPVFR\n" + // end insertion + + "GSTTGLSATPPASLPGSLTNVKALQKSP\n" + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n" + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n" + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n" @@ -124,24 +132,41 @@ public class EnsemblSeqProxyTest + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n" + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH" } }; + @BeforeClass(alwaysRun = true) + public void setUp() + { + SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite()); + } + + @AfterClass(alwaysRun = true) + public void tearDown() + { + SequenceOntologyFactory.setSequenceOntology(null); + } + + @DataProvider(name = "ens_seqs") + public Object[][] createData(Method m) + { + System.out.println(m.getName()); + return allSeqs; + } + @Test(dataProvider = "ens_seqs", suiteName = "live") - public void testGetOneSeqs(EnsemblSeqType type, String sq, String fastasq) - throws Exception + public void testGetSequenceRecords(EnsemblSeqProxy proxy, String sq, + String fastasq) throws Exception { - SeqFetcher sf = new SeqFetcher(); - FileParse fp = sf.getSequenceReader(type, Arrays.asList(new String[] - { sq })); - SequenceI[] sqs = new FastaFile(fp).getSeqsAsArray(); - FastaFile trueRes = new FastaFile(fastasq, AppletFormatAdapter.PASTE); - SequenceI[] trueSqs = trueRes.getSeqsAsArray(); - Assert.assertEquals(sqs.length, trueSqs.length, + FastaFile trueRes = new FastaFile(fastasq, DataSourceType.PASTE); + SequenceI[] expected = trueRes.getSeqsAsArray(); + AlignmentI retrieved = proxy.getSequenceRecords(sq); + + Assert.assertEquals(retrieved.getHeight(), expected.length, "Different number of sequences retrieved for query " + sq); - Alignment ral = new Alignment(sqs); - for (SequenceI tr : trueSqs) + + for (SequenceI tr : expected) { SequenceI[] rseq; Assert.assertNotNull( - rseq = ral.findSequenceMatch(tr.getName()), + rseq = retrieved.findSequenceMatch(tr.getName()), "Couldn't find sequences matching expected sequence " + tr.getName()); Assert.assertEquals(rseq.length, 1, @@ -152,48 +177,54 @@ public class EnsemblSeqProxyTest "Sequences differ for " + tr.getName() + "\n" + "Exp:" + tr.getSequenceAsString() + "\n" + "Got:" + rseq[0].getSequenceAsString()); - } } - @Test(dataProvider = "ens_seqs") - public void testRegexForProxy(EnsemblSeqType type, String sq, - String fastasq) throws Exception + @Test(groups = "Functional") + public void getGenomicRangesFromFeatures() { - EnsemblSeqProxy esq = new EnsemblProtein(); - Assert.assertTrue(esq.isValidReference(sq), - "Expected reference string " + sq + " to be valid for regex " - + esq.getAccessionValidator().toString()); - - Assert.assertEquals(sq, DBRefUtils.processQueryToAccessionFor(esq, sq), - "Regex for " + esq.getClass().toString() + " not correct."); + + } + + /** + * Test the method that appends a single allele's reverse complement to a + * string buffer + */ + @Test(groups = "Functional") + public void testReverseComplementAllele() + { + StringBuilder sb = new StringBuilder(); + EnsemblSeqProxy.reverseComplementAllele(sb, "G"); // comp=C + EnsemblSeqProxy.reverseComplementAllele(sb, "g"); // comp=c + EnsemblSeqProxy.reverseComplementAllele(sb, "C"); // comp=G + EnsemblSeqProxy.reverseComplementAllele(sb, "T"); // comp=A + EnsemblSeqProxy.reverseComplementAllele(sb, "A"); // comp=T + assertEquals("C,c,G,A,T", sb.toString()); + + sb = new StringBuilder(); + EnsemblSeqProxy.reverseComplementAllele(sb, "-GATt"); // revcomp=aATC- + EnsemblSeqProxy.reverseComplementAllele(sb, "hgmd_mutation"); + EnsemblSeqProxy.reverseComplementAllele(sb, "PhenCode_variation"); + assertEquals("aATC-,hgmd_mutation,PhenCode_variation", sb.toString()); + } + + /** + * Test the method that computes the reverse complement of the alleles in a + * sequence_variant feature + */ + @Test(groups = "Functional") + public void testReverseComplementAlleles() + { + String alleles = "C,G,-TAC,HGMD_MUTATION,gac"; + SequenceFeature sf = new SequenceFeature("sequence_variant", alleles, + 1, 2, 0f, null); + sf.setValue("alleles", alleles); + + EnsemblSeqProxy.reverseComplementAlleles(sf); + String revcomp = "G,C,GTA-,HGMD_MUTATION,gtc"; + // verify description is updated with reverse complement + assertEquals(revcomp, sf.getDescription()); + // verify alleles attribute is updated with reverse complement + assertEquals(revcomp, sf.getValue("alleles")); } - // TODO: - // sequence query with ENSG and anything other than a genomic type will yield - // sequences with different IDs which will - // break the post-processing stage where DBRefs are assigned to sequences. - // -> multiple_sequences = true is needed additional parameter - // http://rest.ensembl.org/sequence/id/ENSG00000157764?content-type=text/x-json;type=protein;multiple_sequences=true - // result with four transcripts, cds, cdna, and protein products. - // * - // features for ENG - - // http://rest.ensembl.org/overlap/id/ENSG00000157764?feature=cds&feature=exon&feature=transcript&content-type=text/x-gff3 - // transcript: gives locus, all transcript products with ENSG parents - // gene: give all ENSG on locus - // exon: all exon boundaries. CDS same info. - - // @Test(dataProvider = "ens_seqs", suiteName = "live") - // public void testGetOneSeqs(EnsemblSeqType type, String sq, String fastasq) - // throws Exception - // { - // - // { - // Assert.assertTrue(rseq[0].getDBRef() != null - // && rseq[0].getDBRef().length > 0, - // "No database references added to sequence by fetcher."); - // Assert.assertNotNull(DBRefUtils.searchRefs(rseq[0].getDBRef(), - // new DBRefEntry("ENSEMBL", null, sq)), - // "Could't find database references added to sequence by fetcher."); - // - // } -} \ No newline at end of file +}