@@ -1089,8 +1089,7 @@ int bam_set_qname(bam1_t *b, const char *qname);
10891089/** @param fp File handle for the data file being written.
10901090 @param h Bam header structured (needed for BAI and CSI).
10911091 @param min_shift 0 for BAI, or larger for CSI (CSI defaults to 14).
1092- @param fnidx Filename to write index to. This pointer must remain valid
1093- until after sam_idx_save is called.
1092+ @param fnidx Filename to write index to.
10941093 @return 0 on success, <0 on failure.
10951094
10961095 @note This must be called after the header has been written, but before
@@ -1325,6 +1324,20 @@ const char *sam_parse_region(sam_hdr_t *h, const char *s, int *tid,
13251324 const char * mode ,
13261325 const char * format );
13271326
1327+ /// sam_open_write - Open a file for writing only
1328+ /** The method opens a new alignment file for writing, writes header hdr to it
1329+ * and attaches the header struct to the returned htsFile struct.
1330+ * If successful, ownership of hdr is given to the htsFile struct and hdr
1331+ * should not be freed separately.
1332+ * @param fn Name of the file
1333+ * @param h Pointer to the header previously read or created
1334+ * @param mode Pointer to the mode string (must contain "w")
1335+ * @param fmt Pointer to the format
1336+ * @return Pointer to the htsFile (with hdr) on success, NULL on failure
1337+ */
1338+ HTSLIB_EXPORT
1339+ htsFile * sam_open_write (const char * fn , sam_hdr_t * hdr , const char * mode , const htsFormat * fmt );
1340+
13281341 HTSLIB_EXPORT
13291342 int sam_hdr_change_HD (sam_hdr_t * h , const char * key , const char * val );
13301343
@@ -1343,7 +1356,8 @@ const char *sam_parse_region(sam_hdr_t *h, const char *s, int *tid,
13431356 int sam_read1 (samFile * fp , sam_hdr_t * h , bam1_t * b ) HTS_RESULT_USED ;
13441357/// sam_write1 - Write a record to a file
13451358/** @param fp Pointer to the destination file
1346- * @param h Pointer to the header structure previously read
1359+ * @param h Pointer to the header structure previously read. Can be NULL,
1360+ * if fp has a non-NULL pointer to a valid header struct.
13471361 * @param b Pointer to the record to be written
13481362 * @return >= 0 on successfully writing the record, -1 on error
13491363 */
0 commit comments