Skip to content

Commit

Permalink
Added fasta_kraken2
Browse files Browse the repository at this point in the history
  • Loading branch information
GallVp committed Feb 22, 2024
1 parent d6ba080 commit 43255b6
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 1 deletion.
10 changes: 9 additions & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ process {
]
}

withName: RUN_KRAKEN2 {
withName: KRAKEN2 {
publishDir = [
path: { "${params.outdir}/kraken2" },
mode: params.publish_dir_mode,
saveAs: { filename -> filename.equals("versions.yml") ? null : filename }
]
}

withName: KRAKEN2_KRONA_PLOT {
publishDir = [
path: { "${params.outdir}/kraken2" },
mode: params.publish_dir_mode,
Expand Down
5 changes: 5 additions & 0 deletions lib/WorkflowMain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ class WorkflowMain {
if (!params.busco_skip && !params.busco_lineage_datasets) {
Nextflow.error('busco_lineage_datasets must be provided when executing BUSCO')
}

// Check for kraken2_db_path
if (!params.kraken2_skip && !params.kraken2_db_path) {
Nextflow.error('kraken2_db_path must be provided when executing Kraken2')
}
}
//
// Get attribute from genome config file e.g. fasta
Expand Down
5 changes: 5 additions & 0 deletions modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
"branch": "master",
"git_sha": "669a329f4aa37f5b7f03776c2ed1cd0ef122c626",
"installed_by": ["fasta_explore_search_plot_tidk"]
},
"untar": {
"branch": "master",
"git_sha": "e719354ba77df0a1bd310836aa2039b45c29d620",
"installed_by": ["modules"]
}
}
},
Expand Down
47 changes: 47 additions & 0 deletions modules/local/kraken2.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
process KRAKEN2 {
tag "${asm_tag}"
label 'process_single'
label 'process_high_memory'

container "${ workflow.containerEngine == 'singularity' || workflow.containerEngine == 'apptainer' ?
'https://depot.galaxyproject.org/singularity/kraken2:2.1.2--pl5321h9f5acd7_2':
'biocontainers/kraken2:2.1.2--pl5321h9f5acd7_2' }"

input:
tuple val(asm_tag), path(fasta_file)
path db_path

output:
tuple val(asm_tag), path("*.kraken2.cut"), path("*.kraken2.report") , emit: report
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
"""
kraken2 \\
--output "${asm_tag}.kraken2.cut" \\
--report "${asm_tag}.kraken2.report" \\
--use-names \\
--db $db_path \\
--threads ${task.cpus} \\
$fasta_file > kraken2.log
cat <<-END_VERSIONS > versions.yml
"${task.process}":
kraken2: \$(echo \$(kraken2 --version 2>&1) | sed 's/^.*Kraken version //; s/ .*\$//')
END_VERSIONS
"""

stub:
"""
touch "${asm_tag}.kraken2.cut"
touch "${asm_tag}.kraken2.report"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
kraken2: \$(echo \$(kraken2 --version 2>&1) | sed 's/^.*Kraken version //; s/ .*\$//')
END_VERSIONS
"""
}
27 changes: 27 additions & 0 deletions modules/local/kraken2_krona_plot.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
process KRAKEN2_KRONA_PLOT {
tag "${hap_name}"
label 'process_single'

container "docker.io/nanozoo/krona:2.7.1--e7615f7"

input:
tuple val(hap_name), path(kraken2_cut), path(kraken2_report)

output:
tuple path("*.kraken2.krona.cut"), path("*.kraken2.krona.html") , emit: plot
path "versions.yml" , emit: versions

when:
task.ext.when == null || task.ext.when

script:
"""
perl -lane '@a=split /\\t/; if (\$a[2] =~ /taxid\\s+(\\d+)/) {print "\$a[1]\\t\$1\\t1\\t\$a[3]";}' $kraken2_cut > "${hap_name}.kraken2.krona.cut"
ktImportTaxonomy -i -o "${hap_name}.kraken2.krona.html" -m "4" "${hap_name}.kraken2.krona.cut"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
KronaTools: \$(ktImportTaxonomy | sed -n '/KronaTools/s/KronaTools//p' | tr -d ' _/[:space:]' | sed 's/-ktImportTaxonomy\\\\//1')
END_VERSIONS
"""
}
11 changes: 11 additions & 0 deletions modules/nf-core/untar/environment.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions modules/nf-core/untar/main.nf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions modules/nf-core/untar/meta.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions modules/nf-core/untar/tests/main.nf.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions modules/nf-core/untar/tests/main.nf.test.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions modules/nf-core/untar/tests/tags.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions subworkflows/local/fasta_kraken2.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
include { UNTAR } from '../../modules/nf-core/untar/main'
include { KRAKEN2 } from '../../modules/local/kraken2'
include { KRAKEN2_KRONA_PLOT } from '../../modules/local/kraken2_krona_plot'

workflow FASTA_KRAKEN2 {
take:
tuple_of_hap_file
db_path // channel: path

main:
ch_tar_db = db_path
| filter { db -> "$db".endsWith('.tar.gz') }

ch_untar_db = db_path
| filter { db -> !( "$db".endsWith('.tar.gz') ) }

// MODULE: UNTAR
UNTAR ( ch_tar_db.map { tar -> [ [ id: "kraken2_db" ], tar ] } )

ch_kraken2_inputs = UNTAR.out.untar
| map { meta, untar -> untar }
| mix(
ch_untar_db
)
| combine(tuple_of_hap_file)

// MODULE: KRAKEN2
KRAKEN2(
ch_kraken2_inputs.map { db, tag, fasta -> [ tag, fasta ] },
ch_kraken2_inputs.map { db, tag, fasta -> db }
)

// MODULE: KRAKEN2_KRONA_PLOT
KRAKEN2_KRONA_PLOT ( KRAKEN2.out.report )

ch_versions = Channel.empty()
| mix(KRAKEN2.out.versions.first())
| mix(UNTAR.out.versions.first())
| mix(KRAKEN2_KRONA_PLOT.out.versions.first())

emit:
plot = KRAKEN2_KRONA_PLOT.out.plot
versions = ch_versions
}
Empty file.
3 changes: 3 additions & 0 deletions tests/stub/stub.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ params {

lai_skip = false

kraken2_skip = false
kraken2_db_path = 'tests/stub/kraken2/k2_minusb_20231009.tar.gz'

// Limit resources so that this can run on GitHub Actions
max_cpus = 2
max_memory = '6.GB'
Expand Down
Loading

0 comments on commit 43255b6

Please sign in to comment.