countCells: Count cells in neighbourhoods

View source: R/countCells.R

countCellsR Documentation

Count cells in neighbourhoods

Description

This function quantifies the number of cells in each neighbourhood according to an input experimental design. This forms the basis for the differential neighbourhood abundance testing.

Usage

countCells(x, samples, meta.data = NULL)

Arguments

x

A Milo object with non-empty graph and nhoods slots.

samples

Either a string specifying which column of data should be used to identify the experimental samples for counting, or a named vector of sample ids mapping each single cell to it's respective sample.

meta.data

A cell X variable data.frame containing study meta-data including experimental sample IDs. Assumed to be in the same order as the cells in the input Milo object.

Details

This function generates a counts matrix of nhoods X samples, and populates the nhoodCounts slot of the input Milo object. This matrix is used down-stream for differential abundance testing.

Value

A Milo object containing a counts matrix in the nhoodCounts slot.

Author(s)

Mike Morgan, Emma Dann

Examples


library(igraph)
m <- matrix(rnorm(100000), ncol=100)
milo <- buildGraph(t(m), k=20, d=10)
milo <- makeNhoods(milo, k=20, d=10, prop=0.3)

cond <- rep("A", nrow(m))
cond.a <- sample(seq_len(nrow(m)), size=floor(nrow(m)*0.25))
cond.b <- setdiff(seq_len(nrow(m)), cond.a)
cond[cond.b] <- "B"
meta.df <- data.frame(Condition=cond, Replicate=c(rep("R1", 330), rep("R2", 330), rep("R3", 340)))
meta.df$SampID <- paste(meta.df$Condition, meta.df$Replicate, sep="_")
milo <- countCells(milo, meta.data=meta.df, samples="SampID")
milo


MikeDMorgan/miloR documentation built on Feb. 29, 2024, 6:20 p.m.