Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in run_qc()and test run_qc() #45

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export(gimap_annotate)
export(gimap_filter)
export(run_qc)
export(setup_data)
import(dplyr)
import(ggplot2)
import(kableExtra)
importFrom(dplyr,across)
Expand Down
4 changes: 2 additions & 2 deletions R/01-qc.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ run_qc <- function(gimap_dataset,
results_file <- gsub("\\.Rmd$", "\\.html", output_file)
message("Results in: ", results_file)

results_file <- normalizePath(list.files(pattern = results_file, full.names = TRUE))

if (results_file != "") browseURL(results_file)

results_file
}
57 changes: 29 additions & 28 deletions R/plots-qc.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @importFrom ggplot2 ggplot labs
#' @return counts_cdf a ggplot
#' @examples \dontrun{
#'
#'
#' gimap_dataset <- get_example_data("gimap")
#' qc_cdf(gimap_dataset)
#'
Expand Down Expand Up @@ -76,6 +76,7 @@ qc_sample_hist <- function(gimap_dataset, wide_ar = 0.75) {
#' @importFrom tidyr pivot_longer
#' @importFrom magrittr %>%
#' @import ggplot2
#' @import dplyr
#' @return a ggplot histogram
#' @examples \dontrun{
#' gimap_dataset <- get_example_data("gimap")
Expand All @@ -86,14 +87,14 @@ qc_sample_hist <- function(gimap_dataset, wide_ar = 0.75) {
qc_variance_hist <- function(gimap_dataset, filter_replicates_target_col = NULL, wide_ar = 0.75){

if(is.null(filter_replicates_target_col)){ filter_replicates_target_col <- c((ncol(gimap_dataset$transformed_data$log2_cpm)-2) : ncol(gimap_dataset$transformed_data$log2_cpm))} #last 3 columns of the data

return(
gimap_dataset$transformed_data$log2_cpm[,filter_replicates_target_col] %>%
as.data.frame() %>%
mutate(row = row_number()) %>%
tidyr::pivot_longer(-row) %>%
group_by(row) %>%
summarize(var = var(value)) %>%
dplyr::summarize(var = var(value)) %>%
ggplot(aes(x=var)) +
geom_histogram(binwidth = 0.1) +
theme(panel.background = element_blank(),
Expand All @@ -116,17 +117,18 @@ qc_variance_hist <- function(gimap_dataset, filter_replicates_target_col = NULL,
#' @importFrom tidyr pivot_longer
#' @importFrom magrittr %>%
#' @import ggplot2
#' @import dplyr
#' @return a ggplot barplot
#' @examples \dontrun{
#' gimap_dataset <- get_example_data("gimap")
#' qc_constructs_countzero_bar(gimap_dataset)
#'
#'
#' #or if you want to select a specific column(s) for looking at where/which samples zero counts are present for
#' qc_constructs_countzero_bar(gimap_dataset, filter_zerocount_target_col = 3:5)
#'
#'
#' #or if you want to select a specific column(s) for the final day/sample replicates
#' qc_constructs_countzero_bar(gimap_dataset, filter_replicates_target_col = 3:5)
#'
#'
#' #or some combination of those
#' qc_constructs_countzero_bar(gimap_dataset, filter_zerocount_target_col = 3:5, filter_replicates_target_col = 3:5)
#' }
Expand All @@ -135,19 +137,19 @@ qc_variance_hist <- function(gimap_dataset, filter_replicates_target_col = NULL,
qc_constructs_countzero_bar <- function(gimap_dataset, filter_zerocount_target_col = NULL, filter_replicates_target_col = NULL, wide_ar = 0.75){

if(is.null(filter_zerocount_target_col)){filter_zerocount_target_col <- c(1:ncol(gimap_dataset$raw_counts))}

if (!all(filter_zerocount_target_col %in% 1:ncol(gimap_dataset$raw_counts))) {
stop("The columns selected do not exist. `filter_zerocount_target_col` needs to correspond to the index of the columns in `gimap_dataset$raw_counts` that you need to filter by")
stop("The columns selected do not exist. `filter_zerocount_target_col` needs to correspond to the index of the columns in `gimap_dataset$raw_counts` that you need to filter by")
}

qc_filter_output <- qc_filter_zerocounts(gimap_dataset, filter_zerocount_target_col = filter_zerocount_target_col)

if(is.null(filter_replicates_target_col)){ filter_replicates_target_col <- c((ncol(gimap_dataset$transformed_data$log2_cpm)-2) : ncol(gimap_dataset$transformed_data$log2_cpm))} #last 3 columns of the data

if (!all(filter_replicates_target_col %in% 1:ncol(gimap_dataset$transformed_data$log2_cpm))) {
stop("The columns selected do not exist. `filter_replicates_target_col` needs to correspond to the index of the columns in `gimap_dataset$transformed_data$log2_cpm` that you need to filter by")
stop("The columns selected do not exist. `filter_replicates_target_col` needs to correspond to the index of the columns in `gimap_dataset$transformed_data$log2_cpm` that you need to filter by")
}


return(
gimap_dataset$raw_counts[qc_filter_output$filter, filter_replicates_target_col] %>%
Expand Down Expand Up @@ -211,42 +213,41 @@ qc_cor_heatmap <- function(gimap_dataset) {
#' @import ggplot2
#' @return a ggplot histogram
#' @examples \dontrun{
#'
#'
#' gimap_dataset <- get_example_data("gimap")
#'
#'
#' qc_plasmid_histogram(gimap_dataset)
#'
#'
#' # or to specify a "cutoff" value that will be displayed as a dashed vertical line
#' qc_plasmid_histogram(gimap_dataset, cutoff=1.75)
#'
#'
#' # or to specify a different column (or set of columns) to select
#' qc_plasmid_histogram(gimap_dataset, filter_plasmid_target_col=1:2)
#'
#' # or to specify a "cutoff" value that will be displayed as a dashed vertical line as well as to specify a different column (or set of columns) to select
#' qc_plasmid_histogram(gimap_dataset, cutoff=2, filter_plasmid_target_col=1:2)
#' }
#'

qc_plasmid_histogram <- function(gimap_dataset, cutoff = NULL, filter_plasmid_target_col = NULL, wide_ar = 0.75) {

if (is.null(filter_plasmid_target_col)) {filter_plasmid_target_col <- c(1)}

if (!all(filter_plasmid_target_col %in% 1:ncol(gimap_dataset$transformed_data$log2_cpm))) {
stop("The columns selected do not exist. `filter_plasmid_target_col` needs to correspond to the index of the columns in `gimap_dataset$transformed_data$log2_cpm` that you need to filter by")
stop("The columns selected do not exist. `filter_plasmid_target_col` needs to correspond to the index of the columns in `gimap_dataset$transformed_data$log2_cpm` that you need to filter by")
}

to_plot <- data.frame(gimap_dataset$transformed_data$log2_cpm[, filter_plasmid_target_col]) %>% `colnames<-`(rep(c("plasmid_log2_cpm"), length(filter_plasmid_target_col))) %>% clean_names()
if (length(filter_plasmid_target_col >1)){ #if more than one column was selected, collapse all of the columns into the same vector and store in a df to plot

if (length(filter_plasmid_target_col >1)){ #if more than one column was selected, collapse all of the columns into the same vector and store in a df to plot
to_plot <- data.frame(unlist(to_plot %>% select(starts_with("plasmid_log2_cpm")), use.names = FALSE)) %>% `colnames<-`(c("plasmid_log2_cpm"))
}

quantile_info <- quantile(to_plot$plasmid_log2_cpm)

if (is.null(cutoff)) { cutoff <- quantile_info["25%"] - (1.5 * (quantile_info["75%"] - quantile_info["25%"]))}
# if cutoff is null, suggest a cutoff and plot with suggested
return(

return(
ggplot(to_plot, aes(x = plasmid_log2_cpm)) +
geom_histogram(binwidth = 0.2, color = "black", fill = "gray60") +
plot_options() +
Expand Down
33 changes: 30 additions & 3 deletions man/gimap_filter.Rd

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

3 changes: 3 additions & 0 deletions man/qc_cdf.Rd

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

24 changes: 22 additions & 2 deletions man/qc_constructs_countzero_bar.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/qc_cor_heatmap.Rd

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

44 changes: 44 additions & 0 deletions man/qc_filter_plasmid.Rd

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

12 changes: 9 additions & 3 deletions man/qc_filter_zerocounts.Rd

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

Loading
Loading