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 cellassign organs to metadata #608

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
21 changes: 21 additions & 0 deletions bin/add_celltypes_to_sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ option_list <- list(
type = "character",
help = "Name of marker by cell type reference file used with CellAssign.
File name is expected to be in form: `<ref_name>_<source>_<version>.tsv`"
),
make_option(
opt_str = c("--celltype_ref_metafile"),
type = "character",
help = "Metadata TSV file containing cell type reference metadata.
This file is used to obtain a list of organs used for CellAssign annotation."
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
)
)

Expand Down Expand Up @@ -177,6 +183,10 @@ if (!is.null(opt$cellassign_predictions)) {
stop("CellAssign reference filename must be provided")
}

if (is.null(opt$celltype_ref_metafile)) {
stop("Cell type reference metadata filename must be provided")
}

predictions <- readr::read_tsv(opt$cellassign_predictions)

# get cell type with maximum prediction value for each cell
Expand Down Expand Up @@ -216,6 +226,17 @@ if (!is.null(opt$cellassign_predictions)) {
# note that if `metadata(sce)$celltype_methods` doesn't exist yet, this will
# come out to just the string "cellassign"
metadata(sce)$celltype_methods <- c(metadata(sce)$celltype_methods, "cellassign")

# add cellassign reference organs to metadata
cellassign_organs <- opt$celltype_ref_metafile |>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I say we just keep it at organs to keep it consistent with how PanglaoDB (and we) refer to them.

readr::read_tsv() |>
dplyr::filter(celltype_ref_name == cellassign_ref_info[["ref_name"]]) |>
dplyr::pull(organs)

if (cellassign_organs == "" | is.na(cellassign_organs)) {
stop("Failed to obtain CellAssign reference organ list.")
}
metadata(sce)$cellassign_reference_organs <- cellassign_organs
}

# export annotated object with cellassign assignments
Expand Down
12 changes: 12 additions & 0 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ if (!resolution_strategies.contains(params.af_resolution)) {
param_error = true
}

// cell type annotation file checks
if (params.perform_celltyping) {
if (!file(params.project_celltype_metafile).exists()) {
log.error("The 'project_celltype_metafile' file '${params.project_celltype_metafile}' can not be found.")
param_error = true
}
if (!file(params.celltype_ref_metadata).exists()) {
log.error("The 'celltype_ref_metadata' file '${params.celltype_ref_metadata}' can not be found.")
param_error = true
}
}

if(param_error){
System.exit(1)
}
Expand Down
11 changes: 8 additions & 3 deletions modules/classify-celltypes.nf
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ process add_celltypes_to_sce {
tag "${meta.library_id}"
input:
tuple val(meta), path(processed_rds), path(singler_dir), path(cellassign_dir)
path(celltype_ref_metadata) // TSV file of references metadata needed for CellAssign only
output:
tuple val(meta), path(annotated_rds)
script:
Expand All @@ -112,7 +113,8 @@ process add_celltypes_to_sce {
${singler_present ? "--singler_results ${singler_results}" : ''} \
${singler_present ? "--singler_model_file ${meta.singler_model_file}" : ''} \
${cellassign_present ? "--cellassign_predictions ${cellassign_predictions}" : ''} \
${cellassign_present ? "--cellassign_ref_file ${meta.cellassign_reference_file}" : ''}
${cellassign_present ? "--cellassign_ref_file ${meta.cellassign_reference_file}" : ''} \
${cellassign_present ? "--celltype_ref_metafile ${celltype_ref_metadata}" : ''}
"""
stub:
annotated_rds = "${meta.library_id}_processed_annotated.rds"
Expand Down Expand Up @@ -190,7 +192,7 @@ workflow annotate_celltypes {
.mix(classify_singler.out)

// create cellassign input channel: [meta, processed sce, cellassign reference file]
cellassign_input_ch = celltype_input_ch
cellassign_input_ch = celltype_input_ch
// add in cellassign reference
.map{it.toList() + [file(it[0].cellassign_reference_file ?: empty_file)]}
// skip if no cellassign reference file or reference name is not defined
Expand Down Expand Up @@ -234,7 +236,10 @@ workflow annotate_celltypes {


// incorporate annotations into SCE object
add_celltypes_to_sce(assignment_input_ch.add_celltypes)
add_celltypes_to_sce(
assignment_input_ch.add_celltypes,
file(params.celltype_ref_metadata) // file with CellAssign reference organs
)

// mix in libraries without new celltypes
// result is [meta, proccessed rds]
Expand Down