pysam can't find bam index

2,039 views
Skip to first unread message

Luke Noble

unread,
Nov 26, 2011, 9:21:33 PM11/26/11
to pysam-us...@googlegroups.com
Hello,

pysam seemed to install without complaint and works fine for me on sam files, but fails to find the matching .bai file when I try to iterate over bam files.

e.g.
File "csamtools.pyx", line 749, in csamtools.Samfile.fetch (pysam/csamtools.c:8439)
ValueError: fetch called on bamfile without index

Any ideas?
probably, sigh, system specific... I've not found any reference to this error elsewhere.

Cheers,
Luke

pysam 0.5
python 2.7
pyrex 0.9.9
cython 0.14.1 
on Mac OS X 10.7

Readman Chiu

unread,
Nov 27, 2011, 12:33:25 AM11/27/11
to pysam-us...@googlegroups.com
Hi Luke,

You have to use Samtools sort and index your bam file before it's usable by Pysam for accessing read alignments.

cheers,
Readman

Luke Noble

unread,
Nov 27, 2011, 2:42:51 AM11/27/11
to pysam-us...@googlegroups.com
Thanks Readman, 

But for all cases, the .bai is sitting there in the same directory as the .bam, identically named but for the extension. They're just not being recognised.

Luke

Peter Cock

unread,
Nov 27, 2011, 6:18:11 AM11/27/11
to pysam-us...@googlegroups.com
Using example.bam do you have example.bai or
example.bam.bai as the index? Sadly samtools
and Picard picked different conventions, I'm not
sure if pysam checks both.

Peter

Sean Davis

unread,
Nov 27, 2011, 7:45:14 AM11/27/11
to pysam-us...@googlegroups.com

You'll need a file called example.bam.bai (samtools convention) for pysam.  Either rename or softlink the .bai file and you should be set.

Sean

Reply all
Reply to author
Forward
0 new messages