Skip to content

RFC: htslib header parser - #116

Closed
SamStudio8 wants to merge 1 commit into
samtools:developfrom
SamStudio8:mergemem
Closed

SamStudio8 wants to merge 1 commit into
samtools:developfrom
SamStudio8:mergemem

Conversation

@SamStudio8

Copy link
Copy Markdown

Following issue samtools/samtools#203 I have been experimenting with adding a BAM header parser in htslib and implementing use of its functionality in the reading in of BAM files for samtools merge, replacing the heavy and inefficient use of regular expressions. Currently this only handles the @rg and @pg lines, whose fields are each stored in a struct, which in turn make up a linked list stored in bam_hdr_t.

My C is a little rusty and I imagine my implementation could be simplified and polished somewhat, but I am happy to get some feedback on this as necessary so as I might be able to continue finishing this parser in the right direction.

See also samtools/samtools#259

@SamStudio8

Copy link
Copy Markdown
Author

Minor note; I'll need to check https://www.gnu.org/software/gnulib/manual/gnulib.html for portability of the datetime handling.

* Added bam_hdr_rg_entry struct to store metadata on each read group line
* Added bam_hdr_pg_entry struct to store metadata on each program group line
* bam_hdr_t stores pointer to next bam_hdr_[r|p]g_entry as rg, pg
* process_bam_hdr_entries accepts bam_hdr_t* and populates linked list
  structure of bam_hdr_rg_entry and bam_hdr_pg_entry by parsing contents
  of h->text
* bam_hdr_destroy frees rg and pg linked list structures via destroy functions
  bam_hdr_rg_entry_destroy and bam_hdr_pg_entry_destroy
* sam_hdr_read, bam_hdr_read and bam_hdr_dup populates header data via call to
  process_bam_hdr_entries before returning bam_hdr_t*
* Used by sister commit in samtools to drastically improve the
  performance of samtools merge command
@SamStudio8

Copy link
Copy Markdown
Author

Bump

@jkbonfield

Copy link
Copy Markdown
Contributor

It's worth coming up with a series of requirements and evaluating the current implementations, as we have several. Nils Homer's I think was the first (I forget where it is, probably in a pull request or his fork), I have one in CRAM (https://github.com/samtools/htslib/blob/develop/cram/sam_header.h) and there is this. Obviously I'm biased so I'll leave that evaluation to others. :-)

Likely some amalgamation of all of them is required.

@SamStudio8

Copy link
Copy Markdown
Author

Presumably any such series of requirements need be defined by those steering the project so implementations can be tested empirically and finally merged.

@jenniferliddle

Copy link
Copy Markdown
Member

I'm now in the position where I need to parse and edit header information.
Should I write my own functions, or use one of the existing non-canonical versions? If so, which one?
Are there any plans to integrate any of them into the main code and make an official API for doing this, or is everybody expected to write their own?

@SamStudio8

Copy link
Copy Markdown
Author

Hi Jennifer,
I think there is a plan to integrate header parsing with an officially
supported API (potentially by samtools 1.4, but perhaps that is my own
optimism?).
I've slowly been working on my own implementation in my spare time (atop of
this previous [somewhat hacky] implementation) but I imagine that's not
particularly useful as it sounds like you are in need of this functionality
now.
I suspect John or James could provide a better run down on the currently
existing non-canon versions that you might be able to use.

If desired, I'm happy to at least try and bring this previous
implementation up to speed with the current develop branch as it is at
least the most recent (I think).

Sam

On Wed, Mar 9, 2016 at 9:13 AM, Jennifer Liddle [email protected]
wrote:

I'm now in the position where I need to parse and edit header information.
Should I write my own functions, or use one of the existing non-canonical
versions? If so, which one?
Are there any plans to integrate any of them into the main code and make
an official API for doing this, or is everybody expected to write their own?

—
Reply to this email directly or view it on GitHub
#116 (comment).

@jenniferliddle

Copy link
Copy Markdown
Member

On 09/03/16 14:30, Sam Nicholls wrote:

Hi Jennifer,
I think there is a plan to integrate header parsing with an officially
supported API (potentially by samtools 1.4, but perhaps that is my own
optimism?).
I've slowly been working on my own implementation in my spare time (atop of
this previous [somewhat hacky] implementation) but I imagine that's not
particularly useful as it sounds like you are in need of this functionality
now.

What I've decided to do at the moment is go with James's version in
cram, on the grounds that it is already in htslib. A minor problem with
it is that it doesn't (yet) support deleting header items, so I'm
currently trying to implement that. And write some unit tests :-)

@valeriuo

valeriuo commented Aug 5, 2019

Copy link
Copy Markdown
Contributor

Implemented as #812

@valeriuo valeriuo closed this Aug 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants