Extracting a chromosome from an indexed bam file?
0
0
Entering edit mode
5.2 years ago
tuj92050 • 0

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?

bam chromosome samtools • 5.2k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
1
Entering edit mode

you want

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

not the bai file

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1622 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