From c8dbf5be47b388d9b711859c820d2c9fd1c5f6ef Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Tue, 13 Sep 2022 15:47:28 +0200 Subject: [PATCH 1/4] Adds KRAKEN_COMBINEKREPORTS for 'native' multi-sample OTU --- conf/modules.config | 9 ++++ modules.json | 4 ++ .../krakentools/combinekreports/main.nf | 34 +++++++++++++++ .../krakentools/combinekreports/meta.yml | 43 +++++++++++++++++++ .../local/standardisation_profiles.nf | 19 +++++++- 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 modules/nf-core/modules/krakentools/combinekreports/main.nf create mode 100644 modules/nf-core/modules/krakentools/combinekreports/meta.yml diff --git a/conf/modules.config b/conf/modules.config index e367a67..f31eff5 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -294,6 +294,15 @@ process { ] } + withName: KRAKENTOOLS_COMBINEKREPORTS { + ext.prefix = { "${meta.id}_combined_reports" } + publishDir = [ + path: { "${params.outdir}/kraken2/" }, + mode: params.publish_dir_mode, + pattern: '*.{txt}' + ] + } + withName: KRONA_CLEANUP { ext.prefix = params.perform_runmerging ? { "${meta.id}-${meta.db_name}" } : { "${meta.id}-${meta.run_accession}-${meta.db_name}" } publishDir = [ diff --git a/modules.json b/modules.json index 385149a..aa358fc 100644 --- a/modules.json +++ b/modules.json @@ -73,6 +73,10 @@ "branch": "master", "git_sha": "409a308ba46284d8ebb48c2c1befd6f6433db3f7" }, + "krakentools/combinekreports": { + "branch": "master", + "git_sha": "ee0346b4d14ffdc15ce7e093ca1363cd07c9bd78" + }, "krakentools/kreport2krona": { "branch": "master", "git_sha": "233fa70811a03a4cecb2ece483b5c8396e2cee1d" diff --git a/modules/nf-core/modules/krakentools/combinekreports/main.nf b/modules/nf-core/modules/krakentools/combinekreports/main.nf new file mode 100644 index 0000000..849f39c --- /dev/null +++ b/modules/nf-core/modules/krakentools/combinekreports/main.nf @@ -0,0 +1,34 @@ +process KRAKENTOOLS_COMBINEKREPORTS { + label 'process_low' + + conda (params.enable_conda ? "bioconda::krakentools=1.2" : null) + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/krakentools:1.2--pyh5e36f6f_0': + 'quay.io/biocontainers/krakentools:1.2--pyh5e36f6f_0' }" + + input: + tuple val(meta), path(kreports) + + output: + tuple val(meta), path("*.txt"), emit: txt + path "versions.yml", emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + prefix = task.ext.prefix ?: "${meta.id}" + def VERSION = '1.2' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions. + """ + combine_kreports.py \\ + -r ${kreports} \\ + -o ${prefix}.txt \\ + ${args} + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + combine_kreports.py: ${VERSION} + END_VERSIONS + """ +} diff --git a/modules/nf-core/modules/krakentools/combinekreports/meta.yml b/modules/nf-core/modules/krakentools/combinekreports/meta.yml new file mode 100644 index 0000000..213fc8c --- /dev/null +++ b/modules/nf-core/modules/krakentools/combinekreports/meta.yml @@ -0,0 +1,43 @@ +name: krakentools_combinekreports +description: Takes a Kraken report file and prints out a krona-compatible TEXT file +keywords: + - kraken + - krakentools + - metagenomics + - table + - combining + - merging +tools: + - krakentools: + description: KrakenTools is a suite of scripts to be used for post-analysis of Kraken/KrakenUniq/Kraken2/Bracken results. Please cite the relevant paper if using KrakenTools with any of the listed programs. + homepage: https://github.com/jenniferlu717/KrakenTools + licence: ["GPL v3"] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - kreports: + type: file + description: List of kraken-style report files + pattern: "*.{txt,kreport}" + +output: + - 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" + - txt: + type: file + description: Combined kreport file of all input files + pattern: "*.txt" + +authors: + - "@jfy133" diff --git a/subworkflows/local/standardisation_profiles.nf b/subworkflows/local/standardisation_profiles.nf index 8be6020..14fb718 100644 --- a/subworkflows/local/standardisation_profiles.nf +++ b/subworkflows/local/standardisation_profiles.nf @@ -3,7 +3,8 @@ // include { KAIJU_KAIJU2TABLE } from '../../modules/nf-core/modules/kaiju/kaiju2table/main' -include { MOTUS_MERGE } from '../../modules/nf-core/modules/motus/merge/main' +include { KRAKENTOOLS_COMBINEKREPORTS } from '../../modules/nf-core/modules/krakentools/combinekreports/main' +include { MOTUS_MERGE } from '../../modules/nf-core/modules/motus/merge/main' workflow STANDARDISATION_PROFILES { take: @@ -23,6 +24,7 @@ workflow STANDARDISATION_PROFILES { ch_input_profiles = profiles .branch { motus: it[0]['tool'] == 'motus' + kraken2: it[0]['tool'] == 'kraken2' unknown: true } @@ -58,6 +60,21 @@ workflow STANDARDISATION_PROFILES { ch_multiqc_files = ch_multiqc_files.mix( KAIJU_KAIJU2TABLE.out.summary ) ch_versions = ch_versions.mix( KAIJU_KAIJU2TABLE.out.versions ) + // Kraken2 + + // Collect and replace id for db_name for prefix + ch_profiles_for_kraken2 = ch_input_profiles.kraken2 + .map { [it[0]['db_name'], it[1]] } + .groupTuple(sort: {-it.size()} ) + .map { + [[id:it[0]], it[1]] + } + + KRAKENTOOLS_COMBINEKREPORTS ( ch_profiles_for_kraken2 ) + ch_standardised_tables = ch_standardised_tables.mix( KRAKENTOOLS_COMBINEKREPORTS.out.txt ) + ch_multiqc_files = ch_multiqc_files.mix( KRAKENTOOLS_COMBINEKREPORTS.out.txt ) + ch_versions = ch_versions.mix( KRAKENTOOLS_COMBINEKREPORTS.out.versions ) + // mOTUs has a 'single' database, and cannot create custom ones. // Therefore removing db info here, and publish merged at root mOTUs results // directory From 05e9d92444d4689c172d2df3176bf180482fa5aa Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Tue, 13 Sep 2022 16:47:19 +0200 Subject: [PATCH 2/4] Add centrigue kreports --- conf/modules.config | 13 +++++++-- .../local/standardisation_profiles.nf | 27 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/conf/modules.config b/conf/modules.config index f31eff5..2dd163f 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -295,7 +295,7 @@ process { } withName: KRAKENTOOLS_COMBINEKREPORTS { - ext.prefix = { "${meta.id}_combined_reports" } + ext.prefix = { "kraken2_${meta.id}_combined_reports" } publishDir = [ path: { "${params.outdir}/kraken2/" }, mode: params.publish_dir_mode, @@ -367,6 +367,15 @@ process { ] } + withName: KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE { + ext.prefix = { "centrifuge_${meta.id}_combined_reports" } + publishDir = [ + path: { "${params.outdir}/centrifuge/" }, + mode: params.publish_dir_mode, + pattern: '*.{txt}' + ] + } + withName: KAIJU_KAIJU { ext.prefix = params.perform_runmerging ? { "${meta.id}-${meta.db_name}" } : { "${meta.id}-${meta.run_accession}-${meta.db_name}" } publishDir = [ @@ -378,7 +387,7 @@ process { } withName: KAIJU_KAIJU2TABLE { - ext.prefix = { "${meta.id}_combined_reports" } + ext.prefix = { "kaiju_${meta.id}_combined_reports" } publishDir = [ path: { "${params.outdir}/kaiju/" }, mode: params.publish_dir_mode, diff --git a/subworkflows/local/standardisation_profiles.nf b/subworkflows/local/standardisation_profiles.nf index 14fb718..269a22c 100644 --- a/subworkflows/local/standardisation_profiles.nf +++ b/subworkflows/local/standardisation_profiles.nf @@ -2,9 +2,10 @@ // Standardise output files e.g. aggregation // -include { KAIJU_KAIJU2TABLE } from '../../modules/nf-core/modules/kaiju/kaiju2table/main' -include { KRAKENTOOLS_COMBINEKREPORTS } from '../../modules/nf-core/modules/krakentools/combinekreports/main' -include { MOTUS_MERGE } from '../../modules/nf-core/modules/motus/merge/main' +include { KRAKENTOOLS_COMBINEKREPORTS as KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE } from '../../modules/nf-core/modules/krakentools/combinekreports/main' +include { KAIJU_KAIJU2TABLE } from '../../modules/nf-core/modules/kaiju/kaiju2table/main' +include { KRAKENTOOLS_COMBINEKREPORTS } from '../../modules/nf-core/modules/krakentools/combinekreports/main' +include { MOTUS_MERGE } from '../../modules/nf-core/modules/motus/merge/main' workflow STANDARDISATION_PROFILES { take: @@ -25,6 +26,7 @@ workflow STANDARDISATION_PROFILES { .branch { motus: it[0]['tool'] == 'motus' kraken2: it[0]['tool'] == 'kraken2' + centrifuge: it[0]['tool'] == 'centrifuge' unknown: true } @@ -45,6 +47,23 @@ workflow STANDARDISATION_PROFILES { Standardise and aggregate */ + // CENTRIFUGE + + // Collect and replace id for db_name for prefix + // Have to sort by size to ensure first file actually has hits otherwise + // the script fails + ch_profiles_for_centrifuge = ch_input_profiles.centrifuge + .map { [it[0]['db_name'], it[1]] } + .groupTuple(sort: {-it.size()} ) + .map { + [[id:it[0]], it[1]] + } + + KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE ( ch_profiles_for_centrifuge ) + ch_standardised_tables = ch_standardised_tables.mix( KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE.out.txt ) + ch_multiqc_files = ch_multiqc_files.mix( KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE.out.txt ) + ch_versions = ch_versions.mix( KRAKENTOOLS_COMBINEKREPORTS_CENTRIFUGE.out.versions ) + // Kaiju // Collect and replace id for db_name for prefix @@ -63,6 +82,8 @@ workflow STANDARDISATION_PROFILES { // Kraken2 // Collect and replace id for db_name for prefix + // Have to sort by size to ensure first file actually has hits otherwise + // the script fails ch_profiles_for_kraken2 = ch_input_profiles.kraken2 .map { [it[0]['db_name'], it[1]] } .groupTuple(sort: {-it.size()} ) From abbbf9c7ab7eb6ead310bbe9a47706b933c00ac2 Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Wed, 14 Sep 2022 11:16:28 +0200 Subject: [PATCH 3/4] Update to use tar module compatible for our test databases --- modules.json | 6 +++--- modules/nf-core/modules/untar/main.nf | 23 +++++++++++++++++------ modules/nf-core/modules/untar/meta.yml | 8 +++++--- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/modules.json b/modules.json index aa358fc..c503b74 100644 --- a/modules.json +++ b/modules.json @@ -107,7 +107,7 @@ }, "minimap2/index": { "branch": "master", - "git_sha": "e745e167c1020928ef20ea1397b6b4d230681b4d" + "git_sha": "73e062cf5e0ef346f65d73009b1b656299359fc5" }, "motus/merge": { "branch": "master", @@ -119,7 +119,7 @@ }, "multiqc": { "branch": "master", - "git_sha": "16eee433b87b303bda650131ac5a0b1ad725e166" + "git_sha": "5587389874dac9c9953a2ab6f01d49af81969492" }, "porechop": { "branch": "master", @@ -139,7 +139,7 @@ }, "untar": { "branch": "master", - "git_sha": "5e7b1ef9a5a2d9258635bcbf70fcf37dacd1b247" + "git_sha": "393dbd6ddafe3f18eac02893dd4a21e4d45de679" } } } diff --git a/modules/nf-core/modules/untar/main.nf b/modules/nf-core/modules/untar/main.nf index 4128652..007871b 100644 --- a/modules/nf-core/modules/untar/main.nf +++ b/modules/nf-core/modules/untar/main.nf @@ -25,12 +25,23 @@ process UNTAR { """ mkdir output - tar \\ - -C output --strip-components 1 \\ - -xzvf \\ - $args \\ - $archive \\ - $args2 + ## Ensures --strip-components only applied when top level of tar contents is a directory + ## If just files or multiple directories, place all in output + if [[ \$(tar -tzf ${archive} | grep "/\$" | wc -l) -eq 1 ]]; then + tar \\ + -C output --strip-components 1 \\ + -xzvf \\ + $args \\ + $archive \\ + $args2 + else + tar \\ + -C output \\ + -xzvf \\ + $args \\ + $archive \\ + $args2 + fi mv output ${untar} diff --git a/modules/nf-core/modules/untar/meta.yml b/modules/nf-core/modules/untar/meta.yml index d426919..ea7a3f3 100644 --- a/modules/nf-core/modules/untar/meta.yml +++ b/modules/nf-core/modules/untar/meta.yml @@ -26,9 +26,9 @@ output: Groovy Map containing sample information e.g. [ id:'test', single_end:false ] - untar: - type: file - description: - pattern: "*.*" + type: directory + description: Directory containing contents of archive + pattern: "*/" - versions: type: file description: File containing software versions @@ -36,3 +36,5 @@ output: authors: - "@joseespinosa" - "@drpatelh" + - "@matthdsm" + - "@jfy133" From 5414ae2e554c834269573ea7c792fd4f5147ee3f Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Wed, 14 Sep 2022 11:20:40 +0200 Subject: [PATCH 4/4] Apply suggestions from code review --- modules.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules.json b/modules.json index c503b74..242e8e8 100644 --- a/modules.json +++ b/modules.json @@ -107,7 +107,7 @@ }, "minimap2/index": { "branch": "master", - "git_sha": "73e062cf5e0ef346f65d73009b1b656299359fc5" + "git_sha": "e745e167c1020928ef20ea1397b6b4d230681b4d" }, "motus/merge": { "branch": "master", @@ -119,7 +119,7 @@ }, "multiqc": { "branch": "master", - "git_sha": "5587389874dac9c9953a2ab6f01d49af81969492" + "git_sha": "16eee433b87b303bda650131ac5a0b1ad725e166" }, "porechop": { "branch": "master",