rename for naming consistency

This commit is contained in:
Heng Li
2020-03-25 19:25:57 -04:00
parent e116f6e09d
commit 5a6b97145a
+60 -60
View File
@@ -61,24 +61,24 @@ void yak_copt_init(yak_copt_t *o)
* Count hash table * * Count hash table *
********************/ ********************/
#define yak_ch_eq(a, b) ((a)>>YAK_COUNTER_BITS == (b)>>YAK_COUNTER_BITS) // lower 8 bits for counts; higher bits for k-mer #define yak_ct_eq(a, b) ((a)>>YAK_COUNTER_BITS == (b)>>YAK_COUNTER_BITS) // lower 8 bits for counts; higher bits for k-mer
#define yak_ch_hash(a) ((a)>>YAK_COUNTER_BITS) #define yak_ct_hash(a) ((a)>>YAK_COUNTER_BITS)
KHASHL_SET_INIT(static klib_unused, yak_ht_t, yak_ht, uint64_t, yak_ch_hash, yak_ch_eq) KHASHL_SET_INIT(static klib_unused, yak_ht_t, yak_ht, uint64_t, yak_ct_hash, yak_ct_eq)
typedef struct { typedef struct {
yak_ht_t *h; yak_ht_t *h;
yak_bf_t *b; yak_bf_t *b;
} yak_ch1_t; } ha_ct1_t;
typedef struct { typedef struct {
int k, pre, n_hash, n_shift; int k, pre, n_hash, n_shift;
uint64_t tot; uint64_t tot;
yak_ch1_t *h; ha_ct1_t *h;
} yak_ch_t; } ha_ct_t;
static yak_ch_t *yak_ch_init(int k, int pre, int n_hash, int n_shift) static ha_ct_t *ha_ct_init(int k, int pre, int n_hash, int n_shift)
{ {
yak_ch_t *h; ha_ct_t *h;
int i; int i;
if (pre < YAK_COUNTER_BITS) return 0; if (pre < YAK_COUNTER_BITS) return 0;
CALLOC(h, 1); CALLOC(h, 1);
@@ -94,7 +94,7 @@ static yak_ch_t *yak_ch_init(int k, int pre, int n_hash, int n_shift)
return h; return h;
} }
static void yak_ch_destroy_bf(yak_ch_t *h) static void ha_ct_destroy_bf(ha_ct_t *h)
{ {
int i; int i;
for (i = 0; i < 1<<h->pre; ++i) { for (i = 0; i < 1<<h->pre; ++i) {
@@ -104,20 +104,20 @@ static void yak_ch_destroy_bf(yak_ch_t *h)
} }
} }
static void yak_ch_destroy(yak_ch_t *h) static void ha_ct_destroy(ha_ct_t *h)
{ {
int i; int i;
if (h == 0) return; if (h == 0) return;
yak_ch_destroy_bf(h); ha_ct_destroy_bf(h);
for (i = 0; i < 1<<h->pre; ++i) for (i = 0; i < 1<<h->pre; ++i)
yak_ht_destroy(h->h[i].h); yak_ht_destroy(h->h[i].h);
free(h->h); free(h); free(h->h); free(h);
} }
static int yak_ch_insert_list(yak_ch_t *h, int create_new, int n, const uint64_t *a) static int ha_ct_insert_list(ha_ct_t *h, int create_new, int n, const uint64_t *a)
{ {
int j, mask = (1<<h->pre) - 1, n_ins = 0; int j, mask = (1<<h->pre) - 1, n_ins = 0;
yak_ch1_t *g; ha_ct1_t *g;
if (n == 0) return 0; if (n == 0) return 0;
g = &h->h[a[0]&mask]; g = &h->h[a[0]&mask];
for (j = 0; j < n; ++j) { for (j = 0; j < n; ++j) {
@@ -150,7 +150,7 @@ typedef struct {
} buf_cnt_t; } buf_cnt_t;
typedef struct { typedef struct {
const yak_ch_t *h; const ha_ct_t *h;
buf_cnt_t *cnt; buf_cnt_t *cnt;
} hist_aux_t; } hist_aux_t;
@@ -165,7 +165,7 @@ static void worker_hist(void *data, long i, int tid) // callback for kt_for()
++cnt[kh_key(g, k)&YAK_MAX_COUNT]; ++cnt[kh_key(g, k)&YAK_MAX_COUNT];
} }
static void yak_ch_hist(const yak_ch_t *h, int64_t cnt[YAK_N_COUNTS], int n_thread) static void ha_ct_hist(const ha_ct_t *h, int64_t cnt[YAK_N_COUNTS], int n_thread)
{ {
hist_aux_t a; hist_aux_t a;
int i, j; int i, j;
@@ -184,13 +184,13 @@ static void yak_ch_hist(const yak_ch_t *h, int64_t cnt[YAK_N_COUNTS], int n_thre
typedef struct { typedef struct {
int min, max; int min, max;
yak_ch_t *h; ha_ct_t *h;
} shrink_aux_t; } shrink_aux_t;
static void worker_shrink(void *data, long i, int tid) // callback for kt_for() static void worker_shrink(void *data, long i, int tid) // callback for kt_for()
{ {
shrink_aux_t *a = (shrink_aux_t*)data; shrink_aux_t *a = (shrink_aux_t*)data;
yak_ch_t *h = a->h; ha_ct_t *h = a->h;
yak_ht_t *g = h->h[i].h, *f; yak_ht_t *g = h->h[i].h, *f;
khint_t k; khint_t k;
f = yak_ht_init(); f = yak_ht_init();
@@ -206,7 +206,7 @@ static void worker_shrink(void *data, long i, int tid) // callback for kt_for()
h->h[i].h = f; h->h[i].h = f;
} }
static void yak_ch_shrink(yak_ch_t *h, int min, int max, int n_thread) static void ha_ct_shrink(ha_ct_t *h, int min, int max, int n_thread)
{ {
int i; int i;
shrink_aux_t a; shrink_aux_t a;
@@ -220,7 +220,7 @@ static void yak_ch_shrink(yak_ch_t *h, int min, int max, int n_thread)
* Position hash table * * Position hash table *
***********************/ ***********************/
KHASHL_MAP_INIT(static klib_unused, yak_pt_t, yak_pt, uint64_t, uint64_t, yak_ch_hash, yak_ch_eq) KHASHL_MAP_INIT(static klib_unused, yak_pt_t, yak_pt, uint64_t, uint64_t, yak_ct_hash, yak_ct_eq)
typedef struct { typedef struct {
yak_pt_t *h; yak_pt_t *h;
@@ -235,15 +235,15 @@ typedef struct {
} ha_pt_t; } ha_pt_t;
typedef struct { typedef struct {
const yak_ch_t *ch; const ha_ct_t *ct;
ha_pt_t *ph; ha_pt_t *pt;
} pt_gen_aux_t; } pt_gen_aux_t;
static void worker_pt_gen(void *data, long i, int tid) // callback for kt_for() static void worker_pt_gen(void *data, long i, int tid) // callback for kt_for()
{ {
pt_gen_aux_t *a = (pt_gen_aux_t*)data; pt_gen_aux_t *a = (pt_gen_aux_t*)data;
ha_pt1_t *b = &a->ph->h[i]; ha_pt1_t *b = &a->pt->h[i];
yak_ht_t *g = a->ch->h[i].h; yak_ht_t *g = a->ct->h[i].h;
khint_t k; khint_t k;
for (k = 0, b->n = 0; k != kh_end(g); ++k) { for (k = 0, b->n = 0; k != kh_end(g); ++k) {
if (kh_exist(g, k)) { if (kh_exist(g, k)) {
@@ -257,21 +257,21 @@ static void worker_pt_gen(void *data, long i, int tid) // callback for kt_for()
CALLOC(b->a, b->n); CALLOC(b->a, b->n);
} }
ha_pt_t *ha_pt_gen(const yak_ch_t *ch, int n_thread) ha_pt_t *ha_pt_gen(const ha_ct_t *ct, int n_thread)
{ {
pt_gen_aux_t a; pt_gen_aux_t a;
int i; int i;
ha_pt_t *ph; ha_pt_t *pt;
CALLOC(ph, 1); CALLOC(pt, 1);
ph->k = ch->k, ph->pre = ch->pre, ph->tot = ch->tot; pt->k = ct->k, pt->pre = ct->pre, pt->tot = ct->tot;
CALLOC(ph->h, 1<<ph->pre); CALLOC(pt->h, 1<<pt->pre);
for (i = 0; i < 1<<ph->pre; ++i) { for (i = 0; i < 1<<pt->pre; ++i) {
ph->h[i].h = yak_pt_init(); pt->h[i].h = yak_pt_init();
yak_pt_resize(ph->h[i].h, kh_size(ch->h[i].h)); yak_pt_resize(pt->h[i].h, kh_size(ct->h[i].h));
} }
a.ch = ch, a.ph = ph; a.ct = ct, a.pt = pt;
kt_for(n_thread, worker_pt_gen, &a, 1<<ph->pre); kt_for(n_thread, worker_pt_gen, &a, 1<<pt->pre);
return ph; return pt;
} }
static int ha_pt_insert_list(ha_pt_t *h, int n, const ha_mz1_t *a) static int ha_pt_insert_list(ha_pt_t *h, int n, const ha_mz1_t *a)
@@ -376,8 +376,8 @@ typedef struct { // global data structure for kt_pipeline()
const void *flt_tab; const void *flt_tab;
int create_new, is_store; int create_new, is_store;
kseq_t *ks; kseq_t *ks;
yak_ch_t *h; ha_ct_t *ct;
ha_pt_t *ph; ha_pt_t *pt;
} pl_data_t; } pl_data_t;
typedef struct { // data structure for each step in kt_pipeline() typedef struct { // data structure for each step in kt_pipeline()
@@ -394,10 +394,10 @@ static void worker_for_insert(void *data, long i, int tid) // callback for kt_fo
{ {
st_data_t *s = (st_data_t*)data; st_data_t *s = (st_data_t*)data;
ch_buf_t *b = &s->buf[i]; ch_buf_t *b = &s->buf[i];
if (s->p->ph) if (s->p->pt)
b->n_ins += ha_pt_insert_list(s->p->ph, b->n, b->b); b->n_ins += ha_pt_insert_list(s->p->pt, b->n, b->b);
else else
b->n_ins += yak_ch_insert_list(s->p->h, s->p->create_new, b->n, b->a); b->n_ins += ha_ct_insert_list(s->p->ct, s->p->create_new, b->n, b->a);
} }
static void worker_for_mz(void *data, long i, int tid) static void worker_for_mz(void *data, long i, int tid)
@@ -466,7 +466,7 @@ static void *worker_count(void *data, int step, void *in) // callback for kt_pip
free(s->mz_buf[i].a); free(s->mz_buf[i].a);
free(s->mz_buf); free(s->mz_buf);
// insert minimizers // insert minimizers
if (p->ph) { if (p->pt) {
for (i = 0; i < s->n_seq; ++i) for (i = 0; i < s->n_seq; ++i)
for (j = 0; j < s->mz[i].n; ++j) for (j = 0; j < s->mz[i].n; ++j)
pt_insert_buf(s->buf, p->opt->pre, &s->mz[i].a[j]); pt_insert_buf(s->buf, p->opt->pre, &s->mz[i].a[j]);
@@ -493,16 +493,16 @@ static void *worker_count(void *data, int step, void *in) // callback for kt_pip
n_ins += s->buf[i].n_ins; n_ins += s->buf[i].n_ins;
free(s->buf[i].a); free(s->buf[i].a);
} }
p->h->tot += n_ins; p->ct->tot += n_ins;
free(s->buf); free(s->buf);
fprintf(stderr, "[M::%s::%.3f*%.2f] processed %d sequences; %ld distinct k-mers in the hash table\n", __func__, fprintf(stderr, "[M::%s::%.3f*%.2f] processed %d sequences; %ld distinct k-mers in the hash table\n", __func__,
yak_realtime(), yak_cputime() / yak_realtime(), s->n_seq, (long)p->h->tot); yak_realtime(), yak_cputime() / yak_realtime(), s->n_seq, (long)p->ct->tot);
free(s); free(s);
} }
return 0; return 0;
} }
static yak_ch_t *yak_count(const char *fn, const yak_copt_t *opt, yak_ch_t *h0, const void *flt_tab) static ha_ct_t *yak_count(const char *fn, const yak_copt_t *opt, ha_ct_t *h0, const void *flt_tab)
{ {
pl_data_t pl; pl_data_t pl;
gzFile fp; gzFile fp;
@@ -512,33 +512,33 @@ static yak_ch_t *yak_count(const char *fn, const yak_copt_t *opt, yak_ch_t *h0,
pl.flt_tab = flt_tab; pl.flt_tab = flt_tab;
pl.opt = opt; pl.opt = opt;
if (h0) { if (h0) {
pl.h = h0, pl.create_new = 0; pl.ct = h0, pl.create_new = 0;
assert(h0->k == opt->k && h0->pre == opt->pre); assert(h0->k == opt->k && h0->pre == opt->pre);
} else { } else {
pl.create_new = 1; pl.create_new = 1;
pl.h = yak_ch_init(opt->k, opt->pre, opt->bf_n_hash, opt->bf_shift); pl.ct = ha_ct_init(opt->k, opt->pre, opt->bf_n_hash, opt->bf_shift);
} }
kt_pipeline(3, worker_count, &pl, 3); kt_pipeline(3, worker_count, &pl, 3);
kseq_destroy(pl.ks); kseq_destroy(pl.ks);
gzclose(fp); gzclose(fp);
return pl.h; return pl.ct;
} }
static yak_ch_t *yak_count_file(const yak_copt_t *opt, int n_fn, char **fn, const void *flt_tab) static ha_ct_t *yak_count_file(const yak_copt_t *opt, int n_fn, char **fn, const void *flt_tab)
{ {
int i; int i;
yak_ch_t *h = 0; ha_ct_t *h = 0;
for (i = 0; i < n_fn; ++i) for (i = 0; i < n_fn; ++i)
h = yak_count(fn[i], opt, h, flt_tab); h = yak_count(fn[i], opt, h, flt_tab);
if (opt->bf_shift > 0) if (opt->bf_shift > 0)
yak_ch_destroy_bf(h); ha_ct_destroy_bf(h);
return h; return h;
} }
yak_ch_t *ha_count(const hifiasm_opt_t *asm_opt, int is_exact, int count_all, const void *flt_tab) ha_ct_t *ha_count(const hifiasm_opt_t *asm_opt, int is_exact, int count_all, const void *flt_tab)
{ {
yak_copt_t opt; yak_copt_t opt;
yak_ch_t *h; ha_ct_t *h;
yak_copt_init(&opt); yak_copt_init(&opt);
opt.k = asm_opt->k_mer_length; opt.k = asm_opt->k_mer_length;
opt.is_HPC = !asm_opt->no_HPC; opt.is_HPC = !asm_opt->no_HPC;
@@ -555,7 +555,7 @@ yak_ch_t *ha_count(const hifiasm_opt_t *asm_opt, int is_exact, int count_all, co
KHASHL_SET_INIT(static klib_unused, yak_ft_t, yak_ft, uint64_t, kh_hash_dummy, kh_eq_generic) KHASHL_SET_INIT(static klib_unused, yak_ft_t, yak_ft, uint64_t, kh_hash_dummy, kh_eq_generic)
static yak_ft_t *gen_hh(const yak_ch_t *h) static yak_ft_t *gen_hh(const ha_ct_t *h)
{ {
int i; int i;
yak_ft_t *hh; yak_ft_t *hh;
@@ -597,16 +597,16 @@ void *ha_gen_flt_tab(const hifiasm_opt_t *asm_opt)
yak_ft_t *flt_tab; yak_ft_t *flt_tab;
int64_t cnt[YAK_N_COUNTS]; int64_t cnt[YAK_N_COUNTS];
int peak_hom, peak_het, cutoff; int peak_hom, peak_het, cutoff;
yak_ch_t *h; ha_ct_t *h;
h = ha_count(asm_opt, 0, 1, 0); h = ha_count(asm_opt, 0, 1, 0);
yak_ch_hist(h, cnt, asm_opt->thread_num); ha_ct_hist(h, cnt, asm_opt->thread_num);
peak_hom = yak_analyze_count(YAK_N_COUNTS, cnt, &peak_het); peak_hom = yak_analyze_count(YAK_N_COUNTS, cnt, &peak_het);
if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het); if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
cutoff = (int)(peak_hom * asm_opt->high_factor); cutoff = (int)(peak_hom * asm_opt->high_factor);
if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1; if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1;
yak_ch_shrink(h, cutoff, YAK_MAX_COUNT, asm_opt->thread_num); ha_ct_shrink(h, cutoff, YAK_MAX_COUNT, asm_opt->thread_num);
flt_tab = gen_hh(h); flt_tab = gen_hh(h);
yak_ch_destroy(h); ha_ct_destroy(h);
fprintf(stderr, "[M::%s] filtered out %ld k-mers occurring %d or more times\n", fprintf(stderr, "[M::%s] filtered out %ld k-mers occurring %d or more times\n",
__func__, (long)kh_size(flt_tab), cutoff); __func__, (long)kh_size(flt_tab), cutoff);
return (void*)flt_tab; return (void*)flt_tab;
@@ -616,13 +616,13 @@ void *ha_gen_mzidx(const hifiasm_opt_t *asm_opt, const void *flt_tab)
{ {
int64_t cnt[YAK_N_COUNTS]; int64_t cnt[YAK_N_COUNTS];
int peak_hom, peak_het; int peak_hom, peak_het;
yak_ch_t *h; ha_ct_t *h;
h = ha_count(asm_opt, 1, 0, flt_tab); h = ha_count(asm_opt, 1, 0, flt_tab);
yak_ch_hist(h, cnt, asm_opt->thread_num); ha_ct_hist(h, cnt, asm_opt->thread_num);
fprintf(stderr, "[M::%s] count[%d] = %ld (for sanity check)\n", __func__, YAK_MAX_COUNT, (long)cnt[YAK_MAX_COUNT]); fprintf(stderr, "[M::%s] count[%d] = %ld (for sanity check)\n", __func__, YAK_MAX_COUNT, (long)cnt[YAK_MAX_COUNT]);
peak_hom = yak_analyze_count(YAK_N_COUNTS, cnt, &peak_het); peak_hom = yak_analyze_count(YAK_N_COUNTS, cnt, &peak_het);
if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het); if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
yak_ch_shrink(h, 2, YAK_MAX_COUNT - 1, asm_opt->thread_num); ha_ct_shrink(h, 2, YAK_MAX_COUNT - 1, asm_opt->thread_num);
yak_ch_destroy(h); ha_ct_destroy(h);
return 0; return 0;
} }