Skip to content

Commit

Permalink
Merge branch 'main' into addMainPlots
Browse files Browse the repository at this point in the history
  • Loading branch information
cansavvy authored Jan 8, 2025
2 parents 7698ed0 + 70ce18b commit d054c1b
Show file tree
Hide file tree
Showing 21 changed files with 294,758 additions and 187 deletions.
9 changes: 8 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ docs/*
gimap_QC_Report.html
gimap_QC_Report.Rmd
qc_plots
missing_ids_file.csv
missing_ids_file.csv
CODE_OF_CONDUCT.md
SECURITY.md
gimap_QC_Report.Rmd
gimap_QC_Report.html
gimap_dataset_final.RDS’
missing_ids_file.csv
qc_plots/*
24 changes: 6 additions & 18 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:

- name: Query dependencies
run: |
install.packages('remotes')
install.packages('remotes', repos='http://cran.us.r-project.org')
install.packages('rcmdcheck', repos='http://cran.us.r-project.org')
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}
Expand All @@ -68,26 +69,13 @@ jobs:
remotes::install_cran("rcmdcheck")
shell: Rscript {0}

- name: Check
run: |
options(crayon.enabled = TRUE)
rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), check_dir = "check")
shell: Rscript {0}

- name: Check testthat
if: runner.os != 'Windows'
id: check_check
run: |
error_num=$(Rscript --vanilla '.github/workflows/check_testthat.R')
echo "error_num=$error_num" >> $GITHUB_OUTPUT
- name: Stop if there are errors!
if: ${{ steps.check_check.outputs.error_num != '0' }}
run: exit 1
- name: Check package
uses: r-lib/actions/check-r-package@v2
with:
args: 'c("--no-manual")'

- name: Upload check results
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Authors@R: c(
)
)
Description: This package allows a pipeline to be built for analyzing genetic interactions of paired guide CRISPR screens. It is based off of original research from the Alice Berger lab at Fred Hutchinson Cancer Center.
License: GPL-3
License: GPL-3 + file LICENSE
URL: https://github.com/FredHutch/gimap
BugReports: https://github.com/FredHutch/gimap/issues
Imports:
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ importFrom(magrittr,"%>%")
importFrom(pheatmap,pheatmap)
importFrom(purrr,map)
importFrom(purrr,reduce)
importFrom(readr,write_rds)
importFrom(readr,write_tsv)
importFrom(stats,cor)
importFrom(stats,p.adjust)
importFrom(stats,quantile)
importFrom(stats,t.test)
importFrom(stats,var)
importFrom(stats,wilcox.test)
importFrom(stringr,str_split)
importFrom(stringr,word)
importFrom(tidyr,pivot_longer)
importFrom(tidyr,pivot_wider)
Expand Down
2 changes: 1 addition & 1 deletion R/03-annotate.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gimap_annotate <- function(.data = NULL,
# Read in the CN data
depmap_cn <- readr::read_csv(cn_file,
show_col_types = FALSE,
col_select = c("genes", my_depmap_id)
col_select = c("genes", dplyr::all_of(my_depmap_id))
) %>%
dplyr::rename(log2_cn = my_depmap_id)

Expand Down
2 changes: 1 addition & 1 deletion R/04-normalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#' gimap_filter() %>%
#' gimap_annotate(cell_line = "HELA") %>%
#' gimap_normalize(
#' timepoints = "day",
#' timepoints = "day"
#' )
#'
#' # To see results
Expand Down
5 changes: 3 additions & 2 deletions R/06-calculate_gi.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#' @param .data Data can be piped in with tidyverse pipes from function to function. But the data must still be a gimap_dataset
#' @param gimap_dataset A special dataset structure that is setup using the `setup_data()` function.
#' @export
#' @examples {
#' @examples \dontrun{
#' gimap_dataset <- get_example_data("gimap")
#'
#' # Highly recommended but not required
Expand Down Expand Up @@ -171,7 +171,8 @@ calc_gi <- function(.data = NULL,
#' Do tests for each replicate --an internal function used by calc_gi() function
#' @description Create results table that has t test p values
#' @param replicate a name of a replicate to filter out from gi_calc_adj
#' @param gi_calc_adj a data.frame with adjusted gi scores
#' @param gi_calc_single a data.frame with adjusted single gi scores
#' @param gi_calc_double a data.frame with adjusted double gi scores
#' @importFrom stats p.adjust t.test wilcox.test
gimap_rep_stats <- function(replicate, gi_calc_double, gi_calc_single) {
## get a vector of GI scores for all single-targeting ("control") pgRNAs for each rep
Expand Down
1 change: 1 addition & 0 deletions R/missing_ids_file.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
missing_ids
89 changes: 11 additions & 78 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
utils::globalVariables(c(
"timepoints", "value", "timepoint_avg", "target_type",
"mean_observed_cs", "timepoints", "value", "timepoint_avg", "target_type",
"unexpressed_ctrl_flag", "median", "lfc_adj", "median", "gRNA1_seq", "gRNA2_seq",
"control_gRNA_seq", "crispr_score", "pgRNA_target", "mean_double_control_crispr",
"pgRNA_target", "targeting_gRNA_seq", "mean_single_target_crispr", "double_crispr_score",
"single_crispr_score_1", "single_crispr_score_2", "pgRNA_target_double", "mean_single_target_crispr_1",
"mean_single_target_crispr_2", "mean_double_control_crispr_2", "pgRNA_target_double",
"pgRNA_target", "targeting_gRNA_seq", "mean_single_crispr", "double_crispr_score",
"single_crispr_score_1", "single_crispr_score_2", "pgRNA_target_double", "mean_single_crispr_1",
"mean_single_crispr_2", "mean_double_control_crispr_2",
"expected_crispr", "term", "estimate", "mean_expected_crispr", "intercept", "slope",
"p_val_ttest", "p_val_wil", "fde_vals_ttest", "fdr_vals_wil", "double_target_gi_score",
"single_target_gi_score_1", "single_target_gi_score_2", "gene", "DepMap_ID",
"p_val_ttest", "p_val_wil", "fde_vals_ttest", "fdr_vals_wil", "double_gi_score",
"single_gi_score_1", "single_gi_score_2", "gene", "DepMap_ID",
"gene1_symbol", "gene2_symbol", "expressed_flag", "norm_ctrl_flag", "bool_vals",
"filter_name", "counts", "numzero", "name", "value", "lfc_plasmid_vs_late", "lfc_adj",
"pg_RNA_target_double", "double_target_gi_score", "count_normalized", "construct",
"double_gi_score", "count_normalized", "construct",
"filterFlag", "plasmid_log2_cpm", "log2_cpm", "gene_symbol", "gene_symbol_1", "gene_symbol_2",
"mean_double_control_crispr_1", "expected_crispr_double", "expected_crispr_single_1",
"expected_crispr_single_2", "fdr_vals_ttest", "read_table", "stripped_cell_line_name",
"comparison", ".", "col_names", "lfc_adj1", "t.test", "wilcox.test", "p.adjust",
"cor", "quantile", "var", "browseURL", "mean_expected_single_crispr", "expected_crispr_single"
"cor", "quantile", "var", "browseURL", 'single_crispr', "mean_single_crispr_2",
"mean_single_crispr_1", "expected_single_crispr", "double_crispr", "double_gi_score",
"fdr", "lfc", "mean_expected_cs", "mean_gi_score", "mean_single_crispr",
"expected_double_crispr", "p_val", "single_gi_score"
))


Expand Down Expand Up @@ -89,76 +92,6 @@ get_example_data <- function(which_data) {
}
}

#' @import ggplot2

## ggplot themes
## see: https://www.rdocumentation.org/packages/ggplot2/versions/2.1.0/topics/theme_update
## and https://stackoverflow.com/questions/23173915/can-ggplot-theme-formatting-be-saved-as-an-object
plot_theme <- function() {
theme(
axis.text = element_text(colour = "black"),
axis.ticks = element_line(color = "black")
)
}

#' @import ggplot2
plot_options <- function() {
list(theme_bw(base_size = 12))
}

#' @import kableExtra
print_kbl <- function(tbl) {
kbl(tbl) %>%
kable_styling(
full_width = FALSE,
position = "left",
bootstrap_options = c("striped", "hover", "responsive")
)
}

#' Save tbl
#' @description This function saves table
#' @importFrom stringr str_split
#' @importFrom readr write_tsv write_rds
save_tbl <- function(tbl, out_dir = NULL, params = NULL) {
tbl_str <- deparse(substitute(tbl))
tbl_name <- str_split(tbl_str, pattern = "\\.")[[1]][2]
write_tsv(tbl, file.path(out_dir, "tables", "tsv", paste0(params$cell_line, "_", tbl_name, ".txt")))
write_rds(tbl, file.path(out_dir, "tables", "rds", paste0("d.", params$cell_line, "_", tbl_name)))
}

#' @import ggplot2
save_plot <- function(plt, out_dir = NULL, params = list(cell_line = NULL)) {
plt_str <- deparse(substitute(plt))
if (!dir.exists(file.path(out_dir, "plots", "pdf"))) {
dir.create(file.path(out_dir, "plots", "pdf"), recursive = TRUE)
}
ggsave(
plot = plt,
filename = file.path(out_dir, "plots", "pdf", paste0(params$cell_line, "_", plt_str, ".pdf"))
)
if (!dir.exists(file.path(out_dir, "plots", "png"))) {
dir.create(file.path(out_dir, "plots", "png"), recursive = TRUE)
}
ggsave(
plot = plt,
filename = file.path(out_dir, "plots", "png", paste0(params$cell_line, "_", plt_str, ".png"))
)
}

make_out_dir <- function(out_dir) {
if (dir.exists(out_dir)) {
## print a message with the output directory location
print(paste("Output directory already exists at:", out_dir, sep = " "))
} else {
## make output dirs
dir.create(file.path(out_dir, "tables", "rds"), recursive = TRUE)
dir.create(file.path(out_dir, "tables", "tsv"), recursive = TRUE)
dir.create(file.path(out_dir, "plots", "png"), recursive = TRUE)
dir.create(file.path(out_dir, "plots", "pdf"), recursive = TRUE)
print(paste("Output directory created at:", out_dir, sep = " "))
}
}

#' Get file path to an default credentials RDS
#' @export
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Now you can [go to our quick start tutorial to get started!](https://fredhutch.g
We also have tutorial examples that show how to run timepoint or treatment experimental set ups with gimap:

- [Timepoint example](https://fredhutch.github.io/gimap/articles/timepoint-example.html)
- [Treatment example](https://fredhutch.github.io/gimap/articles/treatment-example.html)
- [Treatment example](https://fredhutch.github.io/gimap/articles/treatment_example.html)

Follow the steps there that will walk you through the example data. Then you can tailor that tutorial to use your own data.

Expand Down
Loading

0 comments on commit d054c1b

Please sign in to comment.