Skip to content

predictCoding on empty ranges drops REFAA/VARAA, should be empty AAStringSet instead? #86

@mschubert

Description

@mschubert

Running predictCoding on an empty range object currently does not return columns for REFAA and VARAA:

library(VariantAnnotation)
library(BSgenome.Hsapiens.UCSC.hg19)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)

fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")
vcf <- readVcf(fl, "hg19")[123] # non-coding variant
seqlevels(vcf) <- "chr22"
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
coding <- predictCoding(vcf, txdb, seqSource=Hsapiens)

coding$REFAA # NULL instead of AAStringSet()
coding$VARAA # NULL instead of AAStringSet()

Shouldn't this rather return empty AAStringSet objects? If so, the following changes would be required:

--- a/R/methods-predictCoding.R
+++ b/R/methods-predictCoding.R
@@ -104,8 +110,6 @@ setMethod("predictCoding", c("VRanges", "ANY", "ANY", "missing"),
     ## variant location in cds region
     mcols(query) <- append(mcols(query), DataFrame(varAllele=varAllele))
     txlocal <- .localCoordinates(query, cdsbytx, ignore.strand=FALSE, ...)
-    if (length(txlocal) == 0)
-        return(txlocal)

     ## reverse complement "-" strand
     valid <- rep(TRUE, length(txlocal))
@@ -189,7 +193,7 @@ setMethod("predictCoding", c("VRanges", "ANY", "ANY", "missing"),
     consequence <- factor(consequence)

     mcols(txlocal) <- append(mcols(txlocal),
-        DataFrame(GENEID=NA_character_,
+        DataFrame(GENEID=rep(NA_character_, length(txlocal)),
                   CONSEQUENCE=consequence,
                   REFCODON=refCodon,
                   VARCODON=varCodon,

The reason for this is that any downstream operation on those two fields (e.g. reverse or subseq) errors instead of returning an empty result. This patch fixes that behavior, without adding any significant computation time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions