Clover icon

Coverage Report

  1. Project Clover database Fri Dec 6 2024 13:47:14 GMT
  2. Package jalview.ext.ensembl

File EnsemblCdsTest.java

 

Code metrics

0
80
7
1
214
134
7
0.09
11.43
7
1

Classes

Class Line # Actions
EnsemblCdsTest 43 80 7
1.0100%
 

Contributing tests

This file is covered by 4 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 static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertTrue;
26   
27    import jalview.datamodel.Sequence;
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;
35   
36    import java.util.List;
37   
38    import org.testng.Assert;
39    import org.testng.annotations.AfterClass;
40    import org.testng.annotations.BeforeClass;
41    import org.testng.annotations.Test;
42   
 
43    public class EnsemblCdsTest
44    {
45   
 
46  1 toggle @BeforeClass(alwaysRun = true)
47    public void setUpJvOptionPane()
48    {
49  1 JvOptionPane.setInteractiveMode(false);
50  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51    }
52   
 
53  1 toggle @BeforeClass(alwaysRun = true)
54    public void setUp()
55    {
56  1 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
57    }
58   
 
59  1 toggle @AfterClass(alwaysRun = true)
60    public void tearDown()
61    {
62  1 SequenceOntologyFactory.setInstance(null);
63    }
64   
65    /**
66    * Test that the cdna part of genomic sequence is correctly identified by
67    * 'CDS' features (or subtypes) with the desired transcript as parent
68    */
 
69  1 toggle @Test(groups = "Functional")
70    public void testGetGenomicRangesFromFeatures()
71    {
72  1 EnsemblCds testee = new EnsemblCds();
73  1 SequenceI genomic = new SequenceDummy("chr7");
74  1 genomic.setStart(10000);
75  1 genomic.setEnd(50000);
76  1 String transcriptId = "ABC123";
77   
78    // CDS at (start+10000) length 501
79  1 SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
80    null);
81  1 sf.setValue("Parent", transcriptId);
82  1 sf.setStrand("+");
83  1 genomic.addSequenceFeature(sf);
84   
85    // CDS (sub-type) at (start + 10500) length 101
86  1 sf = new SequenceFeature("CDS_predicted", "", 10500, 10600, 0f, null);
87  1 sf.setValue("Parent", transcriptId);
88  1 sf.setStrand("+");
89  1 genomic.addSequenceFeature(sf);
90   
91    // CDS belonging to a different transcript doesn't count
92  1 sf = new SequenceFeature("CDS", "", 11500, 12600, 0f, null);
93  1 sf.setValue("Parent", "anotherOne");
94  1 genomic.addSequenceFeature(sf);
95   
96    // exon feature doesn't count
97  1 sf = new SequenceFeature("exon", "", 10000, 50000, 0f, null);
98  1 genomic.addSequenceFeature(sf);
99   
100    // mRNA_region feature doesn't count (parent of CDS)
101  1 sf = new SequenceFeature("mRNA_region", "", 10000, 50000, 0f, null);
102  1 genomic.addSequenceFeature(sf);
103   
104  1 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
105    transcriptId, 23);
106  1 List<int[]> fromRanges = ranges.getFromRanges();
107  1 assertEquals(2, fromRanges.size());
108    // from ranges should be sorted by start order
109  1 assertEquals(10500, fromRanges.get(0)[0]);
110  1 assertEquals(10600, fromRanges.get(0)[1]);
111  1 assertEquals(20000, fromRanges.get(1)[0]);
112  1 assertEquals(20500, fromRanges.get(1)[1]);
113    // to range should start from given start numbering
114  1 List<int[]> toRanges = ranges.getToRanges();
115  1 assertEquals(1, toRanges.size());
116  1 assertEquals(23, toRanges.get(0)[0]);
117  1 assertEquals(624, toRanges.get(0)[1]);
118    }
119   
120    /**
121    * Test the method that retains features except for 'CDS' (or subtypes), or
122    * features with parent other than the given id
123    */
 
124  1 toggle @Test(groups = "Functional")
125    public void testRetainFeature()
126    {
127  1 String accId = "ABC123";
128  1 EnsemblCds testee = new EnsemblCds();
129   
130  1 SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
131    null);
132  1 assertFalse(testee.retainFeature(sf, accId));
133   
134  1 sf = new SequenceFeature("CDS_predicted", "", 20000, 20500, 0f, null);
135  1 assertFalse(testee.retainFeature(sf, accId));
136   
137    // other feature with no parent is retained
138  1 sf = new SequenceFeature("anotherType", "", 20000, 20500, 0f, null);
139  1 assertTrue(testee.retainFeature(sf, accId));
140   
141    // other feature with desired parent is retained
142  1 sf.setValue("Parent", accId);
143  1 assertTrue(testee.retainFeature(sf, accId));
144   
145    // feature with wrong parent is not retained
146  1 sf.setValue("Parent", "XYZ");
147  1 assertFalse(testee.retainFeature(sf, accId));
148    }
149   
150    /**
151    * Test the method that picks out 'CDS' (or subtype) features with the
152    * accession id as parent
153    */
 
154  1 toggle @Test(groups = "Functional")
155    public void testGetIdentifyingFeatures()
156    {
157  1 String accId = "ABC123";
158  1 SequenceI seq = new Sequence(accId, "MKDONS");
159   
160    // cds with no parent not valid
161  1 SequenceFeature sf1 = new SequenceFeature("CDS", "", 1, 2, 0f, null);
162  1 seq.addSequenceFeature(sf1);
163   
164    // cds with wrong parent not valid
165  1 SequenceFeature sf2 = new SequenceFeature("CDS", "", 1, 2, 0f, null);
166  1 sf2.setValue("Parent", "XYZ");
167  1 seq.addSequenceFeature(sf2);
168   
169    // cds with right parent is valid
170  1 SequenceFeature sf3 = new SequenceFeature("CDS", "", 1, 2, 0f, null);
171  1 sf3.setValue("Parent", accId);
172  1 seq.addSequenceFeature(sf3);
173   
174    // cds sub-type with right parent is valid
175  1 SequenceFeature sf4 = new SequenceFeature("CDS_predicted", "", 1, 2, 0f,
176    null);
177  1 sf4.setValue("Parent", accId);
178  1 seq.addSequenceFeature(sf4);
179   
180    // transcript not valid:
181  1 SequenceFeature sf5 = new SequenceFeature("transcript", "", 1, 2, 0f,
182    null);
183  1 sf5.setValue("Parent", accId);
184  1 seq.addSequenceFeature(sf5);
185   
186    // exon not valid:
187  1 SequenceFeature sf6 = new SequenceFeature("exon", "", 1, 2, 0f, null);
188  1 sf6.setValue("Parent", accId);
189  1 seq.addSequenceFeature(sf6);
190   
191  1 List<SequenceFeature> sfs = new EnsemblCds().getIdentifyingFeatures(seq,
192    accId);
193  1 assertFalse(sfs.contains(sf1));
194  1 assertFalse(sfs.contains(sf2));
195  1 assertTrue(sfs.contains(sf3));
196  1 assertTrue(sfs.contains(sf4));
197  1 assertFalse(sfs.contains(sf5));
198  1 assertFalse(sfs.contains(sf6));
199    }
200   
 
201  1 toggle @Test(groups = "Functional")
202    public void testIsValidReference() throws Exception
203    {
204  1 EnsemblSequenceFetcher esq = new EnsemblCds();
205  1 Assert.assertTrue(esq.isValidReference("CCDS5863.1"));
206  1 Assert.assertTrue(esq.isValidReference("ENST00000288602"));
207  1 Assert.assertTrue(esq.isValidReference("ENSG00000288602"));
208  1 Assert.assertTrue(esq.isValidReference("ENSP00000288602"));
209  1 Assert.assertFalse(esq.isValidReference("ENST0000288602"));
210    // non-human species have a 3 character identifier included:
211  1 Assert.assertTrue(esq.isValidReference("ENSMUSG00000099398"));
212    }
213   
214    }