Skip to content

Commit

Permalink
support cqc_insert in cqc_fix.cqc_solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Jul 11, 2020
1 parent 3cc5a67 commit 937ab1e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
46 changes: 38 additions & 8 deletions R/cqc_fix.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
#' Peform the actual fixing action (i.e update or delete)
#' @param x the \code{cqc_solution} returned by \code{\link{cqc_match}} calls
#' @param ... addiitional arguments not for the user.
#' @examples
#' @examples
#' # Read in FCS files with inconsistencies
#' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE)
#' qc_cf_list <- cqc_load_fcs(fcs_files)
#'
#'
#' # Check for marker inconsitencies
#' groups <- cqc_check(qc_cf_list, type = "marker")
#'
#'
#' # Attempt to fix them automatically
#' match_result <- cqc_match(groups, ref = c("CD14 PerCP", "CD15 FITC", "CD33 APC", "CD45 PE", "FSC-Height", "SSC-Height", "Time"))
#'
#'
#' # Add a manual match that automatic matching could not find
#' match_result <- cqc_update_match(match_result, map = c("PTPRC PE" = "CD45 PE"))
#'
#'
#' # Apply the fix to the original cytoframes
#' cqc_fix(match_result)
#' @export
Expand All @@ -40,15 +40,45 @@ cqc_fix.cqc_solution <- function(x, ...) {
invisible(group %>% inner_join(x, "group_id") %>%
select(object, from, to) %>% distinct() %>% rowwise() %>% do({
obj <- cqc_data[[.[["object"]]]]
if (is.na(.[["to"]])) {
if (!is.na(.[["from"]])&&is.na(.[["to"]])) {#xxx -> NA
cqc_delete(obj, .[["from"]], type)
} else {
} else if(!is.na(.[["from"]])&&!is.na(.[["to"]])){#xxx -> yyy
cqc_update(obj, .[["from"]], .[["to"]], type)
}
} else if(is.na(.[["from"]])&&!is.na(.[["to"]]))#NA -> yyy
{
cqc_insert(obj, is.na(.[["to"]]))
}else#NA -> NA
stop("both 'from' and 'to' are NA!")
tibble()
}))
}

#' insertion methods for cyto data
#'
#' It is typically called automatically by cqc_fix call
#'
#' @param x cytoframe or GatingSet
#' @param value the value to be deleted
#' @param type one of qc task "channel", "marker", "keyword", "gate"
#' @param ... unused
cqc_insert <- function(x, value, type, ...) UseMethod("cqc_delete")

cqc_insert.cytoframe <- function(x, value, type, ...) {
if (type == "keyword") {
cf_keyword_insert(x, value, "")
} else {
stop("insert ", type, " not supported yet!")
}
}

cqc_insert.GatingSet <- function(x, value, type, ...) {
cs <- gs_cyto_data(x) # cs is a new view
lapply(cs, function(cf) {
cqc_insert(cf, value, type, ...)
})

}


#' Delete methods for cyto data
#'
Expand Down
2 changes: 1 addition & 1 deletion lyoplate/parsews.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for(center in centers) {
dir.create(this_out)
this_ws_path <- file.path(ws_path, center, paste0("CA c3 v2 ", center, ".xml"))
ws <- open_flowjo_xml(this_ws_path)
groupNames <- levels(fj_ws_get_sample_groups(ws)[,"groupName"])
groupNames <- unique(fj_ws_get_sample_groups(ws)[,"groupName"])
#NOTE: here we use the fussy match due to the short name used in auto gating
#ideally, we want to do the strict full string match avoid picking up the wrong panel
#in case the panel name are similar. But in this particular panel set, it is safe to do so.
Expand Down
14 changes: 11 additions & 3 deletions man/cqc_write_fcs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions vignettes/keywords.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ library(cytoqc)
```{r include=FALSE}
# prepare the test data
data("GvHD")
fs <- GvHD
set.seed(1)
fs <- Subset(GvHD, sampleFilter(10))
data_dir <- tempfile()
dir.create(data_dir)
write.flowSet(fs, data_dir)
Expand Down Expand Up @@ -131,5 +132,5 @@ grps <- split(groups)
grps
```


## or insert the missing keywords for selected groups

0 comments on commit 937ab1e

Please sign in to comment.