Skip to content
Draft
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
8 changes: 5 additions & 3 deletions bin/seurat_subset.R → bin/seurat_append_and_subset.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ option_list <- list(
make_option(c("-m", "--metadata"), type = "character",
help = "Metadata with cell status (TME/Malignant)", metavar = "character"),
make_option(c("-o", "--outdir"), type = "character", default = './',
help = "Output directory path", metavar = "character")
help = "Output directory path", metavar = "character"),
make_option(c("-s", "--subset"), action = "store_true", default = FALSE,
help = "Whether to save a subset of the original object")
)

opt_parser <- OptionParser(option_list = option_list)
Expand All @@ -42,11 +44,11 @@ seurat_object <- Seurat::AddMetaData(
seurat_object, metadata = metadata
)

if (opt$subset) {
seurat_object <- subset(
seurat_object, subset = cell_status == "TME"
)

#
}

saveRDS(
seurat_object, file = file.path(opt$outdir, gsub(".RDS", "_filtered.RDS", basename(opt$file))))
27 changes: 27 additions & 0 deletions modules/local/helpers/append/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

process HELPER_SEURAT_APPEND {
tag "Adding metadata"
label 'process_medium'
container 'oandrefonseca/scratch-annotation:main'
publishDir "${params.outdir}/data/${task.process}", mode: 'copy', overwrite: true

input:
path seurat_object
path metadata

output:
path ("${seurat_object.baseName}_filtered.RDS"), emit: project_rds

when:
task.ext.when == null || task.ext.when

script:
"""
seurat_append_and_subset.R -f ${seurat_object} -m ${metadata}
"""

stub:
"""
touch ${seurat_object.baseName}_filtered.RDS
"""
}
1 change: 1 addition & 0 deletions modules/local/helpers/append/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TO BE DONE
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ option_list <- list(
make_option(c("-m", "--metadata"), type = "character",
help = "Metadata with cell status (TME/Malignant)", metavar = "character"),
make_option(c("-o", "--outdir"), type = "character", default = './',
help = "Output directory path", metavar = "character")
help = "Output directory path", metavar = "character"),
make_option(c("-s", "--subset"), action = "store_true", default = FALSE,
help = "Whether to save a subset of the original object")
)

opt_parser <- OptionParser(option_list = option_list)
Expand All @@ -42,11 +44,11 @@ seurat_object <- Seurat::AddMetaData(
seurat_object, metadata = metadata
)

if (opt$subset) {
seurat_object <- subset(
seurat_object, subset = cell_status == "TME"
)

#
}

saveRDS(
seurat_object, file = file.path(opt$outdir, gsub(".RDS", "_filtered.RDS", basename(opt$file))))
2 changes: 1 addition & 1 deletion modules/local/helpers/subset/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ process HELPER_SEURAT_SUBSET {

script:
"""
seurat_subset.R -f ${seurat_object} -m ${cell_malignancy}
seurat_append_and_subset.R -f ${seurat_object} -m ${cell_malignancy} --subset
"""
stub:
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env Rscript

library(Seurat)
library(dplyr)
library(readr)
library(tibble)
library(optparse)

#Sys.setenv(KMP_DUPLICATE_LIB_OK = "TRUE")

#

option_list <- list(
make_option(c("-f", "--file"), type = "character", default = NULL,
help = "Input dump name", metavar = "character"),
make_option(c("-m", "--metadata"), type = "character",
help = "Metadata with cell status (TME/Malignant)", metavar = "character"),
make_option(c("-o", "--outdir"), type = "character", default = './',
help = "Output directory path", metavar = "character"),
make_option(c("-s", "--subset"), action = "store_true", default = FALSE,
help = "Whether to save a subset of the original object")
)

opt_parser <- OptionParser(option_list = option_list)
opt <- parse_args(opt_parser)

#

if (length(opt) == 3) {
print_help(opt_parser)
stop("At least one argument must be supplied (input file).n", call. = FALSE)
}

#

seurat_object <- readRDS(file = opt$file)
metadata <- readr::read_csv(opt$metadata)

metadata <- metadata %>%
tibble::column_to_rownames(var = "barcode") %>%
as.data.frame()

seurat_object <- Seurat::AddMetaData(
seurat_object, metadata = metadata
)

if (opt$subset) {
seurat_object <- subset(
seurat_object, subset = cell_status == "TME"
)
}

saveRDS(
seurat_object, file = file.path(opt$outdir, gsub(".RDS", "_filtered.RDS", basename(opt$file))))