This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How do I extract aligned reads from BAM file?

Hi, I have a fasta sequence to which I have aligned a fastq file using bowtie and got a BAM file. I need to extract all the reads in fastq file that aligned to my fasta sequence. Can I just extract all the reads from the BAM file I got from bowtie alignment in this case? Please suggest me if I should be doing something different. Thanks!

fastq bam

1 answer

Yes, just use samtools fastq with the BAM file produced by bowtie2. You'll presumably want to use the -F 4 option.

Thanks Devon. Since I will be extracting all the aligned reads from bam file, I had to use this command: samtools fasta input.bam -F 4 > output.fasta

Log in to answer this question.