bampysam

How do i get and use AlignmentHeader from pysam?


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?


Solution

  • 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