Skip to content

Commit

Permalink
Allow sam_write1 to take a NULL header parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriuo committed Apr 20, 2020
1 parent b3c7a61 commit 060b48c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
7 changes: 1 addition & 6 deletions hts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ int hts_close(htsFile *fp)
hts_idx_destroy(fp->idx);
free(fp->fn);
free(fp->fn_aux);
free(fp->fnidx);
free((void *)fp->fnidx);
free(fp->line.s);
free(fp);
errno = save;
Expand All @@ -1243,11 +1243,6 @@ const htsFormat *hts_get_format(htsFile *fp)
return fp? &fp->format : NULL;
}

const struct sam_hdr_t *hts_get_hdr(htsFile *fp)
{
return fp? fp->bam_header : NULL;
}

const char *hts_get_fn(htsFile *fp)
{
return fp? fp->fn : NULL;
Expand Down
10 changes: 1 addition & 9 deletions htslib/hts.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ typedef struct {
void *state; // format specific state information
htsFormat format;
hts_idx_t *idx;
char *fnidx;
const char *fnidx;
struct sam_hdr_t *bam_header;
} htsFile;

Expand Down Expand Up @@ -508,14 +508,6 @@ int hts_close(htsFile *fp);
HTSLIB_EXPORT
const htsFormat *hts_get_format(htsFile *fp);

/*!
@abstract Returns the file's header field
@param fp The file handle
@return Read-only pointer to the file's bam_header field.
*/
HTSLIB_EXPORT
const struct sam_hdr_t *hts_get_hdr(htsFile *fp);

/*!
@abstract Returns the file's name
@param fp The file handle
Expand Down
6 changes: 3 additions & 3 deletions htslib/sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -1089,8 +1089,7 @@ int bam_set_qname(bam1_t *b, const char *qname);
/** @param fp File handle for the data file being written.
@param h Bam header structured (needed for BAI and CSI).
@param min_shift 0 for BAI, or larger for CSI (CSI defaults to 14).
@param fnidx Filename to write index to. This pointer must remain valid
until after sam_idx_save is called.
@param fnidx Filename to write index to.
@return 0 on success, <0 on failure.
@note This must be called after the header has been written, but before
Expand Down Expand Up @@ -1357,7 +1356,8 @@ const char *sam_parse_region(sam_hdr_t *h, const char *s, int *tid,
int sam_read1(samFile *fp, sam_hdr_t *h, bam1_t *b) HTS_RESULT_USED;
/// sam_write1 - Write a record to a file
/** @param fp Pointer to the destination file
* @param h Pointer to the header structure previously read
* @param h Pointer to the header structure previously read. Can be NULL,
* if fp has a non-NULL pointer to a valid header struct.
* @param b Pointer to the record to be written
* @return >= 0 on successfully writing the record, -1 on error
*/
Expand Down
4 changes: 3 additions & 1 deletion sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -3218,8 +3218,10 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)

// Sadly we need to be able to modify the bam_hdr here so we can
// reference count the structure.
int sam_write1(htsFile *fp, const sam_hdr_t *h, const bam1_t *b)
int sam_write1(htsFile *fp, const sam_hdr_t *hdr, const bam1_t *b)
{
const sam_hdr_t *h = hdr;
if (!h) h = fp->bam_header;
switch (fp->format.format) {
case binary_format:
fp->format.category = sequence_data;
Expand Down

0 comments on commit 060b48c

Please sign in to comment.