<commit_before>#ifndef BAM_UTIL_H
#define BAM_UTIL_H
#include "io_util.h"
#include <stdlib.h>
#include <stdio.h>
#include <zlib.h>
#include <unistd.h>
#include "htslib/sam.h"
#include "bam.h"
#include "char_util.h"
#include "compiler_util.h"
#include "logging_util.h"
#include "misc_util.h"

typedef void (*pair_fn)(bam1_t *b,bam1_t *b1);
typedef void (*single_fn)(bam1_t *b);
typedef void (*single_aux)(bam1_t *b, void *data);
typedef int (*single_aux_check)(bam1_t *b, void *data);

const int8_t seq_comp_table[16];

#ifdef __cplusplus
extern "C" {
#endif
static inline void add_unclipped_mate_starts(bam1_t *b1, bam1_t *b2);
void abstract_pair_iter(samFile *in, bam_hdr_t *hdr, samFile *ofp, pair_fn function);
void abstract_single_filter(samFile *in, bam_hdr_t *hdr, samFile *out, single_aux_check function, void *data);
void abstract_single_data(samFile *in, bam_hdr_t *hdr, samFile *out, single_aux function, void *data);
void abstract_single_iter(samFile *in, bam_hdr_t *hdr, samFile *out, single_fn function);

inline void bam_seq_cpy(char *read_str, bam1_t *b) {
	uint8_t *seq = (uint8_t *)bam_get_seq(b);
	int32_t qlen = b->core.l_qseq - 1;
	if(b->core.flag & BAM_FREVERSE) {
		for(; qlen != -1; --qlen) *read_str++ = seq_nt16_str[seq_comp_table[bam_seqi(seq, qlen)]];
		*read_str++ = '\0';
	} else {
		read_str += qlen;
		*read_str-- = '\0';
		for(;qlen != -1; --qlen) *read_str-- = seq_nt16_str[bam_seqi(seq, qlen)];
	}
}
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
#include <set>
void abstract_pair_set(samFile *in, bam_hdr_t *hdr, samFile *ofp, std::set<pair_fn> functions);
#endif

enum htseq {
	HTS_A = 1,
	HTS_C = 2,
	HTS_G = 4,
	HTS_T = 8,
	HTS_N = 15
};

static const uint8_t seq_nt16_rc[] = {15, 8, 4, 15, 2, 15, 15, 15, 1, 15, 15, 15, 15, 15, 15, 15};

#define bam_seqi_cmpl(seq, index) seq_nt16_rc[bam_seqi(seq, index)]

// bam utility macros.

/* @func inc_tag increments a numeric tag with a given type
 * :param: p [bam1_t *] One bam record
 * :param: b [bam1_t *] Second bam record
 * :param: key [const char *] Bam aux key
 */
#define inc_tag(p, b, key, type) *(type *)(bam_aux_get(p, key) + 1) += *(type *)(bam_aux_get(b, key) + 1);

/* @func inc_tag_int increments an integer tag with another integer tag.
 * :param: p [bam1_t *] One bam record
 * :param: b [bam1_t *] Second bam record<commit_msg>Handle const arrays<commit_after>#ifndef BAM_UTIL_H
#define BAM_UTIL_H
#include "io_util.h"
#include <stdlib.h>
#include <stdio.h>
#include <zlib.h>
#include <unistd.h>
#include "htslib/sam.h"
#include "bam.h"
#include "char_util.h"
#include "compiler_util.h"
#include "logging_util.h"
#include "misc_util.h"

typedef void (*pair_fn)(bam1_t *b,bam1_t *b1);
typedef void (*single_fn)(bam1_t *b);
typedef void (*single_aux)(bam1_t *b, void *data);
typedef int (*single_aux_check)(bam1_t *b, void *data);

const int8_t seq_comp_table[16] = {0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};

#ifdef __cplusplus
extern "C" {
#endif
static inline void add_unclipped_mate_starts(bam1_t *b1, bam1_t *b2);
void abstract_pair_iter(samFile *in, bam_hdr_t *hdr, samFile *ofp, pair_fn function);
void abstract_single_filter(samFile *in, bam_hdr_t *hdr, samFile *out, single_aux_check function, void *data);
void abstract_single_data(samFile *in, bam_hdr_t *hdr, samFile *out, single_aux function, void *data);
void abstract_single_iter(samFile *in, bam_hdr_t *hdr, samFile *out, single_fn function);

inline void bam_seq_cpy(char *read_str, bam1_t *b) {
	uint8_t *seq = (uint8_t *)bam_get_seq(b);
	int32_t qlen = b->core.l_qseq - 1;
	if(b->core.flag & BAM_FREVERSE) {
		for(; qlen != -1; --qlen) *read_str++ = seq_nt16_str[seq_comp_table[bam_seqi(seq, qlen)]];
		*read_str++ = '\0';
	} else {
		read_str += qlen;
		*read_str-- = '\0';
		for(;qlen != -1; --qlen) *read_str-- = seq_nt16_str[bam_seqi(seq, qlen)];
	}
}
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
#include <set>
void abstract_pair_set(samFile *in, bam_hdr_t *hdr, samFile *ofp, std::set<pair_fn> functions);
#endif

enum htseq {
	HTS_A = 1,
	HTS_C = 2,
	HTS_G = 4,
	HTS_T = 8,
	HTS_N = 15
};

const uint8_t seq_nt16_rc[] = {15, 8, 4, 15, 2, 15, 15, 15, 1, 15, 15, 15, 15, 15, 15, 15};

#define bam_seqi_cmpl(seq, index) seq_nt16_rc[bam_seqi(seq, index)]

// bam utility macros.

/* @func inc_tag increments a numeric tag with a given type
 * :param: p [bam1_t *] One bam record
 * :param: b [bam1_t *] Second bam record
 * :param: key [const char *] Bam aux key
 */
#define inc_tag(p, b, key, type) *(type *)(bam_aux_get(p, key) + 1) += *(type *)(bam_aux_get(b, key) + 1);

/* @func inc_tag_int increments an integer tag with another integer tag.
 * :param: p [bam1_t *] One bam record
 * :param: b [bam1_t *] Second bam record
{'fraction_non_alphanumeric': 0.1572700296735905, 'fraction_numerical': 0.035184400169563375, 'mean_word_length': 5.136540962288686, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1002541', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2081, 'n_words': 534}