DillonHammill / CytoExploreR

Interactive Cytometry Data Analysis
61 stars 13 forks source link

Downsampling #90

Closed Mieszkol closed 3 years ago

Mieszkol commented 4 years ago

Hi Dillon, Is there a way to downsample e.g., when exporting a population to new FCS files by cyto_save()?

Best Mieszko

DillonHammill commented 4 years ago

@Mieszkol, a combination of cyto_sample() and cyto_save() should do the trick:

library(CytoExploreRData)

gs <- GatingSet(Activation)
gs <- cyto_compensate(gs)
gs <- cyto_transform(gs)
gs <- cyto_gatingTemplate_apply(gs, Activation_gatingTemplate)

# Extract T Cells
cs <- cyto_extract(gs, "T Cells")

# Sample T Cells to minimum across samples
cyto_counts <- cyto_stats_compute(gs, alias = "T Cells", stat = "count", format = "wide")
min_count <- min(cyto_counts$count)

# Down sample to minimum T Cells count
cs <- cyto_sample(cs, min_count, seed = 56) # you can set seed to ensure that the same sample is returned

# Save downsampled T Cells to FCS files
cyto_save(cs,
save_as = "Downsampled T Cells",
names = paste0(gsub(".fcs", "", cyto_names(cs)), "-", "Downsample", ".fcs"))

There is a new cyto_sample_to_node() function coming soon that will do this more elegantly. Unfortunately I have been preoccupied with many other thing the past few weeks, I am hoping to get back to finishing off the new version soon.

Mieszkol commented 4 years ago

@DillonHammill Thank you! Do you know when are you going to release a new version?

DillonHammill commented 4 years ago

Hopefully in the next couple of weeks, I am working on DataEditR at the moment but will be back working on CytoExploreR next week.