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.api.FeatureSettingsModelI;
29 import jalview.datamodel.SequenceDummy;
30 import jalview.datamodel.SequenceFeature;
31 import jalview.datamodel.SequenceI;
32 import jalview.gui.JvOptionPane;
33 import jalview.io.gff.SequenceOntologyFactory;
34 import jalview.io.gff.SequenceOntologyLite;
35 import jalview.util.MapList;
37 import java.awt.Color;
38 import java.util.List;
40 import org.testng.annotations.AfterClass;
41 import org.testng.annotations.BeforeClass;
42 import org.testng.annotations.Test;
44 public class EnsemblGeneTest
47 @BeforeClass(alwaysRun = true)
48 public void setUpJvOptionPane()
50 JvOptionPane.setInteractiveMode(false);
51 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
54 @BeforeClass(alwaysRun = true)
57 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
60 @AfterClass(alwaysRun = true)
61 public void tearDown()
63 SequenceOntologyFactory.setInstance(null);
67 * Test that the gene part of genomic sequence is uniquely identified by a
68 * 'gene' features (or subtype) with the correct gene ID
70 @Test(groups = "Functional")
71 public void testGetGenomicRangesFromFeatures()
73 EnsemblGene testee = new EnsemblGene();
74 SequenceI genomic = new SequenceDummy("chr7");
75 genomic.setStart(10000);
76 genomic.setEnd(50000);
77 String geneId = "ABC123";
79 // gene at (start+10000) length 501
80 SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
82 sf.setValue("ID", "gene:" + geneId);
84 genomic.addSequenceFeature(sf);
86 // gene at (start + 10500) length 101
87 // should be ignored - the first 'gene' found defines the whole range
88 sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
89 sf.setValue("ID", "gene:" + geneId);
91 genomic.addSequenceFeature(sf);
93 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
95 List<int[]> fromRanges = ranges.getFromRanges();
96 assertEquals(1, fromRanges.size());
97 assertEquals(20000, fromRanges.get(0)[0]);
98 assertEquals(20500, fromRanges.get(0)[1]);
99 // to range should start from given start numbering
100 List<int[]> toRanges = ranges.getToRanges();
101 assertEquals(1, toRanges.size());
102 assertEquals(23, toRanges.get(0)[0]);
103 assertEquals(523, toRanges.get(0)[1]);
107 * Test variant using a sub-type of gene from the Sequence Ontology
109 @Test(groups = "Functional")
110 public void testGetGenomicRangesFromFeatures_ncRNA_gene_reverseStrand()
112 EnsemblGene testee = new EnsemblGene();
113 SequenceI genomic = new SequenceDummy("chr7");
114 genomic.setStart(10000);
115 genomic.setEnd(50000);
116 String geneId = "ABC123";
118 // gene at (start+10000) length 501
119 SequenceFeature sf = new SequenceFeature("ncRNA_gene", "", 20000,
121 sf.setValue("ID", "gene:" + geneId);
123 genomic.addSequenceFeature(sf);
125 // gene at (start + 10500) length 101
126 // should be ignored - the first 'gene' found defines the whole range
127 // (real data would only have one such feature)
128 sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
129 sf.setValue("ID", "gene:" + geneId);
131 genomic.addSequenceFeature(sf);
133 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
135 List<int[]> fromRanges = ranges.getFromRanges();
136 assertEquals(1, fromRanges.size());
137 // from range on reverse strand:
138 assertEquals(20500, fromRanges.get(0)[0]);
139 assertEquals(20000, fromRanges.get(0)[1]);
140 // to range should start from given start numbering
141 List<int[]> toRanges = ranges.getToRanges();
142 assertEquals(1, toRanges.size());
143 assertEquals(23, toRanges.get(0)[0]);
144 assertEquals(523, toRanges.get(0)[1]);
148 * Test the method that extracts transcript (or subtype) features with a
149 * specified gene as parent
151 @Test(groups = "Functional")
152 public void testGetTranscriptFeatures()
154 SequenceI genomic = new SequenceDummy("chr7");
155 genomic.setStart(10000);
156 genomic.setEnd(50000);
157 String geneId = "ABC123";
159 // transcript feature
160 SequenceFeature sf1 = new SequenceFeature("transcript", "", 20000,
162 sf1.setValue("Parent", "gene:" + geneId);
163 sf1.setValue("transcript_id", "transcript1");
164 genomic.addSequenceFeature(sf1);
166 // transcript sub-type feature
167 SequenceFeature sf2 = new SequenceFeature("snRNA", "", 20000, 20500,
169 sf2.setValue("Parent", "gene:" + geneId);
170 sf2.setValue("transcript_id", "transcript2");
171 genomic.addSequenceFeature(sf2);
173 // NMD_transcript_variant treated like transcript in Ensembl
174 SequenceFeature sf3 = new SequenceFeature("NMD_transcript_variant", "",
175 20000, 20500, 0f, null);
176 sf3.setValue("Parent", "gene:" + geneId);
177 sf3.setValue("transcript_id", "transcript3");
178 genomic.addSequenceFeature(sf3);
180 // transcript for a different gene - ignored
181 SequenceFeature sf4 = new SequenceFeature("snRNA", "", 20000, 20500,
183 sf4.setValue("Parent", "gene:XYZ");
184 sf4.setValue("transcript_id", "transcript4");
185 genomic.addSequenceFeature(sf4);
187 EnsemblGene testee = new EnsemblGene();
192 List<SequenceFeature> features = testee.getTranscriptFeatures(geneId,
194 assertEquals(3, features.size());
195 assertSame(sf1, features.get(0));
196 assertSame(sf2, features.get(1));
197 assertSame(sf3, features.get(2));
201 * Test the method that retains features except for 'gene', or 'transcript'
202 * with parent other than the given id
204 @Test(groups = "Functional")
205 public void testRetainFeature()
207 String geneId = "ABC123";
208 EnsemblGene testee = new EnsemblGene();
209 SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
211 sf.setValue("ID", "gene:" + geneId);
212 assertFalse(testee.retainFeature(sf, geneId));
214 sf.setType("transcript");
215 sf.setValue("Parent", "gene:" + geneId);
216 assertTrue(testee.retainFeature(sf, geneId));
218 sf.setType("mature_transcript");
219 sf.setValue("Parent", "gene:" + geneId);
220 assertTrue(testee.retainFeature(sf, geneId));
222 sf.setType("NMD_transcript_variant");
223 sf.setValue("Parent", "gene:" + geneId);
224 assertTrue(testee.retainFeature(sf, geneId));
226 sf.setValue("Parent", "gene:XYZ");
227 assertFalse(testee.retainFeature(sf, geneId));
229 sf.setType("anything");
230 assertTrue(testee.retainFeature(sf, geneId));
234 * Test the method that picks out 'gene' (or subtype) features with the
237 @Test(groups = "Functional")
238 public void testIdentifiesSequence()
240 String accId = "ABC123";
241 EnsemblGene testee = new EnsemblGene();
243 // gene with no ID not valid
244 SequenceFeature sf = new SequenceFeature("gene", "", 1, 2, 0f, null);
245 assertFalse(testee.identifiesSequence(sf, accId));
247 // gene with wrong ID not valid
248 sf.setValue("ID", "gene:XYZ");
249 assertFalse(testee.identifiesSequence(sf, accId));
251 // gene with right ID is valid
252 sf.setValue("ID", "gene:" + accId);
253 assertTrue(testee.identifiesSequence(sf, accId));
255 // gene sub-type with right ID is valid
256 sf.setType("snRNA_gene");
257 assertTrue(testee.identifiesSequence(sf, accId));
259 // transcript not valid:
260 sf.setType("transcript");
261 assertFalse(testee.identifiesSequence(sf, accId));
265 assertFalse(testee.identifiesSequence(sf, accId));
269 * Check behaviour of feature colour scheme for EnsemblGene sequences.
270 * Currently coded to display exon and sequence_variant (or sub-types) only,
271 * with sequence_variant in red above exon coloured by label.
273 @Test(groups = "Functional")
274 public void testGetFeatureColourScheme()
276 FeatureSettingsModelI fc = new EnsemblGene().getFeatureColourScheme();
277 assertTrue(fc.isFeatureDisplayed("exon"));
278 assertTrue(fc.isFeatureDisplayed("coding_exon")); // subtype of exon
279 assertTrue(fc.isFeatureDisplayed("sequence_variant"));
280 assertTrue(fc.isFeatureDisplayed("feature_variant")); // subtype
281 assertFalse(fc.isFeatureDisplayed("transcript"));
282 assertEquals(Color.RED, fc.getFeatureColour("sequence_variant")
284 assertEquals(Color.RED, fc.getFeatureColour("feature_variant")
286 assertTrue(fc.getFeatureColour("exon").isColourByLabel());
287 assertTrue(fc.getFeatureColour("coding_exon").isColourByLabel());
288 assertEquals(1, fc.compare("sequence_variant", "exon"));
289 assertEquals(-1, fc.compare("exon", "sequence_variant"));
290 assertEquals(1, fc.compare("feature_variant", "coding_exon"));
291 assertEquals(-1, fc.compare("coding_exon", "feature_variant"));
292 assertEquals(1f, fc.getTransparency());