From d5183a7fec77de467750913c3abcb81cbdf63f07 Mon Sep 17 00:00:00 2001 From: Gisela Gabernet Date: Thu, 28 Oct 2021 13:33:57 +0200 Subject: [PATCH] new module `cellranger mkref` (#896) * add cellranger mkref module * add cellranger mkref tests * update test yml chksum * fix module linting * fix test yml * fix getprocessname * fix versions typo * fix cellranger test.yml * fix versions.yml * test versions.yml * fix grep version * fix cellranger version * add dockerfile and readme * review container statement * Update modules/cellranger/mkref/meta.yml Co-authored-by: Gregor Sturm * add disclaimers * change location dockerfile Co-authored-by: Gregor Sturm --- modules/cellranger/Dockerfile | 21 +++++ modules/cellranger/mkref/functions.nf | 78 ++++++++++++++++++ modules/cellranger/mkref/main.nf | 40 +++++++++ modules/cellranger/mkref/meta.yml | 39 +++++++++ modules/cellranger/readme.md | 18 ++++ ...t_versions_yml.cpython-39-pytest-6.2.5.pyc | Bin 3558 -> 0 bytes tests/config/pytest_modules.yml | 4 + tests/modules/cellranger/mkref/main.nf | 16 ++++ tests/modules/cellranger/mkref/test.yml | 43 ++++++++++ 9 files changed, 259 insertions(+) create mode 100644 modules/cellranger/Dockerfile create mode 100644 modules/cellranger/mkref/functions.nf create mode 100644 modules/cellranger/mkref/main.nf create mode 100644 modules/cellranger/mkref/meta.yml create mode 100644 modules/cellranger/readme.md delete mode 100644 tests/__pycache__/test_versions_yml.cpython-39-pytest-6.2.5.pyc create mode 100644 tests/modules/cellranger/mkref/main.nf create mode 100644 tests/modules/cellranger/mkref/test.yml diff --git a/modules/cellranger/Dockerfile b/modules/cellranger/Dockerfile new file mode 100644 index 00000000..aced4233 --- /dev/null +++ b/modules/cellranger/Dockerfile @@ -0,0 +1,21 @@ +FROM continuumio/miniconda3:4.8.2 +LABEL authors="Gisela Gabernet " \ + description="Docker image containing Cell Ranger" +# Disclaimer: this container is not provided nor supported by 10x Genomics. + +# Install procps and clean apt cache +RUN apt-get update \ + && apt-get install -y procps \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# Copy pre-downloaded cellranger file +ENV CELLRANGER_VER 6.0.2 +COPY cellranger-$CELLRANGER_VER.tar.gz /opt/cellranger-$CELLRANGER_VER.tar.gz + +# Install cellranger +RUN \ + cd /opt && \ + tar -xzvf cellranger-$CELLRANGER_VER.tar.gz && \ + export PATH=/opt/cellranger-$CELLRANGER_VER:$PATH && \ + ln -s /opt/cellranger-$CELLRANGER_VER/cellranger /usr/bin/cellranger && \ + rm -rf /opt/cellranger-$CELLRANGER_VER.tar.gz diff --git a/modules/cellranger/mkref/functions.nf b/modules/cellranger/mkref/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/cellranger/mkref/functions.nf @@ -0,0 +1,78 @@ +// +// Utility functions used in nf-core DSL2 module files +// + +// +// Extract name of software tool from process name using $task.process +// +def getSoftwareName(task_process) { + return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase() +} + +// +// Extract name of module from process name using $task.process +// +def getProcessName(task_process) { + return task_process.tokenize(':')[-1] +} + +// +// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules +// +def initOptions(Map args) { + def Map options = [:] + options.args = args.args ?: '' + options.args2 = args.args2 ?: '' + options.args3 = args.args3 ?: '' + options.publish_by_meta = args.publish_by_meta ?: [] + options.publish_dir = args.publish_dir ?: '' + options.publish_files = args.publish_files + options.suffix = args.suffix ?: '' + return options +} + +// +// Tidy up and join elements of a list to return a path string +// +def getPathFromList(path_list) { + def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries + paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes + return paths.join('/') +} + +// +// Function to save/publish module results +// +def saveFiles(Map args) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + + // Do not publish versions.yml unless running from pytest workflow + if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) { + return null + } + if (ioptions.publish_by_meta) { + def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta + for (key in key_list) { + if (args.meta && key instanceof String) { + def path = key + if (args.meta.containsKey(key)) { + path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key] + } + path = path instanceof String ? path : '' + path_list.add(path) + } + } + } + if (ioptions.publish_files instanceof Map) { + for (ext in ioptions.publish_files) { + if (args.filename.endsWith(ext.key)) { + def ext_list = path_list.collect() + ext_list.add(ext.value) + return "${getPathFromList(ext_list)}/$args.filename" + } + } + } else if (ioptions.publish_files == null) { + return "${getPathFromList(path_list)}/$args.filename" + } +} diff --git a/modules/cellranger/mkref/main.nf b/modules/cellranger/mkref/main.nf new file mode 100644 index 00000000..22ad66ba --- /dev/null +++ b/modules/cellranger/mkref/main.nf @@ -0,0 +1,40 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process CELLRANGER_MKREF { + tag 'mkref' + label 'process_high' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:[:], publish_by_meta:[]) } + + if (params.enable_conda) { + exit 1, "Conda environments cannot be used when using the Cell Ranger tool. Please use docker or singularity containers." + } + container "nfcore/cellranger:6.0.2" + + input: + path fasta + path gtf + val(reference_name) + + output: + path "versions.yml" , emit: versions + path "${reference_name}", emit: reference + + script: + """ + cellranger mkref \\ + --genome=${reference_name} \\ + --fasta=${fasta} \\ + --genes=${gtf} + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$(echo \$( cellranger --version 2>&1) | sed 's/^.*[^0-9]\\([0-9]*\\.[0-9]*\\.[0-9]*\\).*\$/\\1/' ) + END_VERSIONS + """ +} diff --git a/modules/cellranger/mkref/meta.yml b/modules/cellranger/mkref/meta.yml new file mode 100644 index 00000000..9b849af7 --- /dev/null +++ b/modules/cellranger/mkref/meta.yml @@ -0,0 +1,39 @@ +name: cellranger_mkref +description: Module to build the reference needed by the 10x Genomics Cell Ranger tool. Uses the cellranger mkref command. +keywords: + - reference + - mkref + - index +tools: + - cellranger: + description: Cell Ranger by 10x Genomics is a set of analysis pipelines that process Chromium single-cell data to align reads, generate feature-barcode matrices, perform clustering and other secondary analysis, and more. + homepage: https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/what-is-cell-ranger + documentation: https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/tutorial_ov + tool_dev_url: https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/latest/using/tutorial_ov + doi: "" + licence: 10x Genomics EULA + +input: + - fasta: + type: file + description: fasta genome file + pattern: "*.{fasta,fa}" + - gtf: + type: file + description: gtf transcriptome file + pattern: "*.gtf" + - reference_name: + type: val + description: name to give the reference folder + pattern: str + +output: + - versions: + type: file + description: File containing software version + pattern: "versions.yml" + - reference: + type: folder + description: Folder containing all the reference indices needed by Cell Ranger +authors: + - "@ggabernet" diff --git a/modules/cellranger/readme.md b/modules/cellranger/readme.md new file mode 100644 index 00000000..ed8ccb73 --- /dev/null +++ b/modules/cellranger/readme.md @@ -0,0 +1,18 @@ +# Updating the docker container and making a new module release + +Cell Ranger is a commercial tool by 10X Genomics. The container provided for the cellranger nf-core module is not provided nor supported by 10x Genomics. Updating the Cell Ranger version in the container and pushing the update to Dockerhub needs to be done manually. + +1. Navigate to the [Cell Ranger download page](https://support.10xgenomics.com/single-cell-gene-expression/software/downloads/latest) and download the tar ball of the desired Cell Ranger version with `curl` or `wget`. Place this file in the same folder where the Dockerfile lies. + +2. Edit the Dockerfile: update the Cell Ranger version in this line: + + ```bash + ENV CELLRANGER_VER + ``` + +3. Create the container: + + ```bash + docker build . -t nfcore/cellranger: + docker push nfcore/cellranger: + ``` diff --git a/tests/__pycache__/test_versions_yml.cpython-39-pytest-6.2.5.pyc b/tests/__pycache__/test_versions_yml.cpython-39-pytest-6.2.5.pyc deleted file mode 100644 index 33acb8369a1bc62b5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