Clover icon

Coverage Report

  1. Project Clover database Fri Nov 15 2024 13:56:46 GMT
  2. Package jalview.ext.ensembl

File EnsemblGenomeTest.java

 

Code metrics

0
83
6
1
221
138
6
0.07
13.83
6
1

Classes

Class Line # Actions
EnsemblGenomeTest 42 83 6
1.0100%
 

Contributing tests

This file is covered by 3 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.annotations.AfterClass;
39    import org.testng.annotations.BeforeClass;
40    import org.testng.annotations.Test;
41   
 
42    public class EnsemblGenomeTest
43    {
44   
 
45  1 toggle @BeforeClass(alwaysRun = true)
46    public void setUpJvOptionPane()
47    {
48  1 JvOptionPane.setInteractiveMode(false);
49  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
50    }
51   
 
52  1 toggle @BeforeClass(alwaysRun = true)
53    public void setUp()
54    {
55  1 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
56    }
57   
 
58  1 toggle @AfterClass(alwaysRun = true)
59    public void tearDown()
60    {
61  1 SequenceOntologyFactory.setInstance(null);
62    }
63   
64    /**
65    * Test that the genomic sequence part of genomic sequence is correctly
66    * identified by 'transcript' features (or subtypes) with the correct gene ID
67    */
 
68  1 toggle @Test(groups = "Functional")
69    public void testGetGenomicRangesFromFeatures()
70    {
71  1 EnsemblGenome testee = new EnsemblGenome();
72  1 SequenceI genomic = new SequenceDummy("chr7");
73  1 genomic.setStart(10000);
74  1 genomic.setEnd(50000);
75  1 String transcriptId = "ABC123";
76   
77    // transcript at (start+10000) length 501
78  1 SequenceFeature sf = new SequenceFeature("transcript", "", 20000, 20500,
79    0f, null);
80  1 sf.setValue("id", transcriptId);
81  1 sf.setStrand("+");
82  1 genomic.addSequenceFeature(sf);
83   
84    // transcript (sub-type) at (start + 10500) length 101
85  1 sf = new SequenceFeature("ncRNA", "", 10500, 10600, 0f, null);
86  1 sf.setValue("id", transcriptId);
87  1 sf.setStrand("+");
88  1 genomic.addSequenceFeature(sf);
89   
90    // Ensembl treats NMD_transcript_variant as if transcript
91    // although strictly it is a sequence_variant in SO
92  1 sf = new SequenceFeature("NMD_transcript_variant", "", 11000, 12000, 0f,
93    null);
94  1 sf.setValue("id", transcriptId);
95  1 sf.setStrand("+");
96  1 genomic.addSequenceFeature(sf);
97   
98    // transcript with a different ID doesn't count
99  1 sf = new SequenceFeature("transcript", "", 11500, 12600, 0f, null);
100  1 sf.setValue("id", "anotherOne");
101  1 genomic.addSequenceFeature(sf);
102   
103    // parent of transcript feature doesn't count
104  1 sf = new SequenceFeature("gene_member_region", "", 10000, 50000, 0f,
105    null);
106  1 genomic.addSequenceFeature(sf);
107   
108  1 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
109    transcriptId, 23);
110  1 List<int[]> fromRanges = ranges.getFromRanges();
111  1 assertEquals(3, fromRanges.size());
112    // from ranges should be sorted by start order
113  1 assertEquals(10500, fromRanges.get(0)[0]);
114  1 assertEquals(10600, fromRanges.get(0)[1]);
115  1 assertEquals(11000, fromRanges.get(1)[0]);
116  1 assertEquals(12000, fromRanges.get(1)[1]);
117  1 assertEquals(20000, fromRanges.get(2)[0]);
118  1 assertEquals(20500, fromRanges.get(2)[1]);
119    // to range should start from given start numbering
120  1 List<int[]> toRanges = ranges.getToRanges();
121  1 assertEquals(1, toRanges.size());
122  1 assertEquals(23, toRanges.get(0)[0]);
123  1 assertEquals(1625, toRanges.get(0)[1]);
124    }
125   
126    /**
127    * Test the method that retains features except for 'transcript' (or
128    * sub-type), or those with parent other than the given id
129    */
 
130  1 toggle @Test(groups = "Functional")
131    public void testRetainFeature()
132    {
133  1 String accId = "ABC123";
134  1 EnsemblGenome testee = new EnsemblGenome();
135   
136  1 SequenceFeature sf = new SequenceFeature("transcript", "", 20000, 20500,
137    0f, null);
138  1 assertFalse(testee.retainFeature(sf, accId));
139   
140  1 sf = new SequenceFeature("mature_transcript", "", 20000, 20500, 0f,
141    null);
142  1 assertFalse(testee.retainFeature(sf, accId));
143   
144  1 sf = new SequenceFeature("NMD_transcript_variant", "", 20000, 20500, 0f,
145    null);
146  1 assertFalse(testee.retainFeature(sf, accId));
147   
148    // other feature with no parent is kept
149  1 sf = new SequenceFeature("anything", "", 20000, 20500, 0f, null);
150  1 assertTrue(testee.retainFeature(sf, accId));
151   
152    // other feature with correct parent is kept
153  1 sf.setValue("Parent", accId);
154  1 assertTrue(testee.retainFeature(sf, accId));
155   
156    // other feature with wrong parent is not kept
157  1 sf.setValue("Parent", "XYZ");
158  1 assertFalse(testee.retainFeature(sf, accId));
159    }
160   
161    /**
162    * Test the method that picks out 'transcript' (or subtype) features with the
163    * accession id as ID
164    */
 
165  1 toggle @Test(groups = "Functional")
166    public void testGetIdentifyingFeatures()
167    {
168  1 String accId = "ABC123";
169  1 SequenceI seq = new Sequence(accId, "HEARTS");
170   
171    // transcript with no ID not valid
172  1 SequenceFeature sf1 = new SequenceFeature("transcript", "", 1, 2, 0f,
173    null);
174  1 seq.addSequenceFeature(sf1);
175   
176    // transcript with wrong ID not valid
177    // NB change desc to avoid rejection of duplicate feature!
178  1 SequenceFeature sf2 = new SequenceFeature("transcript", "a", 1, 2, 0f,
179    null);
180  1 sf2.setValue("id", "transcript");
181  1 seq.addSequenceFeature(sf2);
182   
183    // transcript with right ID is valid
184  1 SequenceFeature sf3 = new SequenceFeature("transcript", "b", 1, 2, 0f,
185    null);
186  1 sf3.setValue("id", accId);
187  1 seq.addSequenceFeature(sf3);
188   
189    // transcript sub-type with right ID is valid
190  1 SequenceFeature sf4 = new SequenceFeature("ncRNA", "", 1, 2, 0f, null);
191  1 sf4.setValue("id", accId);
192  1 seq.addSequenceFeature(sf4);
193   
194    // Ensembl treats NMD_transcript_variant as if a transcript
195  1 SequenceFeature sf5 = new SequenceFeature("NMD_transcript_variant", "",
196    1, 2, 0f, null);
197  1 sf5.setValue("id", accId);
198  1 seq.addSequenceFeature(sf5);
199   
200    // gene not valid:
201  1 SequenceFeature sf6 = new SequenceFeature("gene", "", 1, 2, 0f, null);
202  1 sf6.setValue("id", accId);
203  1 seq.addSequenceFeature(sf6);
204   
205    // exon not valid:
206  1 SequenceFeature sf7 = new SequenceFeature("exon", "", 1, 2, 0f, null);
207  1 sf7.setValue("id", accId);
208  1 seq.addSequenceFeature(sf7);
209   
210  1 List<SequenceFeature> sfs = new EnsemblGenome()
211    .getIdentifyingFeatures(seq, accId);
212  1 assertFalse(sfs.contains(sf1));
213  1 assertFalse(sfs.contains(sf2));
214  1 assertTrue(sfs.contains(sf3));
215  1 assertTrue(sfs.contains(sf4));
216  1 assertTrue(sfs.contains(sf5));
217  1 assertFalse(sfs.contains(sf6));
218  1 assertFalse(sfs.contains(sf7));
219    }
220   
221    }