Skip to content

Instantly share code, notes, and snippets.

@bag-man
Created April 21, 2017 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bag-man/8d95c02ab29552e13abee151b753b144 to your computer and use it in GitHub Desktop.
Save bag-man/8d95c02ab29552e13abee151b753b144 to your computer and use it in GitHub Desktop.
Find a coding sequence in a contig
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