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.assertTrue;
7 import jalview.datamodel.SequenceDummy;
8 import jalview.datamodel.SequenceFeature;
9 import jalview.datamodel.SequenceI;
10 import jalview.io.gff.SequenceOntologyFactory;
11 import jalview.io.gff.SequenceOntologyLite;
12 import jalview.util.MapList;
14 import java.util.List;
16 import org.testng.Assert;
17 import org.testng.annotations.AfterClass;
18 import org.testng.annotations.BeforeClass;
19 import org.testng.annotations.Test;
21 public class EnsemblCdsTest
23 @BeforeClass(alwaysRun = true)
26 SequenceOntologyFactory.setInstance(new SequenceOntologyLite());
29 @AfterClass(alwaysRun = true)
30 public void tearDown()
32 SequenceOntologyFactory.setInstance(null);
36 * Test that the cdna part of genomic sequence is correctly identified by
37 * 'CDS' features (or subtypes) with the desired transcript as parent
39 @Test(groups = "Functional")
40 public void testGetGenomicRangesFromFeatures()
42 EnsemblCds testee = new EnsemblCds();
43 SequenceI genomic = new SequenceDummy("chr7");
44 genomic.setStart(10000);
45 genomic.setEnd(50000);
46 String transcriptId = "ABC123";
48 // CDS at (start+10000) length 501
49 SequenceFeature sf = new SequenceFeature("CDS", "", 20000, 20500, 0f,
51 sf.setValue("Parent", "transcript:" + transcriptId);
53 genomic.addSequenceFeature(sf);
55 // CDS (sub-type) at (start + 10500) length 101
56 sf = new SequenceFeature("CDS_predicted", "", 10500, 10600, 0f, null);
57 sf.setValue("Parent", "transcript:" + transcriptId);
59 genomic.addSequenceFeature(sf);
61 // CDS belonging to a different transcript doesn't count
62 sf = new SequenceFeature("CDS", "", 11500, 12600, 0f, null);
63 sf.setValue("Parent", "transcript:anotherOne");
64 genomic.addSequenceFeature(sf);
66 // exon feature doesn't count
67 sf = new SequenceFeature("exon", "", 10000, 50000, 0f, null);
68 genomic.addSequenceFeature(sf);
70 // mRNA_region feature doesn't count (parent of CDS)
71 sf = new SequenceFeature("mRNA_region", "", 10000, 50000, 0f, null);
72 genomic.addSequenceFeature(sf);
74 MapList ranges = testee.getGenomicRangesFromFeatures(genomic,
76 List<int[]> fromRanges = ranges.getFromRanges();
77 assertEquals(2, fromRanges.size());
78 // from ranges should be sorted by start order
79 assertEquals(10500, fromRanges.get(0)[0]);
80 assertEquals(10600, fromRanges.get(0)[1]);
81 assertEquals(20000, fromRanges.get(1)[0]);
82 assertEquals(20500, fromRanges.get(1)[1]);
83 // to range should start from given start numbering
84 List<int[]> toRanges = ranges.getToRanges();
85 assertEquals(1, toRanges.size());
86 assertEquals(23, toRanges.get(0)[0]);
87 assertEquals(624, toRanges.get(0)[1]);
91 * Test the method that retains features except for 'CDS' (or subtypes), or
92 * features with parent other than the given id
94 @Test(groups = "Functional")
95 public void testRetainFeature()
97 String accId = "ABC123";
98 EnsemblCds testee = new EnsemblCds();
100 SequenceFeature sf = new SequenceFeature("CDS", "", 20000,
102 assertFalse(testee.retainFeature(sf, accId));
104 sf.setType("CDS_predicted");
105 assertFalse(testee.retainFeature(sf, accId));
107 // other feature with no parent is retained
108 sf.setType("sequence_variant");
109 assertTrue(testee.retainFeature(sf, accId));
111 // other feature with desired parent is retained
112 sf.setValue("Parent", "transcript:" + accId);
113 assertTrue(testee.retainFeature(sf, accId));
115 // feature with wrong parent is not retained
116 sf.setValue("Parent", "transcript:XYZ");
117 assertFalse(testee.retainFeature(sf, accId));
121 * Test the method that picks out 'CDS' (or subtype) features with the
122 * accession id as parent
124 @Test(groups = "Functional")
125 public void testIdentifiesSequence()
127 String accId = "ABC123";
128 EnsemblCds testee = new EnsemblCds();
130 // cds with no parent not valid
131 SequenceFeature sf = new SequenceFeature("CDS", "", 1, 2, 0f, null);
132 assertFalse(testee.identifiesSequence(sf, accId));
134 // cds with wrong parent not valid
135 sf.setValue("Parent", "transcript:XYZ");
136 assertFalse(testee.identifiesSequence(sf, accId));
138 // cds with right parent is valid
139 sf.setValue("Parent", "transcript:" + accId);
140 assertTrue(testee.identifiesSequence(sf, accId));
142 // cds sub-type with right parent is valid
143 sf.setType("CDS_predicted");
144 assertTrue(testee.identifiesSequence(sf, accId));
146 // transcript not valid:
147 sf.setType("transcript");
148 assertFalse(testee.identifiesSequence(sf, accId));
152 assertFalse(testee.identifiesSequence(sf, accId));
155 @Test(groups = "Functional")
156 public void testIsValidReference() throws Exception
158 EnsemblSequenceFetcher esq = new EnsemblCds();
159 Assert.assertTrue(esq.isValidReference("CCDS5863.1"));
160 Assert.assertTrue(esq.isValidReference("ENST00000288602"));
161 Assert.assertTrue(esq.isValidReference("ENSG00000288602"));
162 Assert.assertTrue(esq.isValidReference("ENSP00000288602"));
163 Assert.assertFalse(esq.isValidReference("ENST0000288602"));
164 // non-human species have a 3 character identifier included:
165 Assert.assertTrue(esq.isValidReference("ENSMUSG00000099398"));