4.3 downsample

Downsampling a BAM file by removing reads

downsample creates downsampled BAM files that contain a specified percentage of the original number of reads. More than one percentage/probability can be specified, and thus allows the creation of several downsampled BAM files at a time. In this task, all reads are considered, even those that do not pass the usual SAM flag filters.

4.3.1 Input

Required inputs :

--bam Input_bam_file.bam Input bam file

Optional inputs :

  • None

Specific parameters :

--prob numeric_value One value or a vector of percentages of reads to be kept in the downsampled BAM files. The numeric value must be between 0 and 1 (inclusive). It is possible to obtain replicates by adding the desired number of replicates in curly brackets {} after the concerned percentage. Incompatible with --depth.
--depth numeric_value One value or a vector of sequencing depths to downsample to. The original depth will be estimated by the task, unless provided with --averageDepth. Incompatible with --prob.
--separateReads or --writeN --separateReads will downsample by removing reads and --writeN will downsample by setting bases to N. Default = --writeN

Optional parameters :

--outQual integer_1,integer_2 to constrain the quality scores to the indicated range (inclusive) when writing alignments. Default = uses the full range of quality scores when writing alignments.
--writeBinnedQualities to write Illumina-binned quality scores. Default = writes raw quality scores.
--averageDepth numeric_value When using the --depth parameter to downsample, the original sequencing depth can be provided with --averageDepth (available in BAMDiagnostics outputs). Default = the average will be computed, significantly increasing the runtime
--regions \*.bed To limit analysis to regions defined in BED file. Default = Parse all available positions in .bam
--acceptedDistance integer_value To specify distance up-to which mates will not be considered orphans. Default = 10000 bp.
--downsampleTarget Downsampling to a specific depth at target sites defined in a bed file additionally provided using --bed target.bed. Whenever read data is available, the downsampling depth provided using --depth will be reached at these positions.

Engine parameters that are common to all tasks can be found here.

4.3.2 Output

*_separated_*Prob*.bam or *_downsampled_*Prob*.bam or Downsampled BAM files(downsampled by removing reads) or Downsampled BAM files(downsampled by setting bases to N).
*_separated_*Prob*.bam.bai or *_downsampled_*Prob*.bam.bai Index files for downsampled BAM files (downsampled by removing reads) or Index files for downsampled BAM files (downsampled by setting bases to N).
*_filterSummary.txt .txt file with per readgroup general filter counts and all readgroups general filter counts.

4.3.3 Usage Example

#! /bin/bash

# Set atlas path
atlas=$(dirname "$0")/../build/atlas

# Simulate a BAM File with depth 15
$atlas simulate --depth 15

# downsample to depth 3.14
$atlas downsample --bam ATLAS_simulations.bam --depth 3.14

# simplify name of downsampled bam-file
mv ATLAS_simulations_downsample_downsampled_3.14x.bam downsampled.bam
mv ATLAS_simulations_downsample_downsampled_3.14x.bam.bai downsampled.bam.bai

# Calculate depth of downsampled BAM File
$atlas BAMDiagnostics --bam downsampled.bam