diff --git a/DESCRIPTION b/DESCRIPTION index 8442eee..9f18af3 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bcbioR Type: Package Title: Templates and functions to guide downstream analysis and data interpretation -Version: 0.3.0 +Version: 0.3.1 Authors@R: person("Pantano", "Lorena", , "lorena.pantano@gmail.com", role = c("aut", "cre")) Description: Collaborative code repository at the Harvard Chan Bioinformatics Core. diff --git a/NAMESPACE b/NAMESPACE index 5882394..109dd17 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -7,6 +7,7 @@ export(cb_friendly_pal) export(list_cb_friendly_cols) export(scale_color_cb_friendly) export(scale_fill_cb_friendly) +export(use_library) import(R.utils) import(fs) import(usethis) diff --git a/NEWS.md b/NEWS.md index 4ab3378..978bcd7 100755 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# bcbioR 0.3.1 + +- Fix bugs in RNAseq +- Add function to set up library + # bcbioR 0.3.0 * re-structure templates diff --git a/R/helpers.R b/R/helpers.R index d88209f..bc7d39d 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -251,6 +251,29 @@ bcbio_render <- function(path, pipeline, data){ } } + +#' Set custom library to your project +#' +#' This function will create the .Rprofile file in a project path +#' to use a custom library path for future session +#' @param custom_lib_path path with a R library folder +#' @param project_path project path +#' @examples +#' path <- withr::local_tempdir() +#' use_library(.libPaths(), path) +#' @export +use_library <- function(custom_lib_path, project_path="."){ + # Path to your project's .Rprofile file + project_path <- fs::path_abs(project_path) + ui_info("Using this project path: {project_path}") + rprofile_path <- file.path(project_path, ".Rprofile") + # Command to set the library path + lib_path_command <- sprintf('.libPaths("%s")\n', custom_lib_path) + # Write the command to .Rprofile + writeLines(lib_path_command, con = rprofile_path) + source(rprofile_path) +} + # help with bcbio analysis setup use_bcbio_analysis <- function(path, pipeline, copy=TRUE, metadata=NULL){ diff --git a/README.md b/README.md index 45ea579..f4eda56 100755 --- a/README.md +++ b/README.md @@ -1,11 +1,7 @@ # bcbioR - - [![R-CMD-check](https://github.com/bcbio/bcbioR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/bcbio/bcbioR/actions/workflows/R-CMD-check.yaml) - - The goal of `bcbioR` is to create guidelines for NGS data interpretation based on the experience of the Harvard Chan Bioinformatics Core and everybody who contributes to this package. ## Installation @@ -24,13 +20,13 @@ devtools::install_github("bcbio/bcbioR",ref = "devel") use `setwd()` to set your current directory to the place where you want to work. The bcbioR functions will automatically write to whatever directory you have set. -``` +``` setwd("/path/to/analysis/folder") ``` The following code will pop up a Rmd template will populate that folder with HCBC data structure guidelines -``` +``` path="/path/to/analysis/folder" bcbio_templates(type="base", outpath=path) bcbio_templates(type="rnaseq", outpath=path) @@ -41,10 +37,27 @@ bcbio_templates(type="singlecell", outpath=path) This code will populate the folder with HCBC data structure guidelines and Rmd code: **You do not need to create a reports folder prior to running this code. This will create and populate the reports folder.** -``` +``` bcbio_templates(type="rnaseq", outpath="/path/to/analysis/folder/reports") ``` +## Supported analyses + +- base/reports/example.Rmd: ![](https://img.shields.io/badge/status-stable-green) +- rnaseq/DE/Intersections.Rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- rnaseq/DE/GSVA.Rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- rnaseq/DE/DEG.Rmd: ![](https://img.shields.io/badge/status-stable-green) +- rnaseq/DE/Cross-comparison-analysis.Rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- rnaseq/QC/QC_nf-core.Rmd: ![](https://img.shields.io/badge/status-stable-green) +- singlecell/Integration/norm_integration.rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- singlecell/QC/QC.rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- singlecell_delux/CellToCell/cellchat.Rmd: ![](https://img.shields.io/badge/status-draft-grey) +- chipseq/diffbind/diffbind.Rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- chipseq/QC/QC.Rmd: ![](https://img.shields.io/badge/status-alpha-yellow) +- spatial/cosmx/QC/QC.Rmd: ![](https://img.shields.io/badge/status-draft-grey) +- methylation/QC/QC.Rmd: ![](https://img.shields.io/badge/status-draft-grey) +- multiomics/teaseq/QC/QC.Rmd: ![](https://img.shields.io/badge/status-draft-grey) + ### Discover moreā€¦ Go to the vignette to know more `vignette("bcbioR_quick_start", package="bcbioR")` diff --git a/inst/templates/base/reports/example.Rmd b/inst/templates/base/reports/example.Rmd index 772e8dd..2a0d7f8 100644 --- a/inst/templates/base/reports/example.Rmd +++ b/inst/templates/base/reports/example.Rmd @@ -27,7 +27,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` @@ -76,3 +76,11 @@ opts_chunk[["set"]]( - PI: `r PI` - Analyst: `r analyst` - Experiment: `r experiment` + +# R session + +List and version of tools used for the QC report generation. + +```{r} +sessionInfo() +``` diff --git a/inst/templates/chipseq/QC/QC.Rmd b/inst/templates/chipseq/QC/QC.Rmd index 4a7dbef..85efbb7 100644 --- a/inst/templates/chipseq/QC/QC.Rmd +++ b/inst/templates/chipseq/QC/QC.Rmd @@ -33,7 +33,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")>=0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` diff --git a/inst/templates/chipseq/diffbind/diffbind.Rmd b/inst/templates/chipseq/diffbind/diffbind.Rmd index 71f028f..03ab342 100644 --- a/inst/templates/chipseq/diffbind/diffbind.Rmd +++ b/inst/templates/chipseq/diffbind/diffbind.Rmd @@ -40,7 +40,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")>=0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` diff --git a/inst/templates/methylation/QC/QC.Rmd b/inst/templates/methylation/QC/QC.Rmd index bb912a0..a3bb540 100644 --- a/inst/templates/methylation/QC/QC.Rmd +++ b/inst/templates/methylation/QC/QC.Rmd @@ -28,7 +28,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(BiocManager::version(), "3.18")>=0) ``` diff --git a/inst/templates/rnaseq/DE/Cross-comparison-analysis.Rmd b/inst/templates/rnaseq/DE/Cross-comparison-analysis.Rmd index 3a6674d..d61b6a8 100644 --- a/inst/templates/rnaseq/DE/Cross-comparison-analysis.Rmd +++ b/inst/templates/rnaseq/DE/Cross-comparison-analysis.Rmd @@ -27,7 +27,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` @@ -178,7 +178,7 @@ ggplot(lfc, aes(x=comp1, y=comp2, color=col)) + geom_point() + ``` -## Compare ajusted P-values +## Compare adjusted P-values We plot adjusted P-values for our contrasts and color points by whether or not they are significant in our contrasts. The black line is 1:1. diff --git a/inst/templates/rnaseq/DE/DEG.Rmd b/inst/templates/rnaseq/DE/DEG.Rmd index 098a49d..9f02750 100644 --- a/inst/templates/rnaseq/DE/DEG.Rmd +++ b/inst/templates/rnaseq/DE/DEG.Rmd @@ -21,11 +21,11 @@ params: # numerator: tumor # denominator: normal column: "sample_type" - contrasts: !r list(c("sample_type", "tumor", "normal")) + contrasts: !r list(c("sample_type", "tumor", "normal"),c("sample_type", "normal", "tumor")) subset_column: null subset_value: null genome: hg38 - ruv: true + ruv: false combatseq: false params_file: params_de-example.R project_file: ../information.R @@ -41,7 +41,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` @@ -58,9 +58,10 @@ map(list.files(params$functions_file,pattern = "*.R$",full.names = T), source) % # IMPORTANT set these values if you are not using the parameters in the header (lines 22-31) genome=params$genome column=params$column +# use contrast to set up multiple comparisons +# this is set up in the top as well, but you can change it here: +# example would be: list(c("sample_type", "tumor", "normal")) contrasts=params$contrasts -# numerator=params$numerator -# denominator=params$denominator subset_column=params$subset_column subset_value=params$subset_value run_ruv=params$ruv @@ -197,7 +198,7 @@ pca <- degPCA(norm_matrix, metrics, pca$plot + ggtitle(paste0("All samples", "\nPCA using ", nrow(vsd_before), " genes")) + theme(plot.title=element_text(hjust=0.5)) + - geom_mark_ellipse(aes(color = sample_type)) + scale_color_cb_friendly() + geom_mark_ellipse(aes(color = .data[[column]])) + scale_color_cb_friendly() ``` ## Analysis of the variance by group @@ -417,6 +418,7 @@ de_list=lapply(contrasts, function(contrast){ ## MA plot {.tabset} This plot can help to: + - Identify Differential Expression: Genes that show a significant log-fold change (M value away from 0) indicate changes in expression between conditions. - Assess Data Quality: The plot can help in identifying biases or systematic errors in the data. Ideally, most points should scatter around the M=0 line, indicating that there is no significant systematic difference between the conditions. - Visualize data dispersion: The distribution of points along the A-axis gives a sense of the spread of expression levels and any patterns or anomalies in the dataset. @@ -537,7 +539,6 @@ for (contrast in names(de_list)){ From the set of differentially expressed genes and using publicly available information about gene sets involved in biological processes and functions, we can calculate which biological processes and functions are significantly perturbed as a result of the treatment. ```{r} -all_in_life=get_databases() all_in_life=get_databases_v2() ``` @@ -571,7 +572,7 @@ fa_gsea_list=lapply(de_list,function(contrast){ # multiple times dt_list=list() for (contrast in names(de_list)){ - res_sig=fa_gsea_list[[contrast]] + res_sig=fa_gsea_list[[contrast]] %>% filter(padj < 0.05) dt_list=c(dt_list, list(h3(contrast)), list(sanitize_datatable(res_sig))) @@ -622,7 +623,7 @@ fa_list=lapply(de_list,function(contrast){ # multiple times dt_list=list() for (contrast in names(de_list)){ - res_sig=fa_list[[contrast]][["all"]] + res_sig=fa_list[[contrast]][["all"]] %>% filter(padj < 0.05) dt_list=c(dt_list, list(h3(contrast)), list(sanitize_datatable(res_sig))) @@ -636,7 +637,7 @@ tagList(dt_list) ```{r, results='asis'} dt_list=list() for (contrast in names(de_list)){ - res_sig=fa_list[[contrast]][["down"]] + res_sig=fa_list[[contrast]][["down"]] %>% filter(padj < 0.05) dt_list=c(dt_list, list(h3(contrast)), list(sanitize_datatable(res_sig))) @@ -650,7 +651,7 @@ tagList(dt_list) ```{r, results='asis'} dt_list=list() for (contrast in names(de_list)){ - res_sig=fa_list[[contrast]][["up"]] + res_sig=fa_list[[contrast]][["up"]] %>% filter(padj < 0.05) dt_list=c(dt_list, list(h3(contrast)), list(sanitize_datatable(res_sig))) @@ -668,18 +669,18 @@ if (!is.null(subset_value) & !is.null(subset_value)){ filenames = "full" } for (contrast in names(contrasts)){ - filenames = paste0(filenames, "_", contrast) + filename = paste0(filenames, "_", contrast) name_expression_fn=file.path( basedir, - str_interp("${filenames}_expression.csv")) + str_interp("${filename}_expression.csv")) name_deg_fn=file.path( basedir, - str_interp("${filenames}_deg.csv")) + str_interp("${filename}_deg.csv")) name_pathways_fn=file.path( basedir, - str_interp("${filenames}_pathways.csv")) + str_interp("${filename}_pathways.csv")) counts_norm=norm_matrix %>% as.data.frame() %>% rownames_to_column("gene_id") %>% diff --git a/inst/templates/rnaseq/DE/GSVA.Rmd b/inst/templates/rnaseq/DE/GSVA.Rmd index c7028a3..d43db2f 100644 --- a/inst/templates/rnaseq/DE/GSVA.Rmd +++ b/inst/templates/rnaseq/DE/GSVA.Rmd @@ -36,7 +36,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` diff --git a/inst/templates/rnaseq/DE/Intersections.Rmd b/inst/templates/rnaseq/DE/Intersections.Rmd index fc1778b..02f01d4 100644 --- a/inst/templates/rnaseq/DE/Intersections.Rmd +++ b/inst/templates/rnaseq/DE/Intersections.Rmd @@ -28,7 +28,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` diff --git a/inst/templates/rnaseq/QC/QC_nf-core.Rmd b/inst/templates/rnaseq/QC/QC_nf-core.Rmd index a60e4e4..61c2a46 100644 --- a/inst/templates/rnaseq/QC/QC_nf-core.Rmd +++ b/inst/templates/rnaseq/QC/QC_nf-core.Rmd @@ -36,7 +36,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) ``` diff --git a/inst/templates/singlecell/Integration/norm_integration.rmd b/inst/templates/singlecell/Integration/norm_integration.rmd index 68ab9d4..0890acf 100644 --- a/inst/templates/singlecell/Integration/norm_integration.rmd +++ b/inst/templates/singlecell/Integration/norm_integration.rmd @@ -30,7 +30,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) stopifnot(compareVersion(as.character(packageVersion("Seurat")), "5.0.0")>=0) ``` @@ -591,7 +591,7 @@ We take a look at how the clusters look at resolutions 0.1, 0.2,0.4, and 0.6 ### 0.1 ```{r umap_0.1} -cluster_res <- 0.2 +cluster_res <- 0.1 Idents(object = seurat_clust) <- paste0(prefix_clu, cluster_res) DimPlot(seurat_clust, reduction = show_this, diff --git a/inst/templates/singlecell/QC/QC.rmd b/inst/templates/singlecell/QC/QC.rmd index 6c24e4c..bdd3f50 100644 --- a/inst/templates/singlecell/QC/QC.rmd +++ b/inst/templates/singlecell/QC/QC.rmd @@ -16,7 +16,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(as.character(BiocManager::version()), "3.18")>=0) stopifnot(compareVersion(as.character(packageVersion("Seurat")), "5.0.0")>=0) ``` diff --git a/inst/templates/spatial/cosmx/QC/QC.Rmd b/inst/templates/spatial/cosmx/QC/QC.Rmd index bff6628..a514031 100644 --- a/inst/templates/spatial/cosmx/QC/QC.Rmd +++ b/inst/templates/spatial/cosmx/QC/QC.Rmd @@ -33,7 +33,7 @@ setwd(fs::path_dir(getSourceEditorContext()$path)) # NOTE: This code will check version, this is our recommendation, it may work #. other versions stopifnot(R.version$major>= 4) # requires R4 -stopifnot(compareVersion(R.version$minor,"3.3")==0) # requires >=4.3.3 +if (compareVersion(R.version$minor,"3.1")<0) warning("We recommend >= R4.3.1") stopifnot(compareVersion(BiocManager::version(), "3.18")>=0) stopifnot(compareVersion(package.version("Seurat"), "5.0.0")>=0) ``` diff --git a/man/use_library.Rd b/man/use_library.Rd new file mode 100644 index 0000000..6ce1a46 --- /dev/null +++ b/man/use_library.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/helpers.R +\name{use_library} +\alias{use_library} +\title{Set custom library to your project} +\usage{ +use_library(custom_lib_path, project_path = ".") +} +\arguments{ +\item{custom_lib_path}{path with a R library folder} + +\item{project_path}{project path} +} +\description{ +This function will create the .Rprofile file in a project path +to use a custom library path for future session +} +\examples{ +path <- withr::local_tempdir() +use_library(.libPaths(), path) +}