From 504028346bc4b7c37bab0f40d437e4fa7b45904f Mon Sep 17 00:00:00 2001 From: Priyanka Surana <86618929+priyanka-surana@users.noreply.github.com> Date: Thu, 29 Sep 2022 08:10:44 +0100 Subject: [PATCH] samtools fasta module (#2128) --- modules/samtools/fasta/main.nf | 37 ++++++++++++++++ modules/samtools/fasta/meta.yml | 46 ++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/samtools/fasta/main.nf | 15 +++++++ tests/modules/samtools/fasta/nextflow.config | 5 +++ tests/modules/samtools/fasta/test.yml | 10 +++++ 6 files changed, 117 insertions(+) create mode 100644 modules/samtools/fasta/main.nf create mode 100644 modules/samtools/fasta/meta.yml create mode 100644 tests/modules/samtools/fasta/main.nf create mode 100644 tests/modules/samtools/fasta/nextflow.config create mode 100644 tests/modules/samtools/fasta/test.yml diff --git a/modules/samtools/fasta/main.nf b/modules/samtools/fasta/main.nf new file mode 100644 index 00000000..130c2a5a --- /dev/null +++ b/modules/samtools/fasta/main.nf @@ -0,0 +1,37 @@ +process SAMTOOLS_FASTA { + tag "$meta.id" + label 'process_low' + + conda (params.enable_conda ? "bioconda::samtools=1.15.1" : null) + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/samtools:1.15.1--h1170115_0': + 'quay.io/biocontainers/samtools:1.15.1--h1170115_0' }" + + input: + tuple val(meta), path(input) + + output: + tuple val(meta), path("*.fasta.gz"), emit: fasta + path "versions.yml", emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def endedness = meta.single_end ? "-0 ${prefix}.fasta.gz" : "-1 ${prefix}_1.fasta.gz -2 ${prefix}_2.fasta.gz" + """ + samtools \\ + fasta \\ + $args \\ + --threads ${task.cpus-1} \\ + $endedness \\ + $input + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//' )) + END_VERSIONS + """ +} diff --git a/modules/samtools/fasta/meta.yml b/modules/samtools/fasta/meta.yml new file mode 100644 index 00000000..4c662269 --- /dev/null +++ b/modules/samtools/fasta/meta.yml @@ -0,0 +1,46 @@ +name: "samtools_fasta" +description: Converts a SAM/BAM/CRAM file to FASTA +keywords: + - bam + - sam + - cram + - fasta +tools: + - "samtools": + description: "Tools for dealing with SAM, BAM and CRAM files" + homepage: "http://www.htslib.org" + documentation: "https://www.htslib.org/doc/samtools-fasta.html" + tool_dev_url: "https://github.com/samtools/samtools" + doi: "10.1093/bioinformatics/btp352" + licence: "['MIT']" + +input: + # Only when we have meta + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - input: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" + +output: + #Only when we have meta + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - fasta: + type: file + description: compressed FASTA file + pattern: "*.fasta.gz" + +authors: + - "@priyanka-surana" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 16156bbf..cae10d10 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -2103,6 +2103,10 @@ samtools/faidx: - modules/samtools/faidx/** - tests/modules/samtools/faidx/** +samtools/fasta: + - modules/samtools/fasta/** + - tests/modules/samtools/fasta/** + samtools/fastq: - modules/samtools/fastq/** - tests/modules/samtools/fastq/** diff --git a/tests/modules/samtools/fasta/main.nf b/tests/modules/samtools/fasta/main.nf new file mode 100644 index 00000000..c0ef91f4 --- /dev/null +++ b/tests/modules/samtools/fasta/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { SAMTOOLS_FASTA } from '../../../../modules/samtools/fasta/main.nf' + +workflow test_samtools_fasta { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + SAMTOOLS_FASTA ( input ) +} diff --git a/tests/modules/samtools/fasta/nextflow.config b/tests/modules/samtools/fasta/nextflow.config new file mode 100644 index 00000000..50f50a7a --- /dev/null +++ b/tests/modules/samtools/fasta/nextflow.config @@ -0,0 +1,5 @@ +process { + + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + +} \ No newline at end of file diff --git a/tests/modules/samtools/fasta/test.yml b/tests/modules/samtools/fasta/test.yml new file mode 100644 index 00000000..6c992caf --- /dev/null +++ b/tests/modules/samtools/fasta/test.yml @@ -0,0 +1,10 @@ +- name: samtools fasta test_samtools_fasta + command: nextflow run ./tests/modules/samtools/fasta -entry test_samtools_fasta -c ./tests/config/nextflow.config -c ./tests/modules/samtools/fasta/nextflow.config + tags: + - samtools + - samtools/fasta + files: + - path: output/samtools/test_1.fasta.gz + md5sum: 3abd682290bc7c75f1ce2b80db995237 + - path: output/samtools/test_2.fasta.gz + md5sum: 6ada09ce66f68b8732985e14aac1bf1f