Running BamTools Commands

BamTools Convert

One of the most frequently used BamTools command is convert.

The basic usage of the BamTools convert is:

$ bamtools convert -format [bed|fasta|fastq|json|pileup|sam|yaml] -in input_alignments.bam -out output_reads.[bed|fasta|fastq|json|pileup|sam|yaml]
where the option -format specifies the type of the output file, input_alignments.bam is the input BAM file, and -out defines the name and the type of the converted file.

Running BamTools convert on Tusker with input file input_alignments.bam and output file output_reads.fastq is shown below:

bamtools_convert.submit
#!/bin/sh
#SBATCH --job-name=BamTools_Convert
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=168:00:00
#SBATCH --mem=10gb
#SBATCH --output=BamTools.%J.out
#SBATCH --error=BamTools.%J.err

module load bamtools/2.4

bamtools convert -format fastq -in input_alignments.bam -out output_reads.fastq

All BamTools commands are single threaded, and therefore both #SBATCH --nodes and #SBATCH --ntasks-per-node are set to 1.

BamTools Count

The basic usage of the BamTools count is:

$ bamtools count -in input_alignments.bam
The command bamtools count outputs the total number of alignments in the BAM file.

BamTools Coverage

The basic usage of the BamTools coverage is:

$ bamtools coverage -in input_alignments.bam -out output_reads_coverage.txt
The command bamtools coverage prints the coverage data for a single BAM file.

BamTools Filter

The basic usage of the BamTools filter is:

$ bamtools filter -in input_alignments.bam -out output_alignments_filtered.bam -length 100
The command bamtools filter filters the BAM file based on specified options. In this example, the resulting bam file output_alignments_filtered.bam contains alignments with length longer than 100 base pairs.

BamTools Header

The basic usage of the BamTools header is:

$ bamtools header -in input_alignments.bam -out output_alignments_header.txt
The command bamtools header prints the header from BAM file.

BamTools Index

The basic usage of the BamTools index is:

$ bamtools index -in input_alignments.bam
The command bamtools index creates index for BAM file and prints input_alignments.bam.bai file.

BamTools Merge

The basic usage of the BamTools merge is:

$ bamtools merge -in input_alignments_1.bam -in input_alignments_2.bam -in input_alignments_3.bam -out output_alignments_merged.bam
The command bamtools merge merges multiple (more than 2) BAM files into one.

BamTools Random

The basic usage of the BamTools random is:

$ bamtools random -in input_alignments.bam -out output_alignments_100.bam -n 100
The command bamtools random grabs a random subset of alignments. With the option -n 100, 100 randomly chosen alignments are stored in the output file output_alignments_100.bam.

BamTools Resolve

The basic usage of the BamTools resolve is:

$ bamtools resolve -twoPass -in input_alignments.bam -out output_alignments.bam
The command bamtools resolve resolves paired-end reads. The resolving mode is required, and it can be -makeStats, -markPairs, or -twoPass.

BamTools Revert

The basic usage of the BamTools revert is:

$ bamtools revert -in input_alignments.bam -out output_alignments_reverted.bam
The command bamtools revert removes duplicate marks and restores original base qualities.

BamTools Sort

The basic usage of the BamTools sort is:

$ bamtools sort -in input_alignments.bam -out output_alignments_sorted.bam -byname
The command bamtools sort sorts a BAM file according to a given option. output_alignments_sorted.bam is the resulting file, where the alignments are sorted by name.

BamTools Split

The basic usage of the BamTools split is:

$ bamtools split -in input_alignments.bam -mapped
The command bamtools split splits BAM file on user-specified property and creates a new BAM output file for each value found. In the given example, an output file input_alignments.MAPPED.bam is produced after -mapped split option is specified. Beside mapped, the split option can be: -paired, -reference, or -tag <tag_name>.

BamTools Stats

The basic usage of the BamTools stats is:

$ bamtools stats -in input_alignments.bam
The command bamtools stats prints general alignment statistics from the BAM file.