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.assertSame;
6 import static org.testng.AssertJUnit.assertTrue;
8 import jalview.api.FeatureSettingsModelI;
9 import jalview.datamodel.SequenceDummy;
10 import jalview.datamodel.SequenceFeature;
11 import jalview.datamodel.SequenceI;
12 import jalview.io.gff.SequenceOntologyFactory;
13 import jalview.io.gff.SequenceOntologyLite;
14 import jalview.util.MapList;
16 import java.awt.Color;
17 import java.util.List;
19 import org.testng.annotations.AfterClass;
20 import org.testng.annotations.BeforeClass;
21 import org.testng.annotations.Test;
23 public class EnsemblGeneTest
25 @BeforeClass(alwaysRun = true)
28 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
31 @AfterClass(alwaysRun = true)
32 public void tearDown()
34 SequenceOntologyFactory.setInstance(null);
38 * Test that the gene part of genomic sequence is uniquely identified by a
39 * 'gene' features (or subtype) with the correct gene ID
41 @Test(groups = "Functional")
42 public void testGetGenomicRangesFromFeatures()
44 EnsemblGene testee = new EnsemblGene();
45 SequenceI genomic = new SequenceDummy("chr7");
46 genomic.setStart(10000);
47 genomic.setEnd(50000);
48 String geneId = "ABC123";
50 // gene at (start+10000) length 501
51 SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
53 sf.setValue("ID", "gene:" + geneId);
55 genomic.addSequenceFeature(sf);
57 // gene at (start + 10500) length 101
58 // should be ignored - the first 'gene' found defines the whole range
59 sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
60 sf.setValue("ID", "gene:" + geneId);
62 genomic.addSequenceFeature(sf);
64 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
66 List<int[]> fromRanges = ranges.getFromRanges();
67 assertEquals(1, fromRanges.size());
68 assertEquals(20000, fromRanges.get(0)[0]);
69 assertEquals(20500, fromRanges.get(0)[1]);
70 // to range should start from given start numbering
71 List<int[]> toRanges = ranges.getToRanges();
72 assertEquals(1, toRanges.size());
73 assertEquals(23, toRanges.get(0)[0]);
74 assertEquals(523, toRanges.get(0)[1]);
78 * Test variant using a sub-type of gene from the Sequence Ontology
80 @Test(groups = "Functional")
81 public void testGetGenomicRangesFromFeatures_ncRNA_gene_reverseStrand()
83 EnsemblGene testee = new EnsemblGene();
84 SequenceI genomic = new SequenceDummy("chr7");
85 genomic.setStart(10000);
86 genomic.setEnd(50000);
87 String geneId = "ABC123";
89 // gene at (start+10000) length 501
90 SequenceFeature sf = new SequenceFeature("ncRNA_gene", "", 20000,
92 sf.setValue("ID", "gene:" + geneId);
94 genomic.addSequenceFeature(sf);
96 // gene at (start + 10500) length 101
97 // should be ignored - the first 'gene' found defines the whole range
98 // (real data would only have one such feature)
99 sf = new SequenceFeature("gene", "", 10500, 10600, 0f, null);
100 sf.setValue("ID", "gene:" + geneId);
102 genomic.addSequenceFeature(sf);
104 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
106 List<int[]> fromRanges = ranges.getFromRanges();
107 assertEquals(1, fromRanges.size());
108 // from range on reverse strand:
109 assertEquals(20500, fromRanges.get(0)[0]);
110 assertEquals(20000, fromRanges.get(0)[1]);
111 // to range should start from given start numbering
112 List<int[]> toRanges = ranges.getToRanges();
113 assertEquals(1, toRanges.size());
114 assertEquals(23, toRanges.get(0)[0]);
115 assertEquals(523, toRanges.get(0)[1]);
119 * Test the method that extracts transcript (or subtype) features with a
120 * specified gene as parent
122 @Test(groups = "Functional")
123 public void testGetTranscriptFeatures()
125 SequenceI genomic = new SequenceDummy("chr7");
126 genomic.setStart(10000);
127 genomic.setEnd(50000);
128 String geneId = "ABC123";
130 // transcript feature
131 SequenceFeature sf1 = new SequenceFeature("transcript", "", 20000,
133 sf1.setValue("Parent", "gene:" + geneId);
134 sf1.setValue("transcript_id", "transcript1");
135 genomic.addSequenceFeature(sf1);
137 // transcript sub-type feature
138 SequenceFeature sf2 = new SequenceFeature("snRNA", "", 20000,
140 sf2.setValue("Parent", "gene:" + geneId);
141 sf2.setValue("transcript_id", "transcript2");
142 genomic.addSequenceFeature(sf2);
144 // NMD_transcript_variant treated like transcript in Ensembl
145 SequenceFeature sf3 = new SequenceFeature("NMD_transcript_variant", "",
146 20000, 20500, 0f, null);
147 sf3.setValue("Parent", "gene:" + geneId);
148 sf3.setValue("transcript_id", "transcript3");
149 genomic.addSequenceFeature(sf3);
151 // transcript for a different gene - ignored
152 SequenceFeature sf4 = new SequenceFeature("snRNA", "", 20000, 20500,
154 sf4.setValue("Parent", "gene:XYZ");
155 sf4.setValue("transcript_id", "transcript4");
156 genomic.addSequenceFeature(sf4);
158 EnsemblGene testee = new EnsemblGene();
163 List<SequenceFeature> features = testee.getTranscriptFeatures(geneId,
165 assertEquals(3, features.size());
166 assertSame(sf1, features.get(0));
167 assertSame(sf2, features.get(1));
168 assertSame(sf3, features.get(2));
172 * Test the method that retains features except for 'gene', or 'transcript'
173 * with parent other than the given id
175 @Test(groups = "Functional")
176 public void testRetainFeature()
178 String geneId = "ABC123";
179 EnsemblGene testee = new EnsemblGene();
180 SequenceFeature sf = new SequenceFeature("gene", "", 20000,
182 sf.setValue("ID", "gene:" + geneId);
183 assertFalse(testee.retainFeature(sf, geneId));
185 sf.setType("transcript");
186 sf.setValue("Parent", "gene:" + geneId);
187 assertTrue(testee.retainFeature(sf, geneId));
189 sf.setType("mature_transcript");
190 sf.setValue("Parent", "gene:" + geneId);
191 assertTrue(testee.retainFeature(sf, geneId));
193 sf.setType("NMD_transcript_variant");
194 sf.setValue("Parent", "gene:" + geneId);
195 assertTrue(testee.retainFeature(sf, geneId));
197 sf.setValue("Parent", "gene:XYZ");
198 assertFalse(testee.retainFeature(sf, geneId));
200 sf.setType("anything");
201 assertTrue(testee.retainFeature(sf, geneId));
205 * Test the method that picks out 'gene' (or subtype) features with the
208 @Test(groups = "Functional")
209 public void testIdentifiesSequence()
211 String accId = "ABC123";
212 EnsemblGene testee = new EnsemblGene();
214 // gene with no ID not valid
215 SequenceFeature sf = new SequenceFeature("gene", "", 1, 2, 0f, null);
216 assertFalse(testee.identifiesSequence(sf, accId));
218 // gene with wrong ID not valid
219 sf.setValue("ID", "gene:XYZ");
220 assertFalse(testee.identifiesSequence(sf, accId));
222 // gene with right ID is valid
223 sf.setValue("ID", "gene:" + accId);
224 assertTrue(testee.identifiesSequence(sf, accId));
226 // gene sub-type with right ID is valid
227 sf.setType("snRNA_gene");
228 assertTrue(testee.identifiesSequence(sf, accId));
230 // transcript not valid:
231 sf.setType("transcript");
232 assertFalse(testee.identifiesSequence(sf, accId));
236 assertFalse(testee.identifiesSequence(sf, accId));
240 * Check behaviour of feature colour scheme for EnsemblGene sequences.
241 * Currently coded to display exon and sequence_variant (or sub-types) only,
242 * with sequence_variant in red above exon coloured by label.
244 @Test(groups = "Functional")
245 public void testGetFeatureColourScheme()
247 FeatureSettingsModelI fc = new EnsemblGene().getFeatureColourScheme();
248 assertTrue(fc.isFeatureDisplayed("exon"));
249 assertTrue(fc.isFeatureDisplayed("coding_exon")); // subtype of exon
250 assertTrue(fc.isFeatureDisplayed("sequence_variant"));
251 assertTrue(fc.isFeatureDisplayed("feature_variant")); // subtype
252 assertFalse(fc.isFeatureDisplayed("transcript"));
253 assertEquals(Color.RED, fc.getFeatureColour("sequence_variant")
255 assertEquals(Color.RED, fc.getFeatureColour("feature_variant")
257 assertTrue(fc.getFeatureColour("exon").isColourByLabel());
258 assertTrue(fc.getFeatureColour("coding_exon").isColourByLabel());
259 assertEquals(1, fc.compare("sequence_variant", "exon"));
260 assertEquals(-1, fc.compare("exon", "sequence_variant"));
261 assertEquals(1, fc.compare("feature_variant", "coding_exon"));
262 assertEquals(-1, fc.compare("coding_exon", "feature_variant"));
263 assertEquals(1f, fc.getTransparency());