Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base mod API improvements #1636

Merged
merged 6 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ LIBHTS_OBJS = \
regidx.o \
region.o \
sam.o \
sam_mods.o \
synced_bcf_reader.o \
vcf_sweep.o \
tbx.o \
Expand Down Expand Up @@ -457,6 +458,7 @@ hts_expr.o hts_expr.pico: hts_expr.c config.h $(htslib_hts_expr_h) $(htslib_hts_
hts_os.o hts_os.pico: hts_os.c config.h $(htslib_hts_defs_h) os/rand.c
vcf.o vcf.pico: vcf.c config.h $(htslib_vcf_h) $(htslib_bgzf_h) $(htslib_tbx_h) $(htslib_hfile_h) $(hts_internal_h) $(htslib_khash_str2int_h) $(htslib_kstring_h) $(htslib_sam_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_hts_endian_h)
sam.o sam.pico: sam.c config.h $(htslib_hts_defs_h) $(htslib_sam_h) $(htslib_bgzf_h) $(cram_h) $(hts_internal_h) $(sam_internal_h) $(htslib_hfile_h) $(htslib_hts_endian_h) $(htslib_hts_expr_h) $(header_h) $(htslib_khash_h) $(htslib_kseq_h) $(htslib_kstring_h)
sam_mods.o sam_mods.pico: sam_mods.c config.h $(htslib_sam_h) $(textutils_internal_h)
tbx.o tbx.pico: tbx.c config.h $(htslib_tbx_h) $(htslib_bgzf_h) $(htslib_hts_endian_h) $(hts_internal_h) $(htslib_khash_h)
faidx.o faidx.pico: faidx.c config.h $(htslib_bgzf_h) $(htslib_faidx_h) $(htslib_hfile_h) $(htslib_khash_h) $(htslib_kstring_h) $(hts_internal_h)
bcf_sr_sort.o bcf_sr_sort.pico: bcf_sr_sort.c config.h $(bcf_sr_sort_h) $(htslib_khash_str2int_h) $(htslib_kbitset_h)
Expand Down
42 changes: 42 additions & 0 deletions htslib/sam.h
Original file line number Diff line number Diff line change
Expand Up @@ -2224,6 +2224,12 @@ typedef struct hts_base_mod {
int qual;
} hts_base_mod;

#define HTS_MOD_UNKNOWN -1 // In MM but no ML
#define HTS_MOD_UNCHECKED -2 // Not in MM and in explicit mode

// Flags for hts_parse_basemod2
#define HTS_MOD_REPORT_UNCHECKED 1

/// Allocates an hts_base_mode_state.
/**
* @return An hts_base_mode_state pointer on success,
Expand Down Expand Up @@ -2260,6 +2266,22 @@ void hts_base_mod_state_free(hts_base_mod_state *state);
HTSLIB_EXPORT
int bam_parse_basemod(const bam1_t *b, hts_base_mod_state *state);

/// Parses the Mm and Ml tags out of a bam record.
/**
* @param b BAM alignment record
* @param state The base modification state pointer.
* @param flags A bit-field controlling base modification processing
*
* @return 0 on success,
* -1 on failure.
*
* This fills out the contents of the modification state, resetting the
* iterator location to the first sequence base.
*/
HTSLIB_EXPORT
int bam_parse_basemod2(const bam1_t *b, hts_base_mod_state *state,
uint32_t flags);

/// Returns modification status for the next base position in the query seq.
/**
* @param b BAM alignment record
Expand Down Expand Up @@ -2349,6 +2371,26 @@ HTSLIB_EXPORT
int bam_mods_query_type(hts_base_mod_state *state, int code,
int *strand, int *implicit, char *canonical);

/// Returns data about the i^th modification type for the alignment record.
/**
* @param b BAM alignment record
* @param state The base modification state pointer.
* @param i Modification index, from 0 to ntype-1
* @param strand Boolean for top (0) or bottom (1) strand
* @param implicit Boolean for whether unlisted positions should be
* implicitly assumed to be unmodified, or require an
* explicit score and should be considered as unknown.
* Returned.
* @param canonical Canonical base type associated with this modification
* Returned.
*
* @return 0 on success or -1 if not found. The strand, implicit and canonical
* fields are filled out if passed in as non-NULL pointers.
*/
HTSLIB_EXPORT
int bam_mods_queryi(hts_base_mod_state *state, int i,
int *strand, int *implicit, char *canonical);

/// Returns the list of base modification codes provided for this
/// alignment record as an array of character codes (+ve) or ChEBI numbers
/// (negative).
Expand Down
Loading