diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 19d8ed0..84803e6 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -23,8 +23,11 @@ If you're not used to this workflow with git, you can start with some [docs from ## Tests -You can optionally test your changes by running the pipeline locally. Then it is recommended to use the `debug` profile to -receive warnings about process selectors and other debug info. Example: `nextflow run . -profile debug,test,docker --outdir `. +You have the option to test your changes locally by running the pipeline. For receiving warnings about process selectors and other `debug` information, it is recommended to use the debug profile. Execute all the tests with the following command: + +```bash +nf-test test --profile debug,test,docker --verbose +``` When you create a pull request with changes, [GitHub Actions](https://github.com/features/actions) will run automatic tests. Typically, pull-requests are only fully reviewed when these tests are passing, though of course we can help out before then. @@ -40,7 +43,7 @@ If any failures or warnings are encountered, please follow the listed URL for mo ### Pipeline tests -Each `nf-core` pipeline should be set up with a minimal set of test-data. +Each of the Microbiome Informatics pipelines should be set up with a minimal set of test-data. `GitHub Actions` then runs the pipeline on this data to ensure that it exits successfully. If there are any failures then the automated tests fail. These tests are run both with the latest available version of `Nextflow` and also the minimum required version that is stated in the pipeline code. @@ -82,7 +85,7 @@ Once there, use `nf-core schema build` to add to `nextflow_schema.json`. Sensible defaults for process resource requirements (CPUs / memory / time) for a process should be defined in `conf/base.config`. These should generally be specified generic with `withLabel:` selectors so they can be shared across multiple processes/steps of the pipeline. A nf-core standard set of labels that should be followed where possible can be seen in the [nf-core pipeline template](https://github.com/nf-core/tools/blob/master/nf_core/pipeline-template/conf/base.config), which has the default process as a single core-process, and then different levels of multi-core configurations for increasingly large memory requirements defined with standardised labels. -The process resources can be passed on to the tool dynamically within the process with the `${task.cpu}` and `${task.memory}` variables in the `script:` block. +The process resources can be passed on to the tool dynamically within the process with the `${task.cpus}` and `${task.memory}` variables in the `script:` block. ### Naming schemes diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..64040ae --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,36 @@ +name: nf-test CI +on: + push: + branches: + - dev + pull_request: + release: + types: [published] + +env: + NXF_ANSI_LOG: false + NFTEST_VER: "0.8.4" + +jobs: + test: + name: Run pipeline with test data + runs-on: ubuntu-latest + + steps: + - name: Check out pipeline code + uses: actions/checkout@v4 + + - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4 + with: + distribution: "temurin" + java-version: "17" + + - name: Setup Nextflow + uses: nf-core/setup-nextflow@v2 + + - name: Install nf-test + uses: nf-core/setup-nf-test@v1 + + - name: Run pipeline with test data + run: | + nf-test test diff --git a/.gitignore b/.gitignore index 8ede5a8..708fd26 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,8 @@ testing* results/ *.pyc +.pytest_cache/ -assets/fetch_tool_credentials.json \ No newline at end of file +assets/fetch_tool_credentials.json +.nf-test.log +.nf-test/ diff --git a/.nf-core.yml b/.nf-core.yml index 9e9227a..4b141b6 100644 --- a/.nf-core.yml +++ b/.nf-core.yml @@ -1,9 +1,17 @@ +repository_type: pipeline +template: + prefix: ebi-metagenomics + skip: + - ci + - github_badges lint: files_exist: - CODE_OF_CONDUCT.md - assets/nf-core-miassembler_logo_light.png - docs/images/nf-core-miassembler_logo_light.png - docs/images/nf-core-miassembler_logo_dark.png + - docs/output.md + - docs/usage.md - .github/ISSUE_TEMPLATE/config.yml - .github/workflows/awstest.yml - .github/workflows/awsfulltest.yml @@ -11,22 +19,30 @@ lint: - .github/workflows/ci.yml - .github/workflows/linting_comment.yml - .github/workflows/linting.yml + - conf/test_full.config + - lib/Utils.groovy + - lib/WorkflowMain.groovy + - lib/NfcoreTemplate.groovy + - lib/WorkflowMiassembler.groovy + - lib/nfcore_external_java_deps.jar files_unchanged: - CODE_OF_CONDUCT.md - assets/nf-core-miassembler_logo_light.png - docs/images/nf-core-miassembler_logo_light.png - docs/images/nf-core-miassembler_logo_dark.png - .github/ISSUE_TEMPLATE/bug_report.yml + - .github/CONTRIBUTING.md + - LICENSE + - docs/README.md + - .gitignore multiqc_config: - report_comment - nextflow_config: + nextflow_config: False + - params.input + - params.validationSchemaIgnoreParams + - params.custom_config_version + - params.custom_config_base - manifest.name - manifest.homePage readme: - nextflow_badge -repository_type: pipeline -template: - prefix: ebi-metagenomics - skip: - - ci - - github_badges diff --git a/README.md b/README.md index aefdf90..54abc00 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ This pipeline is still in early development. It's mostly a direct port of the mi-automation assembly generation pipeline. Some of the bespoke scripts used to remove contaminated contigs or to calculate the coverage of the assembly were replaced with tools provided by the community ([SeqKit](https://doi.org/10.1371/journal.pone.0163962) and [quast](https://doi.org/10.1093/bioinformatics/btu153) respectively). +> [!NOTE] +> This pipeline uses the nf-core template with some tweaks, but it's not part of nf-core. + ## Usage > [!WARNING] @@ -23,12 +26,21 @@ nextflow run ebi-metagenomics/miassembler --help Input/output options --study_accession [string] The ENA Study secondary accession --reads_accession [string] The ENA Run primary accession - --assembler [string] The short reads assembler (accepted: spades, metaspades, megahit) [default: metaspades for PE, megahit for SE] + --private_study [boolean] To use if the ENA study is private [default: false] + --assembler [string] The short reads assembler (accepted: spades, metaspades, megahit) [default: metaspades] --reference_genome [string] The genome to be used to clean the assembly, the genome will be taken from the Microbiome Informatics internal directory (accepted: chicken.fna, salmon.fna, cod.fna, pig.fna, cow.fna, mouse.fna, honeybee.fna, - rainbow_trout.fna, ...) [default: human+phiX] - --reference_genomes_folder [string] The folder with the reference genome blast indexes, defaults to the Microbiome Informatics internal directory - [default: /nfs/production/rdf/metagenomics/pipelines/prod/assembly-pipeline/blast_dbs/] + rainbow_trout.fna, rat.fna, ...) + --blast_reference_genomes_folder [string] The folder with the reference genome blast indexes, defaults to the Microbiome Informatics internal + directory. + --bwamem2_reference_genomes_folder [string] The folder with the reference genome bwa-mem2 indexes, defaults to the Microbiome Informatics internal + directory. + --remove_human_phix [boolean] Remove human and phiX reads pre assembly, and contigs matching those genomes. [default: true] + --human_phix_blast_index_name [string] Combined Human and phiX BLAST db. [default: human_phix] + --human_phix_bwamem2_index_name [string] Combined Human and phiX bwa-mem2 index. [default: human_phix] + --min_contig_length [integer] Minimum contig length filter. [default: 500] + --assembly_memory [integer] Default memory allocated for the assembly process. [default: 100] + --spades_only_assembler [boolean] Run SPAdes/metaSPAdes without the error correction step. [default: true] --outdir [string] The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure. --email [string] Email address for completion summary. @@ -50,7 +62,43 @@ nextflow run ebi-metagenomics/miassembler \ --reads_accession SRR1631361 ``` +## Outputs + +The outputs of the pipeline are organized as follows: + +``` +results/SRP1154 +└── SRP115494 + └── SRR6180 + └── SRR6180434 + ├── assembly + │   └── metaspades + │   └── 3.15.5 + │   ├── coverage + │   ├── decontamination + │   └── qc + │   ├── multiqc + │   └── quast + └── qc + ├── fastp + └── fastqc + +``` + +The nested structure based on ENA Study and Reads accessions was created to suit the Microbiome Informatics team’s needs. The benefit of this structure is that results from different runs of the same study won’t overwrite any results. + +## Tests + +There is a very small test data set ready to use: + +```bash +nextflow run main.nf -resume -profile test,docker +``` + +### End to end tests + Two end-to-end tests can be launched (with megahit and metaspades) with the following command: + ```bash pytest tests/workflows/ --verbose ``` diff --git a/assets/email_template.html b/assets/email_template.html index 83d4739..e4baa40 100644 --- a/assets/email_template.html +++ b/assets/email_template.html @@ -12,7 +12,7 @@ -

ebi-metagenomics/miassembler v${version}

+

ebi-metagenomics/miassembler ${version}

Run Name: $runName

<% if (!success){ diff --git a/assets/mgnify_logo.png b/assets/mgnify_logo.png new file mode 100644 index 0000000..fe6112b Binary files /dev/null and b/assets/mgnify_logo.png differ diff --git a/assets/multiqc_config.yml b/assets/multiqc_config.yml index 2350291..337607f 100644 --- a/assets/multiqc_config.yml +++ b/assets/multiqc_config.yml @@ -1,16 +1,17 @@ report_comment: > - This report has been generated by the ebi-metagenomics/miassembler + This report has been generated by the ebi-metagenomics/miassembler analysis pipeline. + report_section_order: "ebi-metagenomics-miassembler-methods-description": order: -1000 - software_versions: - order: -1001 "ebi-metagenomics-miassembler-summary": order: -1002 export_plots: true +skip_versions_section: true + top_modules: - fastqc - quast diff --git a/assets/samplesheet.csv b/assets/samplesheet.csv deleted file mode 100644 index 5f653ab..0000000 --- a/assets/samplesheet.csv +++ /dev/null @@ -1,3 +0,0 @@ -sample,fastq_1,fastq_2 -SAMPLE_PAIRED_END,/path/to/fastq/files/AEG588A1_S1_L002_R1_001.fastq.gz,/path/to/fastq/files/AEG588A1_S1_L002_R2_001.fastq.gz -SAMPLE_SINGLE_END,/path/to/fastq/files/AEG588A4_S4_L003_R1_001.fastq.gz, diff --git a/conf/modules.config b/conf/modules.config index 21b2825..67b430b 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -12,16 +12,6 @@ process { - withName: 'SAMPLESHEET_CHECK' { - publishDir = [ - [ - path: "${params.outdir}/pipeline_info", - mode: params.publish_dir_mode, - saveAs: { filename -> filename.equals('versions.yml') ? null : filename } - ] - ] - } - withName: 'FETCHTOOL*' { cpus = { check_max( 1 , 'cpus' ) } memory = { check_max( 6.GB * task.attempt, 'memory' ) } @@ -42,25 +32,24 @@ process { saveAs: { filename -> { if ( filename.equals('versions.yml') ) { - return null; - } - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - def file_patterns_to_publish = [ - 'fastp.log', - 'fastp.html', - 'fastp.json' - ] - def output_file = new File(filename); - if ( file_patterns_to_publish.any { output_file.name.contains(it) } ) { - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/qc/fastp/${output_file.name}"; - } return null; + } + def file_patterns_to_publish = [ + 'fastp.log', + 'fastp.html', + 'fastp.json' + ] + def output_file = new File(filename); + if ( file_patterns_to_publish.any { output_file.name.contains(it) } ) { + return "${study_reads_folder()}/qc/fastp/${output_file.name}"; + } + return null; } } ] ] } + withName: 'FASTQC' { cpus = { check_max( 6 * task.attempt, 'cpus' ) } memory = { check_max( 36.GB * task.attempt, 'memory' ) } @@ -73,12 +62,10 @@ process { saveAs: { filename -> { if ( filename.equals('versions.yml') ) { - return null; - } - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); + return null; + } def output_file = new File(filename); - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/qc/fastqc/${output_file.name}"; + return "${study_reads_folder()}/qc/fastqc/${output_file.name}"; } } ] @@ -108,16 +95,57 @@ process { } withName: 'SPADES' { + memory = { check_max(params.assembly_memory.GB * task.attempt, 'memory') } + cpus = { check_max( 32 * task.attempt, 'cpus') } ext.args = params.spades_only_assembler ? "--only-assembler" : "" - memory = { "$params.assembly_memory" + ".GB" * task.attempt } - cpus = 32 + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + failOnError: true, + saveAs: { + filename -> { + if ( filename.equals('versions.yml') ) { + return null; + } + def file_patterns_to_publish = [ + 'params.txt', + 'graph.fastg', + 'contigs.fa.gz', + 'scaffolds.fa.gz', + 'graph_with_scaffolds.gfa.gz' + ] + def output_file = new File(filename); + if ( file_patterns_to_publish.any { output_file.name.contains(it) } ) { + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/${output_file.name}"; + } + return null; + } + } + ] + ] } withName: 'MEGAHIT' { cpus = { check_max( 12 * task.attempt, 'cpus' ) } memory = { check_max( 72.GB * task.attempt, 'memory' ) } time = { check_max( 16.h * task.attempt, 'time' ) } + + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + failOnError: true, + pattern: "megahit_out/*.fa*.gz", + saveAs: { + filename -> { + def output_file = new File(filename); + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/${output_file.name}"; + } + } + ] + ] } withName: 'SEQKIT_SEQ' { @@ -179,6 +207,19 @@ process { cpus = { check_max( 6 * task.attempt, 'cpus' ) } memory = { check_max( 36.GB * task.attempt, 'memory' ) } time = { check_max( 8.h * task.attempt, 'time' ) } + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + pattern: "*.txt.gz", + saveAs: { + filename -> { + def output_file = new File(filename); + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/coverage/${output_file.name}"; + } + } + ] + ] } withName: 'SAMTOOLS_IDXSTATS' { @@ -187,15 +228,17 @@ process { time = { check_max( 4.h * task.attempt, 'time' ) } } - withName: CUSTOM_DUMPSOFTWAREVERSIONS { + withName: 'CUSTOM_DUMPSOFTWAREVERSIONS' { cpus = { check_max( 1 , 'cpus' ) } memory = { check_max( 6.GB * task.attempt, 'memory' ) } time = { check_max( 4.h * task.attempt, 'time' ) } publishDir = [ - path: { "${params.outdir}/pipeline_info" }, - mode: params.publish_dir_mode, - pattern: '*_versions.yml' + [ + path: "${params.outdir}/pipeline_info", + mode: params.publish_dir_mode, + pattern: '*_versions.yml' + ] ] } @@ -205,11 +248,68 @@ process { time = { check_max( 4.h * task.attempt, 'time' ) } ext.args = { params.multiqc_title ? "--title \"$params.multiqc_title\"" : '' } + + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + failOnError: true, + saveAs: { + filename -> { + if ( filename.equals('versions.yml') ) { + return null; + } + def output_file = new File(filename); + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/qc/multiqc/${output_file.name}"; + } + } + ] + ] } withName: 'QUAST' { cpus = { check_max( 1 , 'cpus' ) } memory = { check_max( 6.GB * task.attempt, 'memory' ) } time = { check_max( 4.h * task.attempt, 'time' ) } + + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + failOnError: true, + saveAs: { + filename -> { + if ( filename.equals('versions.yml') ) { + return null; + } + def output_file = new File(filename); + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/qc/quast/${output_file.name}"; + } + } + ] + ] + // Disable Quast reference download + // NOTICE: Maximum number of references (--max-ref-number) is set to 0, search in SILVA 16S rRNA database is disabled // + ext.args = "--max-ref-num 0" + } + + withName: 'PUBLISH_DECONTAMINATED' { + cpus = { check_max( 1 , 'cpus' ) } + memory = { check_max( 250.MB * task.attempt, 'memory' ) } + time = { check_max( 30.m , 'time' ) } + + publishDir = [ + [ + path: "${params.outdir}", + mode: params.publish_dir_mode, + failOnError: true, + saveAs: { + filename -> { + def output_file = new File(filename); + return "${study_reads_folder()}/assembly/${meta.assembler}/${meta.assembler_version}/decontamination/${output_file.name}"; + } + } + ] + ] } } diff --git a/conf/test.config b/conf/test.config index 64c72b8..c283461 100644 --- a/conf/test.config +++ b/conf/test.config @@ -20,4 +20,6 @@ params { reads_accession = "SRR6180434" bwamem2_reference_genomes_folder = "tests/human_phix/bwa2mem" blast_reference_genomes_folder = "tests/human_phix/blast" + human_phix_blast_index_name = "human_phix" + human_phix_bwamem2_index_name = "human_phix" } diff --git a/docs/README.md b/docs/README.md index ca606d8..a176327 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,8 +1,3 @@ # ebi-metagenomics/miassembler: Documentation -The ebi-metagenomics/miassembler documentation is split into the following pages: - -- [Usage](usage.md) - - An overview of how the pipeline works, how to run it and a description of all of the different command-line flags. -- [Output](output.md) - - An overview of the different results produced by the pipeline and how to interpret them. +TODO diff --git a/docs/output.md b/docs/output.md deleted file mode 100644 index 7d89f6d..0000000 --- a/docs/output.md +++ /dev/null @@ -1,71 +0,0 @@ -# ebi-metagenomics/miassembler: Output - -## Introduction - -This document describes the output produced by the pipeline. Most of the plots are taken from the MultiQC report, which summarises results at the end of the pipeline. - -The directories listed below will be created in the results directory after the pipeline has finished. All paths are relative to the top-level results directory. - - - -## Pipeline overview - -The pipeline is built using [Nextflow](https://www.nextflow.io/) and processes data using the following steps: - -- [FastQC](#fastqc) - Raw read QC -- [MultiQC](#multiqc) - Aggregate report describing results and QC from the whole pipeline -- [Pipeline information](#pipeline-information) - Report metrics generated during the workflow execution - -### FastQC - -
-Output files - -- `fastqc/` - - `*_fastqc.html`: FastQC report containing quality metrics. - - `*_fastqc.zip`: Zip archive containing the FastQC report, tab-delimited data file and plot images. - -
- -[FastQC](http://www.bioinformatics.babraham.ac.uk/projects/fastqc/) gives general quality metrics about your sequenced reads. It provides information about the quality score distribution across your reads, per base sequence content (%A/T/G/C), adapter contamination and overrepresented sequences. For further reading and documentation see the [FastQC help pages](http://www.bioinformatics.babraham.ac.uk/projects/fastqc/Help/). - -![MultiQC - FastQC sequence counts plot](images/mqc_fastqc_counts.png) - -![MultiQC - FastQC mean quality scores plot](images/mqc_fastqc_quality.png) - -![MultiQC - FastQC adapter content plot](images/mqc_fastqc_adapter.png) - -:::note -The FastQC plots displayed in the MultiQC report shows _untrimmed_ reads. They may contain adapter sequence and potentially regions with low quality. -::: - -### MultiQC - -
-Output files - -- `multiqc/` - - `multiqc_report.html`: a standalone HTML file that can be viewed in your web browser. - - `multiqc_data/`: directory containing parsed statistics from the different tools used in the pipeline. - - `multiqc_plots/`: directory containing static images from the report in various formats. - -
- -[MultiQC](http://multiqc.info) is a visualization tool that generates a single HTML report summarising all samples in your project. Most of the pipeline QC results are visualised in the report and further statistics are available in the report data directory. - -Results generated by MultiQC collate pipeline QC from supported tools e.g. FastQC. The pipeline has special steps which also allow the software versions to be reported in the MultiQC output for future traceability. For more information about how to use MultiQC reports, see . - -### Pipeline information - -
-Output files - -- `pipeline_info/` - - Reports generated by Nextflow: `execution_report.html`, `execution_timeline.html`, `execution_trace.txt` and `pipeline_dag.dot`/`pipeline_dag.svg`. - - Reports generated by the pipeline: `pipeline_report.html`, `pipeline_report.txt` and `software_versions.yml`. The `pipeline_report*` files will only be present if the `--email` / `--email_on_fail` parameter's are used when running the pipeline. - - Reformatted samplesheet files used as input to the pipeline: `samplesheet.valid.csv`. - - Parameters used by the pipeline run: `params.json`. - -
- -[Nextflow](https://www.nextflow.io/docs/latest/tracing.html) provides excellent functionality for generating various reports relevant to the running and execution of the pipeline. This will allow you to troubleshoot errors with the running of the pipeline, and also provide you with other information such as launch commands, run times and resource usage. diff --git a/docs/usage.md b/docs/usage.md deleted file mode 100644 index 297a07b..0000000 --- a/docs/usage.md +++ /dev/null @@ -1,222 +0,0 @@ -# ebi-metagenomics/miassembler: Usage - -> _Documentation of pipeline parameters is generated automatically from the pipeline schema and can no longer be found in markdown files._ - -## Introduction - - - -## Samplesheet input - -You will need to create a samplesheet with information about the samples you would like to analyse before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row as shown in the examples below. - -```bash ---input '[path to samplesheet file]' -``` - -### Multiple runs of the same sample - -The `sample` identifiers have to be the same when you have re-sequenced the same sample more than once e.g. to increase sequencing depth. The pipeline will concatenate the raw reads before performing any downstream analysis. Below is an example for the same sample sequenced across 3 lanes: - -```csv title="samplesheet.csv" -sample,fastq_1,fastq_2 -CONTROL_REP1,AEG588A1_S1_L002_R1_001.fastq.gz,AEG588A1_S1_L002_R2_001.fastq.gz -CONTROL_REP1,AEG588A1_S1_L003_R1_001.fastq.gz,AEG588A1_S1_L003_R2_001.fastq.gz -CONTROL_REP1,AEG588A1_S1_L004_R1_001.fastq.gz,AEG588A1_S1_L004_R2_001.fastq.gz -``` - -### Full samplesheet - -The pipeline will auto-detect whether a sample is single- or paired-end using the information provided in the samplesheet. The samplesheet can have as many columns as you desire, however, there is a strict requirement for the first 3 columns to match those defined in the table below. - -A final samplesheet file consisting of both single- and paired-end data may look something like the one below. This is for 6 samples, where `TREATMENT_REP3` has been sequenced twice. - -```csv title="samplesheet.csv" -sample,fastq_1,fastq_2 -CONTROL_REP1,AEG588A1_S1_L002_R1_001.fastq.gz,AEG588A1_S1_L002_R2_001.fastq.gz -CONTROL_REP2,AEG588A2_S2_L002_R1_001.fastq.gz,AEG588A2_S2_L002_R2_001.fastq.gz -CONTROL_REP3,AEG588A3_S3_L002_R1_001.fastq.gz,AEG588A3_S3_L002_R2_001.fastq.gz -TREATMENT_REP1,AEG588A4_S4_L003_R1_001.fastq.gz, -TREATMENT_REP2,AEG588A5_S5_L003_R1_001.fastq.gz, -TREATMENT_REP3,AEG588A6_S6_L003_R1_001.fastq.gz, -TREATMENT_REP3,AEG588A6_S6_L004_R1_001.fastq.gz, -``` - -| Column | Description | -| --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `sample` | Custom sample name. This entry will be identical for multiple sequencing libraries/runs from the same sample. Spaces in sample names are automatically converted to underscores (`_`). | -| `fastq_1` | Full path to FastQ file for Illumina short reads 1. File has to be gzipped and have the extension ".fastq.gz" or ".fq.gz". | -| `fastq_2` | Full path to FastQ file for Illumina short reads 2. File has to be gzipped and have the extension ".fastq.gz" or ".fq.gz". | - -An [example samplesheet](../assets/samplesheet.csv) has been provided with the pipeline. - -## Running the pipeline - -The typical command for running the pipeline is as follows: - -```bash -nextflow run ebi-metagenomics/miassembler --input ./samplesheet.csv --outdir ./results --genome GRCh37 -profile docker -``` - -This will launch the pipeline with the `docker` configuration profile. See below for more information about profiles. - -Note that the pipeline will create the following files in your working directory: - -```bash -work # Directory containing the nextflow working files - # Finished results in specified location (defined with --outdir) -.nextflow_log # Log file from Nextflow -# Other nextflow hidden files, eg. history of pipeline runs and old logs. -``` - -If you wish to repeatedly use the same parameters for multiple runs, rather than specifying each flag in the command, you can specify these in a params file. - -Pipeline settings can be provided in a `yaml` or `json` file via `-params-file `. - -:::warning -Do not use `-c ` to specify parameters as this will result in errors. Custom config files specified with `-c` must only be used for [tuning process resource specifications](https://nf-co.re/docs/usage/configuration#tuning-workflow-resources), other infrastructural tweaks (such as output directories), or module arguments (args). -::: - -The above pipeline run specified with a params file in yaml format: - -```bash -nextflow run ebi-metagenomics/miassembler -profile docker -params-file params.yaml -``` - -with `params.yaml` containing: - -```yaml -input: './samplesheet.csv' -outdir: './results/' -genome: 'GRCh37' -<...> -``` - -You can also generate such `YAML`/`JSON` files via [nf-core/launch](https://nf-co.re/launch). - -### Updating the pipeline - -When you run the above command, Nextflow automatically pulls the pipeline code from GitHub and stores it as a cached version. When running the pipeline after this, it will always use the cached version if available - even if the pipeline has been updated since. To make sure that you're running the latest version of the pipeline, make sure that you regularly update the cached version of the pipeline: - -```bash -nextflow pull ebi-metagenomics/miassembler -``` - -### Reproducibility - -It is a good idea to specify a pipeline version when running the pipeline on your data. This ensures that a specific version of the pipeline code and software are used when you run your pipeline. If you keep using the same tag, you'll be running the same version of the pipeline, even if there have been changes to the code since. - -First, go to the [ebi-metagenomics/miassembler releases page](https://github.com/ebi-metagenomics/miassembler/releases) and find the latest pipeline version - numeric only (eg. `1.3.1`). Then specify this when running the pipeline with `-r` (one hyphen) - eg. `-r 1.3.1`. Of course, you can switch to another version by changing the number after the `-r` flag. - -This version number will be logged in reports when you run the pipeline, so that you'll know what you used when you look back in the future. For example, at the bottom of the MultiQC reports. - -To further assist in reproducbility, you can use share and re-use [parameter files](#running-the-pipeline) to repeat pipeline runs with the same settings without having to write out a command with every single parameter. - -:::tip -If you wish to share such profile (such as upload as supplementary material for academic publications), make sure to NOT include cluster specific paths to files, nor institutional specific profiles. -::: - -## Core Nextflow arguments - -:::note -These options are part of Nextflow and use a _single_ hyphen (pipeline parameters use a double-hyphen). -::: - -### `-profile` - -Use this parameter to choose a configuration profile. Profiles can give configuration presets for different compute environments. - -Several generic profiles are bundled with the pipeline which instruct the pipeline to use software packaged using different methods (Docker, Singularity, Podman, Shifter, Charliecloud, Apptainer, Conda) - see below. - -:::info -We highly recommend the use of Docker or Singularity containers for full pipeline reproducibility, however when this is not possible, Conda is also supported. -::: - -The pipeline also dynamically loads configurations from [https://github.com/nf-core/configs](https://github.com/nf-core/configs) when it runs, making multiple config profiles for various institutional clusters available at run time. For more information and to see if your system is available in these configs please see the [nf-core/configs documentation](https://github.com/nf-core/configs#documentation). - -Note that multiple profiles can be loaded, for example: `-profile test,docker` - the order of arguments is important! -They are loaded in sequence, so later profiles can overwrite earlier profiles. - -If `-profile` is not specified, the pipeline will run locally and expect all software to be installed and available on the `PATH`. This is _not_ recommended, since it can lead to different results on different machines dependent on the computer enviroment. - -- `test` - - A profile with a complete configuration for automated testing - - Includes links to test data so needs no other parameters -- `docker` - - A generic configuration profile to be used with [Docker](https://docker.com/) -- `singularity` - - A generic configuration profile to be used with [Singularity](https://sylabs.io/docs/) -- `podman` - - A generic configuration profile to be used with [Podman](https://podman.io/) -- `shifter` - - A generic configuration profile to be used with [Shifter](https://nersc.gitlab.io/development/shifter/how-to-use/) -- `charliecloud` - - A generic configuration profile to be used with [Charliecloud](https://hpc.github.io/charliecloud/) -- `apptainer` - - A generic configuration profile to be used with [Apptainer](https://apptainer.org/) -- `conda` - - A generic configuration profile to be used with [Conda](https://conda.io/docs/). Please only use Conda as a last resort i.e. when it's not possible to run the pipeline with Docker, Singularity, Podman, Shifter, Charliecloud, or Apptainer. - -### `-resume` - -Specify this when restarting a pipeline. Nextflow will use cached results from any pipeline steps where the inputs are the same, continuing from where it got to previously. For input to be considered the same, not only the names must be identical but the files' contents as well. For more info about this parameter, see [this blog post](https://www.nextflow.io/blog/2019/demystifying-nextflow-resume.html). - -You can also supply a run name to resume a specific run: `-resume [run-name]`. Use the `nextflow log` command to show previous run names. - -### `-c` - -Specify the path to a specific config file (this is a core Nextflow command). See the [nf-core website documentation](https://nf-co.re/usage/configuration) for more information. - -## Custom configuration - -### Resource requests - -Whilst the default requirements set within the pipeline will hopefully work for most people and with most input data, you may find that you want to customise the compute resources that the pipeline requests. Each step in the pipeline has a default set of requirements for number of CPUs, memory and time. For most of the steps in the pipeline, if the job exits with any of the error codes specified [here](https://github.com/nf-core/rnaseq/blob/4c27ef5610c87db00c3c5a3eed10b1d161abf575/conf/base.config#L18) it will automatically be resubmitted with higher requests (2 x original, then 3 x original). If it still fails after the third attempt then the pipeline execution is stopped. - -To change the resource requests, please see the [max resources](https://nf-co.re/docs/usage/configuration#max-resources) and [tuning workflow resources](https://nf-co.re/docs/usage/configuration#tuning-workflow-resources) section of the nf-core website. - -### Custom Containers - -In some cases you may wish to change which container or conda environment a step of the pipeline uses for a particular tool. By default nf-core pipelines use containers and software from the [biocontainers](https://biocontainers.pro/) or [bioconda](https://bioconda.github.io/) projects. However in some cases the pipeline specified version maybe out of date. - -To use a different container from the default container or conda environment specified in a pipeline, please see the [updating tool versions](https://nf-co.re/docs/usage/configuration#updating-tool-versions) section of the nf-core website. - -### Custom Tool Arguments - -A pipeline might not always support every possible argument or option of a particular tool used in pipeline. Fortunately, nf-core pipelines provide some freedom to users to insert additional parameters that the pipeline does not include by default. - -To learn how to provide additional arguments to a particular tool of the pipeline, please see the [customising tool arguments](https://nf-co.re/docs/usage/configuration#customising-tool-arguments) section of the nf-core website. - -### nf-core/configs - -In most cases, you will only need to create a custom config as a one-off but if you and others within your organisation are likely to be running nf-core pipelines regularly and need to use the same settings regularly it may be a good idea to request that your custom config file is uploaded to the `nf-core/configs` git repository. Before you do this please can you test that the config file works with your pipeline of choice using the `-c` parameter. You can then create a pull request to the `nf-core/configs` repository with the addition of your config file, associated documentation file (see examples in [`nf-core/configs/docs`](https://github.com/nf-core/configs/tree/master/docs)), and amending [`nfcore_custom.config`](https://github.com/nf-core/configs/blob/master/nfcore_custom.config) to include your custom profile. - -See the main [Nextflow documentation](https://www.nextflow.io/docs/latest/config.html) for more information about creating your own configuration files. - -If you have any questions or issues please send us a message on [Slack](https://nf-co.re/join/slack) on the [`#configs` channel](https://nfcore.slack.com/channels/configs). - -## Azure Resource Requests - -To be used with the `azurebatch` profile by specifying the `-profile azurebatch`. -We recommend providing a compute `params.vm_type` of `Standard_D16_v3` VMs by default but these options can be changed if required. - -Note that the choice of VM size depends on your quota and the overall workload during the analysis. -For a thorough list, please refer the [Azure Sizes for virtual machines in Azure](https://docs.microsoft.com/en-us/azure/virtual-machines/sizes). - -## Running in the background - -Nextflow handles job submissions and supervises the running jobs. The Nextflow process must run until the pipeline is finished. - -The Nextflow `-bg` flag launches Nextflow in the background, detached from your terminal so that the workflow does not stop if you log out of your session. The logs are saved to a file. - -Alternatively, you can use `screen` / `tmux` or similar tool to create a detached session which you can log back into at a later time. -Some HPC setups also allow you to run nextflow within a cluster job submitted your job scheduler (from where it submits more jobs). - -## Nextflow memory requirements - -In some cases, the Nextflow Java virtual machines can start to request a large amount of memory. -We recommend adding the following line to your environment to limit this (typically in `~/.bashrc` or `~./bash_profile`): - -```bash -NXF_OPTS='-Xms1g -Xmx4g' -``` diff --git a/main.nf b/main.nf index fd18121..e578af4 100644 --- a/main.nf +++ b/main.nf @@ -15,7 +15,7 @@ nextflow.enable.dsl = 2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -include { validateParameters; paramsHelp; paramsSummaryLog; paramsSummaryMap; } from 'plugin/nf-validation' +include { validateParameters; paramsHelp; paramsSummaryLog; paramsSummaryMap; } from 'plugin/nf-schema' def summary_params = paramsSummaryMap(workflow) diff --git a/modules.json b/modules.json index 3729bba..2deaa91 100644 --- a/modules.json +++ b/modules.json @@ -2,7 +2,7 @@ "name": "ebi-metagenomics/miassembler", "homePage": "https://github.com/ebi-metagenomics/miassembler", "repos": { - "git@github.com:EBI-Metagenomics/nf-modules.git": { + "https://github.com/EBI-Metagenomics/nf-modules": { "modules": { "ebi-metagenomics": { "bwamem2/mem": { @@ -13,7 +13,8 @@ "samtools/bam2fq": { "branch": "main", "git_sha": "88f2bfbe6f0ba858d0833db590e647c4678656a7", - "installed_by": ["reads_bwamem2_decontamination"] + "installed_by": ["reads_bwamem2_decontamination"], + "patch": "modules/ebi-metagenomics/samtools/bam2fq/samtools-bam2fq.diff" } } }, @@ -58,12 +59,14 @@ "fastqc": { "branch": "master", "git_sha": "65ad3e0b9a4099592e1102e92e10455dc661cf53", - "installed_by": ["modules"] + "installed_by": ["modules"], + "patch": "modules/nf-core/fastqc/fastqc.diff" }, "megahit": { "branch": "master", "git_sha": "3f5420aa22e00bd030a2556dfdffc9e164ec0ec5", - "installed_by": ["modules"] + "installed_by": ["modules"], + "patch": "modules/nf-core/megahit/megahit.diff" }, "metabat2/jgisummarizebamcontigdepths": { "branch": "master", @@ -73,7 +76,8 @@ "multiqc": { "branch": "master", "git_sha": "4ab13872435962dadc239979554d13709e20bf29", - "installed_by": ["modules"] + "installed_by": ["modules"], + "patch": "modules/nf-core/multiqc/multiqc.diff" }, "quast": { "branch": "master", diff --git a/modules/ebi-metagenomics/bwamem2/mem/environment.yml b/modules/ebi-metagenomics/bwamem2/mem/environment.yml index cbf06d3..31db06a 100644 --- a/modules/ebi-metagenomics/bwamem2/mem/environment.yml +++ b/modules/ebi-metagenomics/bwamem2/mem/environment.yml @@ -1,10 +1,11 @@ name: bwamem2_mem + channels: - conda-forge - bioconda - defaults + dependencies: - bwa-mem2=2.2.1 - # renovate: datasource=conda depName=bioconda/samtools - - samtools=1.19.2 - htslib=1.19.1 + - samtools=1.19.2 diff --git a/modules/ebi-metagenomics/samtools/bam2fq/samtools-bam2fq.diff b/modules/ebi-metagenomics/samtools/bam2fq/samtools-bam2fq.diff new file mode 100644 index 0000000..98dfd92 --- /dev/null +++ b/modules/ebi-metagenomics/samtools/bam2fq/samtools-bam2fq.diff @@ -0,0 +1,14 @@ +Changes in module 'ebi-metagenomics/samtools/bam2fq' +--- modules/ebi-metagenomics/samtools/bam2fq/main.nf ++++ modules/ebi-metagenomics/samtools/bam2fq/main.nf +@@ -21,7 +21,7 @@ + + script: + def args = task.ext.args ?: '' +- def prefix = task.ext.prefix ?: "${meta.id}" ++ def prefix = task.ext.prefix ? "${task.ext.prefix}_${meta.id}": "${meta.id}" + + if (split) { + """ + +************************************************************ diff --git a/modules/local/publish_decontaminated.nf b/modules/local/publish_decontaminated.nf new file mode 100644 index 0000000..c57383b --- /dev/null +++ b/modules/local/publish_decontaminated.nf @@ -0,0 +1,13 @@ +process PUBLISH_DECONTAMINATED { + + input: + tuple val(meta), path(decontaminated_contigs) + + output: + path("${meta.id}_decontaminated_contigs.txt") + + script: + """ + mv ${decontaminated_contigs} ${meta.id}_decontaminated_contigs.txt + """ +} diff --git a/modules/local/publish_file.nf b/modules/local/publish_file.nf deleted file mode 100644 index 076854d..0000000 --- a/modules/local/publish_file.nf +++ /dev/null @@ -1,16 +0,0 @@ -process PUBLISH_FILE { - - publishDir( - path: "${params.outdir}/$output_dir", - mode: params.publish_dir_mode - ) - - input: - path(contigs) - val(output_dir) - - script: - """ - echo "$output_dir" - """ -} diff --git a/modules/nf-core/bwamem2/mem/environment.yml b/modules/nf-core/bwamem2/mem/environment.yml new file mode 100644 index 0000000..227d869 --- /dev/null +++ b/modules/nf-core/bwamem2/mem/environment.yml @@ -0,0 +1,9 @@ +name: bwamem2_mem +channels: + - conda-forge + - bioconda + - defaults +dependencies: + - bwa-mem2=2.2.1 + # renovate: datasource=conda depName=bioconda/samtools + - samtools=1.18 diff --git a/modules/nf-core/bwamem2/mem/main.nf b/modules/nf-core/bwamem2/mem/main.nf new file mode 100644 index 0000000..b3874fc --- /dev/null +++ b/modules/nf-core/bwamem2/mem/main.nf @@ -0,0 +1,55 @@ +process BWAMEM2_MEM { + tag "$meta.id" + label 'process_high' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/mulled-v2-e5d375990341c5aef3c9aff74f96f66f65375ef6:6351200f24497efba12c219c2bea4bb0f69a9d47-0' : + 'biocontainers/mulled-v2-e5d375990341c5aef3c9aff74f96f66f65375ef6:6351200f24497efba12c219c2bea4bb0f69a9d47-0' }" + + input: + tuple val(meta), path(reads) + tuple val(meta2), path(index) + val sort_bam + + output: + tuple val(meta), path("*.bam"), emit: bam + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def args2 = task.ext.args2 ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def samtools_command = sort_bam ? 'sort' : 'view' + """ + INDEX=`find -L ./ -name "*.amb" | sed 's/\\.amb\$//'` + + bwa-mem2 \\ + mem \\ + $args \\ + -t $task.cpus \\ + \$INDEX \\ + $reads \\ + | samtools $samtools_command $args2 -@ $task.cpus -o ${prefix}.bam - + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + bwamem2: \$(echo \$(bwa-mem2 version 2>&1) | sed 's/.* //') + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + """ + touch ${prefix}.bam + cat <<-END_VERSIONS > versions.yml + "${task.process}": + bwamem2: \$(echo \$(bwa-mem2 version 2>&1) | sed 's/.* //') + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/bwamem2/mem/meta.yml b/modules/nf-core/bwamem2/mem/meta.yml new file mode 100644 index 0000000..04891b2 --- /dev/null +++ b/modules/nf-core/bwamem2/mem/meta.yml @@ -0,0 +1,61 @@ +name: bwamem2_mem +description: Performs fastq alignment to a fasta reference using BWA +keywords: + - mem + - bwa + - alignment + - map + - fastq + - bam + - sam +tools: + - bwa: + description: | + BWA-mem2 is a software package for mapping DNA sequences against + a large reference genome, such as the human genome. + homepage: https://github.com/bwa-mem2/bwa-mem2 + documentation: http://www.htslib.org/doc/samtools.html + arxiv: arXiv:1303.3997 + licence: ["MIT"] +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: | + List of input FastQ files of size 1 and 2 for single-end and paired-end data, + respectively. + - meta2: + type: map + description: | + Groovy Map containing reference/index information + e.g. [ id:'test' ] + - index: + type: file + description: BWA genome index files + pattern: "Directory containing BWA index *.{0132,amb,ann,bwt.2bit.64,pac}" + - sort_bam: + type: boolean + description: use samtools sort (true) or samtools view (false) + pattern: "true or false" +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: Output BAM file containing read alignments + pattern: "*.{bam}" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" +authors: + - "@maxulysse" +maintainers: + - "@maxulysse" diff --git a/modules/nf-core/bwamem2/mem/tests/main.nf.test b/modules/nf-core/bwamem2/mem/tests/main.nf.test new file mode 100644 index 0000000..d791206 --- /dev/null +++ b/modules/nf-core/bwamem2/mem/tests/main.nf.test @@ -0,0 +1,213 @@ +nextflow_process { + + name "Test Process BWAMEM2_MEM" + script "../main.nf" + process "BWAMEM2_MEM" + + tag "modules" + tag "modules_nfcore" + tag "bwamem2" + tag "bwamem2/mem" + + test("sarscov2 - fastq, index, false") { + + setup { + run("BWAMEM2_INDEX") { + script "../../index/main.nf" + process { + """ + input[0] = [ [:], file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + """ + } + } + } + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:true ], // meta map + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) + ] + input[1] = BWAMEM2_INDEX.out.index + input[2] = false + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + file(process.out.bam[0][1]).name, + process.out.versions + ).match() } + ) + } + + } + + test("sarscov2 - fastq, index, true") { + + setup { + run("BWAMEM2_INDEX") { + script "../../index/main.nf" + process { + """ + input[0] = [ [:], file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + """ + } + } + } + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:true ], // meta map + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) + ] + input[1] = BWAMEM2_INDEX.out.index + input[2] = true + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + file(process.out.bam[0][1]).name, + process.out.versions + ).match() } + ) + } + + } + + test("sarscov2 - [fastq1, fastq2], index, false") { + + setup { + run("BWAMEM2_INDEX") { + script "../../index/main.nf" + process { + """ + input[0] = [ [:], file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + """ + } + } + } + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + [ + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) + ] + ] + input[1] = BWAMEM2_INDEX.out.index + input[2] = false + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + file(process.out.bam[0][1]).name, + process.out.versions + ).match() } + ) + } + + } + + test("sarscov2 - [fastq1, fastq2], index, true") { + + setup { + run("BWAMEM2_INDEX") { + script "../../index/main.nf" + process { + """ + input[0] = [ [:], file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + """ + } + } + } + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + [ + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) + ] + ] + input[1] = BWAMEM2_INDEX.out.index + input[2] = true + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + file(process.out.bam[0][1]).name, + process.out.versions + ).match() } + ) + } + + } + + test("sarscov2 - [fastq1, fastq2], index, true - stub") { + + options "-stub" + + setup { + run("BWAMEM2_INDEX") { + script "../../index/main.nf" + process { + """ + input[0] = [ [:], file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + """ + } + } + } + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + [ + file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) + ] + ] + input[1] = BWAMEM2_INDEX.out.index + input[2] = true + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + file(process.out.bam[0][1]).name, + process.out.versions + ).match() } + ) + } + + } + +} diff --git a/modules/nf-core/bwamem2/mem/tests/main.nf.test.snap b/modules/nf-core/bwamem2/mem/tests/main.nf.test.snap new file mode 100644 index 0000000..db7dd39 --- /dev/null +++ b/modules/nf-core/bwamem2/mem/tests/main.nf.test.snap @@ -0,0 +1,47 @@ +{ + "sarscov2 - [fastq1, fastq2], index, true": { + "content": [ + "test.bam", + [ + "versions.yml:md5,f653bf29c6597481cd0345bd66aafd8a" + ] + ], + "timestamp": "2023-12-04T11:49:07.89544697" + }, + "sarscov2 - [fastq1, fastq2], index, false": { + "content": [ + "test.bam", + [ + "versions.yml:md5,f653bf29c6597481cd0345bd66aafd8a" + ] + ], + "timestamp": "2023-12-04T11:48:56.319355195" + }, + "sarscov2 - [fastq1, fastq2], index, true - stub": { + "content": [ + "test.bam", + [ + "versions.yml:md5,f653bf29c6597481cd0345bd66aafd8a" + ] + ], + "timestamp": "2023-12-04T11:49:17.499101941" + }, + "sarscov2 - fastq, index, false": { + "content": [ + "test.bam", + [ + "versions.yml:md5,f653bf29c6597481cd0345bd66aafd8a" + ] + ], + "timestamp": "2023-12-04T11:48:31.351628851" + }, + "sarscov2 - fastq, index, true": { + "content": [ + "test.bam", + [ + "versions.yml:md5,f653bf29c6597481cd0345bd66aafd8a" + ] + ], + "timestamp": "2023-12-04T11:48:43.978452504" + } +} \ No newline at end of file diff --git a/modules/nf-core/bwamem2/mem/tests/tags.yml b/modules/nf-core/bwamem2/mem/tests/tags.yml new file mode 100644 index 0000000..134efb2 --- /dev/null +++ b/modules/nf-core/bwamem2/mem/tests/tags.yml @@ -0,0 +1,2 @@ +bwamem2/mem: + - "modules/nf-core/bwamem2/mem/**" diff --git a/modules/nf-core/fastqc/fastqc.diff b/modules/nf-core/fastqc/fastqc.diff new file mode 100644 index 0000000..0dd7d4d --- /dev/null +++ b/modules/nf-core/fastqc/fastqc.diff @@ -0,0 +1,27 @@ +Changes in module 'nf-core/fastqc' +--- modules/nf-core/fastqc/main.nf ++++ modules/nf-core/fastqc/main.nf +@@ -21,19 +21,12 @@ + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" +- // Make list of old name and new name pairs to use for renaming in the bash while loop +- def old_new_pairs = reads instanceof Path || reads.size() == 1 ? [[ reads, "${prefix}.${reads.extension}" ]] : reads.withIndex().collect { entry, index -> [ entry, "${prefix}_${index + 1}.${entry.extension}" ] } +- def rename_to = old_new_pairs*.join(' ').join(' ') +- def renamed_files = old_new_pairs.collect{ old_name, new_name -> new_name }.join(' ') ++ + """ +- printf "%s %s\\n" $rename_to | while read old_name new_name; do +- [ -f "\${new_name}" ] || ln -s \$old_name \$new_name +- done +- + fastqc \\ + $args \\ + --threads $task.cpus \\ +- $renamed_files ++ $reads + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + +************************************************************ diff --git a/modules/nf-core/megahit/main.nf b/modules/nf-core/megahit/main.nf index 678fe2e..2620f26 100644 --- a/modules/nf-core/megahit/main.nf +++ b/modules/nf-core/megahit/main.nf @@ -7,21 +7,6 @@ process MEGAHIT { 'https://depot.galaxyproject.org/singularity/mulled-v2-0f92c152b180c7cd39d9b0e6822f8c89ccb59c99:8ec213d21e5d03f9db54898a2baeaf8ec729b447-0' : 'biocontainers/mulled-v2-0f92c152b180c7cd39d9b0e6822f8c89ccb59c99:8ec213d21e5d03f9db54898a2baeaf8ec729b447-0' }" - publishDir( - path: "${params.outdir}", - mode: params.publish_dir_mode, - failOnError: true, - pattern: "megahit_out/*.fa*.gz", - saveAs: { - filename -> { - def output_file = new File(filename); - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/assembly/${meta.assembler}/${meta.assembler_version}/${output_file.name}"; - } - } - ) - input: tuple val(meta), path(reads) diff --git a/modules/nf-core/megahit/megahit.diff b/modules/nf-core/megahit/megahit.diff new file mode 100644 index 0000000..fd26771 --- /dev/null +++ b/modules/nf-core/megahit/megahit.diff @@ -0,0 +1,34 @@ +Changes in module 'nf-core/megahit' +--- modules/nf-core/megahit/main.nf ++++ modules/nf-core/megahit/main.nf +@@ -25,12 +25,20 @@ + def args = task.ext.args ?: '' + def args2 = task.ext.args2 ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" ++ ++ def restart = "" ++ if (task.attempt > 1) { ++ // Set of extra flags to restart the assembly process ++ restart = "--continue" ++ } ++ + if (meta.single_end) { + """ + megahit \\ + -r ${reads} \\ + -t $task.cpus \\ + $args \\ ++ $restart \\ + --out-prefix $prefix + + pigz \\ +@@ -52,6 +60,7 @@ + -2 ${reads[1]} \\ + -t $task.cpus \\ + $args \\ ++ $restart \\ + --out-prefix $prefix + + pigz \\ + +************************************************************ diff --git a/modules/nf-core/metabat2/jgisummarizebamcontigdepths/main.nf b/modules/nf-core/metabat2/jgisummarizebamcontigdepths/main.nf index 7d4e49b..60b38e0 100644 --- a/modules/nf-core/metabat2/jgisummarizebamcontigdepths/main.nf +++ b/modules/nf-core/metabat2/jgisummarizebamcontigdepths/main.nf @@ -7,20 +7,6 @@ process METABAT2_JGISUMMARIZEBAMCONTIGDEPTHS { 'https://depot.galaxyproject.org/singularity/metabat2:2.15--h986a166_1' : 'biocontainers/metabat2:2.15--h986a166_1' }" - publishDir( - path: "${params.outdir}", - mode: params.publish_dir_mode, - pattern: "*.txt.gz", - saveAs: { - filename -> { - def output_file = new File(filename); - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/assembly/${meta.assembler}/${meta.assembler_version}/coverage/${output_file.name}"; - } - } - ) - input: tuple val(meta), path(bam), path(bai) diff --git a/modules/nf-core/multiqc/main.nf b/modules/nf-core/multiqc/main.nf index c0f2ca9..cda6ed2 100644 --- a/modules/nf-core/multiqc/main.nf +++ b/modules/nf-core/multiqc/main.nf @@ -6,23 +6,6 @@ process MULTIQC { 'https://depot.galaxyproject.org/singularity/multiqc:1.18--pyhdfd78af_0' : 'biocontainers/multiqc:1.18--pyhdfd78af_0' }" - publishDir( - path: "${params.outdir}", - mode: params.publish_dir_mode, - failOnError: true, - saveAs: { - filename -> { - if ( filename.equals('versions.yml') ) { - return null; - } - def output_file = new File(filename); - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/assembly/${meta.assembler}/${meta.assembler_version}/qc/multiqc/${output_file.name}"; - } - } - ) - input: path multiqc_files, stageAs: "?/*" path(multiqc_config) diff --git a/modules/nf-core/multiqc/multiqc.diff b/modules/nf-core/multiqc/multiqc.diff new file mode 100644 index 0000000..ca2d23d --- /dev/null +++ b/modules/nf-core/multiqc/multiqc.diff @@ -0,0 +1,13 @@ +Changes in module 'nf-core/multiqc' +--- modules/nf-core/multiqc/main.nf ++++ modules/nf-core/multiqc/main.nf +@@ -11,6 +11,7 @@ + path(multiqc_config) + path(extra_multiqc_config) + path(multiqc_logo) ++ val(meta) + + output: + path "*multiqc_report.html", emit: report + +************************************************************ diff --git a/modules/nf-core/quast/main.nf b/modules/nf-core/quast/main.nf index 0268a92..f69b97e 100644 --- a/modules/nf-core/quast/main.nf +++ b/modules/nf-core/quast/main.nf @@ -7,23 +7,6 @@ process QUAST { 'https://depot.galaxyproject.org/singularity/quast:5.2.0--py39pl5321h2add14b_1' : 'biocontainers/quast:5.2.0--py39pl5321h2add14b_1' }" - publishDir( - path: "${params.outdir}", - mode: params.publish_dir_mode, - failOnError: true, - saveAs: { - filename -> { - if ( filename.equals('versions.yml') ) { - return null; - } - def output_file = new File(filename); - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/assembly/${meta.assembler}/${meta.assembler_version}/qc/quast/${output_file.name}"; - } - } - ) - input: tuple val(meta) , path(consensus) tuple val(meta2), path(fasta) diff --git a/modules/nf-core/quast/quast.diff b/modules/nf-core/quast/quast.diff index a2b9c4f..316c163 100644 --- a/modules/nf-core/quast/quast.diff +++ b/modules/nf-core/quast/quast.diff @@ -1,6 +1,15 @@ Changes in module 'nf-core/quast' --- modules/nf-core/quast/main.nf +++ modules/nf-core/quast/main.nf +@@ -14,7 +14,7 @@ + + output: + tuple val(meta), path("${prefix}") , emit: results +- tuple val(meta), path("${prefix}.tsv") , emit: tsv ++ tuple val(meta), path("${prefix}.tsv") , optional: true , emit: tsv + tuple val(meta), path("${prefix}_transcriptome.tsv") , optional: true , emit: transcriptome + tuple val(meta), path("${prefix}_misassemblies.tsv") , optional: true , emit: misassemblies + tuple val(meta), path("${prefix}_unaligned.tsv") , optional: true , emit: unaligned @@ -29,7 +29,7 @@ def features = gff ? "--features $gff" : '' def reference = fasta ? "-r $fasta" : '' diff --git a/modules/nf-core/samtools/index/environment.yml b/modules/nf-core/samtools/index/environment.yml new file mode 100644 index 0000000..296ed99 --- /dev/null +++ b/modules/nf-core/samtools/index/environment.yml @@ -0,0 +1,7 @@ +name: samtools_index +channels: + - conda-forge + - bioconda + - defaults +dependencies: + - bioconda::samtools=1.18 diff --git a/modules/nf-core/samtools/index/main.nf b/modules/nf-core/samtools/index/main.nf new file mode 100644 index 0000000..8ad18fd --- /dev/null +++ b/modules/nf-core/samtools/index/main.nf @@ -0,0 +1,48 @@ +process SAMTOOLS_INDEX { + tag "$meta.id" + label 'process_low' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/samtools:1.18--h50ea8bc_1' : + 'biocontainers/samtools:1.18--h50ea8bc_1' }" + + input: + tuple val(meta), path(input) + + output: + tuple val(meta), path("*.bai") , optional:true, emit: bai + tuple val(meta), path("*.csi") , optional:true, emit: csi + tuple val(meta), path("*.crai"), optional:true, emit: crai + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + """ + samtools \\ + index \\ + -@ ${task.cpus-1} \\ + $args \\ + $input + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ + + stub: + """ + touch ${input}.bai + touch ${input}.crai + touch ${input}.csi + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/samtools/index/meta.yml b/modules/nf-core/samtools/index/meta.yml new file mode 100644 index 0000000..01a4ee0 --- /dev/null +++ b/modules/nf-core/samtools/index/meta.yml @@ -0,0 +1,57 @@ +name: samtools_index +description: Index SAM/BAM/CRAM file +keywords: + - index + - bam + - sam + - cram +tools: + - samtools: + description: | + SAMtools is a set of utilities for interacting with and post-processing + short DNA sequence read alignments in the SAM, BAM and CRAM formats, written by Heng Li. + These files are generated as output by short read aligners like BWA. + homepage: http://www.htslib.org/ + documentation: http://www.htslib.org/doc/samtools.html + doi: 10.1093/bioinformatics/btp352 + licence: ["MIT"] +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM/CRAM/SAM file + pattern: "*.{bam,cram,sam}" +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bai: + type: file + description: BAM/CRAM/SAM index file + pattern: "*.{bai,crai,sai}" + - crai: + type: file + description: BAM/CRAM/SAM index file + pattern: "*.{bai,crai,sai}" + - csi: + type: file + description: CSI index file + pattern: "*.{csi}" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" +authors: + - "@drpatelh" + - "@ewels" + - "@maxulysse" +maintainers: + - "@drpatelh" + - "@ewels" + - "@maxulysse" diff --git a/modules/nf-core/samtools/index/tests/csi.nextflow.config b/modules/nf-core/samtools/index/tests/csi.nextflow.config new file mode 100644 index 0000000..0ed260e --- /dev/null +++ b/modules/nf-core/samtools/index/tests/csi.nextflow.config @@ -0,0 +1,7 @@ +process { + + withName: SAMTOOLS_INDEX { + ext.args = '-c' + } + +} diff --git a/modules/nf-core/samtools/index/tests/main.nf.test b/modules/nf-core/samtools/index/tests/main.nf.test new file mode 100644 index 0000000..c76a916 --- /dev/null +++ b/modules/nf-core/samtools/index/tests/main.nf.test @@ -0,0 +1,87 @@ +nextflow_process { + + name "Test Process SAMTOOLS_INDEX" + script "../main.nf" + process "SAMTOOLS_INDEX" + tag "modules" + tag "modules_nfcore" + tag "samtools" + tag "samtools/index" + + test("sarscov2 [BAI]") { + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = [ + [ id:'test' ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) + ] + """ + } + } + + then { + assertAll ( + { assert process.success }, + { assert snapshot(process.out.bai).match("bai") }, + { assert path(process.out.versions.get(0)).getText().contains("samtools") } + ) + } + } + + test("homo_sapiens [CRAI]") { + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = [ + [ id:'test' ], // meta map + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_recalibrated_sorted_cram'], checkIfExists: true) + ] + """ + } + } + + then { + assertAll ( + { assert process.success }, + { assert snapshot(process.out.crai).match("crai") }, + { assert path(process.out.versions.get(0)).getText().contains("samtools") } + ) + } + } + + test("homo_sapiens [CSI]") { + + config "./csi.nextflow.config" + + when { + params { + outdir = "$outputDir" + } + process { + """ + input[0] = [ + [ id:'test' ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true) + ] + """ + } + } + + then { + assertAll ( + { assert process.success }, + { assert path(process.out.csi.get(0).get(1)).exists() }, + { assert path(process.out.versions.get(0)).getText().contains("samtools") } + ) + } + } +} diff --git a/modules/nf-core/samtools/index/tests/main.nf.test.snap b/modules/nf-core/samtools/index/tests/main.nf.test.snap new file mode 100644 index 0000000..b3baee7 --- /dev/null +++ b/modules/nf-core/samtools/index/tests/main.nf.test.snap @@ -0,0 +1,28 @@ +{ + "crai": { + "content": [ + [ + [ + { + "id": "test" + }, + "test.paired_end.recalibrated.sorted.cram.crai:md5,14bc3bd5c89cacc8f4541f9062429029" + ] + ] + ], + "timestamp": "2023-11-15T15:17:37.30801" + }, + "bai": { + "content": [ + [ + [ + { + "id": "test" + }, + "test.paired_end.sorted.bam.bai:md5,704c10dd1326482448ca3073fdebc2f4" + ] + ] + ], + "timestamp": "2023-11-15T15:17:30.869234" + } +} \ No newline at end of file diff --git a/modules/nf-core/samtools/index/tests/tags.yml b/modules/nf-core/samtools/index/tests/tags.yml new file mode 100644 index 0000000..e0f58a7 --- /dev/null +++ b/modules/nf-core/samtools/index/tests/tags.yml @@ -0,0 +1,2 @@ +samtools/index: + - modules/nf-core/samtools/index/** diff --git a/modules/nf-core/spades/main.nf b/modules/nf-core/spades/main.nf index d2bd56e..a94542d 100644 --- a/modules/nf-core/spades/main.nf +++ b/modules/nf-core/spades/main.nf @@ -6,33 +6,6 @@ process SPADES { 'https://depot.galaxyproject.org/singularity/spades:3.15.5--h95f258a_1' : 'biocontainers/spades:3.15.5--h95f258a_1' }" - publishDir( - path: "${params.outdir}", - mode: params.publish_dir_mode, - failOnError: true, - saveAs: { - filename -> { - if ( filename.equals('versions.yml') ) { - return null; - } - def studyAccessionPrefix = params.study_accession.substring(0, 7); - def readsAccessionPrefix = params.reads_accession.substring(0, 7); - def file_patterns_to_publish = [ - 'params.txt', - 'graph.fastg', - 'contigs.fa.gz', - 'scaffolds.fa.gz', - 'graph_with_scaffolds.gfa.gz' - ] - def output_file = new File(filename); - if ( file_patterns_to_publish.any { output_file.name.contains(it) } ) { - return "${studyAccessionPrefix}/${params.study_accession}/${readsAccessionPrefix}/${params.reads_accession}/assembly/${meta.assembler}/${meta.assembler_version}/${output_file.name}"; - } - return null; - } - } - ) - input: tuple val(meta), path(illumina), path(pacbio), path(nanopore) val(metaspades) diff --git a/nextflow.config b/nextflow.config index 53769a3..5ba3d07 100644 --- a/nextflow.config +++ b/nextflow.config @@ -15,7 +15,11 @@ params { private_study = false /* - * Assembler options: + * Assembler options, by default the pipeline will pick + * - metaspades for pair-end + * - megahit for single-end + * + * Setting --assembler will force the assembler * * - spades: Use for assembling single end reads * @@ -27,20 +31,20 @@ params { * - Memory >1TB * - Runtime >3-4 days */ - assembler = "metaspades" + assembler = null // Reference genome reference_genome = null remove_human_phix = true - human_phix_blast_index_name = null - human_phix_bwamem2_index_name = null + human_phix_blast_index_name = "human_phix" + human_phix_bwamem2_index_name = "human_phix" bwamem2_reference_genomes_folder = "" blast_reference_genomes_folder = "" // Assembly options - spades_only_assembler = null + spades_only_assembler = true min_contig_length = 500 assembly_memory = 100 @@ -52,7 +56,7 @@ params { multiqc_methods_description = null // Boilerplate options - outdir = null + outdir = "results" publish_dir_mode = 'copy' email = null email_on_fail = null @@ -68,18 +72,18 @@ params { max_cpus = 32 max_time = '168.h' // 7 days - // Schema validation default options - validationFailUnrecognisedParams = false - validationLenientMode = false - validationShowHiddenParams = false - validate_params = true - // Assembler versions spades_version = "3.15.5" megahit_version = "1.2.9" } +validation { + failUnrecognisedParams = true + lenientMode = false + showHiddenParams = false +} + // Load base.config by default for all pipelines includeConfig 'conf/base.config' @@ -188,7 +192,7 @@ singularity.registry = 'quay.io' // Nextflow plugins plugins { - id 'nf-validation@1.1.3' // Validation of pipeline parameters and creation of an input channel from a sample sheet + id 'nf-schema@2.0.0' } // Export these variables to prevent local Python/R libraries from conflicting with those in the container @@ -240,6 +244,16 @@ manifest { // Load modules.config for DSL2 module specific options includeConfig 'conf/modules.config' +// Function to return study / reads folder SRPXXX/SRPXXXXXX/SRRYYYY/SRRYYYYYY +def study_reads_folder() { + return [ + "${params.study_accession.substring(0, 7)}", + "${params.study_accession}", + "${params.reads_accession.substring(0, 7)}", + "${params.reads_accession}", + ].join("/") +} + // Function to ensure that resource requirements don't go beyond // a maximum limit def check_max(obj, type) { diff --git a/nextflow_schema.json b/nextflow_schema.json index 09f6a5f..cc6bc51 100644 --- a/nextflow_schema.json +++ b/nextflow_schema.json @@ -1,10 +1,10 @@ { - "$schema": "http://json-schema.org/draft-07/schema", + "$schema": "https://json-schema.org/draft/2020-12/schema", "$id": "https://raw.githubusercontent.com/ebi-metagenomics/miassembler/master/nextflow_schema.json", "title": "ebi-metagenomics/miassembler pipeline parameters", "description": "Microbiome Informatics metagenomes assembly pipeline", "type": "object", - "definitions": { + "defs": { "input_output_options": { "title": "Input/output options", "type": "object", @@ -13,7 +13,6 @@ "required": [ "study_accession", "reads_accession", - "assembler", "blast_reference_genomes_folder", "bwamem2_reference_genomes_folder", "outdir", @@ -33,15 +32,21 @@ }, "private_study": { "type": "boolean", - "description": "To use if the ENA study is private", - "default": false + "description": "To use if the ENA study is private" }, "assembler": { "type": "string", - "default": "metaspades", "enum": ["spades", "metaspades", "megahit"], "description": "The short reads assembler" }, + "spades_version": { + "type": "string", + "default": "3.15.5" + }, + "megahit_version": { + "type": "string", + "default": "1.2.9" + }, "reference_genome": { "type": "string", "description": "The genome to be used to clean the assembly, the genome will be taken from the Microbiome Informatics internal directory", @@ -104,7 +109,8 @@ "type": "string", "format": "directory-path", "description": "The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.", - "fa_icon": "fas fa-folder-open" + "fa_icon": "fas fa-folder-open", + "default": "results" }, "email": { "type": "string", @@ -235,47 +241,19 @@ "type": "string", "description": "Custom MultiQC yaml file containing HTML including a methods description.", "fa_icon": "fas fa-cog" - }, - "validate_params": { - "type": "boolean", - "description": "Boolean whether to validate parameters against the schema at runtime", - "default": true, - "fa_icon": "fas fa-check-square", - "hidden": true - }, - "validationShowHiddenParams": { - "type": "boolean", - "fa_icon": "far fa-eye-slash", - "description": "Show all params when using `--help`", - "hidden": true, - "help_text": "By default, parameters set as _hidden_ in the schema are not shown on the command line when a user runs with `--help`. Specifying this option will tell the pipeline to show all parameters." - }, - "validationFailUnrecognisedParams": { - "type": "boolean", - "fa_icon": "far fa-check-circle", - "description": "Validation of parameters fails when an unrecognised parameter is found.", - "hidden": true, - "help_text": "By default, when an unrecognised parameter is found, it returns a warinig." - }, - "validationLenientMode": { - "type": "boolean", - "fa_icon": "far fa-check-circle", - "description": "Validation of parameters in lenient more.", - "hidden": true, - "help_text": "Allows string values that are parseable as numbers or booleans. For further information see [JSONSchema docs](https://github.com/everit-org/json-schema#lenient-mode)." } } } }, "allOf": [ { - "$ref": "#/definitions/input_output_options" + "$ref": "#/defs/input_output_options" }, { - "$ref": "#/definitions/max_job_request_options" + "$ref": "#/defs/max_job_request_options" }, { - "$ref": "#/definitions/generic_options" + "$ref": "#/defs/generic_options" } ] } diff --git a/nf-test.config b/nf-test.config new file mode 100644 index 0000000..ac040d5 --- /dev/null +++ b/nf-test.config @@ -0,0 +1,7 @@ +config { + + testsDir "tests" + workDir ".nf-test" + configFile "tests/nextflow.config" + profile "test,docker" +} diff --git a/subworkflows/local/assembly_qc.nf b/subworkflows/local/assembly_qc.nf index a7507fc..a4cdc02 100644 --- a/subworkflows/local/assembly_qc.nf +++ b/subworkflows/local/assembly_qc.nf @@ -2,7 +2,7 @@ include { BLAST_BLASTN as BLAST_BLASTN_HUMAN_PHIX } from '../../modules/nf-core/ include { BLAST_BLASTN as BLAST_BLASTN_HOST } from '../../modules/nf-core/blast/blastn/main' include { SEQKIT_GREP } from '../../modules/nf-core/seqkit/grep/main' include { SEQKIT_SEQ } from '../../modules/nf-core/seqkit/seq/main' -include { PUBLISH_FILE } from '../../modules/local/publish_file' +include { PUBLISH_DECONTAMINATED } from '../../modules/local/publish_decontaminated' workflow ASSEMBLY_QC { @@ -25,7 +25,7 @@ workflow ASSEMBLY_QC { if ( params.remove_human_phix ) { - ch_blast_human_phix_refs = Channel.fromPath( "$params.blast_reference_genomes_folder/${params.human_phix_blast_index_name}*", checkIfExists: true) + ch_blast_human_phix_refs = Channel.fromPath( "${params.blast_reference_genomes_folder}/${params.human_phix_blast_index_name}*", checkIfExists: true) .collect().map { files -> [ ["id": params.human_phix_blast_index_name], files ] } @@ -60,9 +60,8 @@ workflow ASSEMBLY_QC { contaminated_contigs = BLAST_BLASTN_HUMAN_PHIX.out.txt } - collected_contigs = contaminated_contigs.map { meta, hits_txt -> hits_txt }.collectFile(name: "decontaminated.txt", newLine: true) - output_path = contaminated_contigs.map { meta, _ -> "assembly/$meta.assembler/$meta.assembler_version/decontamination/"} - PUBLISH_FILE(collected_contigs, output_path) + // TODO: this process only function is to publish the decontaminated contigs txt file + PUBLISH_DECONTAMINATED( contaminated_contigs ) SEQKIT_GREP( SEQKIT_SEQ.out.fastx, diff --git a/tests/main.nf.test b/tests/main.nf.test new file mode 100644 index 0000000..32a50cf --- /dev/null +++ b/tests/main.nf.test @@ -0,0 +1,25 @@ +nextflow_pipeline { + + name "Test Workflow EBIMETAGENOMICS_MIASSEMBLER" + script "main.nf" + + test("Should run without failures") { + + when { + params { + outdir = "tests/results" + bwamem2_reference_genomes_folder = "$projectDir/tests/human_phix/bwa2mem" + blast_reference_genomes_folder = "$projectDir/tests/human_phix/blast" + } + } + + then { + with(workflow) { + assert success + assert trace.tasks().size() == 19 + } + } + + } + +} diff --git a/tests/nextflow.config b/tests/nextflow.config new file mode 100644 index 0000000..c19b1ad --- /dev/null +++ b/tests/nextflow.config @@ -0,0 +1,5 @@ +/* +======================================================================================== + Nextflow config file for running tests +======================================================================================== +*/ diff --git a/workflows/miassembler.nf b/workflows/miassembler.nf index 9de9c6a..e75ff43 100644 --- a/workflows/miassembler.nf +++ b/workflows/miassembler.nf @@ -4,7 +4,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -include { paramsSummaryLog; paramsSummaryMap } from 'plugin/nf-validation' +include { paramsSummaryLog; paramsSummaryMap } from 'plugin/nf-schema' def logo = NfcoreTemplate.logo(workflow, params.monochrome_logs) def citation = '\n' + WorkflowMain.citation(workflow) + '\n' @@ -21,7 +21,7 @@ log.info logo + paramsSummaryLog(workflow) + citation ch_multiqc_config = Channel.fromPath("$projectDir/assets/multiqc_config.yml", checkIfExists: true) ch_multiqc_custom_config = params.multiqc_config ? Channel.fromPath( params.multiqc_config, checkIfExists: true ) : Channel.empty() -ch_multiqc_logo = params.multiqc_logo ? Channel.fromPath( params.multiqc_logo, checkIfExists: true ) : Channel.empty() +ch_multiqc_logo = params.multiqc_logo ? Channel.fromPath( params.multiqc_logo, checkIfExists: true ) : Channel.fromPath("$projectDir/assets/mgnify_logo.png") ch_multiqc_custom_methods_description = params.multiqc_methods_description ? file(params.multiqc_methods_description, checkIfExists: true) : file("$projectDir/assets/methods_description_template.yml", checkIfExists: true) /* @@ -50,11 +50,11 @@ include { ASSEMBLY_COVERAGE } from '../subworkflows/local/assembly_coverage' // include { FASTQC as FASTQC_BEFORE } from '../modules/nf-core/fastqc/main' include { FASTQC as FASTQC_AFTER } from '../modules/nf-core/fastqc/main' -include { MULTIQC } from '../modules/nf-core/multiqc/main' -include { CUSTOM_DUMPSOFTWAREVERSIONS } from '../modules/nf-core/custom/dumpsoftwareversions/main' -include { SPADES } from '../modules/nf-core/spades/main' -include { MEGAHIT } from '../modules/nf-core/megahit/main' -include { QUAST } from '../modules/nf-core/quast/main' +include { MULTIQC } from '../modules/nf-core/multiqc/main' +include { CUSTOM_DUMPSOFTWAREVERSIONS } from '../modules/nf-core/custom/dumpsoftwareversions/main' +include { SPADES } from '../modules/nf-core/spades/main' +include { MEGAHIT } from '../modules/nf-core/megahit/main' +include { QUAST } from '../modules/nf-core/quast/main' /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -96,6 +96,7 @@ workflow MIASSEMBLER { ) ch_versions = ch_versions.mix(FASTQC_BEFORE.out.versions) + // TODO: we need to refactor this, the metaT info should be part of the meta isMetatranscriptomic = FETCHTOOL_METADATA.out.lib_strategy.contains("METATRANSCRIPTOMIC") // Perform QC on reads // @@ -109,23 +110,24 @@ workflow MIASSEMBLER { READS_QC.out.qc_reads ) + /***************************/ + /* Selecting the assembler */ + /***************************/ /* - Single end reads // paired end reads distinction - We need to split single-end and paired-end reads. - Single-end reads are always assembled with MEGAHIT. + The selection process ensures that: + - The user selected assembler is always used. + - Single-end reads are assembled with MEGAHIT, unless specified otherwise. + - Paired-end reads are assembled with MetaSPAdes, unless specified otherwise + - An error is raised if the assembler and read layout are incompatible (shouldn't happen...) */ - qc_reads_extended = READS_QC.out.qc_reads.map{ meta, reads -> - if (params.assembler == "megahit" || meta.single_end == true) { + if ( params.assembler == "megahit" || meta.single_end ) { return [ meta + [assembler: "megahit", assembler_version: params.megahit_version], reads] - } - else { - if (["metaspades", "spades"].contains(params.assembler) || meta.single_end == false || isMetatranscriptomic) { - return [ meta + [assembler: params.assembler, assembler_version: params.spades_version], reads] - } - else { - error "Incompatible assembler and/or reads layout." - } + } else if ( ["metaspades", "spades"].contains(params.assembler) || !meta.single_end ) { + def xspades_assembler = params.assembler ?: "metaspades" // Default to "metaspades" if the user didn't select one + return [ meta + [assembler: xspades_assembler, assembler_version: params.spades_version], reads] + } else { + error "Incompatible assembler and/or reads layout. We can't assembly data that is. Reads - single end value: ${meta.single_end}." } } qc_reads_extended.branch { meta, reads -> @@ -134,8 +136,11 @@ workflow MIASSEMBLER { }.set { qc_reads } ch_versions = ch_versions.mix(READS_QC.out.versions) - /* Assembly */ - /* -- Clarification -- + /******************/ + /* Assembly */ + /******************/ + /* -- Clarification -- */ + /* At the moment, the pipeline only processes one set of reads at a time. Therefore, running Spades, metaSpades, or MEGAHIT are mutually exclusive. In order to support multiple runs, we need to refactor the code slightly. @@ -144,7 +149,7 @@ workflow MIASSEMBLER { SPADES( qc_reads.xspades.map { meta, reads -> [meta, reads, [], []] }, - params.assembler, + params.assembler ?: "metaspades", [], // yml input parameters, which we don't use [] // hmm, not used )