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.assertTrue;
27 import jalview.datamodel.SequenceDummy;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.gff.SequenceOntologyFactory;
32 import jalview.io.gff.SequenceOntologyLite;
33 import jalview.util.MapList;
35 import java.util.List;
37 import org.testng.Assert;
38 import org.testng.annotations.AfterClass;
39 import org.testng.annotations.BeforeClass;
40 import org.testng.annotations.Test;
42 public class EnsemblCdsTest
45 @BeforeClass(alwaysRun = true)
46 public void setUpJvOptionPane()
48 JvOptionPane.setInteractiveMode(false);
49 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
52 @BeforeClass(alwaysRun = true)
55 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
58 @AfterClass(alwaysRun = true)
59 public void tearDown()
61 SequenceOntologyFactory.setInstance(null);
65 * Test that the cdna part of genomic sequence is correctly identified by
66 * 'CDS' features (or subtypes) with the desired transcript as parent
68 @Test(groups = "Functional")
69 public void testGetGenomicRangesFromFeatures()
71 EnsemblCds testee = new EnsemblCds();
72 SequenceI genomic = new SequenceDummy("chr7");
73 genomic.setStart(10000);
74 genomic.setEnd(50000);
75 String transcriptId = "ABC123";
77 // CDS at (start+10000) length 501
78 SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
80 sf.setValue("Parent", "transcript:" + transcriptId);
82 genomic.addSequenceFeature(sf);
84 // CDS (sub-type) at (start + 10500) length 101
85 sf = new SequenceFeature("CDS_predicted", "", 10500, 10600, 0f, null);
86 sf.setValue("Parent", "transcript:" + transcriptId);
88 genomic.addSequenceFeature(sf);
90 // CDS belonging to a different transcript doesn't count
91 sf = new SequenceFeature("CDS", "", 11500, 12600, 0f, null);
92 sf.setValue("Parent", "transcript:anotherOne");
93 genomic.addSequenceFeature(sf);
95 // exon feature doesn't count
96 sf = new SequenceFeature("exon", "", 10000, 50000, 0f, null);
97 genomic.addSequenceFeature(sf);
99 // mRNA_region feature doesn't count (parent of CDS)
100 sf = new SequenceFeature("mRNA_region", "", 10000, 50000, 0f, null);
101 genomic.addSequenceFeature(sf);
103 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
105 List<int[]> fromRanges = ranges.getFromRanges();
106 assertEquals(2, fromRanges.size());
107 // from ranges should be sorted by start order
108 assertEquals(10500, fromRanges.get(0)[0]);
109 assertEquals(10600, fromRanges.get(0)[1]);
110 assertEquals(20000, fromRanges.get(1)[0]);
111 assertEquals(20500, fromRanges.get(1)[1]);
112 // to range should start from given start numbering
113 List<int[]> toRanges = ranges.getToRanges();
114 assertEquals(1, toRanges.size());
115 assertEquals(23, toRanges.get(0)[0]);
116 assertEquals(624, toRanges.get(0)[1]);
120 * Test the method that retains features except for 'CDS' (or subtypes), or
121 * features with parent other than the given id
123 @Test(groups = "Functional")
124 public void testRetainFeature()
126 String accId = "ABC123";
127 EnsemblCds testee = new EnsemblCds();
129 SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
131 assertFalse(testee.retainFeature(sf, accId));
133 sf.setType("CDS_predicted");
134 assertFalse(testee.retainFeature(sf, accId));
136 // other feature with no parent is retained
137 sf.setType("sequence_variant");
138 assertTrue(testee.retainFeature(sf, accId));
140 // other feature with desired parent is retained
141 sf.setValue("Parent", "transcript:" + accId);
142 assertTrue(testee.retainFeature(sf, accId));
144 // feature with wrong parent is not retained
145 sf.setValue("Parent", "transcript:XYZ");
146 assertFalse(testee.retainFeature(sf, accId));
150 * Test the method that picks out 'CDS' (or subtype) features with the
151 * accession id as parent
153 @Test(groups = "Functional")
154 public void testIdentifiesSequence()
156 String accId = "ABC123";
157 EnsemblCds testee = new EnsemblCds();
159 // cds with no parent not valid
160 SequenceFeature sf = new SequenceFeature("CDS", "", 1, 2, 0f, null);
161 assertFalse(testee.identifiesSequence(sf, accId));
163 // cds with wrong parent not valid
164 sf.setValue("Parent", "transcript:XYZ");
165 assertFalse(testee.identifiesSequence(sf, accId));
167 // cds with right parent is valid
168 sf.setValue("Parent", "transcript:" + accId);
169 assertTrue(testee.identifiesSequence(sf, accId));
171 // cds sub-type with right parent is valid
172 sf.setType("CDS_predicted");
173 assertTrue(testee.identifiesSequence(sf, accId));
175 // transcript not valid:
176 sf.setType("transcript");
177 assertFalse(testee.identifiesSequence(sf, accId));
181 assertFalse(testee.identifiesSequence(sf, accId));
184 @Test(groups = "Functional")
185 public void testIsValidReference() throws Exception
187 EnsemblSequenceFetcher esq = new EnsemblCds();
188 Assert.assertTrue(esq.isValidReference("CCDS5863.1"));
189 Assert.assertTrue(esq.isValidReference("ENST00000288602"));
190 Assert.assertTrue(esq.isValidReference("ENSG00000288602"));
191 Assert.assertTrue(esq.isValidReference("ENSP00000288602"));
192 Assert.assertFalse(esq.isValidReference("ENST0000288602"));
193 // non-human species have a 3 character identifier included:
194 Assert.assertTrue(esq.isValidReference("ENSMUSG00000099398"));