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.assertTrue;
27 import jalview.datamodel.SequenceDummy;
28 import jalview.datamodel.SequenceFeature;
29 import jalview.datamodel.SequenceI;
30 import jalview.gui.JvOptionPane;
31 import jalview.io.gff.SequenceOntologyFactory;
32 import jalview.io.gff.SequenceOntologyLite;
33 import jalview.util.MapList;
35 import java.util.List;
37 import org.testng.annotations.AfterClass;
38 import org.testng.annotations.BeforeClass;
39 import org.testng.annotations.Test;
41 public class EnsemblGenomeTest
44 @BeforeClass(alwaysRun = true)
45 public void setUpJvOptionPane()
47 JvOptionPane.setInteractiveMode(false);
48 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
51 @BeforeClass(alwaysRun = true)
54 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
57 @AfterClass(alwaysRun = true)
58 public void tearDown()
60 SequenceOntologyFactory.setInstance(null);
64 * Test that the genomic sequence part of genomic sequence is correctly
65 * identified by 'transcript' features (or subtypes) with the correct gene ID
67 @Test(groups = "Functional")
68 public void testGetGenomicRangesFromFeatures()
70 EnsemblGenome testee = new EnsemblGenome();
71 SequenceI genomic = new SequenceDummy("chr7");
72 genomic.setStart(10000);
73 genomic.setEnd(50000);
74 String transcriptId = "ABC123";
76 // transcript at (start+10000) length 501
77 SequenceFeature sf = new SequenceFeature("transcript", "", 20000,
79 sf.setValue("ID", "transcript:" + transcriptId);
81 genomic.addSequenceFeature(sf);
83 // transcript (sub-type) at (start + 10500) length 101
84 sf = new SequenceFeature("ncRNA", "", 10500, 10600, 0f, null);
85 sf.setValue("ID", "transcript:" + transcriptId);
87 genomic.addSequenceFeature(sf);
89 // Ensembl treats NMD_transcript_variant as if transcript
90 // although strictly it is a sequence_variant in SO
91 sf = new SequenceFeature("NMD_transcript_variant", "", 11000, 12000,
93 sf.setValue("ID", "transcript:" + transcriptId);
95 genomic.addSequenceFeature(sf);
97 // transcript with a different ID doesn't count
98 sf = new SequenceFeature("transcript", "", 11500, 12600, 0f, null);
99 sf.setValue("ID", "transcript:anotherOne");
100 genomic.addSequenceFeature(sf);
102 // parent of transcript feature doesn't count
103 sf = new SequenceFeature("gene_member_region", "", 10000, 50000, 0f,
105 genomic.addSequenceFeature(sf);
107 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
109 List<int[]> fromRanges = ranges.getFromRanges();
110 assertEquals(3, fromRanges.size());
111 // from ranges should be sorted by start order
112 assertEquals(10500, fromRanges.get(0)[0]);
113 assertEquals(10600, fromRanges.get(0)[1]);
114 assertEquals(11000, fromRanges.get(1)[0]);
115 assertEquals(12000, fromRanges.get(1)[1]);
116 assertEquals(20000, fromRanges.get(2)[0]);
117 assertEquals(20500, fromRanges.get(2)[1]);
118 // to range should start from given start numbering
119 List<int[]> toRanges = ranges.getToRanges();
120 assertEquals(1, toRanges.size());
121 assertEquals(23, toRanges.get(0)[0]);
122 assertEquals(1625, toRanges.get(0)[1]);
126 * Test the method that retains features except for 'transcript' (or
127 * sub-type), or those with parent other than the given id
129 @Test(groups = "Functional")
130 public void testRetainFeature()
132 String accId = "ABC123";
133 EnsemblGenome testee = new EnsemblGenome();
135 SequenceFeature sf = new SequenceFeature("transcript", "", 20000,
137 assertFalse(testee.retainFeature(sf, accId));
139 sf.setType("mature_transcript");
140 assertFalse(testee.retainFeature(sf, accId));
142 sf.setType("NMD_transcript_variant");
143 assertFalse(testee.retainFeature(sf, accId));
145 // other feature with no parent is kept
146 sf.setType("anything");
147 assertTrue(testee.retainFeature(sf, accId));
149 // other feature with correct parent is kept
150 sf.setValue("Parent", "transcript:" + accId);
151 assertTrue(testee.retainFeature(sf, accId));
153 // other feature with wrong parent is not kept
154 sf.setValue("Parent", "transcript:XYZ");
155 assertFalse(testee.retainFeature(sf, accId));
159 * Test the method that picks out 'transcript' (or subtype) features with the
162 @Test(groups = "Functional")
163 public void testIdentifiesSequence()
165 String accId = "ABC123";
166 EnsemblGenome testee = new EnsemblGenome();
168 // transcript with no ID not valid
169 SequenceFeature sf = new SequenceFeature("transcript", "", 1, 2, 0f,
171 assertFalse(testee.identifiesSequence(sf, accId));
173 // transcript with wrong ID not valid
174 sf.setValue("ID", "transcript");
175 assertFalse(testee.identifiesSequence(sf, accId));
177 // transcript with right ID is valid
178 sf.setValue("ID", "transcript:" + accId);
179 assertTrue(testee.identifiesSequence(sf, accId));
181 // transcript sub-type with right ID is valid
183 assertTrue(testee.identifiesSequence(sf, accId));
185 // Ensembl treats NMD_transcript_variant as if a transcript
186 sf.setType("NMD_transcript_variant");
187 assertTrue(testee.identifiesSequence(sf, accId));
191 assertFalse(testee.identifiesSequence(sf, accId));
195 assertFalse(testee.identifiesSequence(sf, accId));