cytoqc -- A QC tool for openCyto

cytoqc performs pre-cleaning, pre-gating and post-gating QC checks.

The basic workflow:

  1. Run cqc_check to see the summary
  2. cqc_match to match against reference group
  3. cqc_fix based on the match results or cqc_drop_groups for unsolvable issues
  4. Iterate 1~3 steps until data is cleaned
  5. split the data into multiple sets for multi-panel cases
library(knitr)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
icuSetCollate(locale="en_US")
library(flowCore)
library(flowWorkspace)
library(cytoqc)
# devtools::load_all()
# prepare the test data
data("GvHD")
fs <- fsApply(GvHD,function(fr)fr[1,])
data_dir <- tempfile()
dir.create(data_dir)
write.flowSet(fs, data_dir)

Load the FCS

files <- list.files(data_dir, ".fcs", full.names = TRUE)
cqc_data <- cqc_load_fcs(files)
cqc_data
#simulate channel discrepancy

#case
cf <- cqc_data[[1]]
colnames(cf)[1] <- "fsc-h"

#missing
cqc_data[[1]] <- cf[,1:7]


#redundant
thisfile <- files[2]
fr <- read.FCS(thisfile)
new_col <- exprs(fr)[,8,drop=F]
colnames(new_col) <- "channelA"
fr <- fr_append_cols(fr, new_col)
write.FCS(fr, files[2])
cqc_data[[2]] <- load_cytoframe_from_fcs(thisfile)

#typo
cf <- cqc_data[[2]]
colnames(cf)[2] <- "SSC1-H"

#both case and typo
cf <- cqc_data[[3]]
colnames(cf)[1:2] <- c("fsc-h", "SSC1-H")

#order
cf <- cqc_data[[4]]
cf_swap_colnames(cf, "FL1-H", "FL2-H")

QC check for channel

groups <- cqc_check(cqc_data, "channel")
groups

Match against the reference to find discrepancy

match_result <-  cqc_match(groups, ref = 3, select = c(1, 4))
match_result

Apply the fix

cqc_fix(match_result)

Refresh QC report

groups <- cqc_check(cqc_data, "channel")
groups

Drop groups that can not be fixed

groups <- cqc_drop_groups(groups, 1)
cqc_data <- cqc_get_data(groups)
length(cqc_data)

QC for marker

#simulate channel discrepancy

cf <- cqc_data[[1]]
cf_rename_marker(cf, "CD15 FITC", "cd15")
cf_rename_marker(cf, "CD33 APC", "apc cd33")


#redundant
cf <- cqc_data[[2]]
markernames(cf) <- c(`FL2-A` = "markerA")
#summarise marker groups
groups <- cqc_check(cqc_data, "marker")
groups

Pick references and groups to fix

solution <- cqc_match(groups, ref = 3) 
solution

Manually fix the match

solution <- cqc_match_update(solution, map = c("apc cd33" = "CD33 APC"))
solution

update checks

cqc_fix(solution)

groups <- cqc_check(cqc_data, "marker")
groups

split by groups

data_list <- split(groups)
data_list

QC for panel

# second data set is already clean
cqc_check(data_list[[2]], "panel")

Save the cleaned data as FCS

cleaned <- data_list[[2]]
out <- tempfile()
cqc_write_fcs(cleaned, out)

Or Coerce it directly into cytoset (zero-copying)

cs <- cytoset(cleaned)
cs

Further split the third data set by panel

grps <- cqc_check(data_list[[3]], "panel")
grps
split(grps)


RGLab/cytoqc documentation built on Jan. 25, 2023, 11:05 p.m.