Skip to content

Commit

Permalink
Update BSseq-mod-class.R
Browse files Browse the repository at this point in the history
  • Loading branch information
yixuan-chen-elisa authored Dec 7, 2023
1 parent 6d98f49 commit ad982ff
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions R/BSseq-mod-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,46 @@
contains = "RangedSummarizedExperiment"
)

# Validity methods -------------------------------------------------------------

setValidity("BSseq_mod", function(object) {
msg <- NULL

if (identical(object, .BSseq_mod())) {
# No validity checks for object returned by internal constructor
return(msg)
}

msg <- validMsg(msg, bsseq:::.checkAssayNames(object, c("U", "M", "Other_mod")))

if(class(rowRanges(object)) != "GRanges") {
msg <- validMsg(msg, sprintf("object of class '%s' needs to have a
'GRanges' in slot 'rowRanges'", class(object)))
}

## benchmarking shows that min(assay()) < 0 is faster than any(assay() < 0) if it is false
if(min(assay(object, "M")) < 0 || any(is.null(assay(object, "M"))) ||
any(is.infinite(assay(object, "M")))){
msg <- validMsg(msg, "the 'M' assay has negative, NA or infinite entries")
}

if(min(assay(object, "U")) < 0 || any(is.null(assay(object, "U"))) ||
any(is.infinite(assay(object, "U")))) {
msg <- validMsg(msg, "the 'U' assay has negative, NA or infinite entries")
}

if(min(assay(object, "Other_mod")) < 0 || any(is.null(assay(object, "Other_mod"))) ||
any(is.infinite(assay(object, "Other_mod")))){
msg <- validMsg(msg, "the 'Other_mod' assay has negative, NA or inifinite entries")
}

if (is.null(msg)) {
TRUE
} else {
msg
}
})

# Exported functions -----------------------------------------------------------

# BSseq class object for handling other modification calls generated by modkit
Expand Down

0 comments on commit ad982ff

Please sign in to comment.