In the SAM format, each alignment line represents the linear alignment of a segment, and each line have 11 mandatory fields, i.e. QNAME, FLAG, RNAME, POS, MAPQ, etc.
Let's say I wanted a NumPy array of all "QNAMES" in a given BAM file. Or, one could take several columns and import them into Pandas Dataframe.
Is this functionality possible with pysam?
One can naturally open a given BAM file with pysam.AlignmentFile()
and then access individual segments with pysam.AlignmentSegment()
, e.g.
seg = AlignmentSegment()
print(seg.qname)
However, could you save all QNAMES into NumPy array?