Skip to content

Commit

Permalink
Simplified consensus workflow
Browse files Browse the repository at this point in the history
Removed racon, now use only medaka against the input reference
  • Loading branch information
mcmero committed Jul 9, 2024
1 parent b60d9ee commit 50d0108
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 69 deletions.
3 changes: 1 addition & 2 deletions envs/racon-medaka.yaml → envs/medaka.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: racon-medaka
name: medaka
channels:
- conda-forge
- bioconda
dependencies:
- racon
- medaka

29 changes: 13 additions & 16 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -129,28 +129,25 @@ workflow {
CollateCounts(count_ch.counts.collect())

if (params.consensus) {
// reformat channel for consensus input
// to tuple (sampleName, bamFile, fastqFile)
// filter out unmapped and out files from splitcode
if (params.count_only) {
count_ch.alignments.filter { sampleName, bamFile, fastqFile ->
!bamFile.getName().startsWith("unmapped.bam") &&
!bamFile.getName().startsWith("out.bam")
}.set{ bam_ch }
demux_ch.set{ fastq_ch }
} else {
// in this case, bamFiles and fastqFiles are arrays
// in this case fastqFiles are arrays
// not singular elements per sample
count_ch.alignments.flatMap { sample ->
def (sampleName, bamFiles, fastqFiles) = sample
// reformat channel for consensus input
// to tuple (sampleName, fastqFile)
// filter out unmapped and out files from splitcode
demux_ch.flatMap { sample ->
def (sampleName, fastqFiles) = sample
return bamFiles.indices.collect { index ->
[sampleName, bamFiles[index], fastqFiles[index]]
[sampleName, fastqFiles[index]]
}
}.filter{ sampleName, bamFile, fastqFile ->
!bamFile.getName().startsWith("unmapped.bam") &&
!bamFile.getName().startsWith("out.bam")
}.set{ bam_ch }
}.filter{ sampleName, fastqFile ->
!fastqFile.getName().startsWith("unmapped.fastq") &&
!fastqFile.getName().startsWith("out.fastq")
}.set{ fastq_ch }
}
Consensus(bam_ch, file(params.guides_fasta), params.medaka_model)
Consensus(fastq_ch, file(params.guides_fasta), params.medaka_model)
}
}
}
13 changes: 7 additions & 6 deletions modules/medaka.nf
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ process Medaka {
publishDir "${params.outdir}/consensus/${sampleName}", mode: 'copy'

conda "${ params.conda_env_location != null && params.conda_env_location != '' ?
params.conda_env_location + '/racon-medaka' :
projectDir + '/envs/racon-medaka.yaml' }"
params.conda_env_location + '/medaka' :
projectDir + '/envs/medaka.yaml' }"

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'https://depot.galaxyproject.org/singularity/medaka:1.11.1--py310h87e71ce_0' :
'biocontainers/medaka:1.11.1--py310h87e71ce_0' }"

input:
tuple val(sampleName), path(reads), path(assembly)
tuple val(sampleName), path(reads)
path(reference)
val(medaka_model)

output:
Expand All @@ -27,15 +28,15 @@ process Medaka {
script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: reads.getSimpleName().replaceFirst("rezip_", "")
// will create a blank fasta file if racon assembly is blank
// will create a blank fasta file if fastq file input is blank
// as for some sample we will not be able to generate a consensus
"""
if [ -s ${assembly} ]; then
if [ -s ${reads} ]; then
medaka_consensus \\
-t $task.cpus \\
$args \\
-i $reads \\
-d $assembly \\
-d $reference \\
-m $medaka_model \\
-o ./
else
Expand Down
36 changes: 0 additions & 36 deletions modules/racon.nf

This file was deleted.

13 changes: 4 additions & 9 deletions subworkflows/consensus.nf
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
include { Racon } from '../modules/racon'
include { Medaka } from '../modules/medaka'
include { AlignPairs } from '../modules/align_pairs.nf'

process PrepareForConsensus {
label = "PrepareForConsensus"
// convert bam file to sam for racon and
// rezip fastq file using bgzip for medaka

publishDir "${params.outdir}/count/${sampleName}"
Expand All @@ -14,15 +12,14 @@ process PrepareForConsensus {
projectDir + '/envs/minimap-samtools.yaml' }"

input:
tuple val(sampleName), path(bam), path(fastq)
tuple val(sampleName), path(fastq)

output:
tuple val(sampleName), path("*.sam"), path("rezip_*.fastq.gz"), emit: racon_input
tuple val(sampleName), path("rezip_*.fastq.gz"), emit: rezipped

script:
def sample = bam.getSimpleName()
def sample = fastq.getSimpleName()
"""
samtools view -h ${bam} > ${sample}.sam
zcat < ${fastq} | bgzip -c - > rezip_${sample}.fastq.gz
"""
}
Expand All @@ -36,9 +33,7 @@ workflow Consensus {
main:
PrepareForConsensus(consensus_input)

Racon(PrepareForConsensus.out.racon_input, reference)

Medaka(Racon.out.racon_consensus, medaka_model)
Medaka(PrepareForConsensus.out.rezipped, reference, medaka_model)

consensus_sequences = Medaka.out.assembly

Expand Down

0 comments on commit 50d0108

Please sign in to comment.