Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:14:12 GMT
  2. Package jalview.ext.ensembl

File EnsemblGeneTest.java

 

Code metrics

0
143
10
1
336
223
10
0.07
14.3
10
1

Classes

Class Line # Actions
EnsemblGeneTest 47 143 10
0.915032791.5%
 

Contributing tests

This file is covered by 6 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.ext.ensembl;
22   
23    import java.util.Locale;
24   
25    import static org.testng.AssertJUnit.assertEquals;
26    import static org.testng.AssertJUnit.assertFalse;
27    import static org.testng.AssertJUnit.assertTrue;
28   
29    import jalview.api.FeatureSettingsModelI;
30    import jalview.bin.Cache;
31    import jalview.datamodel.Sequence;
32    import jalview.datamodel.SequenceDummy;
33    import jalview.datamodel.SequenceFeature;
34    import jalview.datamodel.SequenceI;
35    import jalview.gui.JvOptionPane;
36    import jalview.io.gff.SequenceOntologyFactory;
37    import jalview.io.gff.SequenceOntologyLite;
38    import jalview.util.MapList;
39   
40    import java.awt.Color;
41    import java.util.List;
42   
43    import org.testng.annotations.AfterClass;
44    import org.testng.annotations.BeforeClass;
45    import org.testng.annotations.Test;
46   
 
47    public class EnsemblGeneTest
48    {
49   
 
50  1 toggle @BeforeClass(alwaysRun = true)
51    public void setUpJvOptionPane()
52    {
53  1 JvOptionPane.setInteractiveMode(false);
54  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55    }
56   
 
57  1 toggle @BeforeClass(alwaysRun = true)
58    public void setUp()
59    {
60  1 Cache.loadProperties("test/jalview/io/testProps.jvprops");
61  1 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
62    }
63   
 
64  1 toggle @AfterClass(alwaysRun = true)
65    public void tearDown()
66    {
67  1 SequenceOntologyFactory.setInstance(null);
68    }
69   
70    /**
71    * Test that the gene part of genomic sequence is uniquely identified by a
72    * 'gene' features (or subtype) with the correct gene ID
73    */
 
74  1 toggle @Test(groups = "Functional")
75    public void testGetGenomicRangesFromFeatures()
76    {
77  1 EnsemblGene testee = new EnsemblGene();
78  1 SequenceI genomic = new SequenceDummy("chr7");
79  1 genomic.setStart(10000);
80  1 genomic.setEnd(50000);
81  1 String geneId = "ABC123";
82   
83    // gene at (start + 10500) length 101
84  1 SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
85    null);
86  1 sf.setValue("id", geneId);
87  1 sf.setStrand("+");
88  1 genomic.addSequenceFeature(sf);
89   
90  1 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
91    23);
92  1 List<int[]> fromRanges = ranges.getFromRanges();
93  1 assertEquals(1, fromRanges.size());
94  1 assertEquals(10500, fromRanges.get(0)[0]);
95  1 assertEquals(10600, fromRanges.get(0)[1]);
96    // to range should start from given start numbering
97  1 List<int[]> toRanges = ranges.getToRanges();
98  1 assertEquals(1, toRanges.size());
99  1 assertEquals(23, toRanges.get(0)[0]);
100  1 assertEquals(123, toRanges.get(0)[1]);
101    }
102   
103    /**
104    * Test variant using a sub-type of gene from the Sequence Ontology
105    */
 
106  1 toggle @Test(groups = "Functional")
107    public void testGetGenomicRangesFromFeatures_ncRNA_gene_reverseStrand()
108    {
109  1 EnsemblGene testee = new EnsemblGene();
110  1 SequenceI genomic = new SequenceDummy("chr7");
111  1 genomic.setStart(10000);
112  1 genomic.setEnd(50000);
113  1 String geneId = "ABC123";
114   
115    // gene at (start + 10500) length 101
116  1 SequenceFeature sf = new SequenceFeature("gene", "", 10500, 10600, 0f,
117    null);
118  1 sf.setValue("id", geneId);
119  1 sf.setStrand("+");
120  1 genomic.addSequenceFeature(sf);
121   
122  1 MapList ranges = testee.getGenomicRangesFromFeatures(genomic, geneId,
123    23);
124  1 List<int[]> fromRanges = ranges.getFromRanges();
125  1 assertEquals(1, fromRanges.size());
126    // from range on reverse strand:
127  1 assertEquals(10500, fromRanges.get(0)[0]);
128  1 assertEquals(10600, fromRanges.get(0)[1]);
129    // to range should start from given start numbering
130  1 List<int[]> toRanges = ranges.getToRanges();
131  1 assertEquals(1, toRanges.size());
132  1 assertEquals(23, toRanges.get(0)[0]);
133  1 assertEquals(123, toRanges.get(0)[1]);
134    }
135   
136    /**
137    * Test the method that extracts transcript (or subtype) features with a
138    * specified gene as parent
139    */
 
140  1 toggle @Test(groups = "Functional")
141    public void testGetTranscriptFeatures()
142    {
143  1 SequenceI genomic = new SequenceDummy("chr7");
144  1 genomic.setStart(10000);
145  1 genomic.setEnd(50000);
146  1 String geneId = "ABC123";
147   
148    // transcript feature
149  1 SequenceFeature sf1 = new SequenceFeature("transcript", "", 20000,
150    20500, 0f, null);
151  1 sf1.setValue("Parent", geneId);
152  1 sf1.setValue("id", "transcript1");
153  1 genomic.addSequenceFeature(sf1);
154   
155    // transcript sub-type feature
156  1 SequenceFeature sf2 = new SequenceFeature("snRNA", "", 21000, 21500, 0f,
157    null);
158  1 sf2.setValue("Parent", geneId);
159  1 sf2.setValue("id", "transcript2");
160  1 genomic.addSequenceFeature(sf2);
161   
162    // NMD_transcript_variant treated like transcript in Ensembl
163  1 SequenceFeature sf3 = new SequenceFeature("NMD_transcript_variant", "",
164    22000, 22500, 0f, null);
165    // id matching should not be case-sensitive
166  1 sf3.setValue("Parent", geneId.toLowerCase(Locale.ROOT));
167  1 sf3.setValue("id", "transcript3");
168  1 genomic.addSequenceFeature(sf3);
169   
170    // transcript for a different gene - ignored
171  1 SequenceFeature sf4 = new SequenceFeature("snRNA", "", 23000, 23500, 0f,
172    null);
173  1 sf4.setValue("Parent", "XYZ");
174  1 sf4.setValue("id", "transcript4");
175  1 genomic.addSequenceFeature(sf4);
176   
177  1 EnsemblGene testee = new EnsemblGene();
178   
179    /*
180    * with no filter
181    */
182  1 List<SequenceFeature> features = testee.getTranscriptFeatures(geneId,
183    genomic);
184  1 assertEquals(3, features.size());
185  1 assertTrue(features.contains(sf1));
186  1 assertTrue(features.contains(sf2));
187  1 assertTrue(features.contains(sf3));
188    }
189   
190    /**
191    * Test the method that retains features except for 'gene', or 'transcript'
192    * with parent other than the given id
193    */
 
194  1 toggle @Test(groups = "Functional")
195    public void testRetainFeature()
196    {
197  1 String geneId = "ABC123";
198  1 EnsemblGene testee = new EnsemblGene();
199  1 SequenceFeature sf = new SequenceFeature("gene", "", 20000, 20500, 0f,
200    null);
201  1 sf.setValue("id", geneId);
202  1 assertFalse(testee.retainFeature(sf, geneId));
203   
204  1 sf = new SequenceFeature("transcript", "", 20000, 20500, 0f, null);
205  1 sf.setValue("Parent", geneId);
206  1 assertTrue(testee.retainFeature(sf, geneId));
207   
208  1 sf = new SequenceFeature("mature_transcript", "", 20000, 20500, 0f,
209    null);
210  1 sf.setValue("Parent", geneId);
211  1 assertTrue(testee.retainFeature(sf, geneId));
212   
213  1 sf = new SequenceFeature("NMD_transcript_variant", "", 20000, 20500, 0f,
214    null);
215  1 sf.setValue("Parent", geneId);
216  1 assertTrue(testee.retainFeature(sf, geneId));
217   
218  1 sf.setValue("Parent", "ßXYZ");
219  1 assertFalse(testee.retainFeature(sf, geneId));
220   
221  1 sf = new SequenceFeature("anything", "", 20000, 20500, 0f, null);
222  1 assertTrue(testee.retainFeature(sf, geneId));
223    }
224   
225    /**
226    * Test the method that picks out 'gene' (or subtype) features with the
227    * accession id as ID
228    */
 
229  1 toggle @Test(groups = "Functional")
230    public void testGetIdentifyingFeatures()
231    {
232  1 String accId = "ABC123";
233  1 SequenceI seq = new Sequence(accId, "HIBEES");
234   
235    // gene with no ID not valid
236  1 SequenceFeature sf1 = new SequenceFeature("gene", "", 1, 2, 0f, null);
237  1 seq.addSequenceFeature(sf1);
238   
239    // gene with wrong ID not valid
240  1 SequenceFeature sf2 = new SequenceFeature("gene", "a", 1, 2, 0f, null);
241  1 sf2.setValue("id", "XYZ");
242  1 seq.addSequenceFeature(sf2);
243   
244    // gene with right ID is valid
245  1 SequenceFeature sf3 = new SequenceFeature("gene", "b", 1, 2, 0f, null);
246  1 sf3.setValue("id", accId);
247  1 seq.addSequenceFeature(sf3);
248   
249    // gene sub-type with right ID is valid
250  1 SequenceFeature sf4 = new SequenceFeature("snRNA_gene", "", 1, 2, 0f,
251    null);
252  1 sf4.setValue("id", accId);
253  1 seq.addSequenceFeature(sf4);
254   
255    // transcript not valid:
256  1 SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f,
257    null);
258  1 sf5.setValue("id", accId);
259  1 seq.addSequenceFeature(sf5);
260   
261    // exon not valid:
262  1 SequenceFeature sf6 = new SequenceFeature("exon", "", 1, 2, 0f, null);
263  1 sf6.setValue("id", accId);
264  1 seq.addSequenceFeature(sf6);
265   
266  1 List<SequenceFeature> sfs = new EnsemblGene()
267    .getIdentifyingFeatures(seq, accId);
268  1 assertFalse(sfs.contains(sf1));
269  1 assertFalse(sfs.contains(sf2));
270  1 assertTrue(sfs.contains(sf3));
271  1 assertTrue(sfs.contains(sf4));
272  1 assertFalse(sfs.contains(sf5));
273  1 assertFalse(sfs.contains(sf6));
274    }
275   
276    /**
277    * Check behaviour of feature colour scheme for EnsemblGene sequences.
278    * Currently coded to hide all except exon and sequence_variant (or sub-types)
279    * only, with sequence_variant in red above exon coloured by label.
280    */
 
281  1 toggle @Test(groups = "Functional")
282    public void testGetFeatureColourScheme()
283    {
284  1 FeatureSettingsModelI fc = new EnsemblGene().getFeatureColourScheme();
285  1 assertFalse(fc.isFeatureDisplayed("exon"));
286  1 assertFalse(fc.isFeatureHidden("exon"));
287  1 assertFalse(fc.isFeatureDisplayed("coding_exon")); // subtype of exon
288  1 assertFalse(fc.isFeatureHidden("coding_exon")); // subtype of exon
289  1 assertFalse(fc.isFeatureDisplayed("sequence_variant"));
290  1 assertFalse(fc.isFeatureHidden("sequence_variant"));
291  1 assertFalse(fc.isFeatureDisplayed("feature_variant")); // subtype
292  1 assertFalse(fc.isFeatureHidden("feature_variant")); // subtype
293  1 assertTrue(fc.isFeatureHidden("transcript"));
294  1 assertTrue(fc.isFeatureHidden("CDS"));
295   
296  1 assertEquals(Color.RED,
297    fc.getFeatureColour("sequence_variant").getColour());
298  1 assertEquals(Color.RED,
299    fc.getFeatureColour("feature_variant").getColour());
300  1 assertTrue(fc.getFeatureColour("exon").isColourByLabel());
301  1 assertTrue(fc.getFeatureColour("coding_exon").isColourByLabel());
302  1 assertEquals(1, fc.compare("sequence_variant", "exon"));
303  1 assertEquals(-1, fc.compare("exon", "sequence_variant"));
304  1 assertEquals(1, fc.compare("feature_variant", "coding_exon"));
305  1 assertEquals(-1, fc.compare("coding_exon", "feature_variant"));
306  1 assertEquals(1f, fc.getTransparency());
307    }
308   
 
309  0 toggle @Test(groups = "Network")
310    public void testGetGeneIds()
311    {
312    /*
313    * ENSG00000158828 gene id PINK1 human
314    * ENST00000321556 transcript for the same gene - should not be duplicated
315    * P30419 Uniprot identifier for ENSG00000136448
316    * ENST00000592782 transcript for Uniprot gene - should not be duplicated
317    * BRAF - gene name resolvabe (at time of writing) for 6 model species
318    */
319  0 String ids = "ENSG00000158828 ENST00000321556 P30419 ENST00000592782 BRAF";
320  0 EnsemblGene testee = new EnsemblGene();
321  0 List<String> geneIds = testee.getGeneIds(ids);
322  0 assertTrue(geneIds.contains("ENSG00000158828"));
323  0 assertTrue(geneIds.contains("ENSG00000136448"));
324  0 assertTrue(geneIds.contains("ENSG00000157764")); // BRAF human
325  0 assertTrue(geneIds.contains("ENSMUSG00000002413")); // mouse
326  0 assertTrue(geneIds.contains("ENSRNOG00000010957")); // rat
327  0 assertTrue(geneIds.contains("ENSXETG00000004845")); // xenopus
328  0 assertTrue(geneIds.contains("ENSDARG00000017661")); // zebrafish
329    // was ENSGALG00000012865 - which is still the canonical uniprot BRAF cross
330    // reference via GRCg6a
331  0 assertTrue(geneIds.contains("ENSGALG00010013466")); // chicken BRAF
332    // bGalGal1.mat.broiler.GRCg7b
333  0 assertEquals(8, geneIds.size());
334   
335    }
336    }