2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ext.ensembl;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertSame;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.datamodel.Alignment;
29 import jalview.datamodel.SequenceFeature;
30 import jalview.datamodel.SequenceI;
31 import jalview.datamodel.features.SequenceFeatures;
32 import jalview.gui.JvOptionPane;
33 import jalview.io.DataSourceType;
34 import jalview.io.FastaFile;
35 import jalview.io.FileParse;
36 import jalview.io.gff.SequenceOntologyFactory;
37 import jalview.io.gff.SequenceOntologyLite;
39 import java.lang.reflect.Method;
40 import java.util.Arrays;
41 import java.util.List;
43 import org.testng.Assert;
44 import org.testng.annotations.AfterClass;
45 import org.testng.annotations.BeforeClass;
46 import org.testng.annotations.DataProvider;
47 import org.testng.annotations.Test;
49 public class EnsemblSeqProxyTest
52 @BeforeClass(alwaysRun = true)
53 public void setUpJvOptionPane()
55 JvOptionPane.setInteractiveMode(false);
56 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
59 private static final Object[][] allSeqs = new Object[][] {
64 + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n"
65 + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQ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AACAGTTATTG\n"
86 + "GAATCTCTGGGGAACGGAACTGATTTTTCTGTTTCTAGCTCTGCATCAATGGATACCGTT\n"
87 + "ACATCTTCTTCCTCTTCTAGCCTTTCAGTGCTACCTTCATCTCTTTCAGTTTTTCAAAAT\n"
88 + "CCCACAGATGTGGCACGGAGCAACCCCAAGTCACCACAAAAACCTATCGTTAGAGTCTTC\n"
89 + "CTGCCCAACAAACAGAGGACAGTGGTACCTGCAAGGTGTGGAGTTACAGTCCGAGACAGT\n"
90 + "CTAAAGAAAGCACTGATGATGAGAGGTCTAATCCCAGAGTGCTGTGCTGTTTACAGAATT\n"
91 + "CAGGATGGAGAGAAGAAACCAATTGGTTGGGACACTGATATTTCCTGGCTTACTGGAGAA\n"
92 + "GAATTGCATGTGGAAGTGTTGGAGAATGTTCCACTTACAACACACAACTTTGTACGAAAA\n"
93 + "ACGTTTTTCACCTTAGCATTTTGTGACTTTTGTCGAAAGCTGCTTTTCCAGGGTTTCCGC\n"
94 + "TGTCAAACATGTGGTTATAAATTTCACCAGCGTTGTAGTACAGAAGTTCCACTGATGTGT\n"
95 + "GTTAATTATGACCAACTTGATTTGCTGTTTGTCTCCAAGTTCTTTGAACACCACCCAATA\n"
96 + "CCACAGGAAGAGGCGTCCTTAGCAGAGACTGCCCTAACATCTGGATCATCCCCTTCCGCA\n"
97 + "CCCGCCTCGGACTCTATTGGGCCCCAAATTCTCACCAGTCCGTCTCCTTCAAAATCCATT\n"
98 + "CCAATTCCACAGCCCTTCCGACCAGCAGATGAAGATCATCGAAATCAATTTGGGCAACGA\n"
99 + "GACCGATCCTCATCAGCTCCCAATGTGCATATAAACACAATAGAACCTGTCAATATTGAT\n"
100 + "GACTTGATTAGAGACCAAGGATTTCGTGGTGATGGAGGATCAACCACAGGTTTGTCTGCT\n"
101 + "ACCCCCCCTGCCTCATTACCTGGCTCACTAACTAACGTGAAAGCCTTACAGAAATCTCCA\n"
102 + "GGACCTCAGCGAGAAAGGAAGTCATCTTCATCCTCAGAAGACAGGAATCGAATGAAAACA\n"
103 + "CTTGGTAGACGGGACTCGAGTGATGATTGGGAGATTCCTGATGGGCAGATTACAGTGGGA\n"
104 + "CAAAGAATTGGATCTGGATCATTTGGAACAGTCTACAAGGGAAAGTGGCATGGTGATGTG\n"
105 + "GCAGTGAAAATGTTGAATGTGACAGCACCTACACCTCAGCAGTTACAAGCCTTCAAAAAT\n"
106 + "GAAGTAGGAGTACTCAGGAAAACACGACATGTGAATATCCTACTCTTCATGGGCTATTCC\n"
107 + "ACAAAGCCACAACTGGCTATTGTTACCCAGTGGTGTGAGGGCTCCAGCTTGTATCACCAT\n"
108 + "CTCCATATCATTGAGACCAAATTTGAGATGATCAAACTTATAGATATTGCACGACAGACT\n"
109 + "GCACAGGGCATGGATTACTTACACGCCAAGTCAATCATCCACAGAGACCTCAAGAGTAAT\n"
110 + "AATATATTTCTTCATGAAGACCTCACAGTAAAAATAGGTGATTTTGGTCTAGCTACAGTG\n"
111 + "AAATCTCGATGGAGTGGGTCCCATCAGTTTGAACAGTTGTCTGGATCCATTTTGTGGATG\n"
112 + "GCACCAGAAGTCATCAGAATGCAAGATAAAAATCCATACAGCTTTCAGTCAGATGTATAT\n"
113 + "GCATTTGGAATTGTTCTGTATGAATTGATGACTGGACAGTTACCTTATTCAAACATCAAC\n"
114 + "AACAGGGACCAGATAATTTTTATGGTGGGACGAGGATACCTGTCTCCAGATCTCAGTAAG\n"
115 + "GTACGGAGTAACTGTCCAAAAGCCATGAAGAGATTAATGGCAGAGTGCCTCAAAAAGAAA\n"
116 + "AGAGATGAGAGACCACTCTTTCCCCAAATTCTCGCCTCTATTGAGCTGCTGGCCCGCTCA\n"
117 + "TTGCCAAAAATTCACCGCAGTGCATCAGAACCCTCCTTGAATCGGGCTGGTTTCCAAACA\n"
118 + "GAGGATTTTAGTCTATATGCTTGTGCTTCTCCAAAAACACCCATCCAGGCAGGGGGATAT\n"
119 + "GGTGCGTTTCCTGTCCACTGA\n" },
121 new EnsemblProtein(),
124 + "MAALSGGGGGGAEPGQALFNGDMEPEAGAGAGAAASSAADPAIPEEVWNIKQMIKLTQEH\n"
125 + "IEALLDKFGGEHNPPSIYLEAYEEYTSKLDALQQREQQLLESLGNGTDFSVSSSASMDTV\n"
126 + "TSSSSSSLSVLPSSLSVFQNPTDVARSNPKSPQKPIVRVFLPNKQRTVVPARCGVTVRDS\n"
127 + "LKKALMMRGLIPECCAVYRIQDGEKKPIGWDTDISWLTGEELHVEVLENVPLTTHNFVRK\n"
128 + "TFFTLAFCDFCRKLLFQGFRCQTCGYKFHQRCSTEVPLMCVNYDQLDLLFVSKFFEHHPI\n"
129 + "PQEEASLAETALTSGSSPSAPASDSIGPQILTSPSPSKSIPIPQPFRPADEDHRNQFGQR\n"
130 + "DRSSSAPNVHINTIEPVNIDDLIRDQGFRGDGGSTTGLSATPPASLPGSLTNVKALQKSP\n"
131 + "GPQRERKSSSSSEDRNRMKTLGRRDSSDDWEIPDGQITVGQRIGSGSFGTVYKGKWHGDV\n"
132 + "AVKMLNVTAPTPQQLQAFKNEVGVLRKTRHVNILLFMGYSTKPQLAIVTQWCEGSSLYHH\n"
133 + "LHIIETKFEMIKLIDIARQTAQGMDYLHAKSIIHRDLKSNNIFLHEDLTVKIGDFGLATV\n"
134 + "KSRWSGSHQFEQLSGSILWMAPEVIRMQDKNPYSFQSDVYAFGIVLYELMTGQLPYSNIN\n"
135 + "NRDQIIFMVGRGYLSPDLSKVRSNCPKAMKRLMAECLKKKRDERPLFPQILASIELLARS\n"
136 + "LPKIHRSASEPSLNRAGFQTEDFSLYACASPKTPIQAGGYGAFPVH" } };
138 @BeforeClass(alwaysRun = true)
141 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
144 @AfterClass(alwaysRun = true)
145 public void tearDown()
147 SequenceOntologyFactory.setInstance(null);
150 @DataProvider(name = "ens_seqs")
151 public Object[][] createData(Method m)
153 System.out.println(m.getName());
157 @Test(dataProvider = "ens_seqs", suiteName = "live")
158 public void testGetOneSeqs(EnsemblRestClient proxy, String sq,
159 String fastasq) throws Exception
161 FileParse fp = proxy.getSequenceReader(Arrays
162 .asList(new String[] { sq }));
163 SequenceI[] sqs = new FastaFile(fp).getSeqsAsArray();
164 FastaFile trueRes = new FastaFile(fastasq, DataSourceType.PASTE);
165 SequenceI[] trueSqs = trueRes.getSeqsAsArray();
166 Assert.assertEquals(sqs.length, trueSqs.length,
167 "Different number of sequences retrieved for query " + sq);
168 Alignment ral = new Alignment(sqs);
169 for (SequenceI tr : trueSqs)
171 // 12/05/2017 failing for EnsemblCdna which is returning protein
172 // Ensembl helpdesk ticket 187998
174 Assert.assertNotNull(
175 rseq = ral.findSequenceMatch(tr.getName()),
176 "Couldn't find sequences matching expected sequence "
178 Assert.assertEquals(rseq.length, 1,
179 "Expected only one sequence for sequence ID " + tr.getName());
181 rseq[0].getSequenceAsString(),
182 tr.getSequenceAsString(),
183 "Sequences differ for " + tr.getName() + "\n" + "Exp:"
184 + tr.getSequenceAsString() + "\n" + "Got:"
185 + rseq[0].getSequenceAsString());
190 @Test(groups = "Functional")
191 public void getGenomicRangesFromFeatures()
196 @Test(groups = "Functional")
197 public void testIsTranscriptIdentifier()
199 EnsemblSeqProxy testee = new EnsemblGene();
200 assertFalse(testee.isTranscriptIdentifier(null));
201 assertFalse(testee.isTranscriptIdentifier(""));
202 assertFalse(testee.isTranscriptIdentifier("ENSG00000012345"));
203 assertTrue(testee.isTranscriptIdentifier("ENST00000012345"));
204 assertTrue(testee.isTranscriptIdentifier("ENSMUST00000012345"));
205 assertFalse(testee.isTranscriptIdentifier("enst00000012345"));
206 assertFalse(testee.isTranscriptIdentifier("ENST000000123456"));
207 assertFalse(testee.isTranscriptIdentifier("ENST0000001234"));
210 @Test(groups = "Functional")
211 public void testIsGeneIdentifier()
213 EnsemblSeqProxy testee = new EnsemblGene();
214 assertFalse(testee.isGeneIdentifier(null));
215 assertFalse(testee.isGeneIdentifier(""));
216 assertFalse(testee.isGeneIdentifier("ENST00000012345"));
217 assertTrue(testee.isGeneIdentifier("ENSG00000012345"));
218 assertTrue(testee.isGeneIdentifier("ENSMUSG00000012345"));
219 assertFalse(testee.isGeneIdentifier("ensg00000012345"));
220 assertFalse(testee.isGeneIdentifier("ENSG000000123456"));
221 assertFalse(testee.isGeneIdentifier("ENSG0000001234"));
225 * Test the method that appends a single allele's reverse complement to a
228 @Test(groups = "Functional")
229 public void testReverseComplementAllele()
231 StringBuilder sb = new StringBuilder();
232 EnsemblSeqProxy.reverseComplementAllele(sb, "G"); // comp=C
233 EnsemblSeqProxy.reverseComplementAllele(sb, "g"); // comp=c
234 EnsemblSeqProxy.reverseComplementAllele(sb, "C"); // comp=G
235 EnsemblSeqProxy.reverseComplementAllele(sb, "T"); // comp=A
236 EnsemblSeqProxy.reverseComplementAllele(sb, "A"); // comp=T
237 assertEquals("C,c,G,A,T", sb.toString());
239 sb = new StringBuilder();
240 EnsemblSeqProxy.reverseComplementAllele(sb, "-GATt"); // revcomp=aATC-
241 EnsemblSeqProxy.reverseComplementAllele(sb, "hgmd_mutation");
242 EnsemblSeqProxy.reverseComplementAllele(sb, "PhenCode_variation");
243 assertEquals("aATC-,hgmd_mutation,PhenCode_variation", sb.toString());
247 * Test the method that computes the reverse complement of the alleles in a
248 * sequence_variant feature
250 @Test(groups = "Functional")
251 public void testReverseComplementAlleles()
253 String alleles = "C,G,-TAC,HGMD_MUTATION,gac";
254 SequenceFeature sf = new SequenceFeature("sequence_variant", alleles,
256 sf.setValue("alleles", alleles);
257 sf.setAttributes("x=y,z;alleles=" + alleles + ";a=b,c");
259 EnsemblSeqProxy.reverseComplementAlleles(sf);
260 String revcomp = "G,C,GTA-,HGMD_MUTATION,gtc";
261 // verify description is updated with reverse complement
262 assertEquals(revcomp, sf.getDescription());
263 // verify alleles attribute is updated with reverse complement
264 assertEquals(revcomp, sf.getValue("alleles"));
265 // verify attributes string is updated with reverse complement
266 assertEquals("x=y,z;alleles=" + revcomp + ";a=b,c", sf.getAttributes());
269 @Test(groups = "Functional")
270 public void testSortFeatures()
272 SequenceFeature sf1 = new SequenceFeature("", "", 10, 15, 0f, null);
273 SequenceFeature sf2 = new SequenceFeature("", "", 8, 12, 0f, null);
274 SequenceFeature sf3 = new SequenceFeature("", "", 8, 13, 0f, null);
275 SequenceFeature sf4 = new SequenceFeature("", "", 11, 11, 0f, null);
276 List<SequenceFeature> sfs = Arrays.asList(new SequenceFeature[] { sf1,
279 // sort by start position ascending (forward strand)
280 // sf2 and sf3 tie and should not be reordered by sorting
281 SequenceFeatures.sortFeatures(sfs, true);
282 assertSame(sfs.get(0), sf2);
283 assertSame(sfs.get(1), sf3);
284 assertSame(sfs.get(2), sf1);
285 assertSame(sfs.get(3), sf4);
287 // sort by end position descending (reverse strand)
288 SequenceFeatures.sortFeatures(sfs, false);
289 assertSame(sfs.get(0), sf1);
290 assertSame(sfs.get(1), sf3);
291 assertSame(sfs.get(2), sf2);
292 assertSame(sfs.get(3), sf4);