Question: Extracting a chromosome from an indexed bam file?
0
gravatar for tuj92050
12 weeks ago by
tuj920500
tuj920500 wrote:

This is for a course I am currently taking. I have downloaded an indexed bam file (.bai) of all the exome reads from thr 1000 genomes project. The next step in this assignment is extracting the reads for chromosome 22 of this file. I tried samtools to do this

samtools view -b NA20515.bam.bai chr22 > chr22.bam

But I am met with the error

[E::hts_hopen] Failed to open file NA20515.bam.bai
[E::hts_open_format] Failed to open file NA20515.bam.bai
samtools view: failed to open "NA20515.bam.bai" for reading: Exec format error

Obviously I don't think I can do this with samtools. Is there any other way to do this?

chromosome samtools bam • 243 views
ADD COMMENTlink modified 12 weeks ago • written 12 weeks ago by tuj920500
1

You should do samtools view on bam file, not .bai file.

ADD REPLYlink written 12 weeks ago by genomax67k
1

you want

samtools view -b NA20515.bam chr22 > chr22.bam

not the bai file

ADD REPLYlink written 12 weeks ago by Pierre Lindenbaum120k

I just tried that and I got the error "random alignment retrieval only works for indexed BAM or CRAM files"

ADD REPLYlink written 12 weeks ago by tuj920500

It's not clear to me; do you have both NA20515.bam and NA20515.bam.bai? Are they together in the same directory?

ADD REPLYlink written 12 weeks ago by swbarnes25.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: 1386 users visited in the last hour