Skip to content

Commit

Permalink
Fix github check notes
Browse files Browse the repository at this point in the history
  • Loading branch information
susansjy22 committed Apr 4, 2024
1 parent 272129c commit e2c769d
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 37 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ Imports:
lifecycle,
SingleCellExperiment,
knitr,
digest
digest,
cowplot,
igraph
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Expand Down
13 changes: 11 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -89,14 +92,19 @@ 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)
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)
Expand All @@ -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)
Expand Down
22 changes: 20 additions & 2 deletions R/CellChat.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
31 changes: 31 additions & 0 deletions R/execute_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
61 changes: 36 additions & 25 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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){
Expand All @@ -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
#'
Expand Down
18 changes: 18 additions & 0 deletions R/targets_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Loading

0 comments on commit e2c769d

Please sign in to comment.