From cd3e4aae8e6dc0d3cbf7fbd192820e271f743b1d Mon Sep 17 00:00:00 2001 From: mikejiang Date: Wed, 18 Nov 2020 15:07:43 -0800 Subject: [PATCH] fix check errors --- R/cqc_check.R | 44 +++++++++++++++++++++++--------------------- R/cqc_fix.R | 2 +- R/cqc_io.R | 10 +++++++--- man/cf_get_panel.Rd | 1 + man/cqc_cf_list.Rd | 3 ++- man/cqc_fix.Rd | 2 +- man/cqc_gs.Rd | 2 ++ man/cqc_gs_list.Rd | 3 ++- man/cqc_write_fcs.Rd | 2 +- man/plot_diff.Rd | 1 + 10 files changed, 41 insertions(+), 29 deletions(-) diff --git a/R/cqc_check.R b/R/cqc_check.R index 5fcd577..86061e6 100644 --- a/R/cqc_check.R +++ b/R/cqc_check.R @@ -8,7 +8,8 @@ #' @return a tibble with two columns: "channel" and 'marker' #' @importFrom dplyr select rename #' @importFrom flowCore parameters -#' @examples +#' @examples +#' library(flowWorkspace) #' fcs_path <- system.file("extdata", "GvHD_QC", "s5a01.fcs", package = "cytoqc") #' cf <- load_cytoframe_from_fcs(fcs_path) #' cf_get_panel(cf) @@ -66,7 +67,7 @@ cqc_check_gate <- function(x, ...){ #' @return a tibble with 4 columns: object, qc type (e.g. channel), group_id and nobject (i.e. group count) #' @param x \code{\link{cqc_cf_list}}, \code{\link{cqc_gs}}, or \code{\link{cqc_gs_list}} object #' @param ... additional arguments. -#' +#' #' type -- specify the qc type, can be "channel", "marker" or "panel" #' #' delimiter -- a special character used to separate channel and marker @@ -77,18 +78,18 @@ cqc_check_gate <- function(x, ...){ #' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) -#' +#' #' # You may directly call the method for the parameter you would like to check #' keyword_groups <- cqc_check_keyword(qc_cf_list) #' keyword_groups -#' +#' #' # Or use the type argument #' channel_groups <- cqc_check(qc_cf_list, type = "channel") #' channel_groups -#' +#' #' panel_groups <- cqc_check(qc_cf_list, type = "panel", by = "marker") #' panel_groups -#' +#' #' @export cqc_check <- function(x, ...) UseMethod("cqc_check") @@ -98,7 +99,7 @@ cqc_check.cqc_gs_list <- function(x, type, delimiter = "|", ...) { #extract the first cf from each gs cflist <- sapply(x, function(gs) get_cytoframe_from_cs(gs_pop_get_data(gs), 1)) # TODO:qc within gs to ensure all data are consistent cflist <- cqc_cf_list(cflist) - + # If keys are explicitly provided, pass that down keys <- list(...)[["keys"]] if(is.null(keys)){ @@ -143,18 +144,18 @@ cqc_check.cqc_cf_list <- function(x, type, keys = NULL, delimiter = "|", by = "c } key }) - + # For merker-checking types, filter out those rows where the marker is NA for all groups (usually scatter channels) if (type %in% c("marker", "panel")) { empty_in_all <- Reduce(intersect, lapply(keys, function(df){ filter(df, is.na(marker))$channel })) keys <- lapply(keys, function(key){ - key %>% + key %>% filter(!(channel %in% empty_in_all)) }) } - + # For single-type checks, collapse to single keystring if(type != "panel"){ keys <- sapply(keys, function(key){ @@ -171,7 +172,7 @@ cqc_check.cqc_cf_list <- function(x, type, keys = NULL, delimiter = "|", by = "c filter(!!as.symbol(by) %in% keys) }) } - + if(type == "panel"){ # Spread channel and marker for multi-column key key_names <- names(keys) @@ -194,11 +195,11 @@ cqc_check.cqc_cf_list <- function(x, type, keys = NULL, delimiter = "|", by = "c add_count(`group_id`, name = "nObject") %>% pivot_longer(-c(object, group_id, nObject), names_to = "channel", values_to = "marker") %>% right_join(bind_rows(keys), by = c("object", "channel", "marker")) # Remove artifacts of bind_rows - + if(nrow(res) == 0) stop("No markers available for panel check.") attr(res, "by") <- by - + }else{ #convert to itemized(one entry per object&key) tbl res <- tibble(object = names(keys), key = keys) @@ -213,7 +214,7 @@ cqc_check.cqc_cf_list <- function(x, type, keys = NULL, delimiter = "|", by = "c separate_rows(key, sep = paste0("\\Q", sep, "\\E"))#split the collapsed key string into separate rows(one key per row) res <- rename(res, !!type := key) } - + class(res) <- c("cqc_check", class(res)) class(res) <- c(paste0("cqc_check_", type), class(res)) attr(res, "data") <- x @@ -258,10 +259,10 @@ cqc_check.cqc_gs <- function(x, type, keys = NULL, delimiter = "|", ...) { #' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) -#' +#' #' channel_groups <- cqc_check(qc_cf_list, type = "channel") #' summary(channel_groups) -#' +#' #' @export summary.cqc_check <- function(object, ...) { res <- object %>% @@ -303,7 +304,7 @@ diff.cqc_check_panel <- function(x, ...) { #' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) -#' +#' #' channel_groups <- cqc_check(qc_cf_list, type = "channel") #' diff(channel_groups) #' @importFrom dplyr group_split inner_join anti_join @@ -327,7 +328,7 @@ diff.cqc_check <- function(x, vars, ...) { #' @importFrom purrr walk #' @param x cqc_check object #' @param f,drop,... not used -#' @examples +#' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) #' channel_groups <- cqc_check(qc_cf_list, type = "channel") @@ -353,13 +354,14 @@ split.cqc_check <- function(x, f, drop = FALSE, ...) { #' #' @param groups \code{cqc_check_gate} grouping resulte from \code{cqc_check}. #' @examples +#' library(flowWorkspace) #' gs_paths <- list.files(system.file("extdata", "gslist_manual_QC", package = "cytoqc"), full.names = TRUE) #' gs1 <- load_gs(gs_paths[[1]]) #' gs2 <- load_gs(gs_paths[[2]]) #' qc_gslist <- cqc_gs_list(list(gs1, gs2)) #' groups <- cqc_check(qc_gslist, type="gate") #' plot_diff(groups) -#' +#' #' @export #' @import Rgraphviz graph plot_diff <- function(groups) { @@ -480,7 +482,7 @@ plot_diff <- function(groups) { #' #' @param groups the object returned by 'cqc_checks' #' @param id the group id to be dropped from the dataset -#' @examples +#' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) #' channel_groups <- cqc_check(qc_cf_list, type = "channel") @@ -505,7 +507,7 @@ cqc_drop_groups <- function(groups, id) { #' #' @param groups the object returned by \code{\link{cqc_checks}} #' @param id the group id to be selected from the dataset, default is NULL, meaning all data -#' @examples +#' @examples #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' qc_cf_list <- cqc_load_fcs(fcs_files) #' channel_groups <- cqc_check(qc_cf_list, type = "channel") diff --git a/R/cqc_fix.R b/R/cqc_fix.R index 6209d63..c400fff 100644 --- a/R/cqc_fix.R +++ b/R/cqc_fix.R @@ -15,7 +15,7 @@ #' 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")) +#' match_result <- cqc_match_update(match_result, map = c("PTPRC PE" = "CD45 PE")) #' #' # Apply the fix to the original cytoframes #' cqc_fix(match_result) diff --git a/R/cqc_io.R b/R/cqc_io.R index 0e2995e..dc829bf 100644 --- a/R/cqc_io.R +++ b/R/cqc_io.R @@ -37,6 +37,7 @@ cqc_load_cytoframe <- function(files, ...) { #' #' @param x a named list of \code{\link[flowWorkspace]{cytoframe}} objects #' @examples +#' \dontrun{ #' # This is just for illustration. cqc_load_fcs will normally take care of this step. #' fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) #' cf_list <- lapply(fcs_files[1:3], load_cytoframe_from_fcs) @@ -44,7 +45,7 @@ cqc_load_cytoframe <- function(files, ...) { #' #' # Construct a cqc_cf_list object from a list of cytoframes #' cf_list <- cqc_cf_list(cf_list) -#' +#'} #' @export cqc_cf_list <- function(x) { if (!is.list(x)) { @@ -70,9 +71,11 @@ cqc_cf_list <- function(x) { #' underlying data #' @param x a GatingSet object #' @examples +#' \dontrun{ #' gs_path <- system.file("extdata", "gslist_manual_QC", "gs1", package = "cytoqc") #' gs <- load_gs(gs_path) #' qc_gs <- cqc_gs(gs) +#' } #' @export cqc_gs <- function(x) { if (!is(x, "GatingSet")){ @@ -108,7 +111,7 @@ cqc_gs <- function(x) { #' 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")) +#' match_result <- cqc_match_update(match_result, map = c("PTPRC PE" = "CD45 PE")) #' #' # Apply the fix to the original cytoframes #' cqc_fix(match_result) @@ -168,10 +171,11 @@ cqc_write_cytoframe <- function(x, out, verbose = TRUE, backend = get_default_ba #' #' @param x a list of 'GatingSet' objects #' @examples +#' library(flowWorkspace) #' gs_paths <- list.files(system.file("extdata", "gslist_manual_QC", package = "cytoqc"), full.names = TRUE) #' gs1 <- load_gs(gs_paths[[1]]) #' gs2 <- load_gs(gs_paths[[2]]) -#' qc_gs_list <- cqc_gs_list(list(gs1, gs2)) +#' qc_gslist <- cqc_gs_list(list(gs1, gs2)) #' groups <- cqc_check(qc_gslist, type="gate") #' #' @export diff --git a/man/cf_get_panel.Rd b/man/cf_get_panel.Rd index 43d492b..a9135cf 100644 --- a/man/cf_get_panel.Rd +++ b/man/cf_get_panel.Rd @@ -18,6 +18,7 @@ a tibble with two columns: "channel" and 'marker' Extract channel/marker info from a cytoframe object } \examples{ +library(flowWorkspace) fcs_path <- system.file("extdata", "GvHD_QC", "s5a01.fcs", package = "cytoqc") cf <- load_cytoframe_from_fcs(fcs_path) cf_get_panel(cf) diff --git a/man/cqc_cf_list.Rd b/man/cqc_cf_list.Rd index a9b5b67..73299a8 100644 --- a/man/cqc_cf_list.Rd +++ b/man/cqc_cf_list.Rd @@ -13,6 +13,7 @@ cqc_cf_list(x) This is the core data object for \code{\link[cytoqc:cytoqc-package]{cytoqc}}. } \examples{ +\dontrun{ # This is just for illustration. cqc_load_fcs will normally take care of this step. fcs_files <- list.files(system.file("extdata", "GvHD_QC", package = "cytoqc"), full.names = TRUE) cf_list <- lapply(fcs_files[1:3], load_cytoframe_from_fcs) @@ -20,5 +21,5 @@ names(cf_list) <- fcs_files[1:3] # Construct a cqc_cf_list object from a list of cytoframes cf_list <- cqc_cf_list(cf_list) - +} } diff --git a/man/cqc_fix.Rd b/man/cqc_fix.Rd index 055c729..9649e8b 100644 --- a/man/cqc_fix.Rd +++ b/man/cqc_fix.Rd @@ -26,7 +26,7 @@ groups <- cqc_check(qc_cf_list, type = "marker") 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")) +match_result <- cqc_match_update(match_result, map = c("PTPRC PE" = "CD45 PE")) # Apply the fix to the original cytoframes cqc_fix(match_result) diff --git a/man/cqc_gs.Rd b/man/cqc_gs.Rd index 2eefbb1..bbe864c 100644 --- a/man/cqc_gs.Rd +++ b/man/cqc_gs.Rd @@ -15,7 +15,9 @@ qc operations on a \code{\link{cqc_cf_list}} object for the GatingSet's underlying data } \examples{ +\dontrun{ gs_path <- system.file("extdata", "gslist_manual_QC", "gs1", package = "cytoqc") gs <- load_gs(gs_path) qc_gs <- cqc_gs(gs) } +} diff --git a/man/cqc_gs_list.Rd b/man/cqc_gs_list.Rd index 8ca757d..da8b5c9 100644 --- a/man/cqc_gs_list.Rd +++ b/man/cqc_gs_list.Rd @@ -13,10 +13,11 @@ cqc_gs_list(x) For the methods dispatching purpose } \examples{ +library(flowWorkspace) gs_paths <- list.files(system.file("extdata", "gslist_manual_QC", package = "cytoqc"), full.names = TRUE) gs1 <- load_gs(gs_paths[[1]]) gs2 <- load_gs(gs_paths[[2]]) -qc_gs_list <- cqc_gs_list(list(gs1, gs2)) +qc_gslist <- cqc_gs_list(list(gs1, gs2)) groups <- cqc_check(qc_gslist, type="gate") } diff --git a/man/cqc_write_fcs.Rd b/man/cqc_write_fcs.Rd index 361ddcf..526efc5 100644 --- a/man/cqc_write_fcs.Rd +++ b/man/cqc_write_fcs.Rd @@ -41,7 +41,7 @@ groups <- cqc_check(qc_cf_list, type = "marker") 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")) +match_result <- cqc_match_update(match_result, map = c("PTPRC PE" = "CD45 PE")) # Apply the fix to the original cytoframes cqc_fix(match_result) diff --git a/man/plot_diff.Rd b/man/plot_diff.Rd index 110707e..a955d8b 100644 --- a/man/plot_diff.Rd +++ b/man/plot_diff.Rd @@ -13,6 +13,7 @@ plot_diff(groups) visualize the tree structure difference among the GatingSets } \examples{ +library(flowWorkspace) gs_paths <- list.files(system.file("extdata", "gslist_manual_QC", package = "cytoqc"), full.names = TRUE) gs1 <- load_gs(gs_paths[[1]]) gs2 <- load_gs(gs_paths[[2]])