1 package jalview.ext.ensembl;
3 import static org.testng.AssertJUnit.assertEquals;
4 import static org.testng.AssertJUnit.assertFalse;
5 import static org.testng.AssertJUnit.assertTrue;
6 import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
8 import jalview.datamodel.Alignment;
9 import jalview.datamodel.SequenceFeature;
10 import jalview.datamodel.SequenceI;
11 import jalview.io.AppletFormatAdapter;
12 import jalview.io.FastaFile;
13 import jalview.io.FileParse;
14 import jalview.io.gff.SequenceOntologyFactory;
15 import jalview.io.gff.SequenceOntologyLite;
17 import java.lang.reflect.Method;
18 import java.util.Arrays;
20 import org.testng.Assert;
21 import org.testng.annotations.AfterClass;
22 import org.testng.annotations.BeforeClass;
23 import org.testng.annotations.DataProvider;
24 import org.testng.annotations.Test;
27 public class EnsemblSeqProxyTest
29 private static final Object[][] allSeqs = new Object[][] {
34 + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n"
35 + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQREQQLLESLGNGTDFSVSSSASMDTV\n"
36 + "TSSSSSSLSVLPSSLSVFQNPTDVARSNPKSPQKPIVRVFLPNKQRTVVPARCGVTVRDS\n"
37 + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n"
38 + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n"
39 + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n"
40 + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n"
41 + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n"
42 + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n"
43 + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n"
44 + "KSRWSGSHQFEQLSGSILWMAPEVIRMQDKNPYSFQSDVYAFGIVLYELMTGQLPYSNIN\n"
45 + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n"
46 + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH\n" },
51 + "ATGGCGGCGCTGAGCGGTGGCGGTGGTGGCGGCGCGGAGCCGGGCCAGGCTCTGTTCAAC\n"
52 + "GGGGACATGGAGCCCGAGGCCGGCGCCGGCGCCGGCGCCGCGGCCTCTTCGGCTGCGGAC\n"
53 + "CCTGCCATTCCGGAGGAGGTGTGGAATATCAAACAAATGATTAAGTTGACACAGGAACAT\n"
54 + "ATAGAGGCCCTATTGGACAAATTTGGTGGGGAGCATAATCCACCATCAATATATCTGGAG\n"
55 + "GCCTATGAAGAATACACCAGCAAGCTAGATGCACTCCAACAAAGAGAACAACAGTTATTG\n"
56 + "GAATCTCTGGGGAACGGAACTGATTTTTCTGTTTCTAGCTCTGCATCAATGGATACCGTT\n"
57 + "ACATCTTCTTCCTCTTCTAGCCTTTCAGTGCTACCTTCATCTCTTTCAGTTTTTCAAAAT\n"
58 + "CCCACAGATGTGGCACGGAGCAACCCCAAGTCACCACAAAAACCTATCGTTAGAGTCTTC\n"
59 + "CTGCCCAACAAACAGAGGACAGTGGTACCTGCAAGGTGTGGAGTTACAGTCCGAGACAGT\n"
60 + "CTAAAGAAAGCACTGATGATGAGAGGTCTAATCCCAGAGTGCTGTGCTGTTTACAGAATT\n"
61 + "CAGGATGGAGAGAAGAAACCAATTGGTTGGGACACTGATATTTCCTGGCTTACTGGAGAA\n"
62 + "GAATTGCATGTGGAAGTGTTGGAGAATGTTCCACTTACAACACACAACTTTGTACGAAAA\n"
63 + "ACGTTTTTCACCTTAGCATTTTGTGACTTTTGTCGAAAGCTGCTTTTCCAGGGTTTCCGC\n"
64 + "TGTCAAACATGTGGTTATAAATTTCACCAGCGTTGTAGTACAGAAGTTCCACTGATGTGT\n"
65 + "GTTAATTATGACCAACTTGATTTGCTGTTTGTCTCCAAGTTCTTTGAACACCACCCAATA\n"
66 + "CCACAGGAAGAGGCGTCCTTAGCAGAGACTGCCCTAACATCTGGATCATCCCCTTCCGCA\n"
67 + "CCCGCCTCGGACTCTATTGGGCCCCAAATTCTCACCAGTCCGTCTCCTTCAAAATCCATT\n"
68 + "CCAATTCCACAGCCCTTCCGACCAGCAGATGAAGATCATCGAAATCAATTTGGGCAACGA\n"
69 + "GACCGATCCTCATCAGCTCCCAATGTGCATATAAACACAATAGAACCTGTCAATATTGAT\n"
70 + "GACTTGATTAGAGACCAAGGATTTCGTGGTGATGGAGGATCAACCACAGGTTTGTCTGCT\n"
71 + "ACCCCCCCTGCCTCATTACCTGGCTCACTAACTAACGTGAAAGCCTTACAGAAATCTCCA\n"
72 + "GGACCTCAGCGAGAAAGGAAGTCATCTTCATCCTCAGAAGACAGGAATCGAATGAAAACA\n"
73 + "CTTGGTAGACGGGACTCGAGTGATGATTGGGAGATTCCTGATGGGCAGATTACAGTGGGA\n"
74 + "CAAAGAATTGGATCTGGATCATTTGGAACAGTCTACAAGGGAAAGTGGCATGGTGATGTG\n"
75 + "GCAGTGAAAATGTTGAATGTGACAGCACCTACACCTCAGCAGTTACAAGCCTTCAAAAAT\n"
76 + "GAAGTAGGAGTACTCAGGAAAACACGACATGTGAATATCCTACTCTTCATGGGCTATTCC\n"
77 + "ACAAAGCCACAACTGGCTATTGTTACCCAGTGGTGTGAGGGCTCCAGCTTGTATCACCAT\n"
78 + "CTCCATATCATTGAGACCAAATTTGAGATGATCAAACTTATAGATATTGCACGACAGACT\n"
79 + "GCACAGGGCATGGATTACTTACACGCCAAGTCAATCATCCACAGAGACCTCAAGAGTAAT\n"
80 + "AATATATTTCTTCATGAAGACCTCACAGTAAAAATAGGTGATTTTGGTCTAGCTACAGTG\n"
81 + "AAATCTCGATGGAGTGGGTCCCATCAGTTTGAACAGTTGTCTGGATCCATTTTGTGGATG\n"
82 + "GCACCAGAAGTCATCAGAATGCAAGATAAAAATCCATACAGCTTTCAGTCAGATGTATAT\n"
83 + "GCATTTGGAATTGTTCTGTATGAATTGATGACTGGACAGTTACCTTATTCAAACATCAAC\n"
84 + "AACAGGGACCAGATAATTTTTATGGTGGGACGAGGATACCTGTCTCCAGATCTCAGTAAG\n"
85 + "GTACGGAGTAACTGTCCAAAAGCCATGAAGAGATTAATGGCAGAGTGCCTCAAAAAGAAA\n"
86 + "AGAGATGAGAGACCACTCTTTCCCCAAATTCTCGCCTCTATTGAGCTGCTGGCCCGCTCA\n"
87 + "TTGCCAAAAATTCACCGCAGTGCATCAGAACCCTCCTTGAATCGGGCTGGTTTCCAAACA\n"
88 + "GAGGATTTTAGTCTATATGCTTGTGCTTCTCCAAAAACACCCATCCAGGCAGGGGGATAT\n"
89 + "GGTGCGTTTCCTGTCCACTGA\n" },
94 + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n"
95 + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQREQQLLESLGNGTDFSVSSSASMDTV\n"
96 + "TSSSSSSLSVLPSSLSVFQNPTDVARSNPKSPQKPIVRVFLPNKQRTVVPARCGVTVRDS\n"
97 + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n"
98 + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n"
99 + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n"
100 + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n"
101 + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n"
102 + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n"
103 + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n"
104 + "KSRWSGSHQFEQLSGSILWMAPEVIRMQDKNPYSFQSDVYAFGIVLYELMTGQLPYSNIN\n"
105 + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n"
106 + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH" } };
108 @BeforeClass(alwaysRun = true)
111 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
114 @AfterClass(alwaysRun = true)
115 public void tearDown()
117 SequenceOntologyFactory.setInstance(null);
120 @DataProvider(name = "ens_seqs")
121 public Object[][] createData(Method m)
123 System.out.println(m.getName());
127 @Test(dataProvider = "ens_seqs", suiteName = "live")
128 public void testGetOneSeqs(EnsemblRestClient proxy, String sq, String fastasq)
131 FileParse fp = proxy.getSequenceReader(Arrays
134 SequenceI[] sqs = new FastaFile(fp).getSeqsAsArray();
135 FastaFile trueRes = new FastaFile(fastasq, AppletFormatAdapter.PASTE);
136 SequenceI[] trueSqs = trueRes.getSeqsAsArray();
137 Assert.assertEquals(sqs.length, trueSqs.length,
138 "Different number of sequences retrieved for query " + sq);
139 Alignment ral = new Alignment(sqs);
140 for (SequenceI tr : trueSqs)
143 Assert.assertNotNull(
144 rseq = ral.findSequenceMatch(tr.getName()),
145 "Couldn't find sequences matching expected sequence "
147 Assert.assertEquals(rseq.length, 1,
148 "Expected only one sequence for sequence ID " + tr.getName());
150 rseq[0].getSequenceAsString(),
151 tr.getSequenceAsString(),
152 "Sequences differ for " + tr.getName() + "\n" + "Exp:"
153 + tr.getSequenceAsString() + "\n" + "Got:"
154 + rseq[0].getSequenceAsString());
159 @Test(groups = "Functional")
160 public void getGenomicRangesFromFeatures()
165 @Test(groups = "Functional")
166 public void testIsTranscriptIdentifier()
168 EnsemblSeqProxy testee = new EnsemblGene();
169 assertFalse(testee.isTranscriptIdentifier(null));
170 assertFalse(testee.isTranscriptIdentifier(""));
171 assertFalse(testee.isTranscriptIdentifier("ENSG00000012345"));
172 assertTrue(testee.isTranscriptIdentifier("ENST00000012345"));
173 assertTrue(testee.isTranscriptIdentifier("ENSMUST00000012345"));
174 assertFalse(testee.isTranscriptIdentifier("enst00000012345"));
175 assertFalse(testee.isTranscriptIdentifier("ENST000000123456"));
176 assertFalse(testee.isTranscriptIdentifier("ENST0000001234"));
179 @Test(groups = "Functional")
180 public void testIsGeneIdentifier()
182 EnsemblSeqProxy testee = new EnsemblGene();
183 assertFalse(testee.isGeneIdentifier(null));
184 assertFalse(testee.isGeneIdentifier(""));
185 assertFalse(testee.isGeneIdentifier("ENST00000012345"));
186 assertTrue(testee.isGeneIdentifier("ENSG00000012345"));
187 assertTrue(testee.isGeneIdentifier("ENSMUSG00000012345"));
188 assertFalse(testee.isGeneIdentifier("ensg00000012345"));
189 assertFalse(testee.isGeneIdentifier("ENSG000000123456"));
190 assertFalse(testee.isGeneIdentifier("ENSG0000001234"));
194 * Test the method that appends a single allele's reverse complement to a
197 @Test(groups = "Functional")
198 public void testReverseComplementAllele()
200 StringBuilder sb = new StringBuilder();
201 EnsemblSeqProxy.reverseComplementAllele(sb, "G"); // comp=C
202 EnsemblSeqProxy.reverseComplementAllele(sb, "g"); // comp=c
203 EnsemblSeqProxy.reverseComplementAllele(sb, "C"); // comp=G
204 EnsemblSeqProxy.reverseComplementAllele(sb, "T"); // comp=A
205 EnsemblSeqProxy.reverseComplementAllele(sb, "A"); // comp=T
206 assertEquals("C,c,G,A,T", sb.toString());
208 sb = new StringBuilder();
209 EnsemblSeqProxy.reverseComplementAllele(sb, "-GATt"); // revcomp=aATC-
210 EnsemblSeqProxy.reverseComplementAllele(sb, "hgmd_mutation");
211 EnsemblSeqProxy.reverseComplementAllele(sb, "PhenCode_variation");
212 assertEquals("aATC-,hgmd_mutation,PhenCode_variation", sb.toString());
216 * Test the method that computes the reverse complement of the alleles in a
217 * sequence_variant feature
219 @Test(groups = "Functional")
220 public void testReverseComplementAlleles()
222 String alleles = "C,G,-TAC,HGMD_MUTATION,gac";
223 SequenceFeature sf = new SequenceFeature("sequence_variant", alleles,
225 sf.setValue("alleles", alleles);
226 sf.setAttributes("x=y,z;alleles=" + alleles + ";a=b,c");
228 EnsemblSeqProxy.reverseComplementAlleles(sf);
229 String revcomp = "G,C,GTA-,HGMD_MUTATION,gtc";
230 // verify description is updated with reverse complement
231 assertEquals(revcomp, sf.getDescription());
232 // verify alleles attribute is updated with reverse complement
233 assertEquals(revcomp, sf.getValue("alleles"));
234 // verify attributes string is updated with reverse complement
235 assertEquals("x=y,z;alleles=" + revcomp + ";a=b,c", sf.getAttributes());
238 @Test(groups = "Functional")
239 public void testSortFeatures()
241 SequenceFeature sf1 = new SequenceFeature("", "", 10, 15, 0f, null);
242 SequenceFeature sf2 = new SequenceFeature("", "", 8, 12, 0f, null);
243 SequenceFeature sf3 = new SequenceFeature("", "", 8, 13, 0f, null);
244 SequenceFeature sf4 = new SequenceFeature("", "", 11, 11, 0f, null);
245 SequenceFeature[] sfs = new SequenceFeature[] { sf1, sf2, sf3, sf4 };
247 // sort by start position ascending (forward strand)
248 // sf2 and sf3 tie and should not be reordered by sorting
249 EnsemblSeqProxy.sortFeatures(sfs, true);
250 assertArrayEquals(new SequenceFeature[] { sf2, sf3, sf1, sf4 }, sfs);
252 // sort by end position descending (reverse strand)
253 EnsemblSeqProxy.sortFeatures(sfs, false);
254 assertArrayEquals(new SequenceFeature[] { sf1, sf3, sf2, sf4 }, sfs);