FASTQ Files are huge. The recommended option for long term storage, archival and sharing over internet is BAM format. BAM files are binary aligned compressed files and uses considerably less space. However, often we have to go back to fastq format, because certain analysis works on fastq files only. You may have downloaded BAM files from Internet and want to convert to fastq format.
This article will explain how to Convert a BAM File to FASTQ format using SAMTOOLS and BEDTOOLS
Below are the steps to Convert BAM File to FASTQ format. This will work on Linux and will require SAMTOOLS and BEDTOOLS
- Download SAMTOOLS. It will be in samtools-version.tar.bz2 format.
- Extract using Command tar xzvf samtools-version.tar.bz2
- It will create a folder by the name samtools-version
- Move to the directory cd samtools-version
- Type make (This will compile and create executable)
- This is the directory where samtools will be installed. You can set path or provide the complete path when executing samtools
- SAMTOOLS is required to SORT the BAM Files. If your BAM files are already sorted you can miss the above steps
- Sort the BAM files. Type /complete_path/samtools sort filename.bam -0 filename.sorted.bam. You will be using filename.sort.bam to convert to fastq files.
- Download BedTools. Follow the same process of installation as for SAMTOOLS.
- Move to the bin directory.
- Execute /path_to_bedtools/bin/bamToFastq -i filename.sorted.bam -fq filename.sorted.fq
- For Paired end Bam /path_to_bedtools/bin/bamToFastq -i filename.sorted.bam -fq filename.sorted_1.fq -fq2 filename.sorted_2.fq
Your BAM file has been converted to FASTQ files and will be in the same directory