Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scripts #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions exec/scflow_annotate_integrated.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env Rscript
#' Annotate integrated, dims reduced and clustered sce object
# Mahdi Moradi Marjaneh

# ____________________________________________________________________________
# Initialization ####

options(mc.cores = future::availableCores())

## ............................................................................
## Load packages ####
library(argparse)
library(scFlow)

## ............................................................................
## Parse command-line arguments ####

# create parser object
parser <- ArgumentParser()

# specify options
required <- parser$add_argument_group("Required", "required arguments")
optional <- parser$add_argument_group("Optional", "required arguments")

required$add_argument(
"--sce_path",
help = "-path to the SingleCellExperiment",
metavar = "dir",
required = TRUE
)

required$add_argument(
"--categorical_covariates",
help = "-categorical covariates",
metavar = "individual,diagnosis,region,sex",
required = TRUE
)

### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### Pre-process args ####

args <- parser$parse_args()
args <- purrr::map(args, function(x) {
if (length(x) == 1) {
if (toupper(x) == "TRUE") {
return(TRUE)
}
if (toupper(x) == "FALSE") {
return(FALSE)
}
if (toupper(x) == "NULL") {
return(NULL)
}
}
return(x)
})

## ............................................................................
## Annotate integrated sce ####

sce <- read_sce(args$sce_path)

sce <- annotate_integrated_sce(
sce,
categorical_covariates = args$categorical_covariates
)

dir.create(file.path(getwd(), "integration_report"))

report_integrated_sce(
sce = sce,
report_folder_path = file.path(getwd(), "integration_report"),
report_file = "integrate_reduceDims_cluster_report_scflow",
)

print("Annotation complete, saving outputs..")

## ............................................................................
## Save Outputs ####

# Save SingleCellExperiment
write_sce(
sce = sce,
folder_path = file.path(getwd(), "integrated_sce")
)
108 changes: 108 additions & 0 deletions exec/scflow_cluster.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env Rscript
# Reduce dimensions for a SCE
# Combiz Khozoie <[email protected]>

# ____________________________________________________________________________
# Initialization ####

options(mc.cores = future::availableCores())

## ............................................................................
## Load packages ####
library(argparse)
library(scFlow)
library(parallel)
library(SingleCellExperiment) # due to monocle3 missing namespace::
library(knitr) # due to missing knitr:: namespace in the integrate report

## ............................................................................
## Parse command-line arguments ####

# create parser object
parser <- ArgumentParser()

# specify options
required <- parser$add_argument_group("Required", "required arguments")
optional <- parser$add_argument_group("Optional", "required arguments")

required$add_argument(
"--sce_path",
help = "-path to the SingleCellExperiment",
metavar = "dir",
required = TRUE
)

required$add_argument(
"--cluster_method",
help = "method to use for clustering",
metavar = "louvain",
required = TRUE
)

required$add_argument(
"--reduction_method",
help = "reduced dimension embedding to use for clustering",
metavar = "UMAP",
required = TRUE
)

required$add_argument(
"--res",
type = "double",
default = 0.00001,
help = "clustering resolution",
metavar = "N",
required = TRUE
)

required$add_argument(
"--k",
type = "integer",
default = 100,
help = "the number of kNN",
metavar = "N",
required = TRUE
)

required$add_argument(
"--louvain_iter",
type = "integer",
default = 1,
help = "number of iterations used for Louvain clustering",
metavar = "N",
required = TRUE
)

### . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
### Pre-process args ####

args <- parser$parse_args()

## ............................................................................
## Start ####

sce <- read_sce(args$sce_path, read_metadata = TRUE)

sce <- cluster_sce(
sce,
cluster_method = args$cluster_method,
reduction_method = args$reduction_method,
res = args$res,
k = args$k,
louvain_iter = args$louvain_iter
)

## ............................................................................
## Save Outputs ####

# Save SingleCellExperiment
write_sce(
sce = sce,
folder_path = file.path(getwd(), "clustered_sce"),
write_metadata = TRUE
)

## ............................................................................
## Clean up ####

# Clear biomart cache
Loading