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 seurat conversion #125

Merged
merged 8 commits into from
Jul 5, 2022
Merged
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
25 changes: 25 additions & 0 deletions bin/mtx_to_seurat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env Rscript
library(Seurat)

args <- commandArgs(trailingOnly=TRUE)

mtx_file <- args[1]
barcode_file <- args[2]
feature_file <- args[3]
out.file <- args[4]
aligner <- args[5]

if(aligner %in% c("kallisto", "alevin")) {
# for kallisto and alevin, the features file contains only one column and matrix needs to be transposed
expression.matrix <- ReadMtx(
mtx = mtx_file, features = feature_file, cells = barcode_file, feature.column = 1, mtx.transpose = TRUE
)
} else {
expression.matrix <- ReadMtx(
mtx = mtx_file, features = feature_file, cells = barcode_file
)
}

seurat.object <- CreateSeuratObject(counts = expression.matrix)

saveRDS(seurat.object, file = out.file)
2 changes: 1 addition & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ process {
pattern: '*_versions.yml'
]
}
withName: 'MTX_TO_H5AD|CONCAT_H5AD' {
withName: 'MTX_TO_H5AD|CONCAT_H5AD|MTX_TO_SEURAT' {
publishDir = [
path: { "${params.outdir}/${params.aligner}/mtx_conversions" },
mode: params.publish_dir_mode
Expand Down
51 changes: 51 additions & 0 deletions modules/local/mtx_to_seurat.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
process MTX_TO_SEURAT {
tag "$meta.id"
label 'process_medium'

conda (params.enable_conda ? "seurat-scripts" : null)
container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'docker://satijalab/seurat:4.1.0' :
'satijalab/seurat:4.1.0' }"

input:
// inputs from cellranger nf-core module does not come in a single sample dir
// for each sample, the sub-folders and files come directly in array.
tuple val(meta), path(inputs)

output:
path "*.rds", emit: seuratObjects

script:
def aligner = params.aligner
if (params.aligner == "cellranger") {
matrix = "filtered_feature_bc_matrix/matrix.mtx.gz"
barcodes = "filtered_feature_bc_matrix/barcodes.tsv.gz"
features = "filtered_feature_bc_matrix/features.tsv.gz"
} else if (params.aligner == "kallisto") {
matrix = "*_kallistobustools_count/counts_unfiltered/*.mtx"
barcodes = "*_kallistobustools_count/counts_unfiltered/*.barcodes.txt"
features = "*_kallistobustools_count/counts_unfiltered/*.genes.txt"
} else if (params.aligner == "alevin") {
matrix = "*_alevin_results/alevin/quants_mat.mtx.gz"
barcodes = "*_alevin_results/alevin/quants_mat_rows.txt"
features = "*_alevin_results/alevin/quants_mat_cols.txt"
} else if (params.aligner == 'star') {
matrix = "*.Solo.out/Gene/filtered/matrix.mtx"
barcodes = "*.Solo.out/Gene/filtered/barcodes.tsv"
features = "*.Solo.out/Gene/filtered/features.tsv"
}

"""
mtx_to_seurat.R \\
$matrix \\
$barcodes \\
$features \\
${meta.id}_matrix.rds \\
${aligner}
"""

stub:
"""
touch ${meta.id}_matrix.rds
"""
}
35 changes: 35 additions & 0 deletions subworkflows/local/mtx_conversion.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* -- IMPORT LOCAL MODULES/SUBWORKFLOWS -- */
include { MTX_TO_H5AD } from '../../modules/local/mtx_to_h5ad.nf'
include { CONCAT_H5AD } from '../../modules/local/concat_h5ad.nf'
include { MTX_TO_SEURAT } from '../../modules/local/mtx_to_seurat.nf'

workflow MTX_CONVERSION {

take:
mtx_matrices
samplesheet

main:
//
// Convert matrix do h5ad
//
MTX_TO_H5AD (
mtx_matrices
)

//
// Concat sample-specific h5ad in one
//
CONCAT_H5AD (
MTX_TO_H5AD.out.h5ad.collect(), // gather all sample-specific files
samplesheet
)

//
// Convert matrix do seurat
//
MTX_TO_SEURAT (
mtx_matrices
)

}
4 changes: 2 additions & 2 deletions workflows/scrnaseq.nf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ include { KALLISTO_BUSTOOLS } from '../subworkflows/local/kallisto_bustools'
include { SCRNASEQ_ALEVIN } from '../subworkflows/local/alevin'
include { STARSOLO } from '../subworkflows/local/starsolo'
include { CELLRANGER_ALIGN } from "../subworkflows/local/align_cellranger"
include { H5AD_CONVERSION } from "../subworkflows/local/conversion_to_h5ad"
include { MTX_CONVERSION } from "../subworkflows/local/mtx_conversion"

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -170,7 +170,7 @@ workflow SCRNASEQ {
}

// Run mtx to h5ad conversion subworkflow
H5AD_CONVERSION (
MTX_CONVERSION (
ch_mtx_matrices,
ch_input
)
Expand Down