cytoqc -- qc for keywords

library(knitr)
knitr::opts_chunk$set(warning = FALSE, message = FALSE)
icuSetCollate(locale="en_US")
library(flowCore)
library(flowWorkspace)
library(cytoqc)
# prepare the test data
data("GvHD")
set.seed(1)
fs <- Subset(GvHD, sampleFilter(10))
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
#clean up keywordnames
for(cf in cqc_data)
{
  kw <- keyword(cf)
  kn <- names(kw)
  kn <- gsub("^\\&[0-9]+", "", kn)
  names(kw) <- kn
  keyword(cf) <- kw

}
#simulate channel discrepancy

#case
cf <- cqc_data[[1]]
cf_keyword_rename(cf, "Patient ID",  "patient id")

#missing
cf <- cqc_data[[2]]
cf_keyword_delete(cf, "Patient ID")
#redundant
cf_keyword_insert(cf, "kw1", "test")
cf_keyword_insert(cf, "kw2", "test")


#redundant
cf <- cqc_data[[1]]
cf_keyword_insert(cf, "new_kw", "test")


#typo
cf <- cqc_data[[3]]
kw <- keyword(cf)
kn <- names(kw)
cf_keyword_rename(cf, "Patient ID",  "PatientId")

Group by keywords

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

Match against reference and report the discrepancy

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

Inspect the content of the two keywords that are likely to be semantically the same

sub_data_ref <- cqc_get_data(groups, id = 3)
unique(sapply(sub_data_ref, keyword, keyword = "Patient ID"))

sub_data <- cqc_get_data(groups, id = 5)
unique(sapply(sub_data, keyword, keyword = "pt name"))

Manually adjusted match results generated by automated algorithem

update the match

match_result <- cqc_match_update(match_result, c("pt name" = "Patient ID"))
match_result

remove matched items

# match_result <- cqc_match_remove(match_result, c("pt name" = "Patient ID"))

Mark the redundant keywords for deletion

match_result <- cqc_match_delete_unmatched(match_result, c("kw1", "kw2"))
match_result

Apply the fix

cqc_fix(match_result)

Refresh QC report

cqc_check(cqc_data, "keyword")

Verify the insertion

sub_data_ref <- cqc_get_data(groups, id = 1)
unique(sapply(sub_data_ref, keyword, keyword = "Patient ID"))


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