From 0050f453456cdf7007881b2a7e4244c03a6a6c2c Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Thu, 30 Jun 2022 11:43:52 +0200 Subject: [PATCH 1/4] Add taxonomy directory param --- nextflow.config | 1 + subworkflows/local/visualization_krona.nf | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/nextflow.config b/nextflow.config index 29c87cd..88b8d43 100644 --- a/nextflow.config +++ b/nextflow.config @@ -128,6 +128,7 @@ params { // krona run_krona = false + krona_taxonomy_directory = null } // Load base.config by default for all pipelines diff --git a/subworkflows/local/visualization_krona.nf b/subworkflows/local/visualization_krona.nf index b9f645d..d945184 100644 --- a/subworkflows/local/visualization_krona.nf +++ b/subworkflows/local/visualization_krona.nf @@ -51,6 +51,10 @@ workflow VISUALIZATION_KRONA { ch_krona_html = ch_krona_html.mix( KRONA_KTIMPORTTEXT.out.html ) ch_versions = ch_versions.mix( KRONA_KTIMPORTTEXT.out.versions.first() ) + /* + Convert Krona + */ + emit: html = ch_krona_html versions = ch_versions From 02c06b9f7bc24085cd271cd100f47e02373ff60d Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Thu, 30 Jun 2022 18:33:11 +0200 Subject: [PATCH 2/4] Add support for MALT display in Krona, tweaks other krona modules to dispaly tool name in output file --- conf/modules.config | 27 ++++++++++- modules.json | 6 +++ modules/nf-core/modules/gunzip/main.nf | 34 ++++++++++++++ modules/nf-core/modules/gunzip/meta.yml | 34 ++++++++++++++ .../modules/krona/ktimporttaxonomy/main.nf | 38 +++++++++++++++ .../modules/krona/ktimporttaxonomy/meta.yml | 47 +++++++++++++++++++ subworkflows/local/visualization_krona.nf | 21 ++++++++- workflows/taxprofiler.nf | 2 + 8 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 modules/nf-core/modules/gunzip/main.nf create mode 100644 modules/nf-core/modules/gunzip/meta.yml create mode 100644 modules/nf-core/modules/krona/ktimporttaxonomy/main.nf create mode 100644 modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml diff --git a/conf/modules.config b/conf/modules.config index 6563cc9..098d9bb 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -273,7 +273,7 @@ process { ] } - withName: MEGAN_RMA2INFO { + withName: 'NFCORE_TAXPROFILER:TAXPROFILER:PROFILING:MEGAN_RMA2INFO' { ext.args = "-c2c Taxonomy" ext.prefix = { "${meta.id}" } publishDir = [ @@ -293,7 +293,32 @@ process { ] } + withName: KRONA_CLEANUP { + ext.prefix = params.perform_runmerging ? { "${meta.id}-${meta.db_name}" } : { "${meta.id}-${meta.run_accession}-${meta.db_name}" } + publishDir = [ + path: { "${params.outdir}/krona" }, + mode: params.publish_dir_mode, + pattern: '*.{html}' + ] + } + withName: KRONA_KTIMPORTTEXT { + ext.prefix = { "${meta.tool}-${meta.id}" } + publishDir = [ + path: { "${params.outdir}/krona" }, + mode: params.publish_dir_mode, + pattern: '*.{html}' + ] + } + + withName: 'NFCORE_TAXPROFILER:TAXPROFILER:VISUALIZATION_KRONA:MEGAN_RMA2INFO' { + ext.args = { "--read2class Taxonomy" } + ext.prefix = { "${meta.id}-${meta.db_name}" } + } + + withName: KRONA_KTIMPORTTAXONOMY { + ext.args = "-i" + ext.prefix = { "${meta.tool}-${meta.id}" } publishDir = [ path: { "${params.outdir}/krona" }, mode: params.publish_dir_mode, diff --git a/modules.json b/modules.json index 7da0e79..13c6592 100644 --- a/modules.json +++ b/modules.json @@ -39,6 +39,9 @@ "filtlong": { "git_sha": "089f761f0bf79c4a486f1df9b6205f650196a2c1" }, + "gunzip": { + "git_sha": "9aadd9a6d3f5964476582319b3a1c54a3e3fe7c9" + }, "kaiju/kaiju": { "git_sha": "8856f127c58f6af479128be8b8df4d42e442ddbe" }, @@ -54,6 +57,9 @@ "krakentools/kreport2krona": { "git_sha": "8b2a473f586bed003e72d2b183acc43fc0ddc422" }, + "krona/ktimporttaxonomy": { + "git_sha": "233fa70811a03a4cecb2ece483b5c8396e2cee1d" + }, "krona/ktimporttext": { "git_sha": "cdefbec66999c0b49d8bfeea9d6f9d19056635a2" }, diff --git a/modules/nf-core/modules/gunzip/main.nf b/modules/nf-core/modules/gunzip/main.nf new file mode 100644 index 0000000..61bf1af --- /dev/null +++ b/modules/nf-core/modules/gunzip/main.nf @@ -0,0 +1,34 @@ +process GUNZIP { + tag "$archive" + label 'process_low' + + conda (params.enable_conda ? "conda-forge::sed=4.7" : null) + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/ubuntu:20.04' : + 'ubuntu:20.04' }" + + input: + tuple val(meta), path(archive) + + output: + tuple val(meta), path("$gunzip"), emit: gunzip + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + gunzip = archive.toString() - '.gz' + """ + gunzip \\ + -f \\ + $args \\ + $archive + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + gunzip: \$(echo \$(gunzip --version 2>&1) | sed 's/^.*(gzip) //; s/ Copyright.*\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/modules/gunzip/meta.yml b/modules/nf-core/modules/gunzip/meta.yml new file mode 100644 index 0000000..4d2ebc8 --- /dev/null +++ b/modules/nf-core/modules/gunzip/meta.yml @@ -0,0 +1,34 @@ +name: gunzip +description: Compresses and decompresses files. +keywords: + - gunzip + - compression +tools: + - gunzip: + description: | + gzip is a file format and a software application used for file compression and decompression. + documentation: https://www.gnu.org/software/gzip/manual/gzip.html + licence: ["GPL-3.0-or-later"] +input: + - meta: + type: map + description: | + Optional groovy Map containing meta information + e.g. [ id:'test', single_end:false ] + - archive: + type: file + description: File to be compressed/uncompressed + pattern: "*.*" +output: + - gunzip: + type: file + description: Compressed/uncompressed file + pattern: "*.*" + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" +authors: + - "@joseespinosa" + - "@drpatelh" + - "@jfy133" diff --git a/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf b/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf new file mode 100644 index 0000000..5ea9e9e --- /dev/null +++ b/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf @@ -0,0 +1,38 @@ +process KRONA_KTIMPORTTAXONOMY { + tag "${meta.id}" + label 'process_high' + + // WARN: Version information not provided by tool on CLI. Please update version string below when bumping container versions. + conda (params.enable_conda ? "bioconda::krona=2.8" : null) + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/krona:2.8--pl5262hdfd78af_2' : + 'quay.io/biocontainers/krona:2.8--pl5262hdfd78af_2' }" + + input: + tuple val(meta), path(report) + path taxonomy + + output: + tuple val(meta), path ('*.html'), emit: html + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def VERSION = '2.8' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions. + """ + ktImportTaxonomy \\ + $args \\ + -o ${prefix}.html \\ + -tax $taxonomy \\ + $report + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + krona: $VERSION + END_VERSIONS + """ +} \ No newline at end of file diff --git a/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml b/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml new file mode 100644 index 0000000..df0ad1c --- /dev/null +++ b/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml @@ -0,0 +1,47 @@ +name: krona_ktimporttaxonomy +description: KronaTools Import Taxonomy imports taxonomy classifications and produces an interactive Krona plot. +keywords: + - plot + - taxonomy + - interactive + - html + - visualisation + - krona chart +tools: + - krona: + description: Krona Tools is a set of scripts to create Krona charts from several Bioinformatics tools as well as from text and XML files. + homepage: https://github.com/marbl/Krona/wiki/KronaTools + documentation: http://manpages.ubuntu.com/manpages/impish/man1/ktImportTaxonomy.1.html + tool_dev_url: + doi: https://doi.org/10.1186/1471-2105-12-385 + licence: + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test'] + - database: + type: file + description: | + Path to the taxonomy database .tab file downloaded by krona/ktUpdateTaxonomy + The file will be saved under a folder named "taxonomy" as "taxonomy/taxonomy.tab". + The parent folder will be passed as argument to ktImportTaxonomy. + - report: + type: file + description: "A tab-delimited file with taxonomy IDs and (optionally) query IDs, magnitudes, and scores. Query IDs are taken from column 1, taxonomy IDs from column 2, and scores from column 3. Lines beginning with # will be ignored." + pattern: "*.{tsv}" + +output: + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - html: + type: file + description: A html file containing an interactive krona plot. + pattern: "*.{html}" + +authors: + - "@mjakobs" diff --git a/subworkflows/local/visualization_krona.nf b/subworkflows/local/visualization_krona.nf index aac7475..7a94fc6 100644 --- a/subworkflows/local/visualization_krona.nf +++ b/subworkflows/local/visualization_krona.nf @@ -2,10 +2,13 @@ // Create Krona visualizations // +include { MEGAN_RMA2INFO } from '../../modules/nf-core/modules/megan/rma2info/main' include { KAIJU_KAIJU2KRONA } from '../../modules/nf-core/modules/kaiju/kaiju2krona/main' include { KRAKENTOOLS_KREPORT2KRONA } from '../../modules/nf-core/modules/krakentools/kreport2krona/main' include { KRONA_CLEANUP } from '../../modules/local/krona_cleanup' include { KRONA_KTIMPORTTEXT } from '../../modules/nf-core/modules/krona/ktimporttext/main' +include { KRONA_KTIMPORTTAXONOMY } from '../../modules/nf-core/modules/krona/ktimporttaxonomy/main' +include { GUNZIP } from '../../modules/nf-core/modules/gunzip/main' workflow VISUALIZATION_KRONA { take: @@ -30,6 +33,7 @@ workflow VISUALIZATION_KRONA { ch_input_classifications = classifications .branch { kaiju: it[0]['tool'] == 'kaiju' + malt: it[0]['tool'] == 'malt' unknown: true } @@ -72,15 +76,28 @@ workflow VISUALIZATION_KRONA { Convert Krona text files into html Krona visualizations */ ch_krona_text_for_import = ch_cleaned_krona_text - .map{[[id: it[0]['db_name']], it[1]]} + .map{[[id: it[0]['db_name'], tool: it[0]['tool']], it[1]]} .groupTuple() + .dump(tag: "text") KRONA_KTIMPORTTEXT( ch_krona_text_for_import ) ch_krona_html = ch_krona_html.mix( KRONA_KTIMPORTTEXT.out.html ) ch_versions = ch_versions.mix( KRONA_KTIMPORTTEXT.out.versions.first() ) /* - Convert Krona + Convert MALT/MEGAN RMA2INFO files into html Krona visualisations */ + if ( params.krona_taxonomy_directory ) { + MEGAN_RMA2INFO ( ch_input_classifications.malt, false ) + GUNZIP ( MEGAN_RMA2INFO.out.txt ) + ch_krona_taxonomy_for_input = GUNZIP.out.gunzip + .map{[[id: it[0]['db_name'], tool: it[0]['tool']], it[1]]} + .groupTuple() + .dump(tag: "taxonomy") + KRONA_KTIMPORTTAXONOMY ( ch_krona_taxonomy_for_input, file(params.krona_taxonomy_directory, checkExists: true) ) + ch_krona_html.mix( KRONA_KTIMPORTTAXONOMY.out.html ) + ch_versions = ch_versions.mix( MEGAN_RMA2INFO.out.versions.first() ) + ch_versions = ch_versions.mix( KRONA_KTIMPORTTAXONOMY.out.versions.first() ) + } emit: html = ch_krona_html diff --git a/workflows/taxprofiler.nf b/workflows/taxprofiler.nf index 7eec13d..2037649 100644 --- a/workflows/taxprofiler.nf +++ b/workflows/taxprofiler.nf @@ -35,6 +35,8 @@ if (params.longread_hostremoval_index ) { ch_longread_reference_index = fi if (params.diamond_save_reads ) log.warn "[nf-core/taxprofiler] DIAMOND only allows output of a single format. As --diamond_save_reads supplied, only aligned reads in SAM format will be produced, no taxonomic profiles will be available." +if (params.run_malt && params.run_krona && !params.krona_taxonomy_directory) log.warn "[nf-core/taxprofiler] Krona can only be run on MALT output if path to Krona taxonomy database supplied to --krona_taxonomy_directory. Krona will not be executed in this run for MALT." + /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CONFIG FILES From 97e6cdf4b4a8944fc60fb12389f4a9ab868aa216 Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Thu, 30 Jun 2022 18:36:13 +0200 Subject: [PATCH 3/4] Add Krona taxonomy DB to schema build --- nextflow_schema.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nextflow_schema.json b/nextflow_schema.json index fe77913..78635a7 100644 --- a/nextflow_schema.json +++ b/nextflow_schema.json @@ -438,6 +438,10 @@ }, "run_krona": { "type": "boolean" + }, + "krona_taxonomy_directory": { + "type": "string", + "default": null } } } From 447b8f09057bbd994385ae4490e30c53d599e6b0 Mon Sep 17 00:00:00 2001 From: James Fellows Yates Date: Fri, 1 Jul 2022 17:21:19 +0200 Subject: [PATCH 4/4] Get fixed Krona module and add Krona taxonomy to test profile --- conf/test.config | 1 + modules.json | 2 +- modules/nf-core/modules/krona/ktimporttaxonomy/main.nf | 9 ++++++--- modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml | 7 ++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/conf/test.config b/conf/test.config index 04dfb4d..375f463 100644 --- a/conf/test.config +++ b/conf/test.config @@ -38,6 +38,7 @@ params { run_centrifuge = true run_diamond = true run_krona = true + krona_taxonomy_directory = 'https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/genomics/sarscov2/metagenome/krona_taxonomy.tab' malt_save_reads = true kraken2_save_reads = true centrifuge_save_reads = true diff --git a/modules.json b/modules.json index 13c6592..b4c13f0 100644 --- a/modules.json +++ b/modules.json @@ -58,7 +58,7 @@ "git_sha": "8b2a473f586bed003e72d2b183acc43fc0ddc422" }, "krona/ktimporttaxonomy": { - "git_sha": "233fa70811a03a4cecb2ece483b5c8396e2cee1d" + "git_sha": "0e9fd9370ad1845870b8a9c63fcc47d999a1739e" }, "krona/ktimporttext": { "git_sha": "cdefbec66999c0b49d8bfeea9d6f9d19056635a2" diff --git a/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf b/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf index 5ea9e9e..9b03462 100644 --- a/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf +++ b/modules/nf-core/modules/krona/ktimporttaxonomy/main.nf @@ -10,7 +10,7 @@ process KRONA_KTIMPORTTAXONOMY { input: tuple val(meta), path(report) - path taxonomy + path taxonomy, stageAs: 'taxonomy.tab' output: tuple val(meta), path ('*.html'), emit: html @@ -24,10 +24,13 @@ process KRONA_KTIMPORTTAXONOMY { def prefix = task.ext.prefix ?: "${meta.id}" def VERSION = '2.8' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions. """ + TAXONOMY=\$(find -L . -name '*.tab' -exec dirname {} \\;) + echo \$TAXONOMY + ktImportTaxonomy \\ $args \\ -o ${prefix}.html \\ - -tax $taxonomy \\ + -tax \$TAXONOMY/ \\ $report cat <<-END_VERSIONS > versions.yml @@ -35,4 +38,4 @@ process KRONA_KTIMPORTTAXONOMY { krona: $VERSION END_VERSIONS """ -} \ No newline at end of file +} diff --git a/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml b/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml index df0ad1c..0fd7d5f 100644 --- a/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml +++ b/modules/nf-core/modules/krona/ktimporttaxonomy/meta.yml @@ -25,9 +25,10 @@ input: - database: type: file description: | - Path to the taxonomy database .tab file downloaded by krona/ktUpdateTaxonomy - The file will be saved under a folder named "taxonomy" as "taxonomy/taxonomy.tab". - The parent folder will be passed as argument to ktImportTaxonomy. + Path to a Krona taxonomy .tab file normally downloaded and generated by + krona/ktUpdateTaxonomy. Custom taxonomy files can have any name, but + must end in `.tab`. + pattern: "*tab" - report: type: file description: "A tab-delimited file with taxonomy IDs and (optionally) query IDs, magnitudes, and scores. Query IDs are taken from column 1, taxonomy IDs from column 2, and scores from column 3. Lines beginning with # will be ignored."