-
Notifications
You must be signed in to change notification settings - Fork 0
Add process/script to classify with singler #178
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
Merged
Merged
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 a55d1c1
add process to classify with singler, and test locally hurray
sjspielman 089a779
script docs
sjspielman bc5fcb7
add R script to classify with singler
sjspielman e00a9cb
simplify singler_files definition
sjspielman 4afe8ae
Merge branch 'main' into sjspielman/166-classify-singler
sjspielman c361346
Merge branch 'main' into sjspielman/166-classify-singler
sjspielman ae98ecf
update syntax - we dont want to use the script line singler_files = p…
sjspielman 45cebb4
workflow passed, remove project SCPCP000004 from stub
sjspielman a3db40b
add project 4 to testing profile, for testing; will be reverted befor…
sjspielman 0531248
some better memory guesses based on local runs
sjspielman 709adc8
Additional temp testing changes to be reverted before merge: filter t…
sjspielman 5d8555f
Revert "add project 4 to testing profile, for testing; will be revert…
sjspielman 1c5ab76
bump memory to 32 for atlas conversion
sjspielman 31b41b3
python scripts in fact end in .py
sjspielman 42269b8
specify cpus for multithreaded tasks
sjspielman f67b4b7
use the correct arg name
sjspielman dc24591
train_singler_model indeed needs mem_32
sjspielman a47b2b4
revert testing code - no longer filter to sample
sjspielman 363f18d
add publishdir and emit, just to see
sjspielman 94e02f8
uncomment scimilarity, do you stage?
sjspielman 68c9b7d
backslash. sad.
sjspielman f143576
comment out scimilarity again for testing
sjspielman 347ae46
make sure all modules in main.nf are uncommented
sjspielman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
modules/cell-type-neuroblastoma-04/resources/usr/bin/classify-singler.R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.