Skip to content

RFC: samtools merge to use htslib header parser - #259

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
Contributor

Following issue #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/htslib#116

@SamStudio8

Copy link
Copy Markdown
Contributor Author

Note the major code duplication between the handling of RG and PG structures in bam_sort.c is probably my next task after this RFC.

@SamStudio8

Copy link
Copy Markdown
Contributor Author

Note also the build will fail as it relies upon the additions in htslib.

@SamStudio8 SamStudio8 changed the title RFC: samtools merge to use header parser RFC: samtools merge to use htslib header parser Aug 1, 2014
@SamStudio8

Copy link
Copy Markdown
Contributor Author

@jmarshall Just wondering if you've had any thoughts on this PR (and its sister samtools/htslib/pull/116)? I think we're desperately in need of a proper header parser and I'm happy to take this forward with any recommendations and continue maintenance of it as part of samtools as necessary.

I should add that this dramatically improves the performance of samtools merge as described in /issues/203.

* Previously a regex was performed for each line in the translate->text
  data to initially locate @rg and @pg lines before another regex would
  then isolate the identifier and check whether it required translation.
  IDs matched from these latter expressions would then be checked over the
  entirity of the growing contents of out->text.
* These extensive and expensive searches are no longer required as the
  various @pg and @rg identifiers have already been isolated when
  the input files are read in by htslib.
* @rg and @pg data are stored in the header in linked lists that can
  easily be navigated to compare entries in translate and out for
  matching identifiers without the need for all the use of regular
  expressions.
* Conversion of @rg PG and @pg PP tags has been simplified as these
  values are also stored in the header's linked lists rather than
  requiring use of further regular expressions.
* Speed performance of merges, especially over large data sets has
  been dramatically improved.
@SamStudio8

Copy link
Copy Markdown
Contributor Author

I've brought this PR up to date with the current head of develop.

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.

1 participant