Skip to content

Commit 1583da3

Browse files
committed
fix: predictCoding uses CDS-mapped width for exon/intron boundary deletions (#83)
A deletion starting in an exon and extending into the intron produced incorrect REFCODON/VARCODON because .getRefCodons() and the frameshift calculation used the genomic width of the variant rather than the transcript-space (CDSLOC) width. For example, a 51bp genomic deletion with only 37bp overlapping the CDS would compute cend using 51, causing the reference codon to extend incorrectly into the next exon's sequence. Fix: replace width(txlocal) (genomic width) with width(mcols(txlocal)$CDSLOC) (CDS-mapped width) in both: - .getRefCodons(): codon boundary calculation - frameshift detection: refwidth for length-change check Fixes #83
1 parent c8a9ee0 commit 1583da3

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎R/methods-predictCoding.R‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ setMethod("predictCoding", c("VRanges", "TxDb", "ANY", "missing"),
113113
mcols(txlocal)$varAllele <- va
114114
}
115115

116-
## frameshift
117-
refwidth <- width(txlocal)
116+
## frameshift: use CDS-mapped width, not genomic width, because a
117+
## deletion extending into an intron has genomic width > CDS overlap (#83).
118+
refwidth <- width(mcols(txlocal)$CDSLOC)
118119
altallele <- mcols(txlocal)$varAllele
119120
fmshift <- abs(width(altallele) - refwidth) %% 3 != 0
120121
if (any(fmshift))
@@ -200,10 +201,13 @@ setMethod("predictCoding", c("VRanges", "TxDb", "ANY", "missing"),
200201
.getRefCodons <- function(txlocal, altpos, seqSource, cdsbytx)
201202
{
202203
## adjust codon end for
203-
## - width of the reference sequence
204+
## - width of the reference sequence in transcript space
204205
## - position of alt allele substitution in the codon
206+
## Use CDSLOC width (transcript-space) not genomic width, because
207+
## a deletion extending into an intron has genomic width >> CDS width (#83).
208+
cds_width <- width(mcols(txlocal)$CDSLOC)
205209
cstart <- ((start(mcols(txlocal)$CDSLOC) - 1L) %/% 3L) * 3L + 1L
206-
cend <- cstart + (((altpos + width(txlocal) - 2L) %/% 3L) * 3L + 2L)
210+
cend <- cstart + (((altpos + cds_width - 2L) %/% 3L) * 3L + 2L)
207211
txord <- match(mcols(txlocal)$TXID, names(cdsbytx))
208212
txseqs <- extractTranscriptSeqs(seqSource, cdsbytx[txord])
209213
DNAStringSet(substring(txseqs, cstart, cend))

0 commit comments

Comments
 (0)