Repository navigation
Proposal: Use sam_hdr_ prefix for new header API functions - #887
Conversation
|
Anything that avoids the nonsense of schizophrenic name changes like this would be appreciated: For frell's sake - allocate with sam and destroy with bam. Ugh. I think the problem is the structure is bam_hdr_t which isn't really correct. Our functions should reflect the structure, and the structure is a SAM header (a parsed form of the textual format which is shared between SAM, BAM and CRAM) and not labelling it as a BAM specific structure name. Unfortunately we also have bam1_t for the bam structure, but that - more or less - actually is BAM format in memory. The original API (from io_lib and later htslib/cram) had |
Yep, that compiled without warnings and passed its tests. (I half-expected samtools to define its own |
|
I think I would like to see the structure renamed I think the name clashing may well have been resolved when the parsed headers struct got renamed to |
|
Thanks Rob. That sounds like a likely theory about the intermediate name clashing. Agreed re fully consistent. I'm happy to add to this PR to rename the struct to |
|
Yes, that would be fine, thanks. |
|
Any progress on this yet? |
|
Yep, sorry about the delay: day job got busy, and there's a couple of internal functions to disentangle. Should be ready tomorrow. In the meantime, for mulling on, here are a couple of minor new-API problems I've noticed so far:
|
|
On On |
|
This should be ready to go now. You might or might not want to take the final commit (1faa906) which renames
|
|
Deserves a NEWS entry, I guess… |
|
NEWS entry added and struct tag renamed. |
16d448c to
62b72d2
Compare
|
Sigh… that NEWS update caused a merge conflict so CI couldn't run. Added a commit merging from develop so we can observe the green tick 😄 That |
|
Looks good. Would it be possible to rebase the whole thing and force push the result onto your existing branch? |
|
No problem, will do. So that's a yes to |
|
Yes, consistency for the win. Plus it's internal so shouldn't break anything. |
This follows the convention of sam_-prefixed functions operating on SAM/BAM/CRAM while bam_-prefixed functions operate only on BAM. (Apart from legacy items such as bam_hdr_init().) htslib/cram.h contained sam_hdr_length() and sam_hdr_str() functions even before the header API landed; remove these declarations as compatible functions are now provided by htslib/sam.h. #include that from htslib/cram.h to get those declarations and as cram.h now uses bam_hdr_t directly. (Amend htslib_vars.mk accordingly.) Remove now unnecessary sam_hdr_length()->bam_hdr_length() and *_str() shims from headers.c.
There is already a (legacy) SAM_hdr type, so having sam_hdr as well would be confusing.
These instances of [sb]am_hdr_remove_line_key() were omitted from 919d33c while the remainder appear to have originated as typos.
Add bam_hdr_t compatibility typedef. Rename the struct tag to `struct sam_hdr_t`; in the previous 1.9 release, bam_hdr_t was a typedef for an unnamed struct, so renaming causes no compatibility issue with wrappers such as pysam and Bio::DB::HTS. In some *.c files rename the `bh` parameter accordingly, though not in header.c etc where it is prevalent. In htslib/sam.h, use parameter name `sam_hdr_t *h` rather than `bh` as per existing API functions. Leave some of test/sam.c's functions using bam_hdr_t as a verification that the compatibility typedef is operating correctly.
Add static inline bam_hdr_* compatibility functions, and leave some of test/sam.c's functions using them as a verification that they are operating correctly.
Write sam_hdr_parse() directly and make the legacy sam_hdr_parse_() call it, rather than the other way around. Make both legacy functions sam_hdr_parse_() and sam_hdr_free() static inline wrappers present only in the header file; their names will not appear in the library. Remove comments mentioning sam_hdr_dec_ref(), which no longer exists.
This function has been renamed to sam_hdr_add_line(). Remove the preceding comment block. This comment block has existed unchanged since fe11d21 which created htslib/cram.h. It describes sam_hdr_add_lines(), but no declaration for that legacy cram/sam_header.c function was ever added to the external header! Make htslib/cram.h's enum cram_block_method match the definition in cram/cram_structs.h: the first constant is BM_ERROR.
Rename bam_hdr_parse() to sam_hdr_fill_hrecs() to avoid confusion with the public sam_hdr_parse() function. Add a `sam_hdr_` prefix to update_target_arrays() to avoid polluting the library client's global namespace.
For consistency with the sam_hdr_* parts of the header.c/.h. (Performed mechanically with sed(1).)
Mention that the new header API pertains only to SAM/BAM/CRAM, not to VCF/BCF as well.
62b72d2 to
4694497
Compare
|
Rebased on top of current develop. |
|
Now merged, thanks very much. |
With the exception of some early functions, HTSlib's convention for generic SAM/BAM/CRAM functions is a
sam_prefix. (cf e.g.bam_hdr_read()which works for BAM files only vs.sam_hdr_read()which is for any of SAM/BAM/CRAM.)For your consideration, this PR renames the newly added public header API functions to use a
sam_hdr_prefix rather than thebam_hdr_prefix of PR #812. If the maintainers' consensus is that they would like to go down this route, I would be happy to add commits to rename the new internal functions similarly and/or to add renaming shims for e.g.sam_hdr_init()andsam_hdr_t, i.e., things that have long had a somewhat unfortunatebam_hdr_prefix.I have also tried out the renaming on samtools/samtools#998; that compiles cleanly, and both htslib and samtools test suites pass.
(In #812 (comment) Rob alluded to clashes with pre-existing bits of API. I think that problem must have been mostly limited to an intermediate version of the API. Once cram.h's
sam_hdr_length/_strdeclarations were tidied up, this PR had no such problems.)