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

Enhancement/bam2fastq #960

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions conf/containers.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
//------------- Read alignment

process {
withName:bam2fastq {
container = "broadinstitute/gatk:4.1.9.0"
}
withName:AlignReads {
container = "cmopipeline/fastp-bwa-samtools:2.0.0"
}
Expand Down
4 changes: 4 additions & 0 deletions conf/resources_juno_genome.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
//------------- Read alignment

process {
withName:bam2fastq {
cpus = { 1 }
memory = { 16.GB + (task.attempt).GB }
}
withName:CrossValidateSamples {
cpus = { 1 }
memory = { 1.GB }
Expand Down
23 changes: 19 additions & 4 deletions dsl2.nf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ referenceMap = defineReferenceMap()
targetsMap = loadTargetReferences()

//Sub-workflow Includes
include { bam2fastq } from './modules/process/Alignment/bam2fastq'
include { validate_wf } from './modules/subworkflow/validate_wf' addParams(referenceMap: referenceMap, targetsMap: targetsMap)
include { alignment_wf } from './modules/subworkflow/alignment_wf' addParams(referenceMap: referenceMap, targetsMap: targetsMap)
include { manta_wf } from './modules/subworkflow/manta_wf' addParams(referenceMap: referenceMap, targetsMap: targetsMap)
Expand Down Expand Up @@ -58,7 +59,7 @@ WFs = (!params.mapping && !params.bamMapping && aggregateParamIsFile) ? ['snv','

workflow {
//Set flags for when each pipeline is required to run.
doWF_align = (params.mapping) ? true : false
doWF_align = params.mapping || (params.bam2fastq && params.bamMapping) ? true : false
doWF_manta = ['snv', 'sv', 'mutsig'].any(it -> it in WFs) ? true : false
doWF_scatter = ['snv', 'sv', 'mutsig', 'germsnv'].any(it -> it in WFs) ? true : false
doWF_germSNV = 'germsnv' in WFs ? true : false
Expand Down Expand Up @@ -96,7 +97,7 @@ workflow {
exit 1
}

if (params.bamMapping && WFs == ['']){
if (params.bamMapping && !params.bam2fastq && WFs == ['']){
println "ERROR: No sub-workflows to run.."
println "\tPlease provide sub-workflows using --workflow parameters."
exit 1
Expand Down Expand Up @@ -126,13 +127,27 @@ workflow {
inputMapping = validate_wf.out.inputMapping
inputPairing = validate_wf.out.inputPairing

if (params.bam2fastq)
{
inputBam = inputMapping
bam2fastq(inputBam)
fastqs = bam2fastq.out.fastqOutput
.map { idSample, targets, files_pe1, files_pe2
-> tuple(groupKey(idSample, files_pe1.size()), targets, files_pe1, files_pe2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails with large bams that exceed the max int value. The type of files_pe1.size() would then be 'long' which is not able to be used by groupKey.

}
.transpose()
}
else {
fastqs = inputMapping
}

if (doWF_align)
{
alignment_wf(inputMapping)
alignment_wf(fastqs)
}

//Handle input bams as coming originally from bams, or from an alignment this run.
if (params.bamMapping) {
if (params.bamMapping && !params.bam2fastq) {
inputBam = inputMapping
if (doWF_QC){
inputMapping.map{idSample, target, bam, bai ->
Expand Down
36 changes: 36 additions & 0 deletions modules/process/Alignment/bam2fastq.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
process bam2fastq {
tag "${idSample}"

input:
tuple val(idSample), val(target), file(bam), val(bai)

output:
tuple val(idSample), val(target), path("*_1.fastq.gz"), path("*_2.fastq.gz"), emit: fastqOutput

script:
inputSize = bam.size()
if (workflow.profile == "juno") {
if (inputSize > 80.GB) {
task.time = { params.maxWallTime }
}
else if (inputSize < 40.GB) {
task.time = task.exitStatus.toString() in params.wallTimeExitCode ? { params.medWallTime } : { params.minWallTime }
}
else {
task.time = task.exitStatus.toString() in params.wallTimeExitCode ? { params.maxWallTime } : { params.medWallTime }
}
// if it's the last time to try, use 500h as time limit no matter for what reason it failed before
task.time = task.attempt < 3 ? task.time : { params.maxWallTime }
}
memMultiplier = params.mem_per_core ? task.cpus : 1
// when increase memory requested from system every time it retries, keep java Xmx steady, in order to give more memory for java garbadge collection
originalMem = task.attempt ==1 ? task.memory : originalMem
maxMem = (memMultiplier * originalMem.toString().split(" ")[0].toInteger() - 3)
maxMem = maxMem < 4 ? 5 : maxMem
javaOptions = "--java-options '-Xmx" + originalMem.toString().split(" ")[0].toInteger() * memMultiplier + "g'"

"""
gatk SamToFastq ${javaOptions} VALIDATION_STRINGENCY=LENIENT I=${bam} RG_TAG=ID OUTPUT_PER_RG=true COMPRESS_OUTPUTS_PER_RG=true OUTPUT_DIR=./ INCLUDE_NON_PF_READS=true INCLUDE_NON_PRIMARY_ALIGNMENTS=true
ls *.fastq.gz | xargs -I {} -n1 mv {} `basename ${idSample}`@{}
"""
}
14 changes: 0 additions & 14 deletions modules/subworkflow/alignment_wf.nf
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ workflow alignment_wf
referenceMap = params.referenceMap
targetsMap = params.targetsMap

if (params.bamMapping)
{
println "Alignment workflow cannot accept bam files for input."
exit 1
}
if(params.mapping)
{
// Parse input FASTQ mapping
if (params.watch != true) {
inputMapping.groupTuple(by: [0])
Expand Down Expand Up @@ -180,13 +173,6 @@ workflow alignment_wf
out.println "${obj[0]}\t${obj[1]}\t${obj[2]}\t${obj[3]}"
}
}
}
else{
if(params.pairing){
println "ERROR: When --pairing [tsv], --mapping [tsv] must be provided."
exit 1
}
}


emit:
Expand Down
1 change: 1 addition & 0 deletions nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ params {
pairing = false
bamMapping = false
splitLanes = true
bam2fastq = false
QC = false
aggregate = false
fileTracking = 'fileTracking.tsv'
Expand Down