Skip to content

Commit

Permalink
tidy up code and clean up namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Jan 23, 2024
1 parent 5dec514 commit b2e782c
Show file tree
Hide file tree
Showing 33 changed files with 179 additions and 158 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ Imports:
BiocSingular,
BPCells (>= 0.1.0),
cli,
DelayedArray,
DelayedArray (>= 0.28.0),
Matrix,
methods,
rlang (>= 1.1.0),
S4Vectors
S4Vectors,
SparseArray
Remotes:
bnprks/BPCells
Suggests:
Expand Down
55 changes: 30 additions & 25 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ exportMethods("^")
exportMethods("dimnames<-")
exportMethods(BPCellsSeed)
exportMethods(DelayedArray)
exportMethods(OLD_extract_sparse_array)
exportMethods(acbind)
exportMethods(arbind)
exportMethods(binarize)
Expand Down Expand Up @@ -148,35 +149,39 @@ importClassesFrom(BiocSingular,BiocSingularParam)
importClassesFrom(DelayedArray,DelayedArray)
importClassesFrom(DelayedArray,DelayedMatrix)
importClassesFrom(Matrix,dgCMatrix)
importFrom(BiocSingular,runSVD)
importFrom(DelayedArray,DelayedArray)
importFrom(DelayedArray,OLD_extract_sparse_array)
importFrom(DelayedArray,acbind)
importFrom(DelayedArray,arbind)
importFrom(DelayedArray,bindROWS)
importFrom(DelayedArray,cbind)
importFrom(DelayedArray,colVars)
importFrom(DelayedArray,crossprod)
importFrom(DelayedArray,extract_array)
importFrom(DelayedArray,is_sparse)
importFrom(DelayedArray,matrixClass)
importFrom(DelayedArray,new_DelayedArray)
importFrom(DelayedArray,path)
importFrom(DelayedArray,rbind)
importFrom(DelayedArray,rowVars)
importFrom(DelayedArray,type)
importFrom(S4Vectors,bindCOLS)
importFrom(SparseArray,extract_sparse_array)
importFrom(methods,cbind2)
importFrom(methods,rbind2)
importFrom(methods,show)
importMethodsFrom(BPCells,"%*%")
importMethodsFrom(BPCells,"[")
importMethodsFrom(BPCells,"[<-")
importMethodsFrom(BPCells,"^")
importMethodsFrom(BiocSingular,runSVD)
importMethodsFrom(DelayedArray,"%*%")
importMethodsFrom(DelayedArray,"dimnames<-")
importMethodsFrom(DelayedArray,DelayedArray)
importMethodsFrom(DelayedArray,acbind)
importMethodsFrom(DelayedArray,arbind)
importMethodsFrom(DelayedArray,bindROWS)
importMethodsFrom(DelayedArray,cbind)
importMethodsFrom(DelayedArray,colMeans)
importMethodsFrom(DelayedArray,colSums)
importMethodsFrom(DelayedArray,colVars)
importMethodsFrom(DelayedArray,crossprod)
importMethodsFrom(BPCells,"dimnames<-")
importMethodsFrom(BPCells,colMeans)
importMethodsFrom(BPCells,colSums)
importMethodsFrom(BPCells,rowMeans)
importMethodsFrom(BPCells,rowSums)
importMethodsFrom(BPCells,t)
importMethodsFrom(DelayedArray,OLD_extract_sparse_array)
importMethodsFrom(DelayedArray,dim)
importMethodsFrom(DelayedArray,extract_array)
importMethodsFrom(DelayedArray,extract_sparse_array)
importMethodsFrom(DelayedArray,is_sparse)
importMethodsFrom(DelayedArray,matrixClass)
importMethodsFrom(DelayedArray,path)
importMethodsFrom(DelayedArray,rbind)
importMethodsFrom(DelayedArray,rowMeans)
importMethodsFrom(DelayedArray,rowSums)
importMethodsFrom(DelayedArray,rowVars)
importMethodsFrom(DelayedArray,t)
importMethodsFrom(DelayedArray,type)
importMethodsFrom(S4Vectors,bindCOLS)
importMethodsFrom(methods,cbind2)
importMethodsFrom(methods,rbind2)
importMethodsFrom(methods,show)
26 changes: 17 additions & 9 deletions R/Class-BPCellsMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ methods::setClass("BPCellsMatrix",
)

#' @param x,object A `BPCellsMatrix` object.
#' @importMethodsFrom methods show
#' @importFrom methods show
#' @export
#' @rdname BPCellsMatrix-class
methods::setMethod("show", "BPCellsMatrix", function(object) {
Expand All @@ -36,7 +36,7 @@ methods::setMethod("show", "BPCellsMatrix", function(object) {

#' @return
#' - `t`: A [BPCellsMatrix] object.
#' @importMethodsFrom DelayedArray t
#' @importMethodsFrom BPCells t
#' @export
#' @rdname BPCellsMatrix-class
methods::setMethod("t", "BPCellsMatrix", function(x) {
Expand Down Expand Up @@ -132,9 +132,17 @@ methods::setClassUnion("ListOrNULL", c("list", "NULL"))

# for `dim`, `dimnames`, `extract_array` and `is_sparse` just use the methods
# from DelayedArray
#' For BPCellsMatrix object
#' @importMethodsFrom DelayedArray dim
#' @importMethodsFrom DelayedArray extract_array
#' @importMethodsFrom DelayedArray is_sparse
#' @importMethodsFrom DelayedArray OLD_extract_sparse_array
#' @noRd
NULL

#' @return
#' - `dimnames<-`: A [BPCellsRenameDimsMatrix][BPCellsRenameDims] object.
#' @importMethodsFrom DelayedArray dimnames<-
#' @importMethodsFrom BPCells dimnames<-
#' @export
#' @rdname BPCellsMatrix-class
methods::setMethod(
Expand All @@ -149,21 +157,21 @@ methods::setMethod(
#################### Matrix Statistics ########################
#' BPCellsMatrix row/col summarization
#'
#' @importMethodsFrom DelayedArray rowSums
#' @param x A [BPCellsMatrix][BPCellsMatrix-class] object.
#' @return
#' - `rowSums()`: vector of row sums
#' @aliases rowSums
#' @name BPCells-Summarization
NULL

#' @importMethodsFrom BPCells rowSums
#' @export
#' @rdname BPCells-Summarization
methods::setMethod("rowSums", c(x = "BPCellsMatrix"), function(x) {
rowSums(x@seed)
})

#' @importMethodsFrom DelayedArray colSums
#' @importMethodsFrom BPCells colSums
#' @return
#' - `colSums()`: vector of col sums
#' @aliases colSums
Expand All @@ -173,7 +181,7 @@ methods::setMethod("colSums", c(x = "BPCellsMatrix"), function(x) {
colSums(x@seed)
})

#' @importMethodsFrom DelayedArray rowMeans
#' @importMethodsFrom BPCells rowMeans
#' @return
#' - `rowMeans()`: vector of row means
#' @aliases rowMeans
Expand All @@ -183,7 +191,7 @@ methods::setMethod("rowMeans", c(x = "BPCellsMatrix"), function(x) {
rowMeans(x@seed)
})

#' @importMethodsFrom DelayedArray colMeans
#' @importMethodsFrom BPCells colMeans
#' @return
#' - `colMeans()`: vector of col means
#' @aliases colMeans
Expand All @@ -193,7 +201,7 @@ methods::setMethod("colMeans", c(x = "BPCellsMatrix"), function(x) {
colMeans(x@seed)
})

#' @importMethodsFrom DelayedArray rowVars
#' @importFrom DelayedArray rowVars
#' @return
#' - `rowVars()`: vector of row vars
#' @aliases rowVars
Expand All @@ -206,7 +214,7 @@ methods::setMethod("rowVars", c(x = "BPCellsMatrix"), function(x) {
stats$row_stats["variance", , drop = TRUE]
})

#' @importMethodsFrom DelayedArray colVars
#' @importFrom DelayedArray colVars
#' @return
#' - `colVars()`: vector of col vars
#' @aliases colVars
Expand Down
36 changes: 26 additions & 10 deletions R/Class-BPCellsSeed.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @include utils.R
methods::setClass("BPCellsSeed", contains = get_class("IterableMatrix"))

#' @importMethodsFrom methods show
#' @importFrom methods show
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("show", "BPCellsSeed", function(object) {
Expand All @@ -22,7 +22,7 @@ methods::setMethod("show", "BPCellsSeed", function(object) {
#' - `type`: A string. For all BPCells matrix type of `float` and `double`,
#' always return `double` since R cannot differentiate 32-bit and 64-bit real
#' number.
#' @importMethodsFrom DelayedArray type
#' @importFrom DelayedArray type
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("type", "BPCellsSeed", function(x) {
Expand All @@ -35,15 +35,15 @@ methods::setMethod("type", "BPCellsSeed", function(x) {

#' @return
#' - `is_sparse`: Always return `TRUE` for `BPCellsSeed` object.
#' @importMethodsFrom DelayedArray is_sparse
#' @importFrom DelayedArray is_sparse
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("is_sparse", "BPCellsSeed", function(x) TRUE)

#' @inheritParams S4Arrays::extract_array
#' @return
#' - `extract_array`: A dense matrix.
#' @importMethodsFrom DelayedArray extract_array
#' @importFrom DelayedArray extract_array
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
Expand All @@ -56,18 +56,31 @@ methods::setMethod(
)

#' @return
#' - `extract_sparse_array`: A [SparseArraySeed][DelayedArray::SparseArraySeed]
#' object.
#' @importMethodsFrom DelayedArray extract_sparse_array
#' - `OLD_extract_sparse_array`: A
#' [SparseArraySeed][DelayedArray::SparseArraySeed-class] object.
#' @importFrom DelayedArray OLD_extract_sparse_array
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_sparse_array", "BPCellsSeed",
"OLD_extract_sparse_array", "BPCellsSeed",
function(x, index) {
methods::as(extract_bpcells_array(x, index), "SparseArraySeed")
}
)

#' @return
#' - `extract_sparse_array`: A
#' [SparseArray][SparseArray::SVT_SparseArray-class] object.
#' @importFrom SparseArray extract_sparse_array
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
"extract_sparse_array", "BPCellsSeed",
function(x, index) {
methods::as(extract_bpcells_array(x, index), "SparseArray")
}
)

#######################################################################
# All delayed operations should be wrapped into a `BPCellsSeed` object
# In BPCells, `dimnames<-` was only defined for `IterableMatrix`.
Expand All @@ -80,6 +93,7 @@ methods::setMethod(
#' @return
#' - `dimnames<-`: A [BPCellsSeed] object, usually a `BPCellsRenameDimsSeed`
#' object.
#' @importMethodsFrom BPCells dimnames<-
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
Expand All @@ -89,6 +103,7 @@ methods::setMethod(
}
)

#' @importMethodsFrom BPCells dimnames<-
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod(
Expand All @@ -99,8 +114,9 @@ methods::setMethod(
)

# t will not change the underlying class
#' @return - `t`: A [BPCellsSeed] object.
#' @importMethodsFrom DelayedArray t
#' @return
#' - `t`: A [BPCellsSeed] object.
#' @importMethodsFrom BPCells t
#' @export
#' @rdname BPCellsSeed-class
methods::setMethod("t", "BPCellsSeed", function(x) methods::callNextMethod())
Expand Down
8 changes: 4 additions & 4 deletions R/Class-BindMatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ methods::setClass("BPCellsColBindMatrixArray",
#' @return
#' - `DelayedArray`: A `BPCellsColBindMatrixMatrix` or
#' `BPCellsRowBindMatrixMatrix` object.
#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsBindMatrix
Expand All @@ -93,7 +93,7 @@ methods::setClass("BPCellsColBindMatrixMatrix",
slots = c(seed = "BPCellsColBindMatrixSeed")
)

#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @export
#' @rdname BPCellsBindMatrix
methods::setMethod("matrixClass", "BPCellsColBindMatrixArray", function(x) {
Expand Down Expand Up @@ -145,7 +145,7 @@ methods::setClass("BPCellsRowBindMatrixArray",
slots = c(seed = "BPCellsRowBindMatrixSeed")
)

#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsBindMatrix
Expand All @@ -168,7 +168,7 @@ methods::setClass("BPCellsRowBindMatrixMatrix",
)

#' @export
#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @rdname BPCellsBindMatrix
methods::setMethod("matrixClass", "BPCellsRowBindMatrixArray", function(x) {
"BPCellsRowBindMatrixMatrix"
Expand Down
4 changes: 2 additions & 2 deletions R/Class-Convert.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ methods::setClass("BPCellsConvertArray",
)

#' @param seed A `BPCellsConvertSeed` object.
#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsConvert
Expand All @@ -59,7 +59,7 @@ methods::setClass("BPCellsConvertMatrix",
slots = c(seed = "BPCellsConvertSeed")
)

#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @export
#' @rdname BPCellsConvert
methods::setMethod("matrixClass", "BPCellsConvertArray", function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/Class-Dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ methods::setClass("BPCellsDirArray",
)

#' @param seed A `BPCellsDirSeed` object.
#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsDir
Expand All @@ -72,7 +72,7 @@ methods::setClass("BPCellsDirMatrix",
slots = c(seed = "BPCellsDirSeed")
)

#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @export
#' @rdname BPCellsDir
methods::setMethod("matrixClass", "BPCellsDirArray", function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/Class-Mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ methods::setClass("BPCellsMaskArray",
)

#' @param seed A `BPCellsMaskSeed` object.
#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsMask
Expand All @@ -60,7 +60,7 @@ methods::setClass("BPCellsMaskMatrix",
slots = c(seed = "BPCellsMaskSeed")
)

#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @export
#' @rdname BPCellsMask
methods::setMethod("matrixClass", "BPCellsMaskArray", function(x) {
Expand Down
4 changes: 2 additions & 2 deletions R/Class-Multiply.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ methods::setClass("BPCellsMultiplyArray",
)

#' @param seed A `BPCellsMultiplySeed` object.
#' @importMethodsFrom DelayedArray DelayedArray
#' @importFrom DelayedArray DelayedArray
#' @importFrom DelayedArray new_DelayedArray
#' @export
#' @rdname BPCellsMultiply
Expand All @@ -60,7 +60,7 @@ methods::setClass("BPCellsMultiplyMatrix",
slots = c(seed = "BPCellsMultiplySeed")
)

#' @importMethodsFrom DelayedArray matrixClass
#' @importFrom DelayedArray matrixClass
#' @export
#' @rdname BPCellsMultiply
methods::setMethod("matrixClass", "BPCellsMultiplyArray", function(x) {
Expand Down
Loading

0 comments on commit b2e782c

Please sign in to comment.