Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shovill as optional assembler #56

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions environments/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ dependencies:
- prokka=1.14.5
- quast=5.0.2
- bandage=0.8.1
- shovill=1.0.9
143 changes: 77 additions & 66 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include { prokka } from './modules/prokka.nf'
include { bakta } from './modules/bakta.nf'
include { quast } from './modules/quast.nf'
include { parse_quast_report } from './modules/quast.nf'
include { shovill } from './modules/shovill.nf'
include { bandage } from './modules/long_read_qc.nf'
include { pipeline_provenance } from './modules/provenance.nf'
include { collect_provenance } from './modules/provenance.nf'
Expand All @@ -24,54 +25,54 @@ include { collect_provenance } from './modules/provenance.nf'
workflow {

ch_workflow_metadata = Channel.value([
workflow.sessionId,
workflow.runName,
workflow.manifest.name,
workflow.manifest.version,
workflow.start,
workflow.sessionId,
workflow.runName,
workflow.manifest.name,
workflow.manifest.version,
workflow.start,
])

ch_pipeline_provenance = pipeline_provenance(ch_workflow_metadata)

if (params.samplesheet_input != 'NO_FILE') {
if (params.hybrid) {
ch_assembly_mode = Channel.of("hybrid")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['R1'], it['R2'], it['LONG']]] }
ch_short_reads = ch_fastq.map{ it -> [it[0], [it[1][0], it[1][1]]] }
ch_long_reads = ch_fastq.map{ it -> [it[0], it[1][2]] }
} else if (params.long_only) {
ch_assembly_mode = Channel.of("long")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['LONG']]] }
ch_short_reads = Channel.of()
ch_long_reads = ch_fastq
} else {
ch_assembly_mode = Channel.of("short")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['R1'], it['R2']]] }
ch_short_reads = ch_fastq
ch_long_reads = Channel.of()
}
if (params.hybrid) {
ch_assembly_mode = Channel.of("hybrid")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['R1'], it['R2'], it['LONG']]] }
ch_short_reads = ch_fastq.map{ it -> [it[0], [it[1][0], it[1][1]]] }
ch_long_reads = ch_fastq.map{ it -> [it[0], it[1][2]] }
} else if (params.long_only) {
ch_assembly_mode = Channel.of("long")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['LONG']]] }
ch_short_reads = Channel.of()
ch_long_reads = ch_fastq
} else {
ch_assembly_mode = Channel.of("short")
ch_fastq = Channel.fromPath(params.samplesheet_input).splitCsv(header: true).map{ it -> [it['ID'], [it['R1'], it['R2']]] }
ch_short_reads = ch_fastq
ch_long_reads = Channel.of()
}
} else {
if (params.hybrid) {
ch_assembly_mode = Channel.of("hybrid")
ch_short_reads = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], [it[1], it[2]]] }.unique{ it -> it[0] }
ch_long_reads = Channel.fromPath( params.long_reads_search_path ).map{ it -> [it.baseName.split("_")[0], [it]] }
ch_fastq = ch_short_reads.join(ch_long_reads).map{ it -> [it[0], it[1] + it[2]] }
} else if (params.long_only) {
ch_assembly_mode = Channel.of("long")
ch_short_reads = Channel.of()
ch_long_reads = Channel.fromPath( params.long_reads_search_path ).map{ it -> [it.baseName.split("_")[0], [it]] }
ch_fastq = ch_long_reads
} else {
if (params.hybrid) {
ch_assembly_mode = Channel.of("hybrid")
ch_short_reads = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], [it[1], it[2]]] }.unique{ it -> it[0] }
ch_long_reads = Channel.fromPath( params.long_reads_search_path ).map{ it -> [it.baseName.split("_")[0], [it]] }
ch_fastq = ch_short_reads.join(ch_long_reads).map{ it -> [it[0], it[1] + it[2]] }
} else if (params.long_only) {
ch_assembly_mode = Channel.of("long")
ch_short_reads = Channel.of()
ch_long_reads = Channel.fromPath( params.long_reads_search_path ).map{ it -> [it.baseName.split("_")[0], [it]] }
ch_fastq = ch_long_reads
} else {
ch_assembly_mode = Channel.of("short")
ch_fastq = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], [it[1], it[2]]] }.unique{ it -> it[0] }
ch_short_reads = ch_fastq
ch_long_reads = Channel.of()
}
ch_assembly_mode = Channel.of("short")
ch_fastq = Channel.fromFilePairs( params.fastq_search_path, flat: true ).map{ it -> [it[0].split('_')[0], [it[1], it[2]]] }.unique{ it -> it[0] }
ch_short_reads = ch_fastq
ch_long_reads = Channel.of()
}
}

if (params.long_only && params.hybrid) {
System.out.println("Choose one of --long or --hybrid (but not both).")
System.exit(-1)
System.out.println("Choose one of --long or --hybrid (but not both).")
System.exit(-1)
}

main:
Expand All @@ -80,35 +81,45 @@ workflow {
hash_files(ch_fastq.combine(Channel.of("fastq-input")))

if (params.hybrid) {
fastp(ch_short_reads)
fastp_json_to_csv(fastp.out.json)
nanoq_pre_filter(ch_long_reads.combine(Channel.of("pre_filter")))
filtlong(ch_long_reads)
nanoq_post_filter(filtlong.out.filtered_reads.combine(Channel.of("post_filter")))
merge_nanoq_reports(nanoq_pre_filter.out.report.join(nanoq_post_filter.out.report))
unicycler(fastp.out.trimmed_reads.join(filtlong.out.filtered_reads).map{ it -> [it[0], [it[1], it[2], it[3]]] }.combine(ch_assembly_mode))
fastp(ch_short_reads)
fastp_json_to_csv(fastp.out.json)
nanoq_pre_filter(ch_long_reads.combine(Channel.of("pre_filter")))
filtlong(ch_long_reads)
nanoq_post_filter(filtlong.out.filtered_reads.combine(Channel.of("post_filter")))
merge_nanoq_reports(nanoq_pre_filter.out.report.join(nanoq_post_filter.out.report))
unicycler(fastp.out.trimmed_reads.join(filtlong.out.filtered_reads).map{ it -> [it[0], [it[1], it[2], it[3]]] }.combine(ch_assembly_mode))
} else if (params.long_only) {
nanoq_pre_filter(ch_long_reads.combine(Channel.of("pre_filter")).map{ it -> [it[0], it[1][0], it[2]] })
filtlong(ch_long_reads)
nanoq_post_filter(filtlong.out.filtered_reads.combine(Channel.of("post_filter")))
merge_nanoq_reports(nanoq_pre_filter.out.report.join(nanoq_post_filter.out.report))
unicycler(ch_long_reads.combine(ch_assembly_mode))
} else {
fastp(ch_short_reads)
fastp_json_to_csv(fastp.out.json)
unicycler(fastp.out.trimmed_reads.map{ it -> [it[0], [it[1], it[2]]] }.combine(ch_assembly_mode))
nanoq_pre_filter(ch_long_reads.combine(Channel.of("pre_filter")).map{ it -> [it[0], it[1][0], it[2]] })
filtlong(ch_long_reads)
nanoq_post_filter(filtlong.out.filtered_reads.combine(Channel.of("post_filter")))
merge_nanoq_reports(nanoq_pre_filter.out.report.join(nanoq_post_filter.out.report))
unicycler(ch_long_reads.combine(ch_assembly_mode))
} else {
fastp(ch_short_reads)
fastp_json_to_csv(fastp.out.json)

if (params.shovill) {
shovill(fastp.out.trimmed_reads.map{ it -> [it[0], [it[1], it[2]]] }.combine(ch_assembly_mode))
ch_assembly_out = shovill.out
} else {
unicycler(fastp.out.trimmed_reads.map{ it -> [it[0], [it[1], it[2]]] }.combine(ch_assembly_mode))
ch_assembly_out = unicycler.out
}



}

if (params.prokka) {
prokka(unicycler.out.assembly)
prokka(ch_assembly_out.assembly)
}

if (params.bakta) {
bakta(unicycler.out.assembly)
bakta(ch_assembly_out.assembly)
}

quast(unicycler.out.assembly)
bandage(unicycler.out.assembly_graph)
quast(ch_assembly_out.assembly)
bandage(ch_assembly_out.assembly_graph)

parse_quast_report(quast.out.tsv)

Expand All @@ -121,23 +132,23 @@ workflow {
ch_provenance = ch_provenance.join(hash_files.out.provenance).map{ it -> [it[0], it[1] << it[2]] }

if (params.hybrid || params.long_only) {
ch_provenance = ch_provenance.join(nanoq_pre_filter.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(filtlong.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(nanoq_post_filter.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(nanoq_pre_filter.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(filtlong.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(nanoq_post_filter.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
}

if (!params.long_only) {
ch_provenance = ch_provenance.join(fastp.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(fastp.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
}

ch_provenance = ch_provenance.join(unicycler.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(ch_assembly_out.provenance).map{ it -> [it[0], it[1] << it[2]] }

if (params.prokka) {
ch_provenance = ch_provenance.join(prokka.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(prokka.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
}

if (params.bakta) {
ch_provenance = ch_provenance.join(bakta.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
ch_provenance = ch_provenance.join(bakta.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
}

ch_provenance = ch_provenance.join(quast.out.provenance).map{ it -> [it[0], it[1] << it[2]] }
Expand Down
44 changes: 44 additions & 0 deletions modules/shovill.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
process shovill {

tag { sample_id + ' / ' + assembly_mode }

label 'process_medium'

publishDir "${params.outdir}/${sample_id}", pattern: "${sample_id}_shovill_short.{fa,gfa,log}", mode: 'copy'


input:
tuple val(sample_id), path(reads), val(assembly_mode)

output:
tuple val(sample_id), path("${sample_id}_shovill_${assembly_mode}.fa"), val("shovill"), val(assembly_mode), emit: assembly
tuple val(sample_id), path("${sample_id}_shovill_${assembly_mode}.gfa"), val("shovill"), val(assembly_mode), emit: assembly_graph
tuple val(sample_id), path("${sample_id}_shovill_${assembly_mode}.log"), val("shovill"), val(assembly_mode), emit: log
tuple val(sample_id), path("${sample_id}_shovill_${assembly_mode}_provenance.yml"), emit: provenance


script:
def args = task.ext.args ?: ''
def memory = task.memory ? "--ram ${task.memory.toGiga()} ": ""
"""
printf -- "- process_name: shovill\\n" >> ${sample_id}_shovill_${assembly_mode}_provenance.yml
printf -- " tools:\\n" >> ${sample_id}_shovill_${assembly_mode}_provenance.yml
printf -- " - tool_name: shovill\\n" >> ${sample_id}_shovill_${assembly_mode}_provenance.yml
printf -- " tool_version: \$(shovill --version | cut -d' ' -f2)\\n" >> ${sample_id}_shovill_${assembly_mode}_provenance.yml


shovill \\
--R1 ${reads[0]} \\
--R2 ${reads[1]} \\
$args \\
--cpus $task.cpus \\
$memory \\
--outdir ${sample_id}_shovill \\
--force

cp ${sample_id}_shovill/contigs.fa ${sample_id}_shovill_${assembly_mode}.fa
cp ${sample_id}_shovill/contigs.gfa ${sample_id}_shovill_${assembly_mode}.gfa
cp ${sample_id}_shovill/shovill.log ${sample_id}_shovill_${assembly_mode}.log
"""
}

16 changes: 11 additions & 5 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ manifest {
params {
prokka = false
bakta = false
shovill = false
hybrid = false
long_only = false
bakta_db = '/data/ref_databases/bakta/latest'
Expand Down Expand Up @@ -65,11 +66,12 @@ def parsePipelineName(name) {

profiles {
conda {
conda.enabled = true
process.conda = "$baseDir/environments/environment.yml"
if (params.cache){
conda.cacheDir = params.cache
}
conda.enabled = true
process.conda = "$baseDir/environments/environment.yml"
conda.useMamba = true
if (params.cache){
conda.cacheDir = params.cache
}
}
}

Expand All @@ -90,6 +92,10 @@ process {
withName: unicycler {
cpus = 12
}
withName: shovill {
cpus = 8
memory = '16 GB'
}
withName: prokka {
cpus = 8
}
Expand Down
Loading