Skip to content

Commit

Permalink
Return null for out-of-range sequence fetches, rather than throw erro…
Browse files Browse the repository at this point in the history
…r. Support igv-reports, which might not have complete sequence for an exon
  • Loading branch information
jrobinso committed Aug 4, 2024
1 parent 566b516 commit f7a96f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 6 additions & 4 deletions js/feature/render/renderFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ function renderAminoAcidSequence(ctx, strand, leftExon, exon, riteExon, bpStart,
let aaLetter
if (undefined === aminoAcidLetter) {

const sequence = sequenceInterval.getSequence(start, end)
if(sequenceInterval.hasSequence(start, end)) {

if (sequence && 3 === sequence.length) {
const key = '+' === strand ? sequence : complementSequence(sequence.split('').reverse().join(''))
aaLetter = translationDict[key]
const sequence = sequenceInterval.getSequence(start, end)
if (sequence && 3 === sequence.length) {
const key = '+' === strand ? sequence : complementSequence(sequence.split('').reverse().join(''))
aaLetter = translationDict[key]
}
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion js/genome/nonIndexedFasta.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class NonIndexedFasta {
}

if (end <= 0) {
return Promise.resolve(prefix)
return prefix
}

const seq = seqSlice.sequence
Expand Down
6 changes: 5 additions & 1 deletion js/genome/sequenceInterval.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ class SequenceInterval extends GenomicInterval {

getSequence(start, end) {
if (start < this.start || end > this.end) {
throw Error("Range out of bounds")
return null
}
const offset = start - this.start
const n = end - start
const seq = this.features ? this.features.substring(offset, offset + n) : null
return seq
}

hasSequence(start, end) {
return start >= this.start && end <= this.end
}

}

export default SequenceInterval

0 comments on commit f7a96f7

Please sign in to comment.