convert bam to fastq sequence based on the special region.
2
0
Entering edit mode
8.5 years ago
fufuyou ▴ 110

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 • 3.1k views
ADD COMMENT
1
Entering edit mode
8.5 years ago

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)

ADD COMMENT
0
Entering edit mode

Thanks. I try it.

ADD REPLY
1
Entering edit mode
8.5 years ago
h.mon 35k

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
ADD COMMENT
0
Entering edit mode

Thanks. I have can get it.

ADD REPLY

Login before adding your answer.

Traffic: 3111 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6