Skip to content

Commit b42fd90

Browse files
author
Yana Valasatava
committed
Bugfix: chromosome mapping tool returns -1 if position falls outside coding region on the forward strand
1 parent e8eb0a6 commit b42fd90

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

biojava-genome/src/main/java/org/biojava/nbio/genome/util/ChromosomeMappingTools.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ private static List<Range<Integer>> getCDSExonRangesForward(GeneChromosomePositi
927927
public static int getCDSPosForChromosomeCoordinate(int coordinate, GeneChromosomePosition chromosomePosition) {
928928

929929
if ( chromosomePosition.getOrientation() == '+')
930-
return getCDSPosForward(coordinate,
930+
return getCDSPosForward(coordinate,
931931
chromosomePosition.getExonStarts(),
932932
chromosomePosition.getExonEnds(),
933933
chromosomePosition.getCdsStart(),
@@ -938,7 +938,6 @@ public static int getCDSPosForChromosomeCoordinate(int coordinate, GeneChromosom
938938
chromosomePosition.getExonEnds(),
939939
chromosomePosition.getCdsStart(),
940940
chromosomePosition.getCdsEnd());
941-
942941
}
943942

944943

@@ -1148,10 +1147,20 @@ public static int getCDSPosForward(int chromPos, List<Integer> exonStarts, List<
11481147
boolean inCoding = false;
11491148
int codingLength = 0;
11501149

1151-
11521150
logger.debug("looking for CDS position for " +chromPos);
1151+
1152+
if ( chromPos < cdsStart+1 ) {
1153+
logger.debug(chromPos + " < " + cdsStart+1 );
1154+
return -1; // this is not in a coding region!
1155+
}
11531156

1157+
if ( chromPos > cdsEnd+1 ) {
1158+
logger.debug(chromPos + " > " + cdsEnd+1 );
1159+
return -1; // this is not in a coding region!
1160+
}
1161+
11541162
int lengthExons = 0;
1163+
11551164
// map forward
11561165
for (int i = 0; i < exonStarts.size(); i++) {
11571166

@@ -1226,7 +1235,7 @@ public static int getCDSPosForward(int chromPos, List<Integer> exonStarts, List<
12261235

12271236
}
12281237

1229-
//logger.debug("length exons: " + lengthExons);
1238+
logger.debug("length exons: " + lengthExons);
12301239
//return codingLength - 3;
12311240

12321241
// could not map!

biojava-genome/src/test/java/org/biojava/nbio/genome/TestGenomeMapping.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* Created by andreas on 7/19/16.
1818
*/
19-
public class TestGenomeMapping extends TestCase{
19+
public class TestGenomeMapping extends TestCase {
2020

2121
private static final String geneChromosomeFile = "http://cdn.rcsb.org/gene/hg38/geneChromosome38.tsf.gz";
2222

@@ -27,11 +27,8 @@ protected void setUp() throws Exception {
2727
super.setUp();
2828
InputStream input = new GZIPInputStream(new URL(geneChromosomeFile).openStream());
2929
gcps = GeneChromosomePositionParser.getChromosomeMappings(input);
30-
31-
3230
}
3331

34-
3532
@Test
3633
public void testAK1() {
3734
String geneName = "AK1";
@@ -148,4 +145,34 @@ private void validateExon(int exonNr, int start, int stop, List<Range<Integer>>
148145
assertTrue("Exon " + exonNr + " boundary " + exon.upperEndpoint() + " does not match " + stop, exon.upperEndpoint().equals(stop));
149146

150147
}
148+
149+
@Test
150+
/** Test to make sure the reverse mapping of a genomic coordinate handles border cases
151+
*
152+
* @author Yana Valasatava
153+
*/
154+
public void testReverseMappingForExonBoundaries() {
155+
156+
String geneName = "BCL11B"; // gene on the reverse DNA strand
157+
String genebankId = "NM_138576"; // GeneBank ID for the transcript used for testing (ENST00000357195)
158+
159+
int posExonStart = 99174151; // starting position of the first base in a coding region (1st exon)
160+
int posExonEnd = 99176195; // ending position of the first base in a coding region (1st exon)
161+
162+
for (GeneChromosomePosition gcp : gcps) {
163+
164+
if ( !gcp.getGeneName().equals(geneName) )
165+
continue;
166+
if ( !gcp.getGenebankId().equals(genebankId) )
167+
continue;
168+
169+
int cdsSE = ChromosomeMappingTools.getCDSPosForChromosomeCoordinate(posExonStart-1, gcp);
170+
assertEquals(cdsSE, -1);
171+
172+
int cdsEE = ChromosomeMappingTools.getCDSPosForChromosomeCoordinate(posExonEnd+1, gcp);
173+
assertEquals(cdsEE, -1);
174+
175+
break;
176+
}
177+
}
151178
}

0 commit comments

Comments
 (0)