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.assertNull;
26 import static org.testng.AssertJUnit.assertTrue;
28 import jalview.datamodel.SequenceDummy;
29 import jalview.datamodel.SequenceFeature;
30 import jalview.datamodel.SequenceI;
31 import jalview.gui.JvOptionPane;
32 import jalview.io.gff.SequenceOntologyFactory;
33 import jalview.io.gff.SequenceOntologyLite;
34 import jalview.util.MapList;
36 import java.util.List;
38 import org.testng.Assert;
39 import org.testng.annotations.AfterClass;
40 import org.testng.annotations.BeforeClass;
41 import org.testng.annotations.Test;
43 public class EnsemblCdnaTest
46 @BeforeClass(alwaysRun = true)
47 public void setUpJvOptionPane()
49 JvOptionPane.setInteractiveMode(false);
50 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53 @BeforeClass(alwaysRun = true)
56 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
59 @AfterClass(alwaysRun = true)
60 public void tearDown()
62 SequenceOntologyFactory.setInstance(null);
66 * Test that the cdna part of genomic sequence is correctly identified by
67 * 'exon' features (or subtypes) - reverse strand case.
69 @Test(groups = "Functional")
70 public void testGetGenomicRangesFromFeatures_reverseStrand()
72 EnsemblCdna testee = new EnsemblCdna();
73 SequenceI genomic = new SequenceDummy("chr7");
74 genomic.setStart(10000);
75 genomic.setEnd(50000);
76 String transcriptId = "ABC123";
78 // exon at (start+10000) length 501
79 SequenceFeature sf = new SequenceFeature("exon", "", 20000, 20500, 0f,
81 sf.setValue("Parent", "transcript:" + transcriptId);
83 genomic.addSequenceFeature(sf);
85 // exon (sub-type) at (start + exon_variant) length 101
86 sf = new SequenceFeature("coding_exon", "", 10500, 10600, 0f, null);
87 sf.setValue("Parent", "transcript:" + transcriptId);
89 genomic.addSequenceFeature(sf);
91 // exon belonging to a different transcript doesn't count
92 sf = new SequenceFeature("exon", "", 11500, 12600, 0f, null);
93 sf.setValue("Parent", "transcript:anotherOne");
94 genomic.addSequenceFeature(sf);
96 // transcript feature doesn't count
97 sf = new SequenceFeature("transcript", "", 10000, 50000, 0f, null);
98 genomic.addSequenceFeature(sf);
100 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
102 List<int[]> fromRanges = ranges.getFromRanges();
103 assertEquals(2, fromRanges.size());
106 * from ranges should be sorted by start order descending
107 * and hold mappings from reverse strand sense
109 assertEquals(20500, fromRanges.get(0)[0]);
110 assertEquals(20000, fromRanges.get(0)[1]);
111 assertEquals(10600, fromRanges.get(1)[0]);
112 assertEquals(10500, fromRanges.get(1)[1]);
113 // to range should start from given start numbering
114 List<int[]> toRanges = ranges.getToRanges();
115 assertEquals(1, toRanges.size());
116 assertEquals(23, toRanges.get(0)[0]);
117 assertEquals(624, toRanges.get(0)[1]);
121 * Test that the cdna part of genomic sequence is correctly identified by
122 * 'exon' features (or subtypes) with the desired transcript as parent
124 @Test(groups = "Functional")
125 public void testGetGenomicRangesFromFeatures()
127 EnsemblCdna testee = new EnsemblCdna();
128 SequenceI genomic = new SequenceDummy("chr7");
129 genomic.setStart(10000);
130 genomic.setEnd(50000);
131 String transcriptId = "ABC123";
133 // exon at (start+10000) length 501
134 SequenceFeature sf = new SequenceFeature("exon", "", 20000, 20500, 0f,
136 sf.setValue("Parent", "transcript:" + transcriptId);
138 genomic.addSequenceFeature(sf);
140 // exon (sub-type) at (start + exon_variant) length 101
141 sf = new SequenceFeature("coding_exon", "", 10500, 10600, 0f, null);
142 sf.setValue("Parent", "transcript:" + transcriptId);
144 genomic.addSequenceFeature(sf);
146 // exon belonging to a different transcript doesn't count
147 sf = new SequenceFeature("exon", "", 11500, 12600, 0f, null);
148 sf.setValue("Parent", "transcript:anotherOne");
149 genomic.addSequenceFeature(sf);
151 // transcript feature doesn't count
152 sf = new SequenceFeature("transcript", "", 10000, 50000, 0f, null);
153 sf.setStrand("-"); // weird but ignored
154 genomic.addSequenceFeature(sf);
156 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
158 List<int[]> fromRanges = ranges.getFromRanges();
159 assertEquals(2, fromRanges.size());
160 // from ranges should be sorted by start order
161 assertEquals(10500, fromRanges.get(0)[0]);
162 assertEquals(10600, fromRanges.get(0)[1]);
163 assertEquals(20000, fromRanges.get(1)[0]);
164 assertEquals(20500, fromRanges.get(1)[1]);
165 // to range should start from given start numbering
166 List<int[]> toRanges = ranges.getToRanges();
167 assertEquals(1, toRanges.size());
168 assertEquals(23, toRanges.get(0)[0]);
169 assertEquals(624, toRanges.get(0)[1]);
173 * The method under test should give up and return null if both forward and
174 * reverse strands are present in the features of interest
176 @Test(groups = "Functional")
177 public void testGetGenomicRangesFromFeatures_mixedStrand()
179 EnsemblCdna testee = new EnsemblCdna();
180 SequenceI genomic = new SequenceDummy("chr7");
181 genomic.setStart(10000);
182 genomic.setEnd(50000);
183 String transcriptId = "ABC123";
185 SequenceFeature sf = new SequenceFeature("exon", "", 20000, 20500, 0f,
187 sf.setValue("Parent", "transcript:" + transcriptId);
189 genomic.addSequenceFeature(sf);
191 sf = new SequenceFeature("coding_exon", "", 10500, 10600, 0f, null);
192 sf.setValue("Parent", "transcript:" + transcriptId);
194 genomic.addSequenceFeature(sf);
196 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
202 * Test the method that retains features except for 'transcript' (or
203 * subtypes), or features with parent other than the given id
205 @Test(groups = "Functional")
206 public void testRetainFeature()
208 String accId = "ABC123";
209 EnsemblCdna testee = new EnsemblCdna();
211 SequenceFeature sf = new SequenceFeature("transcript", "", 20000,
213 assertFalse(testee.retainFeature(sf, accId));
215 sf.setType("aberrant_processed_transcript");
216 assertFalse(testee.retainFeature(sf, accId));
218 sf.setType("NMD_transcript_variant");
219 assertFalse(testee.retainFeature(sf, accId));
221 // other feature with no parent is retained
222 sf.setType("sequence_variant");
223 assertTrue(testee.retainFeature(sf, accId));
225 // other feature with desired parent is retained
226 sf.setValue("Parent", "transcript:" + accId);
227 assertTrue(testee.retainFeature(sf, accId));
229 // feature with wrong parent is not retained
230 sf.setValue("Parent", "transcript:XYZ");
231 assertFalse(testee.retainFeature(sf, accId));
235 * Test the method that picks out 'exon' (or subtype) features with the
236 * accession id as parent
238 @Test(groups = "Functional")
239 public void testIdentifiesSequence()
241 String accId = "ABC123";
242 EnsemblCdna testee = new EnsemblCdna();
244 // exon with no parent not valid
245 SequenceFeature sf = new SequenceFeature("exon", "", 1, 2, 0f, null);
246 assertFalse(testee.identifiesSequence(sf, accId));
248 // exon with wrong parent not valid
249 sf.setValue("Parent", "transcript:XYZ");
250 assertFalse(testee.identifiesSequence(sf, accId));
252 // exon with right parent is valid
253 sf.setValue("Parent", "transcript:" + accId);
254 assertTrue(testee.identifiesSequence(sf, accId));
256 // exon sub-type with right parent is valid
257 sf.setType("coding_exon");
258 assertTrue(testee.identifiesSequence(sf, accId));
260 // transcript not valid:
261 sf.setType("transcript");
262 assertFalse(testee.identifiesSequence(sf, accId));
266 assertFalse(testee.identifiesSequence(sf, accId));
269 @Test(groups = "Functional")
270 public void testIsValidReference() throws Exception
272 EnsemblSequenceFetcher esq = new EnsemblCdna();
273 Assert.assertTrue(esq.isValidReference("CCDS5863.1"));
274 Assert.assertTrue(esq.isValidReference("ENST00000288602"));
275 Assert.assertTrue(esq.isValidReference("ENSG00000288602"));
276 Assert.assertFalse(esq.isValidReference("ENSP00000288602"));
277 Assert.assertFalse(esq.isValidReference("ENST0000288602"));
278 // non-human species having a 3 character identifier included:
279 Assert.assertTrue(esq.isValidReference("ENSMUSG00000099398"));