Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Suggests:
tidyverse
Collate:
utils.R
hasGRanges.R
BSseq-class.R
BSseqTstat_class.R
MethylCounts.R
Expand Down
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ importFrom(R.utils, "isGzipped", "isBzipped", "gunzip", "bunzip2")
## Exporting
##

exportClasses("hasGRanges",
"BSseq",
exportClasses("BSseq",
"BSseqTstat",
"BSseqStat",
"MethylCounts",
"matrixOrNULL")
"MethylCounts")

exportMethods("[", "show",
"seqnames", "seqnames<-",
Expand Down
6 changes: 3 additions & 3 deletions R/BSmooth.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Internal functions -----------------------------------------------------------

.rowTickmarks <- function(hasGRanges, maxGap) {
gr <- granges(hasGRanges)
.rowTickmarks <- function(BSseq, maxGap) {
gr <- granges(BSseq)
# NOTE: This relies on 'gr' being sorted, so really want to be sure of this!
stopifnot(!is.unsorted(gr))
clusters <- reduce(gr, min.gapwidth = maxGap, with.revmap = TRUE)
Expand All @@ -13,7 +13,7 @@
makeClusters <- function(hasGRanges, maxGap = 10^8) {
chrOrder <- as.character(runValue(seqnames(hasGRanges)))
if(anyDuplicated(chrOrder))
stop("argument 'hasGRanges' is not properly order")
stop("argument 'hasGRanges' is not properly ordered")
grBase <- granges(hasGRanges)
clusters <- reduce(resize(grBase, width = 2*maxGap + 1, fix = "center"))
start(clusters) <- pmax(rep(1, length(clusters)), start(clusters))
Expand Down
4 changes: 2 additions & 2 deletions R/BSmooth.fstat.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ smoothSds <- function(BSseqStat, k = 101, qSd = 0.75, mc.cores = 1,
stop("need to set argument 'maxGap'")
if(verbose) cat("[smoothSds] preprocessing ... ")
ptime1 <- proc.time()
clusterIdx <- makeClusters(granges(BSseqStat), maxGap = maxGap)
clusterIdx <- makeClusters(BSseqStat, maxGap = maxGap)
ptime2 <- proc.time()
stime <- (ptime2 - ptime1)[3]
if(verbose) cat(sprintf("done in %.1f sec\n", stime))
Expand Down Expand Up @@ -137,7 +137,7 @@ localCorrectStat <- function(BSseqStat, threshold = c(-15,15), mc.cores = 1, ver
maxGap <- BSseqStat$parameters$maxGap
if(verbose) cat("[BSmooth.tstat] preprocessing ... ")
ptime1 <- proc.time()
clusterIdx <- makeClusters(BSseqStat$gr, maxGap = maxGap)
clusterIdx <- makeClusters(BSseqStat, maxGap = maxGap)
ptime2 <- proc.time()
stime <- (ptime2 - ptime1)[3]
if(verbose) cat(sprintf("done in %.1f sec\n", stime))
Expand Down
37 changes: 24 additions & 13 deletions R/BSseqStat_class.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
setClass("BSseqStat", contains = "hasGRanges",
setClass("BSseqStat", contains = "GRanges",
representation(stats = "list",
parameters = "list")
)
Expand All @@ -9,7 +9,7 @@ setValidity("BSseqStat", function(object) {
anyDuplicated(names(object@stats)))
msg <- validMsg(msg, "the 'stats' list needs to be named with unique names.")
for(name in c("rawSds", "smoothsSds", "stat", "rawTstats")) {
if(name %in% names(object@stats) && isTRUE(nrow(object@stats[[name]]) != length(object@gr)))
if(name %in% names(object@stats) && isTRUE(nrow(object@stats[[name]]) != length(object)))
msg <- validMsg(msg, sprintf("component '%s' of slot 'stats' has to have the same number of rows as slot 'gr' is long", name))
}
if(is.null(msg)) TRUE else msg
Expand All @@ -24,11 +24,7 @@ setMethod("show", signature(object = "BSseqStat"),
})

setMethod("[", "BSseqStat", function(x, i, ...) {
if(missing(i))
stop("need [i] for subsetting")
if(missing(i))
return(x)
x@gr <- x@gr[i]
i <- normalizeSingleBracketSubscript(i, x)
statnames <- names(x@stats)
names(statnames) <- statnames
x@stats <- lapply(statnames, function(nam) {
Expand All @@ -38,17 +34,32 @@ setMethod("[", "BSseqStat", function(x, i, ...) {
}
x@stats[[nam]]
})
x
callNextMethod()
})

BSseqStat <- function(gr = NULL, stats = NULL, parameters = NULL) {
out <- new("BSseqStat")
out@gr <- gr
out@stats <- stats
out@parameters <- parameters
out
new("BSseqStat", gr, stats = stats, parameters = parameters)
}

setMethod("updateObject", "BSseqStat",
function(object, ..., verbose = FALSE) {
if (!.hasSlot(object, "gr")) {
return(callNextMethod())
}
if (verbose)
message("[updateObject] ", class(object), " object ",
"uses old internal representation from\n",
"[updateObject] bsseq <= 1.49.2. ",
"Updating it ... ", appendLF=FALSE)
gr <- updateObject(object@gr)
ans <- BSseqStat(gr = gr, stats = object@stats,
parameters = object@parameters)
if (verbose)
message("OK")
ans
}
)

# TODO: updateObject() to use ordinary matrix instead of DelayedMatrix with
# in-memory seed.
# setMethod("updateObject", "BSseqStat",
Expand Down
47 changes: 26 additions & 21 deletions R/BSseqTstat_class.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
setClass("BSseqTstat", contains = "hasGRanges",
representation(stats = "matrix",
## Add new union members as needed (e.g. "SparseMatrix").
setClassUnion("matrix_OR_DelayedMatrix", c("matrix", "DelayedMatrix"))

setClass("BSseqTstat", contains = "GRanges",
representation(stats = "matrix_OR_DelayedMatrix",
parameters = "list")
)
setValidity("BSseqTstat", function(object) {
msg <- NULL
if(length(object@gr) != nrow(object@stats))
msg <- c(msg, "length of 'gr' is different from the number of rows of 'stats'")
if(length(object) != nrow(object@stats))
msg <- c(msg, "'stats' must have one row per methylation locus")
if(is.null(msg)) TRUE else msg
})

Expand All @@ -20,21 +23,13 @@ setMethod("show", signature(object = "BSseqTstat"),
})

setMethod("[", "BSseqTstat", function(x, i, ...) {
if(missing(i))
stop("need [i] for subsetting")
if(missing(i))
return(x)
x@gr <- x@gr[i]
i <- normalizeSingleBracketSubscript(i, x)
x@stats <- x@stats[i,, drop = FALSE]
x
callNextMethod()
})

BSseqTstat <- function(gr = NULL, stats = NULL, parameters = NULL) {
out <- new("BSseqTstat")
out@gr <- gr
out@stats <- stats
out@parameters <- parameters
out
new("BSseqTstat", gr, stats = stats, parameters = parameters)
}

summary.BSseqTstat <- function(object, ...) {
Expand Down Expand Up @@ -68,10 +63,20 @@ plot.BSseqTstat <- function(x, y, ...) {
}

setMethod("updateObject", "BSseqTstat",
function(object, ...) {
stats <- object@stats
stats <- stats
object@stats <- stats
object
}
function(object, ..., verbose = FALSE) {
if (!.hasSlot(object, "gr")) {
return(callNextMethod())
}
if (verbose)
message("[updateObject] ", class(object), " object ",
"uses old internal representation from\n",
"[updateObject] bsseq <= 1.49.2. ",
"Updating it ... ", appendLF=FALSE)
gr <- updateObject(object@gr)
ans <- BSseqTstat(gr = gr, stats = object@stats,
parameters = object@parameters)
if (verbose)
message("OK")
ans
}
)
135 changes: 0 additions & 135 deletions R/hasGRanges.R

This file was deleted.

33 changes: 13 additions & 20 deletions man/BSseqStat-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
}
\arguments{
\item{gr}{The genomic locations as an object of class \code{GRanges}.}
\item{stats}{The statistics, as a list of matrix-like objects (see
'Details' below).}
\item{parameters}{A list of parameters.}
\item{stats}{A list of matrix-like objects (see 'Details' below) with
list elements representing various statistics for methylation loci
along the genome.}
\item{parameters}{A list of parameters, as an object of class \code{list},
representing how the statistics were computed.}
}
\details{
The matrix-like elements of the list in the 'stats' slot will be
Expand All @@ -35,19 +37,8 @@
However, usually objects are returned by \code{BSmooth.fstat(...)} and
not constructed by the user.
}
\section{Slots}{
\describe{
\item{\code{stats}:}{This is a list of \code{\link[DelayedArray]{DelayedMatrix}}
objects with list elements representing various statistics for
methylation loci along the genome.}
\item{\code{parameters}:}{Object of class \code{list}. A list of
parameters representing how the statistics were computed.}
\item{\code{gr}:}{Object of class \code{GRanges} giving genomic
locations.}
}
}
\section{Extends}{
Class \code{\linkS4class{hasGRanges}}, directly.
Class \code{\link[GenomicRanges]{GRanges}}, directly.
}
\section{Methods}{
\describe{
Expand All @@ -57,10 +48,11 @@
}
}
\section{Utilities}{
This class extends \code{hasGRanges} and therefore inherits a number
of useful \code{GRanges} methods that operate on the \code{gr} slot,
used for accessing and setting the genomic locations and also do
\code{subsetByOverlaps}.
This class extends \code{\link[GenomicRanges]{GRanges}} and therefore
inherits the full \code{GRanges} API. This means that \code{BSseqStat}
objects support any operation supported by \code{GRanges} objects, like
\code{seqnames}, \code{start}, \code{end}, \code{width}, \code{strand},
\code{[}, \code{findOverlaps}, \code{subsetByOverlaps}, etc...
}
\section{Coercion}{
Package version 1.11.1 introduced a new version of representing
Expand All @@ -71,7 +63,8 @@
Kasper Daniel Hansen \email{khansen@jhsph.edu}
}
\seealso{
\code{\linkS4class{hasGRanges}} for accessing the genomic locations.
\code{\link[GenomicRanges]{GRanges}} in the \pkg{GenomicRanges} package
for accessing the genomic locations.
\code{\link{BSmooth.fstat}} for a function
that returns objects of class \code{BSseqStat}, and \code{\link{smoothSds}},
\code{\link{computeStat}} and \code{\link{dmrFinder}}
Expand Down
Loading
Loading