From e2c769db26076ce3bfdfd40d76b8fc971c683e6e Mon Sep 17 00:00:00 2001 From: susansjy22 Date: Thu, 4 Apr 2024 11:52:11 +1100 Subject: [PATCH] Fix github check notes --- DESCRIPTION | 4 +- NAMESPACE | 13 +++++- R/CellChat.R | 22 +++++++++- R/execute_pipeline.R | 31 +++++++++++++ R/functions.R | 61 +++++++++++++++----------- R/targets_functions.R | 18 ++++++++ R/utilities.R | 26 +++++++++-- README.rmd | 6 +-- tests/testthat/test_single_functions.R | 2 +- 9 files changed, 146 insertions(+), 37 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 429e9ad..b36d351 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -61,7 +61,9 @@ Imports: lifecycle, SingleCellExperiment, knitr, - digest + digest, + cowplot, + igraph Encoding: UTF-8 LazyData: true RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 56be669..d354833 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,6 @@ export(add_RNA_assay) export(alive_identification) export(annotation_consensus) export(annotation_label_transfer) -export(calc_UMAP) export(cell_cycle_scoring) export(create_pseudobulk) export(doublet_identification) @@ -24,7 +23,6 @@ export(run_targets_pipeline) export(seurat_to_ligand_receptor_count) export(test_differential_abundance_hpc) import(scDblFinder) -import(sctransform) import(targets) import(tidySingleCellExperiment) import(tidySummarizedExperiment) @@ -43,6 +41,7 @@ importFrom(CellChat,projectData) importFrom(CellChat,scPalette) importFrom(CellChat,searchPair) importFrom(CellChat,setIdent) +importFrom(CellChat,subsetCommunication) importFrom(CellChat,subsetDB) importFrom(CellChat,subsetData) importFrom(CellChat,triMean) @@ -63,6 +62,7 @@ importFrom(Seurat,GetAssayData) importFrom(Seurat,NormalizeData) importFrom(Seurat,PercentageFeatureSet) importFrom(Seurat,RunPCA) +importFrom(Seurat,SCTransform) importFrom(Seurat,ScaleData) importFrom(Seurat,VariableFeatures) importFrom(Seurat,as.SingleCellExperiment) @@ -76,8 +76,11 @@ importFrom(cowplot,as_grob) importFrom(crew,crew_controller_local) importFrom(digest,digest) importFrom(dplyr,"%>%") +importFrom(dplyr,add_count) +importFrom(dplyr,bind_rows) importFrom(dplyr,case_when) importFrom(dplyr,count) +importFrom(dplyr,distinct) importFrom(dplyr,filter) importFrom(dplyr,if_else) importFrom(dplyr,left_join) @@ -89,6 +92,8 @@ importFrom(dplyr,select) importFrom(dplyr,with_groups) importFrom(edgeR,estimateDisp) importFrom(glue,glue) +importFrom(grid,grid.grab) +importFrom(gridGraphics,grid.echo) importFrom(igraph,graph_from_adjacency_matrix) importFrom(igraph,layout_) importFrom(magrittr,extract2) @@ -96,7 +101,10 @@ importFrom(patchwork,wrap_elements) importFrom(purrr,map) importFrom(purrr,map2) importFrom(purrr,map2_dbl) +importFrom(purrr,map_chr) +importFrom(purrr,map_int) importFrom(purrr,when) +importFrom(readr,read_csv) importFrom(readr,write_lines) importFrom(rlang,enquo) importFrom(rlang,is_symbolic) @@ -118,6 +126,7 @@ importFrom(targets,tar_option_set) importFrom(targets,tar_script) importFrom(tibble,as_tibble) importFrom(tibble,enframe) +importFrom(tibble,rowid_to_column) importFrom(tibble,tibble) importFrom(tidybulk,as_SummarizedExperiment) importFrom(tidyr,gather) diff --git a/R/CellChat.R b/R/CellChat.R index a892d7f..e4f163e 100644 --- a/R/CellChat.R +++ b/R/CellChat.R @@ -624,7 +624,17 @@ draw_cellchat_circle_plot = function (net, color.use = NULL, title.name = NULL, } +#' @importFrom dplyr distinct +#' select_genes_for_circle_plot = function(x, pathway){ + # Fix GChecks + CellChatDB.human <- NULL + pathway_name <- NULL + ligand <- NULL + . <- NULL + receptor <- NULL + + paste( c( x@data.signaling[rownames(x@data.signaling) %in% (CellChatDB.human$interaction %>% filter(pathway_name == pathway) %>% distinct(ligand) %>% pull(1)),, drop=F] %>% rowSums() %>% .[(.)>100] %>% names(), @@ -635,6 +645,8 @@ select_genes_for_circle_plot = function(x, pathway){ } +#' @importFrom CellChat subsetCommunication +#' get_table_for_cell_vs_axis_bubble_plot = function (object, sources.use = NULL, targets.use = NULL, signaling = NULL, pairLR.use = NULL, color.heatmap = c("Spectral", "viridis"), n.colors = 10, direction = -1, thresh = 0.05, comparison = NULL, @@ -645,6 +657,9 @@ get_table_for_cell_vs_axis_bubble_plot = function (object, sources.use = NULL, t show.legend = TRUE, grid.on = TRUE, color.grid = "grey90", angle.x = 90, vjust.x = NULL, hjust.x = NULL, return.data = FALSE) { + + # Fix GChecks + prob.original = NULL # cells.level <- levels(object@idents) # source.use.numerical = which(cells.level == source.use) @@ -688,7 +703,7 @@ get_table_for_cell_vs_axis_bubble_plot = function (object, sources.use = NULL, t # TRY CATCH df.net <- tryCatch( expr = { - subsetCommunication(object, slot.name = "net", + CellChat::subsetCommunication(object, slot.name = "net", sources.use = sources.use, targets.use = targets.use, signaling = signaling, pairLR.use = pairLR.use, thresh = thresh) @@ -751,7 +766,7 @@ get_table_for_cell_vs_axis_bubble_plot = function (object, sources.use = NULL, t } else { dataset.name <- names(object@net) - df.net.all <- subsetCommunication(object, slot.name = "net", + df.net.all <- CellChat::subsetCommunication(object, slot.name = "net", sources.use = sources.use, targets.use = targets.use, signaling = signaling, pairLR.use = pairLR.use, thresh = thresh) @@ -900,6 +915,9 @@ get_table_for_cell_vs_axis_bubble_plot = function (object, sources.use = NULL, t df } +#' @importFrom gridGraphics grid.echo +#' @importFrom grid grid.grab +#' grab_grob <- function(){ grid.echo() grid.grab() diff --git a/R/execute_pipeline.R b/R/execute_pipeline.R index ee2afca..ed5ca46 100644 --- a/R/execute_pipeline.R +++ b/R/execute_pipeline.R @@ -33,6 +33,37 @@ run_targets_pipeline <- function( cell_type_annotation_column = "Cell_type_in_each_tissue" ){ + # Fix GCHECKS + read_file <- NULL + reference_file <- NULL + tissue_file <- NULL + filtered_file <- NULL + sample_column_file <- NULL + cell_type_annotation_column_file <- NULL + reference_label_coarse <- NULL + reference_label_fine <- NULL + input_read <- NULL + unique_tissues <- NULL + reference_read <- NULL + empty_droplets_tbl <- NULL + cell_cycle_score_tbl <- NULL + annotation_label_transfer_tbl <- NULL + alive_identification_tbl <- NULL + doublet_identification_tbl <- NULL + non_batch_variation_removal_S <- NULL + preprocessing_output_S <- NULL + create_pseudobulk_sample <- NULL + sampleName <- NULL + cellAnno <- NULL + pseudobulk_merge_all_samples <- NULL + calc_UMAP_dbl_report <- NULL + variable_gene_list <- NULL + tar_render <- NULL + empty_droplets_report <- NULL + doublet_identification_report <- NULL + Technical_variation_report <- NULL + pseudobulk_processing_report <- NULL + sample_column = enquo(sample_column) # cell_type_annotation_column = enquo(cell_type_annotation_column) diff --git a/R/functions.R b/R/functions.R index 1c80c26..cb6a869 100644 --- a/R/functions.R +++ b/R/functions.R @@ -182,7 +182,7 @@ annotation_label_transfer <- function(input_read_RNA_assay, input_read_RNA_assay |> # Normalise RNA - not informed by smartly selected variable genes - SCTransform(assay=assay) |> + Seurat::SCTransform(assay=assay) |> ScaleData(assay = "SCT") |> RunPCA(assay = "SCT") @@ -539,14 +539,22 @@ cell_cycle_scoring <- function(input_read_RNA_assay, #' #' @importFrom dplyr left_join #' @importFrom dplyr filter -#' @importFrom Seurat NormalizeData -#' @import sctransform +#' @importFrom Seurat NormalizeData SCTransform #' @export non_batch_variation_removal <- function(input_read_RNA_assay, empty_droplets_tbl, alive_identification_tbl, cell_cycle_score_tbl, assay = NULL){ + #Fix GChecks + empty_droplet = NULL + .cell <- NULL + subsets_Ribo_percent <- NULL + subsets_Mito_percent <- NULL + G2M.Score = NULL + + # Your code for non_batch_variation_removal function here + # Get assay if(is.null(assay)) assay = input_read_RNA_assay@assays |> names() |> extract2(1) @@ -626,6 +634,16 @@ preprocessing_output <- function(tissue, cell_cycle_score_tbl, annotation_label_transfer_tbl, doublet_identification_tbl){ + #Fix GCHECKS + .cell <- NULL + alive <- NULL + subsets_Mito_percent <- NULL + subsets_Ribo_percent <- NULL + high_mitochondrion <- NULL + high_ribosome <- NULL + scDblFinder.class <- NULL + predicted.celltype.l2 <- NULL + processed_data <- non_batch_variation_removal_S |> # Filter dead cells left_join( @@ -728,6 +746,8 @@ create_pseudobulk <- function(preprocessing_output_S , assays ,x ,...) { #' @export #' pseudobulk_merge <- function(create_pseudobulk_sample, assays, x , ...) { + # Fix GCHECKS + . = NULL #browser() x = enquo(x) # Select only common columns @@ -803,9 +823,20 @@ pseudobulk_merge <- function(create_pseudobulk_sample, assays, x , ...) { #' @importFrom purrr map2 #' @importFrom purrr map #' @importFrom purrr map2_dbl +#' @importFrom dplyr distinct add_count #' @export seurat_to_ligand_receptor_count = function(counts, .cell_group, assay, sample_for_plotting = ""){ + #Fix GChecks + cell_type_harmonised <- NULL + n_cells <- NULL + DB <- NULL + cell_vs_all_cells_per_pathway <- NULL + gene <- NULL + + # Your code for seurat_to_ligand_receptor_count function here + + .cell_group = enquo(.cell_group) # If only one cell, return empty @@ -1135,6 +1166,7 @@ map_split_se_by_number_of_genes = function(se_df, .col, chunk_size = 100){ #' @importFrom digest digest #' @importFrom rlang enquo +#' @importFrom purrr map_chr #' #' @export map_split_sce_by_gene = function(sce_df, .col, how_many_chunks_base = 10, max_cells_before_split = 4763){ @@ -1155,31 +1187,10 @@ map_split_sce_by_gene = function(sce_df, .col, how_many_chunks_base = 10, max_ce } )) |> unnest(!!.col) |> - mutate(sce_md5 = map_chr(!!.col, digest)) + mutate(sce_md5 = purrr::map_chr(!!.col, digest)) } -#' Calculate UMAP -#' Scales the input data, performing PCA, clustering the cells and running UMAP and constructs a tibble in preparation for plotting in -#' the doublet identification report -#' -#' @param input_seurat Single Seurat object (Input data) -#' -#' @export -calc_UMAP <- function(input_seurat){ - find_var_genes <- FindVariableFeatures(input_seurat) - var_genes<- find_var_genes@assays$originalexp@var.features - - x<- ScaleData(input_seurat) |> - # Calculate UMAP of clusters - RunPCA(features = var_genes) |> - FindNeighbors(dims = 1:30) |> - FindClusters(resolution = 0.5) |> - RunUMAP(dims = 1:30, spread = 0.5,min.dist = 0.01, n.neighbors = 10L) |> - as_tibble() - return(x) -} - #' Get unique tissues #' Obtain unique tissues/ samples from input dataset #' diff --git a/R/targets_functions.R b/R/targets_functions.R index bf8015f..cdc37e3 100644 --- a/R/targets_functions.R +++ b/R/targets_functions.R @@ -25,6 +25,8 @@ #' @import targets #' @importFrom rlang quo_is_symbolic #' @importFrom SummarizedExperiment assays +#' @importFrom tidyseurat quo_names +#' @importFrom tibble rowid_to_column #' #' @export map2_test_differential_abundance_hpc = function( @@ -39,6 +41,22 @@ map2_test_differential_abundance_hpc = function( ... ){ + #Fix GChecks + file_data = NULL + file_formula = NULL + abundance = NULL + number_of_workers = NULL + number_of_datasets = NULL + pseudobulk_df_tissue = NULL + name = NULL + pseudobulk_df_tissue_dispersion = NULL + pseudobulk_df_tissue_split_by_gene = NULL + pseudobulk_df_tissue_split_by_gene_grouped = NULL + se_md5 = NULL + estimates_chunk = NULL + my_group = NULL + assay_name = NULL + .abundance = enquo(.abundance) if(quo_is_symbolic(.abundance)) .abundance = quo_names(.abundance) diff --git a/R/utilities.R b/R/utilities.R index fa6e03a..72725dc 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -225,11 +225,20 @@ add_RNA_assay <- function(input_read, RNA_assay_name){ #' @importFrom Seurat FindNeighbors #' @importFrom Seurat FindClusters #' @importFrom Seurat VariableFeatures -#' @importFrom dplyr mutate +#' @importFrom dplyr mutate distinct bind_rows #' @importFrom glue glue +#' @importFrom purrr map_int #' @noRd seurat_to_variable_features_by_cell_type = function(counts, assay, .cell_group = NULL, features_number_per_cell_group = 300){ + # Fix GChecks + upper_quantile <- NULL + number_features_overall <- NULL + feature <- NULL + group <- NULL + + + .cell_group = enquo(.cell_group) # Nest @@ -399,6 +408,8 @@ seurat_to_variable_features = function( #' @importFrom dplyr count #' @importFrom dplyr with_groups #' @importFrom dplyr pull +#' @importFrom dplyr bind_rows +#' @importFrom purrr map_int #' @noRd subset_top_rank_variable_genes_across_batches = function( table_across_cell_groups, @@ -408,6 +419,8 @@ subset_top_rank_variable_genes_across_batches = function( features_number_independent_of_cell_groups = 2000, features_number_per_cell_group = 300 ){ + # Fix GChecks + feature = NULL .cell_group = enquo(.cell_group) .batch = enquo(.batch) @@ -938,8 +951,16 @@ harmonise_names_non_immune = function(metadata){ metadata } - +#' @importFrom readr read_csv +#' get_manually_curated_immune_cell_types = function(){ + #Fix GCHECKS + metadata_file = NULL + .cell = NULL + cell_type = NULL + file_id = NULL + .sample = NULL + library(zellkonverter) library(Seurat) @@ -1002,7 +1023,6 @@ get_manually_curated_immune_cell_types = function(){ cell_type = NULL file_id = NULL .sample = NULL - read_csv = NULL azhimut_confirmed = NULL blueprint_confirmed = NULL arrange = NULL diff --git a/README.rmd b/README.rmd index be893b7..4aa97dc 100644 --- a/README.rmd +++ b/README.rmd @@ -160,15 +160,15 @@ store <- "/vast/scratch/users/si.j/store_fibrosis8" # cell_type_annotation_column = "cellAnno" # # debug_step = "variable_gene_list" # ) - +input_data_path_list = "~/HPCell/input_HEorgandata/input_Blood.rds" preprocessed_seurat = HPCell::run_targets_pipeline( input_data = input_data_path_list, tissue = "pbmc", filter_empty_droplets = TRUE, RNA_assay_name = RNA_assay_name, - sample_column = "sampleName", + sample_column = "Tissue", store = store, - cell_type_annotation_column = "cellAnno" + cell_type_annotation_column = "Cell_type_in_each_tissue" # debug_step = "create_pseudobulk_sample" ) diff --git a/tests/testthat/test_single_functions.R b/tests/testthat/test_single_functions.R index 732a3de..6dc3121 100644 --- a/tests/testthat/test_single_functions.R +++ b/tests/testthat/test_single_functions.R @@ -10,7 +10,7 @@ RNA_assay_name<- "originalexp" input_seurat_list = HeOrganAtlasData(ensembl=FALSE,location=FALSE)|> as.Seurat(data = NULL) |> - subset(subset = Tissue %in% c("Heart", "Trachea")) |> + subset(subset = Tissue %in% c("Blood")) |> group_split() # sample_column<- "Tissue"