Skip to content

Create an iterator over PileupColumns from a list of AlignedSegments #1352

@nh13

Description

@nh13

Currently, to create an iterator over PileupColumns, we need to call AlignmentFile.pileup().

If instead we have a list of AlignedSegments and want to a pileup, we have write it to a file and return the pileup, which is pretty ugly and inefficient.

I wanted to inquire about the appetite for adding support for this into pysam via a PR.

Sketching this out quickly to prove to myself this is feasible, I was thinking the following:

  1. Create a htslib pileup struct (bam_plp_t) using bam_plp_init.
  2. Push all the records (bam1_t) onto the pileup using bam_plp_push.
  3. Call bam_plp_next to yield the next pileups (in the next method of the iterator).
  4. Use bam_mplp_t to iterator over the range of possible positions (assumes the records are in coordinate sorted order when pushed on the underlying iterator)
  5. Use the above to implement the IteratorColumn interface.

If that sounds like a reasonable implementation sketch, I'd be glad to make a PR.
I made a draft PR for comments before I go any further (e.g. tests): #1353

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions