X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fext%2Fensembl%2FEnsemblSeqProxyTest.java;h=a4d6d92b98964e6ab8afc925a1b9e5b9f8dee7e1;hb=6200addf078b7f7ace90597dc056dafc7fc602c1;hp=5d95a3cb41cea5da6b704ff58dddc9f0229bc095;hpb=b8058f3f849f44740a695c83e96bdca3a197af5c;p=jalview.git diff --git a/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java b/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java index 5d95a3c..a4d6d92 100644 --- a/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java +++ b/test/jalview/ext/ensembl/EnsemblSeqProxyTest.java @@ -1,26 +1,37 @@ +/* + * 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 static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertFalse; -import static org.testng.AssertJUnit.assertTrue; -import jalview.datamodel.Alignment; import jalview.datamodel.AlignmentI; -import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; -import jalview.io.AppletFormatAdapter; +import jalview.gui.JvOptionPane; +import jalview.io.DataSourceType; import jalview.io.FastaFile; -import jalview.io.FileParse; import jalview.io.gff.SequenceOntologyFactory; import jalview.io.gff.SequenceOntologyLite; -import jalview.util.MappingUtils; import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.List; import org.testng.Assert; import org.testng.annotations.AfterClass; @@ -28,9 +39,16 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; - public class EnsemblSeqProxyTest { + + @BeforeClass(alwaysRun = true) + public void setUpJvOptionPane() + { + JvOptionPane.setInteractiveMode(false); + JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); + } + private static final Object[][] allSeqs = new Object[][] { { new EnsemblProtein(), @@ -102,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" @@ -110,16 +132,16 @@ public class EnsemblSeqProxyTest + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n" + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH" } }; - @BeforeClass + @BeforeClass(alwaysRun = true) public void setUp() { - SequenceOntologyFactory.setInstance(new SequenceOntologyLite()); + SequenceOntologyFactory.setSequenceOntology(new SequenceOntologyLite()); } - @AfterClass + @AfterClass(alwaysRun = true) public void tearDown() { - SequenceOntologyFactory.setInstance(null); + SequenceOntologyFactory.setSequenceOntology(null); } @DataProvider(name = "ens_seqs") @@ -130,23 +152,21 @@ public class EnsemblSeqProxyTest } @Test(dataProvider = "ens_seqs", suiteName = "live") - public void testGetOneSeqs(EnsemblRestClient proxy, String sq, String fastasq) - throws Exception + public void testGetSequenceRecords(EnsemblSeqProxy proxy, String sq, + String fastasq) throws Exception { - FileParse fp = proxy.getSequenceReader(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, @@ -157,168 +177,9 @@ public class EnsemblSeqProxyTest "Sequences differ for " + tr.getName() + "\n" + "Exp:" + tr.getSequenceAsString() + "\n" + "Got:" + rseq[0].getSequenceAsString()); - } } - @Test(suiteName = "live") - public void testLiveCheckEnsembl() - { - EnsemblRestClient sf = new EnsemblRestClient() - { - - @Override - public String getDbName() - { - // TODO Auto-generated method stub - return null; - } - - @Override - public AlignmentI getSequenceRecords(String queries) throws Exception - { - // TODO Auto-generated method stub - return null; - } - - @Override - protected URL getUrl(List ids) throws MalformedURLException - { - // TODO Auto-generated method stub - return null; - } - - @Override - protected boolean useGetRequest() - { - // TODO Auto-generated method stub - return false; - } - - @Override - protected String getRequestMimeType(boolean b) - { - // TODO Auto-generated method stub - return null; - } - - @Override - protected String getResponseMimeType() - { - // TODO Auto-generated method stub - return null; - } - - }; - boolean isAvailable = sf.isEnsemblAvailable(); - System.out.println("Ensembl is " - + (isAvailable ? "UP!" - : "DOWN or unreachable ******************* BAD!")); - } - - /** - * Tests for the method that computes all peptide variants given codon - * variants - */ - @Test(groups = "Functional") - public void testComputePeptideVariants() - { - String[][] codonVariants = new String[][] { { "A" }, { "G" }, { "T" } }; - - /* - * AGT codes for S - this is not included in the variants returned - */ - List variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[]", variants.toString()); - - // S is reported if it differs from the current value (A): - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "A"); - assertEquals("[S]", variants.toString()); - - /* - * synonymous variant is not reported - */ - codonVariants = new String[][] { { "A" }, { "G" }, { "C", "T" } }; - // AGC and AGT both code for S - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "s"); - assertEquals("[]", variants.toString()); - - /* - * equivalent variants are only reported once - */ - codonVariants = new String[][] { { "C" }, { "T" }, - { "A", "C", "G", "T" } }; - // CTA CTC CTG CTT all code for L - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[L]", variants.toString()); - - /* - * vary codons 1 and 2; variant products are sorted and non-redundant - */ - codonVariants = new String[][] { { "a", "C" }, { "g", "T" }, { "A" } }; - // aga ata cga cta code for R, I, R, L - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[I, L, R]", variants.toString()); - - /* - * vary codons 2 and 3 - */ - codonVariants = new String[][] { { "a" }, { "g", "T" }, { "A", "c" } }; - // aga agc ata atc code for R, S, I, I - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[I, R]", variants.toString()); - - /* - * vary codons 1 and 3 - */ - codonVariants = new String[][] { { "a", "t" }, { "a" }, { "t", "g" } }; - // aat aag tat tag code for N, K, Y, STOP - STOP sorted to end - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[K, N, Y, STOP]", variants.toString()); - - /* - * vary codons 1, 2 and 3 - */ - codonVariants = new String[][] { { "a", "t" }, { "G", "C" }, - { "t", "g" } }; - // agt agg act acg tgt tgg tct tcg code for S, R, T, T, C, W, S, S - variants = EnsemblSeqProxy.computePeptideVariants(codonVariants, "S"); - assertEquals("[C, R, T, W]", variants.toString()); - } - - /** - * Tests for the method that maps the subset of a dna sequence that has CDS - * (or subtype) feature. - */ - @Test(groups = "Functional") - public void testGetCdsRanges() - { - EnsemblSeqProxy testee = new EnsemblSeqProxyAdapter(); - - SequenceI dnaSeq = new Sequence("dna", "aaaGGGcccAAATTTttt"); - dnaSeq.createDatasetSequence(); - SequenceI ds = dnaSeq.getDatasetSequence(); - - // CDS for dna 3-6 - SequenceFeature sf = new SequenceFeature("CDS", "", 4, 6, 0f, null); - ds.addSequenceFeature(sf); - // exon feature should be ignored here - sf = new SequenceFeature("exon", "", 7, 9, 0f, null); - ds.addSequenceFeature(sf); - // CDS for dna 10-12 - sf = new SequenceFeature("CDS_predicted", "", 10, 12, 0f, null); - ds.addSequenceFeature(sf); - - List ranges = testee.getCdsRanges(dnaSeq); - assertEquals(6, MappingUtils.getLength(ranges)); - assertEquals(2, ranges.size()); - assertEquals(4, ranges.get(0)[0]); - assertEquals(6, ranges.get(0)[1]); - assertEquals(10, ranges.get(1)[0]); - assertEquals(12, ranges.get(1)[1]); - - } - @Test(groups = "Functional") public void getGenomicRangesFromFeatures() { @@ -326,64 +187,44 @@ public class EnsemblSeqProxyTest } /** - * Tests for the method that maps the subset of a dna sequence that has CDS - * (or subtype) feature - case where the start codon is incomplete. + * Test the method that appends a single allele's reverse complement to a + * string buffer */ @Test(groups = "Functional") - public void testGetCdsRanges_fivePrimeIncomplete() + public void testReverseComplementAllele() { - EnsemblSeqProxy testee = new EnsemblSeqProxyAdapter(); - - SequenceI dnaSeq = new Sequence("dna", "aaagGGCCCaaaTTTttt"); - dnaSeq.createDatasetSequence(); - SequenceI ds = dnaSeq.getDatasetSequence(); - - // CDS for dna 5-6 (incomplete codon), 7-9 - SequenceFeature sf = new SequenceFeature("CDS", "", 5, 9, 0f, null); - sf.setPhase("2"); // skip 2 bases to start of next codon - ds.addSequenceFeature(sf); - // CDS for dna 13-15 - sf = new SequenceFeature("CDS_predicted", "", 13, 15, 0f, null); - ds.addSequenceFeature(sf); - - List ranges = testee.getCdsRanges(dnaSeq); - - /* - * check the mapping starts with the first complete codon - */ - assertEquals(6, MappingUtils.getLength(ranges)); - assertEquals(2, ranges.size()); - assertEquals(7, ranges.get(0)[0]); - assertEquals(9, ranges.get(0)[1]); - assertEquals(13, ranges.get(1)[0]); - assertEquals(15, ranges.get(1)[1]); - } - - @Test(groups = "Functional") - public void testIsTranscriptIdentifier() - { - EnsemblSeqProxy testee = new EnsemblGene(); - assertFalse(testee.isTranscriptIdentifier(null)); - assertFalse(testee.isTranscriptIdentifier("")); - assertFalse(testee.isTranscriptIdentifier("ENSG00000012345")); - assertTrue(testee.isTranscriptIdentifier("ENST00000012345")); - assertTrue(testee.isTranscriptIdentifier("ENSMUST00000012345")); - assertFalse(testee.isTranscriptIdentifier("enst00000012345")); - assertFalse(testee.isTranscriptIdentifier("ENST000000123456")); - assertFalse(testee.isTranscriptIdentifier("ENST0000001234")); + 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 testIsGeneIdentifier() + public void testReverseComplementAlleles() { - EnsemblSeqProxy testee = new EnsemblGene(); - assertFalse(testee.isGeneIdentifier(null)); - assertFalse(testee.isGeneIdentifier("")); - assertFalse(testee.isGeneIdentifier("ENST00000012345")); - assertTrue(testee.isGeneIdentifier("ENSG00000012345")); - assertTrue(testee.isGeneIdentifier("ENSMUSG00000012345")); - assertFalse(testee.isGeneIdentifier("ensg00000012345")); - assertFalse(testee.isGeneIdentifier("ENSG000000123456")); - assertFalse(testee.isGeneIdentifier("ENSG0000001234")); + 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")); } -} \ No newline at end of file +}