Browse code

Enabled celda_C/G/CG functions to take in a sparse matrix as input not in an SCE

Joshua D. Campbell authored on 16/07/2021 20:29:36
Showing 6 changed files

... ...
@@ -6,11 +6,12 @@
6 6
 #'  it exists. Otherwise, the \code{useAssay}
7 7
 #'  \link{assay} slot in \code{x} will be used if
8 8
 #'  \code{x} is a \linkS4class{SingleCellExperiment} object.
9
-#' @param x A numeric \link{matrix} of counts or a
10
-#'  \linkS4class{SingleCellExperiment}
11
-#'  with the matrix located in the assay slot under \code{useAssay} in
12
-#'  \code{altExp(x, altExpName)}.
13
-#'  Rows represent features and columns represent cells.
9
+#' @param x A \linkS4class{SingleCellExperiment}
10
+#'  with the matrix located in the assay slot under \code{useAssay}.
11
+#'  Rows represent features and columns represent cells. Alternatively,
12
+#'  any matrix-like object that can be coerced to a sparse matrix of class
13
+#'  "dgCMatrix" can be directly used as input. The matrix will automatically be
14
+#'  converted to a \linkS4class{SingleCellExperiment} object. 
14 15
 #' @param useAssay A string specifying the name of the
15 16
 #'  \link{assay} slot to use. Default "counts".
16 17
 #' @param altExpName The name for the \link{altExp} slot
... ...
@@ -165,7 +166,7 @@ setMethod("celda_C",
165 166
 #' @rdname celda_C
166 167
 #' @export
167 168
 setMethod("celda_C",
168
-    signature(x = "matrix"),
169
+    signature(x = "ANY"),
169 170
     function(x,
170 171
         useAssay = "counts",
171 172
         altExpName = "featureSubset",
... ...
@@ -186,6 +187,9 @@ setMethod("celda_C",
186 187
         logfile = NULL,
187 188
         verbose = TRUE) {
188 189
 
190
+        # Convert to sparse matrix
191
+        x <- as(x, "dgCMatrix")
192
+        
189 193
         ls <- list()
190 194
         ls[[useAssay]] <- x
191 195
         sce <- SingleCellExperiment::SingleCellExperiment(assays = ls)
... ...
@@ -6,11 +6,12 @@
6 6
 #'  it exists. Otherwise, the \code{useAssay}
7 7
 #'  \link{assay} slot in \code{x} will be used if
8 8
 #'  \code{x} is a \linkS4class{SingleCellExperiment} object.
9
-#' @param x A numeric \link{matrix} of counts or a
10
-#'  \linkS4class{SingleCellExperiment}
11
-#'  with the matrix located in the \link{assay}
12
-#'  slot under \code{useAssay} in \code{altExp(x, altExpName)}.
13
-#'  Rows represent features and columns represent cells.
9
+#' @param x A \linkS4class{SingleCellExperiment}
10
+#'  with the matrix located in the assay slot under \code{useAssay}.
11
+#'  Rows represent features and columns represent cells. Alternatively,
12
+#'  any matrix-like object that can be coerced to a sparse matrix of class
13
+#'  "dgCMatrix" can be directly used as input. The matrix will automatically be
14
+#'  converted to a \linkS4class{SingleCellExperiment} object. 
14 15
 #' @param useAssay A string specifying the name of the
15 16
 #'  \link{assay} slot to use. Default "counts".
16 17
 #' @param altExpName The name for the \link{altExp} slot
... ...
@@ -194,7 +195,7 @@ setMethod("celda_CG",
194 195
 #'     nchains = 1)
195 196
 #' @export
196 197
 setMethod("celda_CG",
197
-    signature(x = "matrix"),
198
+    signature(x = "ANY"),
198 199
     function(x,
199 200
         useAssay = "counts",
200 201
         altExpName = "featureSubset",
... ...
@@ -220,6 +221,9 @@ setMethod("celda_CG",
220 221
         logfile = NULL,
221 222
         verbose = TRUE) {
222 223
 
224
+        # Convert to sparse matrix
225
+        x <- as(x, "dgCMatrix")
226
+      
223 227
         ls <- list()
224 228
         ls[[useAssay]] <- x
225 229
         sce <- SingleCellExperiment::SingleCellExperiment(assays = ls)
... ...
@@ -6,10 +6,12 @@
6 6
 #'  it exists. Otherwise, the \code{useAssay}
7 7
 #'  \link{assay} slot in \code{x} will be used if
8 8
 #'  \code{x} is a \linkS4class{SingleCellExperiment} object.
9
-#' @param x A numeric \link{matrix} of counts or a
10
-#'  \linkS4class{SingleCellExperiment}
9
+#' @param x A \linkS4class{SingleCellExperiment}
11 10
 #'  with the matrix located in the assay slot under \code{useAssay}.
12
-#'  Rows represent features and columns represent cells.
11
+#'  Rows represent features and columns represent cells. Alternatively,
12
+#'  any matrix-like object that can be coerced to a sparse matrix of class
13
+#'  "dgCMatrix" can be directly used as input. The matrix will automatically be
14
+#'  converted to a \linkS4class{SingleCellExperiment} object. 
13 15
 #' @param useAssay A string specifying the name of the
14 16
 #'  \link{assay} slot to use. Default "counts".
15 17
 #' @param altExpName The name for the \link{altExp} slot
... ...
@@ -149,7 +151,7 @@ setMethod("celda_G",
149 151
 #' @rdname celda_G
150 152
 #' @export
151 153
 setMethod("celda_G",
152
-    signature(x = "matrix"),
154
+    signature(x = "ANY"),
153 155
     function(x,
154 156
         useAssay = "counts",
155 157
         altExpName = "featureSubset",
... ...
@@ -169,6 +171,9 @@ setMethod("celda_G",
169 171
         logfile = NULL,
170 172
         verbose = TRUE) {
171 173
 
174
+        # Convert to sparse matrix
175
+        x <- as(x, "dgCMatrix")
176
+      
172 177
         ls <- list()
173 178
         ls[[useAssay]] <- x
174 179
         sce <- SingleCellExperiment::SingleCellExperiment(assays = ls)
... ...
@@ -3,7 +3,7 @@
3 3
 \name{celda_C}
4 4
 \alias{celda_C}
5 5
 \alias{celda_C,SingleCellExperiment-method}
6
-\alias{celda_C,matrix-method}
6
+\alias{celda_C,ANY-method}
7 7
 \title{Cell clustering with Celda}
8 8
 \usage{
9 9
 celda_C(
... ...
@@ -50,7 +50,7 @@ celda_C(
50 50
   verbose = TRUE
51 51
 )
52 52
 
53
-\S4method{celda_C}{matrix}(
53
+\S4method{celda_C}{ANY}(
54 54
   x,
55 55
   useAssay = "counts",
56 56
   altExpName = "featureSubset",
... ...
@@ -73,11 +73,12 @@ celda_C(
73 73
 )
74 74
 }
75 75
 \arguments{
76
-\item{x}{A numeric \link{matrix} of counts or a
77
-\linkS4class{SingleCellExperiment}
78
-with the matrix located in the assay slot under \code{useAssay} in
79
-\code{altExp(x, altExpName)}.
80
-Rows represent features and columns represent cells.}
76
+\item{x}{A \linkS4class{SingleCellExperiment}
77
+with the matrix located in the assay slot under \code{useAssay}.
78
+Rows represent features and columns represent cells. Alternatively,
79
+any matrix-like object that can be coerced to a sparse matrix of class
80
+"dgCMatrix" can be directly used as input. The matrix will automatically be
81
+converted to a \linkS4class{SingleCellExperiment} object.}
81 82
 
82 83
 \item{useAssay}{A string specifying the name of the
83 84
 \link{assay} slot to use. Default "counts".}
... ...
@@ -3,7 +3,7 @@
3 3
 \name{celda_CG}
4 4
 \alias{celda_CG}
5 5
 \alias{celda_CG,SingleCellExperiment-method}
6
-\alias{celda_CG,matrix-method}
6
+\alias{celda_CG,ANY-method}
7 7
 \title{Cell and feature clustering with Celda}
8 8
 \usage{
9 9
 celda_CG(
... ...
@@ -60,7 +60,7 @@ celda_CG(
60 60
   verbose = TRUE
61 61
 )
62 62
 
63
-\S4method{celda_CG}{matrix}(
63
+\S4method{celda_CG}{ANY}(
64 64
   x,
65 65
   useAssay = "counts",
66 66
   altExpName = "featureSubset",
... ...
@@ -88,11 +88,12 @@ celda_CG(
88 88
 )
89 89
 }
90 90
 \arguments{
91
-\item{x}{A numeric \link{matrix} of counts or a
92
-\linkS4class{SingleCellExperiment}
93
-with the matrix located in the \link{assay}
94
-slot under \code{useAssay} in \code{altExp(x, altExpName)}.
95
-Rows represent features and columns represent cells.}
91
+\item{x}{A \linkS4class{SingleCellExperiment}
92
+with the matrix located in the assay slot under \code{useAssay}.
93
+Rows represent features and columns represent cells. Alternatively,
94
+any matrix-like object that can be coerced to a sparse matrix of class
95
+"dgCMatrix" can be directly used as input. The matrix will automatically be
96
+converted to a \linkS4class{SingleCellExperiment} object.}
96 97
 
97 98
 \item{useAssay}{A string specifying the name of the
98 99
 \link{assay} slot to use. Default "counts".}
... ...
@@ -3,7 +3,7 @@
3 3
 \name{celda_G}
4 4
 \alias{celda_G}
5 5
 \alias{celda_G,SingleCellExperiment-method}
6
-\alias{celda_G,matrix-method}
6
+\alias{celda_G,ANY-method}
7 7
 \title{Feature clustering with Celda}
8 8
 \usage{
9 9
 celda_G(
... ...
@@ -48,7 +48,7 @@ celda_G(
48 48
   verbose = TRUE
49 49
 )
50 50
 
51
-\S4method{celda_G}{matrix}(
51
+\S4method{celda_G}{ANY}(
52 52
   x,
53 53
   useAssay = "counts",
54 54
   altExpName = "featureSubset",
... ...
@@ -70,10 +70,12 @@ celda_G(
70 70
 )
71 71
 }
72 72
 \arguments{
73
-\item{x}{A numeric \link{matrix} of counts or a
74
-\linkS4class{SingleCellExperiment}
73
+\item{x}{A \linkS4class{SingleCellExperiment}
75 74
 with the matrix located in the assay slot under \code{useAssay}.
76
-Rows represent features and columns represent cells.}
75
+Rows represent features and columns represent cells. Alternatively,
76
+any matrix-like object that can be coerced to a sparse matrix of class
77
+"dgCMatrix" can be directly used as input. The matrix will automatically be
78
+converted to a \linkS4class{SingleCellExperiment} object.}
77 79
 
78 80
 \item{useAssay}{A string specifying the name of the
79 81
 \link{assay} slot to use. Default "counts".}