Skip to content

Commit

Permalink
Merge pull request #81 from nf-core/rename_bam_flags
Browse files Browse the repository at this point in the history
Adjustments for #76 , rename certain options to be more explicit
  • Loading branch information
apeltzer authored Nov 19, 2018
2 parents 011668d + a05b426 commit d91226f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### `Added`
* [#80](https://github.com/nf-core/eager/pull/80) - BWA Index file handling
* [#77](https://github.com/nf-core/eager/pull/77) - Lots of documentation updates by [@jfy133](https://github.com/jfy133)
* [#81](https://github.com/nf-core/eager/pull/81) - Renaming of certain BAM options

### `Fixed`
* [#84](https://github.com/nf-core/eager/pull/85) - Fix for [Samtools index issues](https://github.com/nf-core/eager/issues/84)


## [2.0.2] - 2018-11-03

### `Changed`
Expand Down
2 changes: 1 addition & 1 deletion conf/binac.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ singularity {
}

process {
beforeScript = 'module load devel/singularity/2.4.1'
beforeScript = 'module load devel/singularity/2.6.0'
executor = 'pbs'
queue = 'short'
}
Expand Down
20 changes: 14 additions & 6 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,17 +383,25 @@ Turn this on to utilize BWA Mem instead of `bwa aln` for alignment. Can be quite

Users can configure to keep/discard/extract certain groups of reads efficiently in the nf-core/eager pipeline.

### `--bam_keep_mapped_only`
### `--bam_retain_unmapped`

This can be used to only keep mapped reads for downstream analysis. By default turned off, all reads are kept in the BAM file. Unmapped reads are stored both in BAM and FastQ format e.g. for different downstream processing.
Specify this to keep also unmapped reads in the BAM file. This is the default setting, only mapping quality filters are applied to all reads.

### `--bam_keep_all`
### `--bam_separate_unmapped`

Turned on by default, keeps all reads that were mapped in the dataset.
Separates the mapped and unmapepd reads, keeps only mapped reads in the BAM file for downstream analysis.

### `--bam_filter_reads`
### `--bam_unmapped_to_fastq`

Specify this, if you want to filter reads for downstream analysis.
Converted unmapped reads in BAM format to compressed FastQ format.

### `--bam_discard_unmapped`

Discards unmapped reads in either FastQ or BAM format, depending on the choice of the `--bam_unmapped_rm_type`.

### `--bam_unmapped_rm_type`

Defines which unmapped read format to discard, options available are `bam` or `fastq.gz`. By default, `fastq.gz` format will be kept and `bam` will be removed.

### `--bam_mapping_quality_threshold`

Expand Down
46 changes: 28 additions & 18 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ def helpMessage() {
--bwamem Turn on BWA Mem instead of CM/BWA aln for mapping
BAM Filtering
--bam_keep_mapped_only Only consider mapped reads for downstream analysis. Unmapped reads are extracted to separate output.
--bam_filter_reads Keep all reads in BAM file for downstream analysis
--bam_mapping_quality_threshold Minimum mapping quality for reads filter
--bam_retain_unmapped Retains all unmapped reads in the BAM file (default)
--bam_separate_unmapped Separates mapped and unmapped reads, keep mapped BAM for downstream analysis.
--bam_unmapped_to_fastq Converts unmapped reads in BAM format to fastq.gz format.
--bam_discard_unmapped Discards unmapped reads in either FASTQ or BAM format, depending on choice in --bam_unmapped_rm_type
--bam_unmapped_rm_type Defines which unmapped read format to discard, options are "bam" or "fastq.gz".
--bam_mapping_quality_threshold Minimum mapping quality for reads filter, default 0.
DeDuplication
--dedupper Deduplication method to use
Expand Down Expand Up @@ -173,11 +176,15 @@ params.circularfilter = false
params.bwamem = false

//BAM Filtering steps (default = keep mapped and unmapped in BAM file)
params.bam_keep_mapped_only = false
params.bam_keep_all = true
params.bam_filter_reads = false
params.bam_retain_unmapped = true
params.bam_separate_unmapped = false
params.bam_discard_unmapped = false
params.bam_unmapped_to_fastq = false
params.bam_unmapped_rm_type = 'bam'

params.bam_mapping_quality_threshold = 0


//DamageProfiler settings
params.damageprofiler_length = 100
params.damageprofiler_threshold = 15
Expand Down Expand Up @@ -715,22 +722,25 @@ process samtools_filter {
file "*.unmapped.bam" optional true
file "*.bai"

when: "${params.bam_filter_reads}"

script:
prefix="$bam" - ~/(\.bam)?/
rm_type = "${params.bam_unmapped_rm_type}" == 'bam' ? 'bam' : 'fastq.gz'
rm_unmapped = "${params.bam_discard_unmapped}" ? "rm *.unmapped.${rm_type}" : ''
fq_convert = "${params.bam_unmapped_to_fastq}" ? "samtools fastq -tn ${prefix}.unmapped.bam | pigz -p ${task.cpus} > ${prefix}.unmapped.fq.gz" : ''


if("${params.bam_keep_mapped_only}"){
"""
samtools view -h $bam | tee >(samtools view - -@ ${task.cpus} -f4 -q ${params.bam_mapping_quality_threshold} -o ${prefix}.unmapped.bam) >(samtools view - -@ ${task.cpus} -F4 -q ${params.bam_mapping_quality_threshold} -o ${prefix}.filtered.bam)
samtools fastq -tn "${prefix}.unmapped.bam" | gzip > "${prefix}.unmapped.fq.gz"
samtools index ${prefix}.filtered.bam
"""
if("${params.bam_separate_unmapped}"){
"""
samtools view -h $bam | tee >(samtools view - -@ ${task.cpus} -f4 -q ${params.bam_mapping_quality_threshold} -o ${prefix}.unmapped.bam) >(samtools view - -@ ${task.cpus} -F4 -q ${params.bam_mapping_quality_threshold} -o ${prefix}.filtered.bam)
samtools index ${prefix}.filtered.bam
$fq_convert
$rm_unmapped
"""
} else {
"""
samtools view -h $bam | tee >(samtools view - -@ ${task.cpus} -f4 -q ${params.bam_mapping_quality_threshold} -o ${prefix}.unmapped.bam) >(samtools view - -@ ${task.cpus} -q ${params.bam_mapping_quality_threshold} -o ${prefix}.filtered.bam)
samtools index ${prefix}.filtered.bam
"""
"""
samtools view -h $bam -@ ${task.cpus} -q ${params.bam_mapping_quality_threshold} -o ${prefix}.filtered.bam)
samtools index ${prefix}.filtered.bam
"""
}
}

Expand Down

0 comments on commit d91226f

Please sign in to comment.