This short tutorial teaches two ways, using samtools or bedtools, on how to convert a BAM to FASTQ.
BAM2FASTQ Using Samtools
You can use samtools to convert a BAM file to FASTQ.
$ samtools bam2fq ${YOUR_BAM_FILE}.bam > ${OUTPUT_FILE}.fastq
If you don’t know how to install it, you can do it using Bioconda by calling:
$ conda install samtools
BAM to FASTQ Using Bedtools
Moreover, you can use bedtools to convert a BAM file2FASTQ.
$ bedtools bamtofastq -i ${YOUR_BAM_FILE}.bam -fq ${OUTPUT_FILE}.fastq
If you don’t know how to install it, you can do it using Bioconda by calling:
$ conda install bedtools
More Resources
Here are three of my favorite Python Bioinformatics Books if you want to learn more about them.
- Python for the Life Sciences: A Gentle Introduction to Python for Life Scientists Paperback by Alexander Lancaster
- Bioinformatics with Python Cookbook by Tiago Antao
- Bioinformatics Programming Using Python: Practical Programming for Biological Data by Mitchell L. Model