@@ -44,6 +44,8 @@ DEALINGS IN THE SOFTWARE. */
4444extern "C" {
4545#endif
4646
47+ struct sam_hrec_type_s ;
48+
4749/// Highest SAM format version supported by this library
4850#define SAM_FORMAT_VERSION "1.6"
4951
@@ -466,6 +468,22 @@ int sam_hdr_nref(const sam_hdr_t *h);
466468
467469/* ==== Line level methods ==== */
468470
471+ /*! @typedef
472+ * @abstract Opaque type used as an iterator over header lines.
473+ */
474+ typedef struct sam_hrec_type_s sam_hdr_line_t ;
475+
476+ /// Return an iterator pointing to the first header line
477+ HTSLIB_EXPORT
478+ sam_hdr_line_t * sam_hdr_first_line (sam_hdr_t * h );
479+
480+ /// Return an iterator pointing to the next header line
481+ /*!
482+ * @return An iterator pointing to the next line, or NULL if there is none.
483+ */
484+ HTSLIB_EXPORT
485+ sam_hdr_line_t * sam_hdr_next_line (sam_hdr_t * h , sam_hdr_line_t * line );
486+
469487/// Add formatted lines to an existing header.
470488/*!
471489 * @param lines Full SAM header record, eg "@SQ\tSN:foo\tLN:100", with
@@ -498,6 +516,36 @@ int sam_hdr_add_lines(sam_hdr_t *h, const char *lines, size_t len);
498516HTSLIB_EXPORT
499517int sam_hdr_add_line (sam_hdr_t * h , const char * type , ...);
500518
519+ /// Returns a complete line of formatted text for the line pointed to.
520+ /*!
521+ * @param line Iterator pointing to a header line
522+ * @param ks kstring to which to append the result
523+ * @return 0 on success;
524+ * -1 if @p line does not point to a header line
525+ * -2 on other failures
526+ *
527+ * Puts a complete line of formatted text for a specific line into @p ks.
528+ * Appends the text to the existing content in @p ks, if any.
529+ */
530+ HTSLIB_EXPORT
531+ int sam_hdr_format_line_append (const sam_hdr_line_t * line , kstring_t * ks );
532+
533+ /// Returns a complete line of formatted text for the line pointed to.
534+ /*!
535+ * @param line Iterator pointing to a header line
536+ * @param ks kstring to hold the result
537+ * @return 0 on success;
538+ * -1 if @p line does not point to a header line
539+ * -2 on other failures
540+ *
541+ * Puts a complete line of formatted text for a specific line into @p ks.
542+ * Any existing content in @p ks will be overwritten.
543+ */
544+ static inline int sam_hdr_format_line (const sam_hdr_line_t * line , kstring_t * ks )
545+ {
546+ return sam_hdr_format_line_append (line , ks_clear (ks ));
547+ }
548+
501549/// Returns a complete line of formatted text for a given type and ID.
502550/*!
503551 * @param type Type of the searched line. Eg. "SQ"
@@ -536,6 +584,14 @@ HTSLIB_EXPORT
536584int sam_hdr_find_line_pos (sam_hdr_t * h , const char * type ,
537585 int pos , kstring_t * ks );
538586
587+ /// Remove line pointed to by iterator from a header
588+ /*!
589+ * @param line Iterator pointing to a header line
590+ * @return An iterator pointing to the following line, or NULL on error FIXME or if it was the last line
591+ */
592+ HTSLIB_EXPORT
593+ sam_hdr_line_t * sam_hdr_remove_line (sam_hdr_t * h , sam_hdr_line_t * line );
594+
539595/// Remove a line with given type / id from a header
540596/*!
541597 * @param type Type of the searched line. Eg. "SQ"
@@ -687,6 +743,21 @@ const char *sam_hdr_line_name(sam_hdr_t *bh, const char *type, int pos);
687743
688744/* ==== Key:val level methods ==== */
689745
746+ /// Return the value associated with a key for a header line identified by iterator
747+ /*!
748+ * @param line Iterator pointing to a header line
749+ * @param key Key of the searched tag. Eg. "LN"
750+ * @param ks kstring where the value will be written
751+ * @return 0 on success
752+ * -1 if the requested tag does not exist
753+ * -2 on other errors
754+ *
755+ * Looks for a specific key in the SAM header line pointed to by @p line and writes the
756+ * associated value into @p ks. Any pre-existing content in @p ks will be overwritten.
757+ */
758+ HTSLIB_EXPORT
759+ int sam_hdr_find_tag (const sam_hdr_line_t * line , const char * key , kstring_t * ks );
760+
690761/// Return the value associated with a key for a header line identified by ID_key:ID_val
691762/*!
692763 * @param type Type of the line to which the tag belongs. Eg. "SQ"
@@ -724,6 +795,15 @@ int sam_hdr_find_tag_id(sam_hdr_t *h, const char *type, const char *ID_key, cons
724795HTSLIB_EXPORT
725796int sam_hdr_find_tag_pos (sam_hdr_t * h , const char * type , int pos , const char * key , kstring_t * ks );
726797
798+ /// Remove the key from the line pointed to by the iterator.
799+ /*!
800+ * @param line Iterator pointing to a header line
801+ * @param key Key of the targeted tag. Eg. "M5"
802+ * @return 1 if the key was removed; 0 if it was not present; -1 on error
803+ */
804+ HTSLIB_EXPORT
805+ int sam_hdr_remove_tag (sam_hdr_t * h , sam_hdr_line_t * line , const char * key );
806+
727807/// Remove the key from the line identified by type, ID_key and ID_value.
728808/*!
729809 * @param type Type of the line to which the tag belongs. Eg. "SQ"
0 commit comments