Question: Convert Part Of A Bam File To Sam
3
gravatar for User 9906
8.1 years ago by
User 990650
User 990650 wrote:

Is it possible to work on a part of a BAM file?

Since these files are huge, I want to extract 1MB of the BAM file and convert it to SAM.

My main intention is to extract a meaningful part from the BAM file and then convert it to SAM instead of converting the whole BAM file to SAM.

Thanks in advance for your answers.

bam sam • 2.6k views
ADD COMMENTlink written 8.1 years ago by User 990650
9
gravatar for Farhat
8.1 years ago by
Farhat2.9k
Pune, India
Farhat2.9k wrote:

It would help if you gave an idea of what you are trying to do with the BAM file. To extract a portion of the BAM file you could try something like

samtools view -h aln.sorted.bam chr2:20,100,000-20,200,000 > out.sam

to get reads from a region of the bam file. Or to get a certain number of reads you may try

samtools view aln.sorted.bam chr2:20,100,000-20,200,000 | head -20000 | samtools view -t ref.fa.fai - > out.sam

where ref.fa.fai is a tab delimited file generated using samtools faidx command. The above command will pick 20000 reads from the selected region.

ADD COMMENTlink written 8.1 years ago by Farhat2.9k
2
gravatar for Pascal
8.1 years ago by
Pascal1.5k
Barcelona
Pascal1.5k wrote:

Just to complete Farhat answer: when using "samtools view" instead of redirecting output with ">" (std output) you should better use the "-o FILE Output file" option.

ADD COMMENTlink written 8.1 years ago by Pascal1.5k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1602 users visited in the last hour