Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Shapiro <[email protected]>
  • Loading branch information
allyhawkins and jashapiro authored Oct 11, 2023
1 parent b619309 commit ce3a5b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions bin/add_celltypes_to_sce.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ option_list <- list(
help = "path to output rds file to store annotated sce object. Must end in .rds"
),
make_option(
opt_str = c("singler_results"),
opt_str = c("--singler_results"),
type = "character",
help = "path to rds file containing SingleR results object"
),
Expand All @@ -34,7 +34,7 @@ option_list <- list(
make_option(
opt_str = c("--cellassign_ref_name"),
type = "character",
help = "Name of reference used for CellAssign"
help = "name of reference used for CellAssign"
)
)

Expand Down Expand Up @@ -109,6 +109,7 @@ if(!is.null(opt$cellassign_predictions)){

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

# get cell type with maximum prediction value for each cell
celltype_assignments <- predictions |>
tidyr::pivot_longer(
!barcode,
Expand Down
19 changes: 13 additions & 6 deletions modules/classify-celltypes.nf
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,26 @@ process add_celltypes_to_sce {
input:
tuple val(meta), path(processed_rds), path(singler_dir), path(cellassign_dir)
output:
tuple val(meta), path(processed_rds)
tuple val(meta), path(annotated_rds)
script:
annotated_rds = "${meta.library_id}_processed_annotated.rds"
singler_present = "${singler_dir.name}" != "NO_FILE"
singler_results = "${singler_dir}/singler_results.rds"
cellassign_present = "${cellassign_dir}.name" != "NO_FILE"
cellassign_predictions = "${cellassign_dir}/cellassign_predictions.tsv"
cellassign_ref_name = file("${meta.cellassign_reference_file}").name
cellassign_ref_name = file("${meta.cellassign_reference_file}").baseName
"""
add_celltypes_to_sce.R \
--input_sce_file ${processed_rds} \
--output_sce_file ${processed_rds} \
--output_sce_file ${annotated_rds} \
${singler_present ? "--singler_results ${singler_results}" : ''} \
${cellassign_present ? "--cellassign_predictions ${cellassign_predictions}" : ''} \
${cellassign_present ? "--cellassign_ref_name ${cellassign_ref_name}" : ''}
"""
stub:
annotated_rds = "${meta.library_id}_processed_annotated.rds"
"""
touch ${processed_rds}
touch ${annotated_rds}
"""
}

Expand Down Expand Up @@ -209,10 +211,15 @@ workflow annotate_celltypes {

// incorporate annotations into SCE object
add_celltypes_to_sce(assignment_input_ch.add_celltypes)

// mix in libraries without new celltypes
// result is [meta, proccessed rds]
celltyped_ch = assignment_input_ch.no_celltypes
.map{[it[0], it[1]]}
.mix(add_celltypes_to_sce.out)

// add back in the unchanged sce files to the results
export_channel = add_celltypes_to_sce.out
.mix(assignment_input_ch.no_celltypes.map{[it[0], it[1]]})
export_channel = celltyped_ch
.map{[it[0]["library_id"]] + it}
// add in unfiltered and filtered sce files
.join(sce_files_channel.map{[it[0]["library_id"], it[1], it[2]]},
Expand Down

0 comments on commit ce3a5b0

Please sign in to comment.