Skip to content

Commit bceab29

Browse files
committed
Adding test for genome mapping
1 parent 3bc719a commit bceab29

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package org.biojava.nbio.genome;
2+
3+
import com.google.common.collect.Lists;
4+
import com.google.common.collect.Range;
5+
import junit.framework.TestCase;
6+
import org.biojava.nbio.genome.parsers.genename.GeneChromosomePosition;
7+
import org.biojava.nbio.genome.parsers.genename.GeneChromosomePositionParser;
8+
import org.biojava.nbio.genome.util.ChromosomeMappingTools;
9+
import org.junit.Test;
10+
11+
import java.io.InputStream;
12+
import java.net.URL;
13+
import java.util.List;
14+
import java.util.zip.GZIPInputStream;
15+
16+
/**
17+
* Created by andreas on 7/19/16.
18+
*/
19+
public class TestGenomeMapping extends TestCase{
20+
21+
private static final String geneChromosomeFile = "http://cdn.rcsb.org/gene/hg38/geneChromosome38.tsf.gz";
22+
23+
private List<GeneChromosomePosition> gcps = null;
24+
25+
@Override
26+
protected void setUp() throws Exception {
27+
super.setUp();
28+
InputStream input = new GZIPInputStream(new URL(geneChromosomeFile).openStream());
29+
gcps = GeneChromosomePositionParser.getChromosomeMappings(input);
30+
31+
32+
}
33+
34+
35+
@Test
36+
public void testAK1() {
37+
String geneName = "AK1";
38+
39+
assertNotNull(gcps);
40+
assertTrue("Problems with downloading refFlat file from UCSC browser ", gcps.size() > 100);
41+
42+
int uniProtLength = 194;
43+
44+
try {
45+
46+
for (GeneChromosomePosition pos : gcps) {
47+
48+
//System.out.println(pos.getGeneName());
49+
if (!pos.getGeneName().equals(geneName))
50+
continue;
51+
52+
/// there are three alternative transcripts for AK1.
53+
// we are just testing one here:
54+
55+
if ( ! pos.getGenebankId().equals("NM_000476"))
56+
continue;
57+
58+
assertTrue(pos.getGeneName().equals(geneName));
59+
assertTrue(pos.getOrientation().equals('-'));
60+
assertTrue(pos.getChromosome().equals("chr9"));
61+
62+
List<Range<Integer>> cdsranges = ChromosomeMappingTools.getCDSExonRanges(pos);
63+
64+
validateExon(0,0,7, cdsranges );
65+
validateExon(1,7,43, cdsranges );
66+
validateExon(2,43,207, cdsranges );
67+
validateExon(3,207,324, cdsranges );
68+
validateExon(4,324,516, cdsranges );
69+
validateExon(5,516,585, cdsranges );
70+
71+
72+
int cdslength = ChromosomeMappingTools.getCDSLength(pos);
73+
74+
assertTrue("CDS length should be 582, but is " + cdslength, cdslength == (uniProtLength *3));
75+
76+
List<Range<Integer>> chromranges = ChromosomeMappingTools.getChromosomalRangesForCDS(pos);
77+
78+
// we are reverse strand. reverse the order
79+
chromranges = Lists.reverse(chromranges);
80+
81+
assertTrue(chromranges.size() == 6);
82+
83+
// compare with https://www.ncbi.nlm.nih.gov/CCDS/CcdsBrowse.cgi?REQUEST=CCDS&DATA=CCDS6881
84+
validateExon(0,127868008,127868076, chromranges );
85+
validateExon(1,127868320,127868512, chromranges );
86+
validateExon(2,127871822,127871939, chromranges );
87+
validateExon(3,127872689,127872853, chromranges );
88+
validateExon(4,127873025,127873061, chromranges );
89+
validateExon(5,127874610,127874617, chromranges );
90+
91+
}
92+
} catch (Exception e) {
93+
fail(e.getMessage());
94+
}
95+
}
96+
97+
@Test
98+
public void testHBA(){
99+
100+
String geneName = "HBA1";
101+
assertNotNull(gcps);
102+
103+
assertTrue("Problems with downloading refFlat file from UCSC browser ", gcps.size() > 100);
104+
105+
try {
106+
107+
for ( GeneChromosomePosition pos : gcps){
108+
109+
//System.out.println(pos.getGeneName());
110+
if ( ! pos.getGeneName().equals(geneName))
111+
continue;
112+
113+
assertTrue(pos.getGeneName().equals("HBA1"));
114+
assertTrue(pos.getGenebankId().equals("NM_000558"));
115+
assertTrue(pos.getChromosome().equals("chr16"));
116+
assertTrue(pos.getTranscriptionStart().equals(176650));
117+
assertTrue(pos.getTranscriptionEnd().equals(177522));
118+
assertTrue(pos.getOrientation().equals('+'));
119+
120+
List<Range<Integer>> cdsranges = ChromosomeMappingTools.getCDSExonRanges(pos);
121+
122+
assertTrue(cdsranges.size() == 3);
123+
124+
validateExon(0,0,95,cdsranges);
125+
validateExon(1,95,300,cdsranges);
126+
validateExon(2,300,429,cdsranges);
127+
128+
129+
List<Range<Integer>> chromranges = ChromosomeMappingTools.getChromosomalRangesForCDS(pos);
130+
131+
validateExon(0,176716,176811, chromranges );
132+
validateExon(1,176928,177133, chromranges );
133+
validateExon(2,177282,177411, chromranges );
134+
135+
136+
}
137+
} catch (Exception e){
138+
fail(e.getMessage());
139+
}
140+
141+
142+
}
143+
144+
private void validateExon(int exonNr, int start, int stop, List<Range<Integer>> cdsranges) {
145+
146+
Range exon = cdsranges.get(exonNr);
147+
assertTrue("Exon " + exonNr + " boundary "+ exon.lowerEndpoint() + " does not match " +start , exon.lowerEndpoint().equals(start));
148+
assertTrue("Exon " + exonNr + " boundary " + exon.upperEndpoint() + " does not match " + stop, exon.upperEndpoint().equals(stop));
149+
150+
}
151+
}

0 commit comments

Comments
 (0)