-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
159 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* @flow */ | ||
|
||
var _ = require('underscore'); | ||
var Interval = require('./Interval'); | ||
|
||
class CodingInterval extends Interval { | ||
isCoding: boolean; | ||
constructor(start, stop, isCoding: boolean) { | ||
super(start, stop); | ||
this.isCoding = isCoding; | ||
} | ||
} | ||
|
||
/** | ||
* Split exons which cross the coding/non-coding boundary into purely coding & | ||
* non-coding parts. | ||
*/ | ||
function splitCodingExons(exons: Interval[], | ||
codingRegion: Interval): CodingInterval[] { | ||
return _.flatten(exons.map(exon => { | ||
// Special case: the coding region is entirely contained by this exon. | ||
if (exon.containsInterval(codingRegion)) { | ||
// split into three parts. | ||
return [ | ||
new CodingInterval(exon.start, codingRegion.start - 1, false), | ||
new CodingInterval(codingRegion.start, codingRegion.stop, true), | ||
new CodingInterval(codingRegion.stop + 1, exon.stop, false) | ||
].filter(interval => interval.start <= interval.stop); | ||
} | ||
|
||
var startIsCoding = codingRegion.contains(exon.start), | ||
stopIsCoding = codingRegion.contains(exon.stop); | ||
if (startIsCoding == stopIsCoding) { | ||
return [new CodingInterval(exon.start, exon.stop, startIsCoding)]; | ||
} else if (startIsCoding) { | ||
return [ | ||
new CodingInterval(exon.start, codingRegion.stop, true), | ||
new CodingInterval(codingRegion.stop + 1, exon.stop, false) | ||
]; | ||
} else { | ||
return [ | ||
new CodingInterval(exon.start, codingRegion.start - 1, false), | ||
new CodingInterval(codingRegion.start, exon.stop, true) | ||
]; | ||
} | ||
})); | ||
} | ||
|
||
module.exports = {splitCodingExons, CodingInterval}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* @flow */ | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
var bedtools = require('../src/bedtools'), | ||
Interval = require('../src/Interval'); | ||
|
||
describe('bedtools', function() { | ||
describe('splitCodingExons', function() { | ||
var splitCodingExons = bedtools.splitCodingExons; | ||
var CodingInterval = bedtools.CodingInterval; | ||
|
||
it('should split one exon', function() { | ||
var exon = new Interval(10, 20); | ||
|
||
expect(splitCodingExons([exon], new Interval(13, 17))).to.deep.equal([ | ||
new CodingInterval(10, 12, false), | ||
new CodingInterval(13, 17, true), | ||
new CodingInterval(18, 20, false) | ||
]); | ||
|
||
expect(splitCodingExons([exon], new Interval(5, 15))).to.deep.equal([ | ||
new CodingInterval(10, 15, true), | ||
new CodingInterval(16, 20, false) | ||
]); | ||
|
||
expect(splitCodingExons([exon], new Interval(15, 25))).to.deep.equal([ | ||
new CodingInterval(10, 14, false), | ||
new CodingInterval(15, 20, true) | ||
]); | ||
|
||
expect(splitCodingExons([exon], new Interval(10, 15))).to.deep.equal([ | ||
new CodingInterval(10, 15, true), | ||
new CodingInterval(16, 20, false) | ||
]); | ||
|
||
expect(splitCodingExons([exon], new Interval(15, 20))).to.deep.equal([ | ||
new CodingInterval(10, 14, false), | ||
new CodingInterval(15, 20, true) | ||
]); | ||
}); | ||
|
||
it('should handle purely coding or non-coding exons', function() { | ||
var exon = new Interval(10, 20); | ||
|
||
expect(splitCodingExons([exon], new Interval(0, 9))).to.deep.equal([ | ||
new CodingInterval(10, 20, false) | ||
]); | ||
expect(splitCodingExons([exon], new Interval(21, 25))).to.deep.equal([ | ||
new CodingInterval(10, 20, false) | ||
]); | ||
expect(splitCodingExons([exon], new Interval(10, 20))).to.deep.equal([ | ||
new CodingInterval(10, 20, true) | ||
]); | ||
}); | ||
}); | ||
}); |