package jalview.ext.ensembl; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertTrue; import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import jalview.datamodel.Alignment; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.io.AppletFormatAdapter; import jalview.io.FastaFile; import jalview.io.FileParse; 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 { private static final Object[][] allSeqs = new Object[][] { { new EnsemblProtein(), "CCDS5863.1", ">CCDS5863.1\n" + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n" + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQREQQLLESLGNGTDFSVSSSASMDTV\n" + "TSSSSSSLSVLPSSLSVFQNPTDVARSNPKSPQKPIVRVFLPNKQRTVVPARCGVTVRDS\n" + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n" + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n" + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n" + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n" + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n" + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n" + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n" + "KSRWSGSHQFEQLSGSILWMAPEVIRMQDKNPYSFQSDVYAFGIVLYELMTGQLPYSNIN\n" + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n" + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH\n" }, { new EnsemblCdna(), "CCDS5863.1", ">CCDS5863.1\n" + "ATGGCGGCGCTGAGCGGTGGCGGTGGTGGCGGCGCGGAGCCGGGCCAGGCTCTGTTCAAC\n" + "GGGGACATGGAGCCCGAGGCCGGCGCCGGCGCCGGCGCCGCGGCCTCTTCGGCTGCGGAC\n" + "CCTGCCATTCCGGAGGAGGTGTGGAATATCAAACAAATGATTAAGTTGACACAGGAACAT\n" + "ATAGAGGCCCTATTGGACAAATTTGGTGGGGAGCATAATCCACCATCAATATATCTGGAG\n" + "GCCTATGAAGAATACACCAGCAAGCTAGATGCACTCCAACAAAGAGAACAACAGTTATTG\n" + "GAATCTCTGGGGAACGGAACTGATTTTTCTGTTTCTAGCTCTGCATCAATGGATACCGTT\n" + "ACATCTTCTTCCTCTTCTAGCCTTTCAGTGCTACCTTCATCTCTTTCAGTTTTTCAAAAT\n" + "CCCACAGATGTGGCACGGAGCAACCCCAAGTCACCACAAAAACCTATCGTTAGAGTCTTC\n" + "CTGCCCAACAAACAGAGGACAGTGGTACCTGCAAGGTGTGGAGTTACAGTCCGAGACAGT\n" + "CTAAAGAAAGCACTGATGATGAGAGGTCTAATCCCAGAGTGCTGTGCTGTTTACAGAATT\n" + "CAGGATGGAGAGAAGAAACCAATTGGTTGGGACACTGATATTTCCTGGCTTACTGGAGAA\n" + "GAATTGCATGTGGAAGTGTTGGAGAATGTTCCACTTACAACACACAACTTTGTACGAAAA\n" + "ACGTTTTTCACCTTAGCATTTTGTGACTTTTGTCGAAAGCTGCTTTTCCAGGGTTTCCGC\n" + "TGTCAAACATGTGGTTATAAATTTCACCAGCGTTGTAGTACAGAAGTTCCACTGATGTGT\n" + "GTTAATTATGACCAACTTGATTTGCTGTTTGTCTCCAAGTTCTTTGAACACCACCCAATA\n" + "CCACAGGAAGAGGCGTCCTTAGCAGAGACTGCCCTAACATCTGGATCATCCCCTTCCGCA\n" + "CCCGCCTCGGACTCTATTGGGCCCCAAATTCTCACCAGTCCGTCTCCTTCAAAATCCATT\n" + "CCAATTCCACAGCCCTTCCGACCAGCAGATGAAGATCATCGAAATCAATTTGGGCAACGA\n" + "GACCGATCCTCATCAGCTCCCAATGTGCATATAAACACAATAGAACCTGTCAATATTGAT\n" + "GACTTGATTAGAGACCAAGGATTTCGTGGTGATGGAGGATCAACCACAGGTTTGTCTGCT\n" + "ACCCCCCCTGCCTCATTACCTGGCTCACTAACTAACGTGAAAGCCTTACAGAAATCTCCA\n" + "GGACCTCAGCGAGAAAGGAAGTCATCTTCATCCTCAGAAGACAGGAATCGAATGAAAACA\n" + "CTTGGTAGACGGGACTCGAGTGATGATTGGGAGATTCCTGATGGGCAGATTACAGTGGGA\n" + "CAAAGAATTGGATCTGGATCATTTGGAACAGTCTACAAGGGAAAGTGGCATGGTGATGTG\n" + "GCAGTGAAAATGTTGAATGTGACAGCACCTACACCTCAGCAGTTACAAGCCTTCAAAAAT\n" + "GAAGTAGGAGTACTCAGGAAAACACGACATGTGAATATCCTACTCTTCATGGGCTATTCC\n" + "ACAAAGCCACAACTGGCTATTGTTACCCAGTGGTGTGAGGGCTCCAGCTTGTATCACCAT\n" + "CTCCATATCATTGAGACCAAATTTGAGATGATCAAACTTATAGATATTGCACGACAGACT\n" + "GCACAGGGCATGGATTACTTACACGCCAAGTCAATCATCCACAGAGACCTCAAGAGTAAT\n" + "AATATATTTCTTCATGAAGACCTCACAGTAAAAATAGGTGATTTTGGTCTAGCTACAGTG\n" + "AAATCTCGATGGAGTGGGTCCCATCAGTTTGAACAGTTGTCTGGATCCATTTTGTGGATG\n" + "GCACCAGAAGTCATCAGAATGCAAGATAAAAATCCATACAGCTTTCAGTCAGATGTATAT\n" + "GCATTTGGAATTGTTCTGTATGAATTGATGACTGGACAGTTACCTTATTCAAACATCAAC\n" + "AACAGGGACCAGATAATTTTTATGGTGGGACGAGGATACCTGTCTCCAGATCTCAGTAAG\n" + "GTACGGAGTAACTGTCCAAAAGCCATGAAGAGATTAATGGCAGAGTGCCTCAAAAAGAAA\n" + "AGAGATGAGAGACCACTCTTTCCCCAAATTCTCGCCTCTATTGAGCTGCTGGCCCGCTCA\n" + "TTGCCAAAAATTCACCGCAGTGCATCAGAACCCTCCTTGAATCGGGCTGGTTTCCAAACA\n" + "GAGGATTTTAGTCTATATGCTTGTGCTTCTCCAAAAACACCCATCCAGGCAGGGGGATAT\n" + "GGTGCGTTTCCTGTCCACTGA\n" }, { new EnsemblProtein(), "ENSP00000288602", ">ENSP00000288602\n" + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n" + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQREQQLLESLGNGTDFSVSSSASMDTV\n" + "TSSSSSSLSVLPSSLSVFQNPTDVARSNPKSPQKPIVRVFLPNKQRTVVPARCGVTVRDS\n" + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n" + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n" + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n" + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n" + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n" + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n" + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n" + "KSRWSGSHQFEQLSGSILWMAPEVIRMQDKNPYSFQSDVYAFGIVLYELMTGQLPYSNIN\n" + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n" + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH" } }; @BeforeClass(alwaysRun = true) public void setUp() { SequenceOntologyFactory.setInstance(new SequenceOntologyLite()); } @AfterClass(alwaysRun = true) public void tearDown() { SequenceOntologyFactory.setInstance(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(EnsemblRestClient 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, "Different number of sequences retrieved for query " + sq); Alignment ral = new Alignment(sqs); for (SequenceI tr : trueSqs) { SequenceI[] rseq; Assert.assertNotNull( rseq = ral.findSequenceMatch(tr.getName()), "Couldn't find sequences matching expected sequence " + tr.getName()); Assert.assertEquals(rseq.length, 1, "Expected only one sequence for sequence ID " + tr.getName()); Assert.assertEquals( rseq[0].getSequenceAsString(), tr.getSequenceAsString(), "Sequences differ for " + tr.getName() + "\n" + "Exp:" + tr.getSequenceAsString() + "\n" + "Got:" + rseq[0].getSequenceAsString()); } } @Test(groups = "Functional") public void getGenomicRangesFromFeatures() { } @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")); } @Test(groups = "Functional") public void testIsGeneIdentifier() { 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")); } /** * 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); sf.setAttributes("x=y,z;alleles=" + alleles + ";a=b,c"); 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")); // verify attributes string is updated with reverse complement assertEquals("x=y,z;alleles=" + revcomp + ";a=b,c", sf.getAttributes()); } @Test(groups = "Functional") public void testSortFeatures() { SequenceFeature sf1 = new SequenceFeature("", "", 10, 15, 0f, null); SequenceFeature sf2 = new SequenceFeature("", "", 8, 12, 0f, null); SequenceFeature sf3 = new SequenceFeature("", "", 8, 13, 0f, null); SequenceFeature sf4 = new SequenceFeature("", "", 11, 11, 0f, null); SequenceFeature[] sfs = new SequenceFeature[] { sf1, sf2, sf3, sf4 }; // sort by start position ascending (forward strand) // sf2 and sf3 tie and should not be reordered by sorting EnsemblSeqProxy.sortFeatures(sfs, true); assertArrayEquals(new SequenceFeature[] { sf2, sf3, sf1, sf4 }, sfs); // sort by end position descending (reverse strand) EnsemblSeqProxy.sortFeatures(sfs, false); assertArrayEquals(new SequenceFeature[] { sf1, sf3, sf2, sf4 }, sfs); } }