CellCounts: Compute Number of Cells Positive for Certain Cytokine...

Description Usage Arguments See Also Examples

View source: R/CellCounts.R

Description

Compute the number of cells expressing a particular combination of markers for each sample.

Usage

1
CellCounts(data, combinations)

Arguments

data

Either a COMPASSContainer, or a list of matrices. Each matrix i is of dimension N_i cells (rows) by K common markers (columns).

combinations

A list of 'combinations', used to denote the subsets of interest. See the examples for usage.

See Also

Combinations

Examples

 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
set.seed(123)
## generate 10 simulated matrices of flow data
K <- 6 ## number of markers
data <- replicate(10, simplify=FALSE, {
  m <- matrix( rnorm(1E4 * K, 2000, 1000 ), ncol=K )
  m[m < 2500] <- 0
  colnames(m) <- c("IL2", "IL4", "IL6", "Mip1B", "IFNg", "TNFa")
  return(m)
})
names(data) <- sample(letters, 10)
head( data[[1]] )

## generate counts over all available combinations of markers in data
str(CellCounts(data)) ## 64 columns, as all 2^6 combinations expressed

## generate marginal counts
combos <- list(1, 2, 3, 4, 5, 6) ## marginal cell counts
cc <- CellCounts(data, combos)

## a base R way of doing the same thing
f <- function(data) {
  do.call(rbind, lapply(data, function(x) apply(x, 2, function(x) sum(x > 0))))
}
cc2 <- f(data)

## check that they're identical
stopifnot(identical( unname(cc), unname(cc2) ))

## We can also generate cell counts by expressing various combinations
## of markers (names) in the data.

## count cells expressing IL2 or IL4
CellCounts(data, "IL2|IL4")

## count cells expressing IL2, IL4 or IL6
CellCounts(data, "IL2|IL4|IL6")

## counts for each of IL2, IL4, IL6 (marginally)
CellCounts(data, c("IL2", "IL4", "IL6"))

## counts for cells that are IL2 positive and IL4 negative
CellCounts(data, "IL2 & !IL4")

## expressing the same intent with indices
CellCounts(data, list(c(1, -2)))

## all possible combinations
str(CellCounts(data, Combinations(6)))

## can also call on COMPASSContainers
data(COMPASS)
CellCounts(CC, "M1&M2")

Example output

          IL2      IL4 IL6    Mip1B     IFNg     TNFa
[1,]    0.000 4370.725   0    0.000    0.000    0.000
[2,]    0.000    0.000   0    0.000 2721.365 2917.511
[3,] 3558.708 2926.961   0    0.000    0.000    0.000
[4,]    0.000    0.000   0    0.000    0.000    0.000
[5,]    0.000    0.000   0 2900.647 3302.121    0.000
[6,] 3715.065 3131.986   0    0.000    0.000 4257.013
 int [1:10, 1:64] 1094 1059 1108 1086 1103 1083 1129 1086 1119 1095 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:10] "h" "a" "y" "w" ...
  ..$ : chr [1:64] "!IL2&!IL4&!IL6&!Mip1B&!IFNg&!TNFa" "IL2&!IL4&!IL6&!Mip1B&!IFNg&!TNFa" "!IL2&IL4&!IL6&!Mip1B&!IFNg&!TNFa" "!IL2&!IL4&IL6&!Mip1B&!IFNg&!TNFa" ...
  IL2|IL4
h    5151
a    5276
y    5181
w    5216
f    5156
d    5239
i    5251
k    5216
c    5244
r    5241
  IL2|IL4|IL6
h        6620
a        6822
y        6669
w        6707
f        6659
d        6706
i        6674
k        6715
c        6691
r        6707
   IL2  IL4  IL6
h 3060 3014 3111
a 3116 3145 3167
y 3027 3072 3031
w 3097 3102 3100
f 3026 3060 3085
d 3082 3102 3102
i 3085 3145 3042
k 3102 3046 3121
c 3105 3096 3054
r 3095 3130 3079
  IL2 & !IL4
h       2137
a       2131
y       2109
w       2114
f       2096
d       2137
i       2106
k       2170
c       2148
r       2111
  IL2&!IL4
h     2137
a     2131
y     2109
w     2114
f     2096
d     2137
i     2106
k     2170
c     2148
r     2111
 int [1:10, 1:64] 10 7 8 5 12 11 10 16 8 10 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:10] "h" "a" "y" "w" ...
  ..$ : chr [1:64] "IL2&IL4&IL6&Mip1B&IFNg&TNFa" "!IL2&IL4&IL6&Mip1B&IFNg&TNFa" "IL2&!IL4&IL6&Mip1B&IFNg&TNFa" "!IL2&!IL4&IL6&Mip1B&IFNg&TNFa" ...
       M1&M2
sid_1     48
sid_2     49
sid_3    515
sid_4    362
sid_5    451
sid_6     89
sid_7     31
sid_8    292
sid_9    289
sid_10   101

COMPASS documentation built on Nov. 8, 2020, 8:05 p.m.