Skip to content

Commit

Permalink
Address code review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriuo committed Mar 19, 2020
1 parent 55b8249 commit 3c9ab09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 10 additions & 2 deletions htslib/sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,16 +820,24 @@ void sam_hdr_incr_ref(sam_hdr_t *h);

/// Gets the inner header from the sam file
HTSLIB_EXPORT
sam_hdr_t *sam_hdr_get(samFile *f);
const sam_hdr_t *sam_hdr_get(samFile *f);

/// Sets the header of the sam file
/*!
* The method sets samFile::bam_header to the new hdr, following the replace
* policy (1 - replace the old header, 0 - keep the old header, if there is
* one).
*
* If the new header struct (hdr) is attached to f, its memory will be freed
* by sam_close, so the user must not attempt to free hdr separately.
*
* @param f SAM/BAM/CRAM file structure
* @param hdr Detached header structure to be set to f
* @param replace 1 - replace the old header, 0 - keep the old header
* @return -1 on failure, 0 header not replaced, 1 header replaced
*/
HTSLIB_EXPORT
void sam_hdr_set(samFile *f, sam_hdr_t *hdr, int replace);
int sam_hdr_set(samFile *f, sam_hdr_t *hdr, int replace);

/*
* Macros for changing the \@HD line. They eliminate the need to use NULL method arguments.
Expand Down
10 changes: 6 additions & 4 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1671,20 +1671,22 @@ int sam_hdr_write(htsFile *fp, const sam_hdr_t *h)
return 0;
}

sam_hdr_t *sam_hdr_get(samFile *f) {
const sam_hdr_t *sam_hdr_get(samFile *f) {
sam_hdr_t *hdr = NULL;
if (f) hdr = f->bam_header;

return hdr;
}

void sam_hdr_set(samFile *f, sam_hdr_t *hdr, int replace) {
if (!f || !hdr) return;
int sam_hdr_set(samFile *f, sam_hdr_t *hdr, int replace) {
if (!f) return -1;
if (f->bam_header) {
if (replace) sam_hdr_destroy(f->bam_header);
else return;
else return 0;
}
f->bam_header = hdr;

return 1;
}

static int old_sam_hdr_change_HD(sam_hdr_t *h, const char *key, const char *val)
Expand Down

0 comments on commit 3c9ab09

Please sign in to comment.