Created
April 21, 2017 14:39
-
-
Save bag-man/8d95c02ab29552e13abee151b753b144 to your computer and use it in GitHub Desktop.
Find a coding sequence in a contig
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
module.exports = function findCodingRange (codingSeq, contig, reverse) { | |
let codingLength = codingSeq.length | |
, start = 0 | |
, end = 0 | |
, selector = 12 | |
, fail = false | |
start = contig.indexOf(codingSeq.substring(0, selector)) | |
end = contig.indexOf(codingSeq.substring(codingLength - selector, codingLength)) + selector | |
if (start < 0 && end <= selector) fail = true | |
if (start === -1) start = 0 | |
if (end <= selector) end = contig.length | |
if (fail && !reverse) { | |
return findCodingRange(reverseCompliment(codingSeq), contig, true) | |
} else { | |
return { start, end, fail } | |
} | |
function reverseCompliment (sequence) { | |
let reverse = sequence.split('').reverse().join('') | |
return reverse.replace(/[ACTG]/g, (base) => { | |
return 'ACTG'.charAt('TGAC'.indexOf(base)) | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment