This is a test version of Biostars. For the public version, visit https://www.biostars.org.
convert bam to fastq sequence based on the special region.

Hi,

I want to extract some sequences from a bam file. But I only want extract them from one special region. For example Chr01:2000-50000.

genome

2 answers

Extract a sub-bam with

samtools view -b -o out.bam in.bam Chr01:2000-50000

and extract the fastqs with SamToFastq (using option UNPAIRED_FASTQ)

Thanks. I try it.

You can do everything with samtools (bam needs to be indexed with samtools index file.bam):

samtools view -h file.bam Chr01:2000-50000 | samtools bam2fq - > file.fastq

Splitting single reads and paired reads to different files:

samtools view -h file.bam Chr01:2000-50000 | samtools bam2fq -s file-se.fastq - > file-pe.fastq

Or compressing the fastq:

samtools view -h file.bam Chr01:2000-50000 | samtools bam2fq - | gzip > file.fastq

Thanks. I have can get it.

Log in to answer this question.