How do I use pysam to read header?

36 views
Skip to first unread message

Gregory Dougherty

unread,
Dec 23, 2023, 4:31:49 PM12/23/23
to Pysam User group

I need to pull header information from a cram file for use in python code. This seemed to be a good use for pysam.

However, I can not find any pysam sample code that lets you look at the header of an existing file.

pysam has the AlignmentHeader class, but nowhere in the pysam git repository can I find any indication of how I would use it, other than creating one to create a file.

Which is not the point.

So, does pysam let you get header information?

Gregory Dougherty

unread,
Jan 4, 2024, 1:05:54 PM1/4/24
to Pysam User group
Turns out the answer is:
import pysam
cram = pysam.AlignmentFile (theCram, 'rc')
cramHeader = cram.header.to_dict ()

Hopefully this will help the next person trying to figure this out
Reply all
Reply to author
Forward
0 new messages