BamUtil: bam2FastQ
Purpose
This converts a BAM file into FastQ files. This is necessary when only BAM files are delivered but a new alignment is desired. By converting BAM to FastQ files new alignments can be done using FastQ files
How to use it
When bam2FastQ is invoked without any arguments the following information is displayed
The following parameters are in effect: Input BAM/SAM File : (-iname) Output FastQ Files Output : --first [], --second [], --single []
Required parameter
-i InputBAM/SAM
Optional parameters for output (however either --single or both --first and --second have to be provided)
--first firstReadInAPair_FastQ --second secondReadInAPair_FastQ --single unpairedReads_FastQ
In order to extract paired end reads, the BAM file has to be sorted by name, e.g. using samtools. Suppose the BAM file is myinput.bam
samtools sort -n myinput.bam myinput.sortByName
Using sorted bam file to extract paired end fastq files
bam2FastQ -i myinput.sortByName.BAM --first myread1.fastQ --second myread2.fastQ
Or to extract both paired end and single end fastq files (if the bam file contains both single and paired end reads)
bam2FastQ -i myinput.sortByName.BAM --first myread1.fastQ --second myread2.fastQ --single myreadSingle.fastQ
Or using bam (sorted or not) file to extract single end fastq files
bam2FastQ -i myinput.sortByName.BAM --single myreadSingle.fastQ