How do i get and use AlignmentHeader from pysam?

80 views Asked by At

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?

1

There are 1 answers

0
Greg Dougherty On BEST ANSWER

Turns out the answer is:

import pysam
cram = pysam.AlignmentFile (theCram, 'rc')
cramHeader = cram.header.to_dict ()

Hopefully this will help someone else in the future