Skip to content

Commit

Permalink
Add BAM input to MINIMAP2_ALIGN (nf-core#6021)
Browse files Browse the repository at this point in the history
* Add BAM input

* Update modules/nf-core/minimap2/align/main.nf

---------

Co-authored-by: Sofia Stamouli <[email protected]>
  • Loading branch information
fellen31 and sofstam authored Jul 26, 2024
1 parent d4ef560 commit a33ef94
Show file tree
Hide file tree
Showing 3 changed files with 490 additions and 14 deletions.
15 changes: 13 additions & 2 deletions modules/nf-core/minimap2/align/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,25 @@ process MINIMAP2_ALIGN {
script:
def args = task.ext.args ?: ''
def args2 = task.ext.args2 ?: ''
def args3 = task.ext.args3 ?: ''
def args4 = task.ext.args4 ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def bam_index = bam_index_extension ? "${prefix}.bam##idx##${prefix}.bam.${bam_index_extension} --write-index" : "${prefix}.bam"
def bam_output = bam_format ? "-a | samtools sort -@ ${task.cpus-1} -o ${bam_index} ${args2}" : "-o ${prefix}.paf"
def cigar_paf = cigar_paf_format && !bam_format ? "-c" : ''
def set_cigar_bam = cigar_bam && bam_format ? "-L" : ''
def bam_input = "${reads.extension}".matches('sam|bam|cram')
def samtools_reset_fastq = bam_input ? "samtools reset --threads ${task.cpus-1} $args3 $reads | samtools fastq --threads ${task.cpus-1} $args4 |" : ''
def query = bam_input ? "-" : reads
def target = reference ?: (bam_input ? error("BAM input requires reference") : reads)

"""
$samtools_reset_fastq \\
minimap2 \\
$args \\
-t $task.cpus \\
${reference ?: reads} \\
$reads \\
$target \\
$query \\
$cigar_paf \\
$set_cigar_bam \\
$bam_output
Expand All @@ -55,6 +63,9 @@ process MINIMAP2_ALIGN {
def prefix = task.ext.prefix ?: "${meta.id}"
def output_file = bam_format ? "${prefix}.bam" : "${prefix}.paf"
def bam_index = bam_index_extension ? "touch ${prefix}.bam.${bam_index_extension}" : ""
def bam_input = "${reads.extension}".matches('sam|bam|cram')
def target = reference ?: (bam_input ? error("BAM input requires reference") : reads)

"""
touch $output_file
${bam_index}
Expand Down
205 changes: 201 additions & 4 deletions modules/nf-core/minimap2/align/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ nextflow_process {
assertAll(
{ assert process.success },
{ assert snapshot(
file(process.out.bam[0][1]).name,
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
process.out.versions
).match() }
)
Expand Down Expand Up @@ -67,7 +68,8 @@ nextflow_process {
assertAll(
{ assert process.success },
{ assert snapshot(
file(process.out.bam[0][1]).name,
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
file(process.out.index[0][1]).name,
process.out.versions
).match() }
Expand Down Expand Up @@ -104,7 +106,8 @@ nextflow_process {
assertAll(
{ assert process.success },
{ assert snapshot(
file(process.out.bam[0][1]).name,
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
process.out.versions
).match() }
)
Expand Down Expand Up @@ -137,14 +140,113 @@ nextflow_process {
assertAll(
{ assert process.success },
{ assert snapshot(
file(process.out.bam[0][1]).name,
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
process.out.versions
).match() }
)
}

}

test("sarscov2 - bam, fasta, true, [], false, false") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)
]
input[2] = true
input[3] = []
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
process.out.versions
).match() }
)
}

}

test("sarscov2 - bam, fasta, true, 'bai', false, false") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)
]
input[2] = true
input[3] = 'bai'
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(
bam(process.out.bam[0][1]).getHeader(),
bam(process.out.bam[0][1]).getReadsMD5(),
file(process.out.index[0][1]).name,
process.out.versions
).match() }
)
}

}

test("sarscov2 - bam, [], true, false, false") {

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
[]
]
input[2] = true
input[3] = []
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.failed }
)
}

}

test("sarscov2 - fastq, fasta, true, [], false, false - stub") {

options "-stub"
Expand Down Expand Up @@ -241,4 +343,99 @@ nextflow_process {

}

test("sarscov2 - bam, fasta, true, [], false, false - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)
]
input[2] = true
input[3] = []
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("sarscov2 - bam, fasta, true, 'bai', false, false - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true)
]
input[2] = true
input[3] = 'bai'
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("sarscov2 - bam, [], true, false, false - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test', single_end:true ], // meta map
file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/bam/test3.single_end.markduplicates.sorted.bam', checkIfExists: true)
]
input[1] = [
[ id:'test_ref' ], // meta map
[]
]
input[2] = true
input[3] = []
input[4] = false
input[5] = false
"""
}
}

then {
assertAll(
{ assert process.failed }
)
}

}

}
Loading

0 comments on commit a33ef94

Please sign in to comment.