Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d3498d5
Add blobtk depth to calculate read coverage
sainsachiko Jun 10, 2025
937f0a5
Apply suggestions from code review
sainsachiko Jun 20, 2025
8e2a7cc
Add BGZIP to compress bedGraph coverage
sainsachiko Jun 23, 2025
1f5e0c3
Update tabix/bgzip
sainsachiko Jun 23, 2025
07fc446
Fix: BAM/CRAM reheader and BLOBTK DEPTH cache
sainsachiko Jun 27, 2025
8bf07e5
Use ln -s to change file names
sainsachiko Jun 27, 2025
f12c5f3
Merge branch 'dev' into hhoang-read-coverage
sainsachiko Jun 30, 2025
677c727
Fix linting
sainsachiko Jun 30, 2025
9e02bf0
Remove module config of SAMTOOLS_REINDEX
sainsachiko Jun 30, 2025
dc04537
Not used
muffato Jul 2, 2025
d9b4bd5
We pass a BAM file, not a CRAM file
muffato Jul 2, 2025
316262b
Too many names like "ch_bams" is confusing !
muffato Jul 2, 2025
684384d
Simplified the CHANGE_NAME module
muffato Jul 2, 2025
4199fd7
It's the CRAM output that we want
muffato Jul 2, 2025
d12030d
No conversion is happening here
muffato Jul 2, 2025
a10f97a
Allow rerunning
muffato Jul 2, 2025
03f6d98
Our convention is not to prefix workflow inputs with "ch_"
muffato Jul 2, 2025
89a8bd8
More straightforward sub-workflow
muffato Jul 2, 2025
ac819b4
Trick for not publishing the BAM when CRAM output is selected
muffato Jul 2, 2025
5034665
More explicit name
muffato Jul 3, 2025
c631bd0
Merge pull request #176 from sanger-tol/hhoang-read-coverage_review
muffato Jul 4, 2025
c48ba52
Input both file and index for stats process
sainsachiko Jul 8, 2025
76a4602
Publish cram index when provide header
sainsachiko Jul 8, 2025
8cde426
Remove trailing whitespace
muffato Jul 9, 2025
6119963
Merge pull request #177 from sanger-tol/hhoang-read-coverage_change_name
muffato Jul 9, 2025
2b4f66a
Remove a trailing empty line
muffato Jul 14, 2025
295e5b6
Merge pacbio chunked bam after alignment
sainsachiko Jul 15, 2025
493b28f
Do not publish BAM from SAMTOOLS_INDEX if re-header BAMs
sainsachiko Jul 15, 2025
f4a660b
[lint] Removed trailing whitespace
muffato Jul 15, 2025
6df042c
Publish bam file when no header
sainsachiko Jul 16, 2025
dad4ee7
[lint] Removed trailing whitespace
muffato Jul 16, 2025
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
5 changes: 5 additions & 0 deletions conf/base.config
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,9 @@ process {
// 100k reads per hour for PacBio, 50m for HiC
time = { 1.h * Math.ceil( meta.read_count / (meta.datatype == "pacbio" ? 100000 : 50000000)) * task.attempt }
}

withName: BLOBTK_DEPTH {
cpus = { log_increase_cpus(4, 2*task.attempt, 1, 2) }
Comment thread
sainsachiko marked this conversation as resolved.
memory = { 1.GB * Math.ceil( meta.read_count / 1000000 ) * task.attempt }
Comment thread
muffato marked this conversation as resolved.
Outdated
}
}
6 changes: 5 additions & 1 deletion conf/modules.config
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ process {
ext.args = { (meta.datatype == "pacbio" ? "-y pbccs " : "") + "-O bam" }
}

withName: '.*:CONVERT_STATS:SAMTOOLS_.*' {
withName: '.*:CONVERT_STATS:SAMTOOLS_.*|BLOBTK_DEPTH' {
beforeScript = { "export REF_PATH=spoof"}
publishDir = [
path: { "${params.outdir}/read_mapping/${meta.datatype}" },
Expand All @@ -172,4 +172,8 @@ process {
]
}

withName: BLOBTK_DEPTH {
ext.prefix = { "${cram.baseName}" }
}

}
13 changes: 13 additions & 0 deletions docs/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ The filtered PacBio reads are aligned with `MINIMAP2_ALIGN`. The sorted and merg

If provided using the `--header` option, all output alignments (`*.cram` or `*.bam`) will include any additional metadata supplied as a SAM header template, replacing the existing _@HD_ and _@SD_ entries (note that this behaviour can be altered by modifying the `ext.args` for `SAMTOOLS_REHEADER` in `modules.config`).

### Read coverage

Read coverage of the output alignment file is calculated with [blotk_depth](https://github.com/genomehubs/blobtk/wiki/blobtk-depth).
Comment thread
sainsachiko marked this conversation as resolved.
Outdated

<details markdown="1">
<summary>Output files</summary>

- `read_mapping`
- `<sequence-type>`
- `<gca_accession>.unmasked.<sequence-type>.<sample_id>.[cr|b]am.regions.bed.gz`: Read coverage in BED format
Comment thread
sainsachiko marked this conversation as resolved.
Outdated

</details>

### Statistics

The output alignments, along with the index, are used to calculate mapping statistics. Output files are generated using `SAMTOOLS_STATS`, `SAMTOOLS_FLAGSTAT` and `SAMTOOLS_IDXSTATS`.
Expand Down
34 changes: 34 additions & 0 deletions modules/local/blobtk_depth.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
process BLOBTK_DEPTH {
tag "${meta.id}"
label 'process_single'

if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) {
exit 1, "BLOBTOOLKIT_DEPTH module does not support Conda. Please use Docker / Singularity / Podman instead."
}
container "docker.io/genomehubs/blobtk:0.6.5"

input:
tuple val(meta), path(cram), path(bai)

output:
tuple val(meta), path('*.regions.bed.gz') , emit: bed
path "versions.yml" , emit: versions

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

script:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
blobtk depth \\
-c ${cram} \\
$args \\
-O ${prefix}.regions.bed.gz \\
Comment thread
muffato marked this conversation as resolved.
Outdated
Comment thread
sainsachiko marked this conversation as resolved.
Outdated

cat <<-END_VERSIONS > versions.yml
"${task.process}":
blobtk: \$(blobtk --version | cut -d' ' -f2)
END_VERSIONS
"""
}
10 changes: 8 additions & 2 deletions subworkflows/local/convert_stats.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Convert BAM to CRAM, create index and calculate statistics
//

include { BLOBTK_DEPTH } from '../../modules/local/blobtk_depth'
include { CRUMBLE } from '../../modules/nf-core/crumble/main'
include { SAMTOOLS_VIEW as SAMTOOLS_CRAM } from '../../modules/nf-core/samtools/view/main'
include { SAMTOOLS_VIEW as SAMTOOLS_REINDEX } from '../../modules/nf-core/samtools/view/main'
Expand Down Expand Up @@ -81,15 +82,20 @@ workflow CONVERT_STATS {

// Set the BAM and BAI channels for emission
ch_bam = SAMTOOLS_REINDEX.out.bam
ch_bai = SAMTOOLS_REINDEX.out.bai
ch_csi = SAMTOOLS_REINDEX.out.csi

// If using BAM for stats, use the reindexed BAM
if ( !("cram" in outfmt_options) ) {
ch_data_for_stats = ch_bam.join ( ch_bai )
ch_data_for_stats = ch_bam.join ( ch_csi )
}
}


// Calculate read depth
BLOBTK_DEPTH ( ch_data_for_stats )
ch_versions = ch_versions.mix( BLOBTK_DEPTH.out.versions.first() )


// Calculate statistics
SAMTOOLS_STATS ( ch_data_for_stats, fasta )
ch_versions = ch_versions.mix( SAMTOOLS_STATS.out.versions.first() )
Expand Down