Skip to content

Commit

Permalink
update with fixed GChecks
Browse files Browse the repository at this point in the history
  • Loading branch information
susansjy22 committed Apr 30, 2024
1 parent f00b4e5 commit aad14a9
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 85 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ README.md
pipeline_store
pipeline_store.R
R_scripts
.R
.RDataTmp
.RDataTmp1
.github
Pipeline_benchmarking_script.R
fibrosis_data
.R
.RDataTmp
.RDataTmp1
.github

37 changes: 7 additions & 30 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,16 @@ Imports:
tarchetypes,
crew,
crew.cluster,
qs,
tidybulk,
tidySummarizedExperiment,
tidySingleCellExperiment,
SummarizedExperiment,
edgeR,
sctransform (>= 0.3.3),
Seurat (>= 5.0.0),
Matrix (>= 1.6),
irlba (>= 2.3.5.1),
glmGamPoi,
dplyr,
tidyr,
ggplot2,
glue,
here,
stringr,
tidyseurat,
purrr,
Expand All @@ -47,47 +41,27 @@ Imports:
celldex,
scuttle,
CellChat,
tidyHeatmap,
gridGraphics,
sccomp,
scDblFinder,
ggupset,
magrittr,
rlang,
S4Vectors,
BiocGenerics,
AnnotationDbi,
broom,
lifecycle,
SingleCellExperiment,
knitr,
scRNAseq,
digest,
cowplot,
igraph,
callr,
circlize,
future,
future.apply,
ids,
methods,
pbapply,
scales,
RColorBrewer,
knitr,
digest,
cowplot,
igraph,
RColorBrewer,
callr,
circlize,
future,
future.apply,
ids,
methods,
pbapply,
reshape2,
scales,
data.table
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.1
Expand All @@ -107,6 +81,9 @@ biocViews:
LazyDataCompression: xz
Config/testthat/edition: 3
Suggests:
testthat (>= 3.0.0),
knitr,
scRNAseq
testthat,
scRNAseq,
ggplot2,
irlba,
sctransform,
knitr
9 changes: 9 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ export(pseudobulk_merge)
export(run_targets_pipeline)
export(seurat_to_ligand_receptor_count)
export(test_differential_abundance_hpc)
import(crew)
import(crew.cluster)
import(dplyr)
import(future.apply)
import(scDblFinder)
import(tarchetypes)
import(targets)
import(tidySingleCellExperiment)
import(tidySummarizedExperiment)
Expand Down Expand Up @@ -51,6 +55,7 @@ importFrom(RColorBrewer,brewer.pal)
importFrom(S4Vectors,cbind)
importFrom(S4Vectors,metadata)
importFrom(Seurat,CellCycleScoring)
importFrom(Seurat,CreateAssayObject)
importFrom(Seurat,CreateSeuratObject)
importFrom(Seurat,DefaultAssay)
importFrom(Seurat,FindClusters)
Expand All @@ -70,13 +75,15 @@ importFrom(Seurat,as.SingleCellExperiment)
importFrom(SingleR,SingleR)
importFrom(SummarizedExperiment,SummarizedExperiment)
importFrom(SummarizedExperiment,assays)
importFrom(SummarizedExperiment,colData)
importFrom(SummarizedExperiment,rowData)
importFrom(callr,r)
importFrom(celldex,BlueprintEncodeData)
importFrom(celldex,MonacoImmuneData)
importFrom(circlize,colorRamp2)
importFrom(cowplot,as_grob)
importFrom(crew,crew_controller_local)
importFrom(data.table,":=")
importFrom(digest,digest)
importFrom(dplyr,"%>%")
importFrom(dplyr,across)
Expand Down Expand Up @@ -106,6 +113,7 @@ importFrom(grid,grid.grab)
importFrom(gridGraphics,grid.echo)
importFrom(ids,random_id)
importFrom(igraph,graph_from_adjacency_matrix)
importFrom(igraph,in_circle)
importFrom(igraph,layout_)
importFrom(magrittr,extract2)
importFrom(methods,slot)
Expand All @@ -115,6 +123,7 @@ 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)
Expand Down
6 changes: 4 additions & 2 deletions R/CellChat.R
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ computeCommunProb = function (object, type = c("triMean", "truncatedMean", "thre
#' @importFrom future nbrOfWorkers
#' @importFrom methods slot
#' @importFrom pbapply pbsapply
#' @importFrom CellChat computeCentralityLocal
#' @import future.apply
netAnalysis_computeCentrality = function (object = NULL, slot.name = "netP", net = NULL, net.name = NULL,
thresh = 0.05)
Expand All @@ -431,11 +432,11 @@ netAnalysis_computeCentrality = function (object = NULL, slot.name = "netP", net
# ADDED BY STEFANO
net0[net0<0] = 0

return(CellChat:::computeCentralityLocal(net0))
return(computeCentralityLocal(net0))
}, simplify = FALSE)
}
else {
centr.all <- as.list(CellChat:::computeCentralityLocal(net))
centr.all <- as.list(computeCentralityLocal(net))
}
names(centr.all) <- net.name
if (is.null(object)) {
Expand Down Expand Up @@ -493,6 +494,7 @@ cellchat_diff_for_circle = function(pathway, x, y){
#' @importFrom circlize colorRamp2
#' @importFrom RColorBrewer brewer.pal
#' @importFrom scales rescale
#' @importFrom igraph in_circle
draw_cellchat_circle_plot = function (net, color.use = NULL, title.name = NULL, sources.use = NULL,
targets.use = NULL, remove.isolate = FALSE, top = 1, top_absolute = NULL, weight.scale = T,
vertex.weight = 20, vertex.weight.max = NULL, vertex.size.max = 15,
Expand Down
11 changes: 7 additions & 4 deletions R/execute_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
#'
#' @importFrom glue glue
#' @importFrom targets tar_script
#' @import tarchetypes
#' @import targets
#' @importFrom future tweak
#' @import crew
#' @import crew.cluster
#' @export
run_targets_pipeline <- function(
input_data,
Expand Down Expand Up @@ -81,10 +84,10 @@ run_targets_pipeline <- function(
# Write pipeline to a file
tar_script({

library(targets)
library(tarchetypes)
library(crew)
library(crew.cluster)
# library(targets)
# library(tarchetypes)
# library(crew)
# library(crew.cluster)

computing_resources = readRDS("temp_computing_resources.rds")
#-----------------------#
Expand Down
42 changes: 35 additions & 7 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(getRversion() >= "2.15.1") utils::globalVariables(c("."))
#' @return A tibble with cell type annotation data.
#'
#' @importFrom celldex BlueprintEncodeData
#' @importFrom Seurat CreateAssayObject
#' @importFrom celldex MonacoImmuneData
#' @importFrom scuttle logNormCounts
#' @importFrom SingleR SingleR
Expand Down Expand Up @@ -456,6 +457,7 @@ alive_identification <- function(input_read_RNA_assay,
#' @importFrom dplyr left_join
#' @importFrom dplyr filter
#' @importFrom Matrix Matrix
#' @importFrom SummarizedExperiment colData
#' @importFrom Seurat as.SingleCellExperiment
#' @import scDblFinder
#' @export
Expand All @@ -466,6 +468,12 @@ doublet_identification <- function(input_read_RNA_assay,
reference_label_fine,
assay = NULL){

# Fix GChecks
.cell = NULL
empty_droplet = NULL
high_mitochondrion = NULL
high_ribosome = NULL

# Get assay
if(is.null(assay)) assay = input_read_RNA_assay@assays |> names() |> extract2(1)

Expand Down Expand Up @@ -740,6 +748,12 @@ preprocessing_output <- function(tissue,

# Create pseudobulk for each sample
create_pseudobulk <- function(preprocessing_output_S , assays ,x ,...) {
#Fix GChecks
.sample = NULL
.feature = NULL
data_source = NULL
symbol = NULL

#browser()
x = enquo(x)

Expand Down Expand Up @@ -768,9 +782,10 @@ create_pseudobulk <- function(preprocessing_output_S , assays ,x ,...) {
#' @description
#' Merge pseudobulk from all samples. Ensures that missing genes are accounted
#' for and aligns data across multiple samples.
#' @param `create_pseudobulk_sample`: A list pseudobulk samples generated by `create_pseudobulk`
#' @param assays: Default is set of `RNA`
#' @param x: User specified character vector for the column from which we subset the samples for pseudobulk analysis
#' @param create_pseudobulk_sample A list pseudobulk samples generated by `create_pseudobulk`
#' @param assays Default is set of `RNA`
#' @param x User specified character vector for the column from which we subset the samples for pseudobulk analysis
#' @param ... Additional arguments
#'
#' @importFrom purrr map
#' @importFrom dplyr select
Expand Down Expand Up @@ -1040,9 +1055,15 @@ seurat_to_ligand_receptor_count = function(counts, .cell_group, assay, sample_fo
#' @importFrom dplyr left_join
#' @importFrom tibble enframe
#' @importFrom purrr map2
#' @import dplyr
#' @importFrom data.table :=
#' @export
map_add_dispersion_to_se = function(se_df, .col, abundance = NULL){

# Fix GitChecks
assay_name = NULL


.col = enquo(.col)

if(abundance |> length() > 1) stop("HPCell says: for now only one feature abundance measure can be selected")
Expand Down Expand Up @@ -1090,6 +1111,7 @@ map_add_dispersion_to_se = function(se_df, .col, abundance = NULL){
#' @return Data frame with test results.
#'
#' @importFrom rlang enquo
#' @import dplyr
#' @export
map_test_differential_abundance = function(

Expand Down Expand Up @@ -1141,6 +1163,7 @@ map_test_differential_abundance = function(
#' @return Data frame with SummarizedExperiment objects split into chunks.
#'
#' @importFrom dplyr n
#' @import dplyr
#' @importFrom dplyr mutate
#' @importFrom tidyr unnest
#' @importFrom dplyr select
Expand Down Expand Up @@ -1172,8 +1195,10 @@ map_split_se_by_gene = function(se_df, .col, .number_of_chunks){
mutate(se_md5 = ids::random_id(n()))
}

#' Split SummarizedExperiment Object by number of genes
#' @importFrom rlang enquo
#' @importFrom dplyr tibble
#' @import dplyr
#'
#' @param se_df A `SingleCellExperiment` DataFrame that contains gene expression or other related data.
#' @param .col A symbol or string indicating the column in `se_df` which should be dynamically split into multiple chunks based on gene count.
Expand Down Expand Up @@ -1207,10 +1232,12 @@ map_split_se_by_number_of_genes = function(se_df, .col, chunk_size = 100){
mutate(se_md5 = ids::random_id(n()))
}


#' Split SingleCellExperiment Object by genes
#' @importFrom digest digest
#' @importFrom rlang enquo
#' @importFrom purrr map_chr
#' @importFrom data.table :=
#' @import dplyr
#'
#' @param sce_df A dataframe (or tibble) where one of the columns contains
#' SingleCellExperiment objects
Expand Down Expand Up @@ -1248,8 +1275,8 @@ map_split_sce_by_gene = function(sce_df, .col, how_many_chunks_base = 10, max_ce
#' @param empty_droplet Single dataframe containing empty droplet filtering information
#' @return A vector of variable gene names
#'
#' @importFrom Seurat VariableFeatures, FindVariableFeatures
#'
#' @importFrom Seurat VariableFeatures
#' @importFrom Seurat FindVariableFeatures
#'
#' @export
# Find set of variable genes
Expand Down Expand Up @@ -1298,6 +1325,7 @@ find_variable_genes <- function(input_seurat, empty_droplet){
#' @importFrom readr read_csv
#' @importFrom dplyr bind_rows
#' @importFrom dplyr join_by
#' @importFrom data.table :=
#'
#'
#' @export
Expand Down Expand Up @@ -1368,7 +1396,7 @@ annotation_consensus = function(single_cell_data, .sample_column, .cell_type, .a
# Clean cell types
mutate(cell_type_clean = cell_type |> clean_cell_types()) |>
left_join(read_csv("~/PostDoc/CuratedAtlasQueryR/dev/metadata_cell_type.csv"), by = "cell_type") |>
HPCell::clean_cell_types_deeper() |>
clean_cell_types_deeper() |>

# Reference annotation link
left_join(reference_annotation )
Expand Down
Loading

0 comments on commit aad14a9

Please sign in to comment.