Skip to content

Commit 8410a63

Browse files
committed
Add coercion method from ExpressionSets; DataLayer docs
1 parent 03c3c30 commit 8410a63

7 files changed

+114
-8
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: SingleCellAssay
22
Type: Package
33
Title: Core data structures for single-cell assays
4-
Version: 0.79
4+
Version: 0.80
55
Date: 2014-04-08
66
Author: Andrew McDavid <[email protected]>, Greg Finak <[email protected]>
77
Maintainer: Greg Finak <[email protected]>

R/AllClasses.R

+39-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,46 @@
55

66
NULL
77

8-
#setOldClass("ncdf")
98

9+
##' DataLayer class
10+
##'
11+
##' DataLayer is a 3-D array, wrapped to make it look like a matrix.
12+
##' It is used to hold matrix-like expression data, for which we might want to keep several representations (transformations) around.
13+
##' The number of matrix "layers" is given by the trailing dimension.
14+
##' Dimensions 1 and 2 correspond to the "rows" and "columns" of the matrix.
15+
##' The layer that is active can be set, and additional layers created (concatenated).
16+
##' }
17+
##' \section{Slots}{
18+
##' DataLayer extends array, and has the following additional slots
19+
##' \describe{
20+
##' \item{.Data}{the underlying array}
21+
##' \item{valid}{a \code{logical} that may optionally indicate the freshness of derived layers (if the underlying data changes). Not currently used.}
22+
##' \item{layer}{which 'slice' of the array is being used}
23+
##' }}
24+
##' \section{Methods}{
25+
##' \describe{
26+
##' \item{addlayer}{Concatentate another slice onto the object}
27+
##' \item{layername}{Return the name of the current slice}
28+
##' \item{layer}{Return the active layer}
29+
##' \item{layer<-}{Set the active layer}
30+
##' \item{exprs}{Return the matrix representation of the active layer}
31+
##' \item{exprs<-}{Replace the matrix on the current layer.}
32+
##' }
33+
##' @examples
34+
##' ar <- array(1:10, dim=c(2, 5, 1))
35+
##' dl <- new('DataLayer', .Data=ar)
36+
##' nrow(dl) #2
37+
##' ncol(dl) #5
38+
##' layer(dl)
39+
##' dl <- addlayer(dl, 'negative')
40+
##' ex <- exprs(dl)
41+
##' layer(dl) <- 'negative' #or could use 2
42+
##' exprs(dl)<- -ex
43+
##' exprs(dl)
44+
##' @name DataLayer-class
45+
##' @docType class
46+
##' @aliases DataLayer
47+
##' @seealso \code{\link{SingleCellAssay}}, \code{\link{SingleCellAssay-class}}
1048
setClass('DataLayer', contains='array', representation=representation(layer='numeric', valid='logical'), prototype=prototype(array(NA, dim=c(0, 0, 1)), layer=1L, valid=TRUE), validity=function(object){
1149
#cat('DL dim ', dim([email protected]), '\n')
1250
length(dim(object@.Data))==3

R/DataLayer.R

+4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ setMethod("exprs",signature(object="DataLayer"),function(object){
115115
setMethod('initialize', 'DataLayer',
116116
function(.Object, ...){
117117
## message('init DataLayer') #DEBUG
118+
## This is (was?) necessary initialize since we inherit from 'array'
119+
## But is rather mysterious, nonetheless.
118120
.Object <- getMethod('initialize', 'ANY')(.Object, ...)
121+
dn <- dimnames(.Object@.Data)
122+
dimnames(.Object@.Data) <-if(is.null(dn)) list(wells=NULL, features=NULL, layers=NULL) else dn
119123
.Object
120124
})
121125

R/Fluidigm-methods.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ filter <- function(sc, groups=NULL, filt_control=NULL, apply_filter=TRUE){
237237
if (!is.null(groups)) {
238238
checkGroups(sc, groups)
239239
scL <- split(sc, groups)
240-
lapp <- lapply(scL, filter, groups=NULL, filt_control, apply_filter)
240+
lapp <- lapply(scL, filter, groups=NULL, filt_control=filt_control, apply_filter=apply_filter)
241241
## Do various things with lapp:
242242
if(apply_filter && filt_control$filter){
243243
## list of SingleCellAssays

R/SingleCellAssay-methods.R

+21-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fixdf <- function(df, idvars, primerid, measurement, cmap, fmap, keep.names){
204204
## unnamed arguments get passed along to callNextMethod
205205
## which eventually just sets the slots
206206
setMethod('initialize', 'SingleCellAssay',
207-
function(.Object, dataframe, idvars, primerid, measurement, cellvars=NULL, featurevars=NULL, phenovars=NULL, sort=TRUE, ...){
207+
function(.Object, dataframe, idvars, primerid, measurement, exprsMatrix, cellvars=NULL, featurevars=NULL, phenovars=NULL, sort=TRUE, ...){
208208
##message(class(.Object), ' calling SingleCellAssay Initialize') #DEBUG
209209
.Object <- callNextMethod()
210210
if(sort) .Object <- sort(.Object)
@@ -639,3 +639,23 @@ setMethod('combine', signature=c(x='SingleCellAssay', y='AnnotatedDataFrame'), f
639639
slot(x, along) <- newdata
640640
x
641641
})
642+
643+
setAs('ExpressionSet', 'SingleCellAssay', function(from){
644+
## just a transposed version
645+
ex <- t(exprs(from))
646+
dn <- dimnames(ex)
647+
names(dn) <- c('wellKey', 'primerid')
648+
dim(ex) <- c(dim(ex), 1)
649+
pd <- phenoData(from)
650+
pData(pd)[,'wellKey'] <- sampleNames(pd)
651+
fd <- featureData(from)
652+
fd$primerid <- sampleNames(fd)
653+
dimnames(ex) <- c(dn, layer='ExpressionSet')
654+
DL <- new('DataLayer', .Data=ex)
655+
new('SingleCellAssay', .Data=DL, featureData=fd, cellData=pd, sort=FALSE)
656+
})
657+
658+
## setAs('SingleCellAssay', 'data.table', function(from){
659+
## dt <- data.table(as.vector(exprs(from)))
660+
661+
## })

inst/tests/test-DataLayer.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ test_that('doubleton dl works', {
3636

3737
context('subset and replace')
3838
test_that('subset works', {
39-
expect_equal(dl[[,1]], mat[,1,drop=FALSE])
40-
expect_equal(dl[[1,]], mat[1,,drop=FALSE])
39+
expect_equal(dl[[,1]], mat[,1,drop=FALSE], check.names=FALSE)
40+
expect_equal(dl[[1,]], mat[1,,drop=FALSE], check.names=FALSE)
4141
matidx <- cbind(c(1, 1, 2), 1:3)
4242
expect_equal(dl[[matidx]], mat[matidx])
4343
mat[matidx] <- -999
4444
dl[[matidx]] <- -999
45-
expect_equal(exprs(dl), mat)
45+
expect_equal(exprs(dl), mat, check.attributes=FALSE)
4646
})
4747

4848
test_that('[ subscripting works', {
4949
expect_is(dl[1,], 'DataLayer')
5050
expect_is(dl[,2:3], 'DataLayer')
51-
expect_equal(exprs(dl[1,]), dl[[1,,drop=FALSE]])
51+
expect_equal(exprs(dl[1,]), dl[[1,,drop=FALSE]], check.attributes=FALSE)
5252
})
5353

5454
spl <- split(dl, 1:2)

man/DataLayer-class.Rd

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
\docType{class}
2+
\name{DataLayer-class}
3+
\alias{DataLayer}
4+
\alias{DataLayer-class}
5+
\title{DataLayer class}
6+
\description{
7+
DataLayer is a 3-D array, wrapped to make it look like a
8+
matrix. It is used to hold matrix-like expression data, for
9+
which we might want to keep several representations
10+
(transformations) around. The number of matrix "layers" is
11+
given by the trailing dimension. Dimensions 1 and 2
12+
correspond to the "rows" and "columns" of the matrix. The
13+
layer that is active can be set, and additional layers
14+
created (concatenated). } \section{Slots}{ DataLayer
15+
extends array, and has the following additional slots
16+
\describe{ \item{.Data}{the underlying array}
17+
\item{valid}{a \code{logical} that may optionally indicate
18+
the freshness of derived layers (if the underlying data
19+
changes). Not currently used.} \item{layer}{which 'slice'
20+
of the array is being used} }} \section{Methods}{
21+
\describe{ \item{addlayer}{Concatentate another slice onto
22+
the object} \item{layername}{Return the name of the current
23+
slice} \item{layer}{Return the active layer}
24+
\item{layer<-}{Set the active layer} \item{exprs}{Return
25+
the matrix representation of the active layer}
26+
\item{exprs<-}{Replace the matrix on the current layer.} }
27+
}
28+
\examples{
29+
ar <- array(1:10, dim=c(2, 5, 1))
30+
dl <- new('DataLayer', .Data=ar)
31+
nrow(dl) #2
32+
ncol(dl) #5
33+
layer(dl)
34+
dl <- addlayer(dl, 'negative')
35+
ex <- exprs(dl)
36+
layer(dl) <- 'negative' #or could use 2
37+
exprs(dl)<- -ex
38+
exprs(dl)
39+
}
40+
\seealso{
41+
\code{\link{SingleCellAssay}},
42+
\code{\link{SingleCellAssay-class}}
43+
}
44+

0 commit comments

Comments
 (0)