Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
536442e
for the PR at least, add in SCPCP000004 for testing
sjspielman Aug 27, 2025
a55d1c1
add process to classify with singler, and test locally hurray
sjspielman Aug 27, 2025
089a779
script docs
sjspielman Aug 27, 2025
bc5fcb7
add R script to classify with singler
sjspielman Aug 27, 2025
e00a9cb
simplify singler_files definition
sjspielman Aug 28, 2025
4afe8ae
Merge branch 'main' into sjspielman/166-classify-singler
sjspielman Aug 28, 2025
c361346
Merge branch 'main' into sjspielman/166-classify-singler
sjspielman Aug 28, 2025
ae98ecf
update syntax - we dont want to use the script line singler_files = p…
sjspielman Aug 28, 2025
45cebb4
workflow passed, remove project SCPCP000004 from stub
sjspielman Aug 28, 2025
a3db40b
add project 4 to testing profile, for testing; will be reverted befor…
sjspielman Aug 29, 2025
0531248
some better memory guesses based on local runs
sjspielman Aug 29, 2025
709adc8
Additional temp testing changes to be reverted before merge: filter t…
sjspielman Aug 29, 2025
5d8555f
Revert "add project 4 to testing profile, for testing; will be revert…
sjspielman Aug 29, 2025
1c5ab76
bump memory to 32 for atlas conversion
sjspielman Aug 29, 2025
31b41b3
python scripts in fact end in .py
sjspielman Aug 29, 2025
42269b8
specify cpus for multithreaded tasks
sjspielman Aug 29, 2025
f67b4b7
use the correct arg name
sjspielman Aug 29, 2025
dc24591
train_singler_model indeed needs mem_32
sjspielman Aug 29, 2025
a47b2b4
revert testing code - no longer filter to sample
sjspielman Aug 29, 2025
363f18d
add publishdir and emit, just to see
sjspielman Sep 2, 2025
94e02f8
uncomment scimilarity, do you stage?
sjspielman Sep 2, 2025
68c9b7d
backslash. sad.
sjspielman Sep 2, 2025
f143576
comment out scimilarity again for testing
sjspielman Sep 2, 2025
347ae46
make sure all modules in main.nf are uncommented
sjspielman Sep 2, 2025
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
1 change: 1 addition & 0 deletions modules/cell-type-neuroblastoma-04/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ Links to specific original scripts used in this module:

* `00_convert-nbatlas.R`: <https://github.com/AlexsLemonade/OpenScPCA-analysis/blob/ad3b3c6ac6bcb7154058e4f725250dc56523caa8/analyses/cell-type-neuroblastoma-04/scripts/00_convert-nbatlas.R>
* `01_train-singler-model.R`: <https://github.com/AlexsLemonade/OpenScPCA-analysis/blob/7c0acea43b6cfc26da75a3a1dbd3558a0d9229ed/analyses/cell-type-neuroblastoma-04/scripts/01_train-singler-model.R>
* `02_classify-singler.R`: <https://github.com/AlexsLemonade/OpenScPCA-analysis/blob/82547028b5a9555d8cee40f6c1883015c990cc4f/analyses/cell-type-neuroblastoma-04/scripts/02_classify-singler.R>
* `03a_train-scanvi-model.py`: <https://github.com/AlexsLemonade/OpenScPCA-analysis/blob/82547028b5a9555d8cee40f6c1883015c990cc4f/analyses/cell-type-neuroblastoma-04/scripts/03a_train-scanvi-model.py>
53 changes: 52 additions & 1 deletion modules/cell-type-neuroblastoma-04/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ process train_singler_model {
train-singler-model.R \
--nbatlas_file ${nbatlas_sce_file} \
--gtf_file ${gtf_file} \
--singler_model_file ${nbatlas_singler_model}
--singler_model_file ${nbatlas_singler_model} \
--threads ${task.cpus}
"""
stub:
nbatlas_singler_model = "nbatlas_singler_model.rds"
Expand Down Expand Up @@ -83,6 +84,44 @@ process train_scanvi_model {
"""
}

process classify_singler {
container params.cell_type_nb_04_container
tag "${sample_id}"
label 'mem_8'
input:
path singler_model
tuple val(sample_id),
val(project_id),
path(library_files)
output:
tuple val(sample_id),
val(project_id),
path(singler_files)
script:
singler_files = library_files
.collect{
it.name.replaceAll(/(?i).rds$/, "_singler.tsv")
}
"""
for file in ${library_files}; do
classify-singler.R \
--sce_file ${file} \
--singler_model_file ${singler_model} \
--singler_output_tsv \$(basename \${file%.rds}_singler.tsv) \
--threads ${task.cpus}
done
"""
stub:
singler_files = library_files
.collect{
it.name.replaceAll(/(?i).rds$/, "_singler.tsv")
}
"""
for file in ${library_files}; do
touch \$(basename \${file%.rds}_singler.tsv)
done
"""
}


workflow cell_type_neuroblastoma_04 {
Expand All @@ -96,6 +135,10 @@ workflow cell_type_neuroblastoma_04 {
return [sample_id, project_id, library_files]
}

/////////////////////////////////////////////////////
// Prepare references for cell type classification //
/////////////////////////////////////////////////////

// convert NBAtlas to SCE and AnnData objects
// emits: sce, anndata, hvg_file
convert_nbatlas(file(params.cell_type_nb_04_nbatlas_url))
Expand All @@ -107,4 +150,12 @@ workflow cell_type_neuroblastoma_04 {
// train scANVI model
// outputs the scanvi model directory
train_scanvi_model(convert_nbatlas.out.anndata)

/////////////////////////////////////////////////////
// Perform cell type classification //
/////////////////////////////////////////////////////

// classify with SingleR
classify_singler(train_singler_model.out, libraries_ch)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env Rscript
#
# This script performs cell type annotation on an SCE using a reference SingleR
# model and exports a TSV file with annotations
# This script was adapted from:
# https://github.com/AlexsLemonade/OpenScPCA-analysis/blob/82547028b5a9555d8cee40f6c1883015c990cc4f/analyses/cell-type-neuroblastoma-04/scripts/02_classify-singler.R

suppressWarnings({
suppressPackageStartupMessages({
library(optparse)
library(SingleCellExperiment)
})
})

option_list <- list(
make_option(
opt_str = c("--sce_file"),
type = "character",
default = "",
help = "Input SCE object to run SingleR on"
),
make_option(
opt_str = c("--singler_model_file"),
type = "character",
default = "",
help = "Path to trained SingleR model"
),
make_option(
opt_str = c("--singler_output_tsv"),
type = "character",
default = "",
help = "Path to output TSV file to save lightweight SingleR annotations"
),
make_option(
opt_str = c("--threads"),
type = "integer",
default = 4,
help = "Number of threads for SingleR to use"
),
make_option(
opt_str = c("--seed"),
type = "integer",
default = 2025,
help = "Random seed"
)
)

# Parse options and check arguments
opts <- parse_args(OptionParser(option_list = option_list))
stopifnot(
"sce_file does not exist" = file.exists(opts$sce_file),
"singler_model_file does not exist" = file.exists(opts$singler_model_file)
)
set.seed(opts$seed)

if (opts$threads == 1) {
bp_param <- BiocParallel::SerialParam()
} else {
bp_param <- BiocParallel::MulticoreParam(opts$threads)
}

# Read trained model
singler_model <- readRDS(opts$singler_model_file)

# Read query SCE and convert ids to symbols
# note that ids that don't map will retain Ensembl ids
sce <- readRDS(opts$sce_file) |>
# use the gene_symbols column in the sce object for mapping
rOpenScPCA::sce_to_symbols(reference = "sce")

# Perform annotation
singler_result <- SingleR::classifySingleR(
sce,
singler_model,
BPPARAM = bp_param
)

# Extract TSV to save separately
singler_df <- singler_result |>
# keep only labels, delta.next, and pruned.labels
purrr::discard_at("scores") |>
as.data.frame() |>
tibble::rownames_to_column("barcodes")

# Export TSV
readr::write_tsv(singler_df, opts$singler_output_tsv)
2 changes: 1 addition & 1 deletion nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ profiles {
release_bucket = "s3://openscpca-test-data-release-public-access" // test bucket
results_bucket = "test/stub/results" // no output
sim_bucket = "test/stub/simulated" // local output
project = "SCPCP000012" // a small project
project = "SCPCP000012,SCPCP000004" // a small project

// Override full NBAtlas with empty file for stub testing
cell_type_nb_04_nbatlas_url = "${projectDir}/modules/cell-type-neuroblastoma-04/resources/test/NBAtlas_test.rds"
Expand Down