Skip to content

Commit

Permalink
fix check errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejiang committed Nov 18, 2020
1 parent 47a963b commit cd3e4aa
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 29 deletions.
44 changes: 23 additions & 21 deletions R/cqc_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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")

Expand All @@ -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)){
Expand Down Expand Up @@ -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){
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 %>%
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/cqc_fix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions R/cqc_io.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ 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)
#' 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)
#'
#'}
#' @export
cqc_cf_list <- function(x) {
if (!is.list(x)) {
Expand All @@ -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")){
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions man/cf_get_panel.Rd

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

3 changes: 2 additions & 1 deletion man/cqc_cf_list.Rd

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

2 changes: 1 addition & 1 deletion man/cqc_fix.Rd

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

2 changes: 2 additions & 0 deletions man/cqc_gs.Rd

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

3 changes: 2 additions & 1 deletion man/cqc_gs_list.Rd

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

2 changes: 1 addition & 1 deletion man/cqc_write_fcs.Rd

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

1 change: 1 addition & 0 deletions man/plot_diff.Rd

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

0 comments on commit cd3e4aa

Please sign in to comment.