HelenaLC / CATALYST

Cytometry dATa anALYsis Tools
67 stars 30 forks source link

Is there a way to export the raw frequency data? #300

Closed JingAnyaSun closed 2 years ago

JingAnyaSun commented 2 years ago

Hi,

There is a function in CATALYST called plotAbundances to plot the population abundances after clustering. I wonder if there is a way to export the raw frequency data of each cell population in each sample? Thanks!

Best, Jing

HelenaLC commented 2 years ago

Probably best/easiest to just compute these independently, directly from the SCE; e.g., using base R:

# clustering to use
k <- "meta20" 

# get counts
n <- talble(
  sample_id = sce$sample_id, 
  cluster_id = cluster_ids(sce, k))

# get proportions (margin = 1 (rows) corresponds to 
# % of cells per sample assigned to each cluster)
p <- prop.table(n, 1)

# turn into tidy table
df <- as.data.frame(p)

# add relevant metadata
i <- match(df$sample_id, sce$sample_id)
cd <- colData(sce)[i, c("condition", ...)]
df <- cbind(df, cd)

# export results
write.csv(df, ...)