/
cellsPerGeneFusion-methods.R
61 lines (55 loc) · 1.44 KB
/
cellsPerGeneFusion-methods.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#' Cells per gene fusion
#'
#' @name cellsPerGeneFusion
#' @inherit AcidGenerics::cellsPerGeneFusion
#' @note Updated 2023-10-06.
#'
#' @inheritParams AcidRoxygen::params
#'
#' @param minCells `integer(1)`.
#' Minimum number of cells per gene fusion.
#'
#' @param ... Additional arguments.
#'
#' @examples
#' data(cello)
#'
#' ## Cellosaurus ====
#' object <- cello
#' df <- cellsPerGeneFusion(object)
NULL
## Updated 2023-10-06.
`cellsPerGeneFusion,Cellosaurus` <- # nolint
function(object, minCells = 2L) {
assert(validObject(object))
cl <- geneFusions(object)
assert(is(cl, "CharacterList"))
tbl <- table(cl)
mat <- .tableToLogicalMatrix(tbl)
keep <- colSums(mat) >= minCells
if (!any(keep)) {
return(NULL)
}
mat <- mat[, keep, drop = FALSE]
keep <- rowSums(mat) > 0L
if (!any(keep)) {
return(NULL)
}
mat <- mat[keep, , drop = FALSE]
i <- order(colSums(mat), decreasing = TRUE)
mat <- mat[, i, drop = FALSE]
df1 <- as.DataFrame(mat)
j <- rownames(mat)
df2 <- as(object, "DFrame")
df2 <- df2[j, .minimalCols, drop = FALSE]
df2 <- decode(df2)
df <- cbind(df2, df1)
df
}
#' @rdname cellsPerGeneFusion
#' @export
setMethod(
f = "cellsPerGeneFusion",
signature = signature(object = "Cellosaurus"),
definition = `cellsPerGeneFusion,Cellosaurus`
)