mirror of
https://github.com/chhylp123/hifiasm.git
synced 2026-10-12 06:20:55 +08:00
Compare commits
220
Commits
0.16.0
...
bca2394b69
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bca2394b69 | ||
|
|
7884b5ad88 | ||
|
|
f5078f7b23 | ||
|
|
6b026f0caa | ||
|
|
ba8627fb23 | ||
|
|
815d709fb9 | ||
|
|
a137a6b06f | ||
|
|
e53fc786bd | ||
|
|
aa4d12b1c6 | ||
|
|
9a2884f518 | ||
|
|
5e5a1568ed | ||
|
|
c0478830e6 | ||
|
|
2fa4ef224f | ||
|
|
86311effb9 | ||
|
|
53e1b150c3 | ||
|
|
67877deed3 | ||
|
|
d6ba102d42 | ||
|
|
ec9a8b222d | ||
|
|
b3b18ab1d0 | ||
|
|
a96191560e | ||
|
|
79387d081f | ||
|
|
4733ef5011 | ||
|
|
2c77b3c87e | ||
|
|
3067771783 | ||
|
|
4889f1c6d8 | ||
|
|
dbdef7ff63 | ||
|
|
184eb0a9fe | ||
|
|
676385cf8e | ||
|
|
80fa5ed436 | ||
|
|
6de4e14782 | ||
|
|
ade800990e | ||
|
|
fc98214321 | ||
|
|
382adb89c5 | ||
|
|
6e33d972d0 | ||
|
|
39a30a8d55 | ||
|
|
b01614fd71 | ||
|
|
63d51c3441 | ||
|
|
49dd83df2a | ||
|
|
e8b18560a5 | ||
|
|
d5f8a8a6c0 | ||
|
|
70fd9a0b1f | ||
|
|
73dd5eeb5b | ||
|
|
358b090e20 | ||
|
|
1ac574adc7 | ||
|
|
61ceb3a4e1 | ||
|
|
7f6d36b2c4 | ||
|
|
4ca8951f9d | ||
|
|
40e2a48706 | ||
|
|
281ae6ba89 | ||
|
|
e974b22ac0 | ||
|
|
c7685e6f19 | ||
|
|
94a284b430 | ||
|
|
858b95a3bb | ||
|
|
30d2ee065e | ||
|
|
64091a76a5 | ||
|
|
d91fc50058 | ||
|
|
adeb2c603d | ||
|
|
abff5fae04 | ||
|
|
44475e2665 | ||
|
|
2cc990ed22 | ||
|
|
2c18ec30da | ||
|
|
5bddae4ae9 | ||
|
|
18b649aadb | ||
|
|
fbfcf72eb3 | ||
|
|
0efcc14499 | ||
|
|
84e642d20d | ||
|
|
b49b4a6cc7 | ||
|
|
7e855ba5e2 | ||
|
|
5df5892f33 | ||
|
|
00959dfdd9 | ||
|
|
503cd0f7cc | ||
|
|
00ad7458c3 | ||
|
|
86b7dd424a | ||
|
|
b763e1ff76 | ||
|
|
d4773a497f | ||
|
|
7bb366688e | ||
|
|
f67faa9c34 | ||
|
|
3407c7029e | ||
|
|
f69166ee3b | ||
|
|
2218bac8aa | ||
|
|
b533067835 | ||
|
|
fa663a9680 | ||
|
|
384b721d84 | ||
|
|
8b79a3f22e | ||
|
|
af4be8ca1a | ||
|
|
85c643e85d | ||
|
|
8a00c6c5f4 | ||
|
|
a0f2f70d91 | ||
|
|
ad4ff5550b | ||
|
|
04f660fd8c | ||
|
|
dd5f368fe6 | ||
|
|
2b4b4f29e0 | ||
|
|
8ea2d5a622 | ||
|
|
27f77dca29 | ||
|
|
7d5c793109 | ||
|
|
3abd3793fb | ||
|
|
b55e4396d2 | ||
|
|
fc598d71f6 | ||
|
|
026cf97d61 | ||
|
|
286b897881 | ||
|
|
f2da12a2ad | ||
|
|
1166b92eb4 | ||
|
|
1dd82e7729 | ||
|
|
78ef43ce8e | ||
|
|
6c91e8b0a7 | ||
|
|
dc07898f68 | ||
|
|
db2edc0ffb | ||
|
|
7280f132b1 | ||
|
|
8ff5a1370d | ||
|
|
f054b11e0e | ||
|
|
25d6857d44 | ||
|
|
46391eba26 | ||
|
|
2969af129d | ||
|
|
2bf5119bb5 | ||
|
|
197cd4d77e | ||
|
|
7ad498f631 | ||
|
|
0613b18af9 | ||
|
|
34948a093c | ||
|
|
a674110b23 | ||
|
|
6743dcf204 | ||
|
|
a3b72457f0 | ||
|
|
5b928dfe1d | ||
|
|
786f8bdff0 | ||
|
|
2400236f7c | ||
|
|
a4d6cebc32 | ||
|
|
25dcaaabec | ||
|
|
9a454576e1 | ||
|
|
6de08fd91f | ||
|
|
deb31948e1 | ||
|
|
fc76af1285 | ||
|
|
b84e7ec328 | ||
|
|
979d83f68d | ||
|
|
f9c5e09388 | ||
|
|
9747c42123 | ||
|
|
b4b53b8efd | ||
|
|
553a8745cc | ||
|
|
a1867ec9a2 | ||
|
|
1afecdcecc | ||
|
|
66ad203018 | ||
|
|
152bae2dfb | ||
|
|
22c44befa5 | ||
|
|
9831afaf26 | ||
|
|
2c7b164f11 | ||
|
|
46acc8a2f6 | ||
|
|
612c1ab712 | ||
|
|
e66c003b65 | ||
|
|
f4b6223fde | ||
|
|
3d1787e57a | ||
|
|
249bee7304 | ||
|
|
df3e0eeaa3 | ||
|
|
3d65bef9de | ||
|
|
1d0562ebd1 | ||
|
|
2443e63ef5 | ||
|
|
f92cef38f2 | ||
|
|
8a4d6a5f24 | ||
|
|
68a74fb16d | ||
|
|
41437764f0 | ||
|
|
bbd3394b4a | ||
|
|
20a7dac82a | ||
|
|
236bc7b9ee | ||
|
|
4c873f9a66 | ||
|
|
a297105258 | ||
|
|
38e00d2086 | ||
|
|
f4cc895fa0 | ||
|
|
4e7bb7eeb9 | ||
|
|
774c585562 | ||
|
|
54b733ef2f | ||
|
|
69d0e18fe5 | ||
|
|
2300dc63bb | ||
|
|
5da05f308f | ||
|
|
ee51a6dddc | ||
|
|
cc16626dfa | ||
|
|
7b89478b2e | ||
|
|
8b7ca5f0c3 | ||
|
|
54465dd9ac | ||
|
|
89e0d1aafa | ||
|
|
91de382bde | ||
|
|
239f087af0 | ||
|
|
33afa25398 | ||
|
|
138610b049 | ||
|
|
0a8c064734 | ||
|
|
a82e05c9f2 | ||
|
|
3934167770 | ||
|
|
a21bc8a336 | ||
|
|
7cf6d82115 | ||
|
|
98bb89227e | ||
|
|
8f1c59a5da | ||
|
|
74ad15846e | ||
|
|
832e43fe3b | ||
|
|
a2198891e7 | ||
|
|
dd8888aa90 | ||
|
|
8a2bb0b112 | ||
|
|
e8399b18f1 | ||
|
|
8138941a26 | ||
|
|
fdf24d5589 | ||
|
|
3064e1373b | ||
|
|
d862711623 | ||
|
|
9c79bdfe7f | ||
|
|
75f8048b18 | ||
|
|
95eb2de2b9 | ||
|
|
60236cd967 | ||
|
|
d3b9de4120 | ||
|
|
9c6a3607d1 | ||
|
|
0ce5a7ba5b | ||
|
|
7af0d85258 | ||
|
|
dbc72b8c2d | ||
|
|
8a0ec3d575 | ||
|
|
9ec286e64e | ||
|
|
b640289b19 | ||
|
|
1e2a9518e5 | ||
|
|
763634e1a9 | ||
|
|
26aacdcc2c | ||
|
|
908b4f3786 | ||
|
|
cb320b88f3 | ||
|
|
7dd4a848b9 | ||
|
|
ed814abf35 | ||
|
|
ab80851b94 | ||
|
|
5e84db0ec9 | ||
|
|
809ca18dda | ||
|
|
17b5cb21d3 |
+600
-86
@@ -11,6 +11,8 @@
|
||||
#include "htab.h"
|
||||
#include "kthread.h"
|
||||
#include "rcut.h"
|
||||
#include "kalloc.h"
|
||||
#include "ecovlp.h"
|
||||
|
||||
void ha_get_candidates_interface(ha_abuf_t *ab, int64_t rid, UC_Read *ucr, overlap_region_alloc *overlap_list, overlap_region_alloc *overlap_list_hp, Candidates_list *cl, double bw_thres,
|
||||
int max_n_chain, int keep_whole_chain, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* chain_idx, ma_hit_t_alloc* paf, ma_hit_t_alloc* rev_paf, overlap_region* f_cigar, kvec_t_u64_warp* dbg_ct, st_mt_t *sp);
|
||||
@@ -20,6 +22,9 @@ void ha_sort_list_by_anchor(overlap_region_alloc *overlap_list);
|
||||
|
||||
All_reads R_INF;
|
||||
Debug_reads R_INF_FLAG;
|
||||
all_ul_t UL_INF, ULG_INF;
|
||||
uint32_t *het_cnt = NULL;
|
||||
// uint32_t debug_out = 0;
|
||||
|
||||
void get_corrected_read_from_cigar(Cigar_record* cigar, char* pre_read, int pre_length, char* new_read, int* new_length)
|
||||
{
|
||||
@@ -417,31 +422,37 @@ long long push_final_overlaps_increment(ma_hit_t_alloc* paf, ma_hit_t_alloc* rev
|
||||
return available_overlaps;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int is_final, save_ov;
|
||||
// chaining and overlapping related buffers
|
||||
UC_Read self_read, ovlp_read;
|
||||
Candidates_list clist;
|
||||
overlap_region_alloc olist;
|
||||
overlap_region_alloc olist_hp;
|
||||
ha_abuf_t *ab;
|
||||
// error correction related buffers
|
||||
int64_t num_read_base, num_correct_base, num_recorrect_base;
|
||||
Cigar_record cigar1;
|
||||
Graph POA_Graph;
|
||||
Graph DAGCon;
|
||||
Correct_dumy correct;
|
||||
haplotype_evdience_alloc hap;
|
||||
Round2_alignment round2;
|
||||
kvec_t_u32_warp b_buf;
|
||||
kvec_t_u64_warp r_buf;
|
||||
kvec_t_u8_warp k_flag;
|
||||
overlap_region tmp_region;
|
||||
ma_utg_v *ua;
|
||||
st_mt_t sp;
|
||||
} ha_ovec_buf_t;
|
||||
ha_ovec_buf_t *ha_ovec_buf_init(void *km, int is_final, int save_ov, int is_ug)
|
||||
{
|
||||
ha_ovec_buf_t *b;
|
||||
KCALLOC(km, b, 1);
|
||||
b->is_final = !!is_final, b->save_ov = !!save_ov;
|
||||
init_UC_Read(&b->self_read);//set 0
|
||||
init_UC_Read(&b->ovlp_read);//set 0
|
||||
init_Candidates_list(&b->clist);//set 0
|
||||
memset(&b->olist, 0, sizeof(overlap_region_alloc));
|
||||
memset(&b->olist_hp, 0, sizeof(overlap_region_alloc));
|
||||
// init_overlap_region_alloc(&b->olist);
|
||||
// init_overlap_region_alloc(&b->olist_hp);
|
||||
init_fake_cigar(&(b->tmp_region.f_cigar));//set 0
|
||||
kv_init(b->b_buf.a);//set 0
|
||||
kv_init(b->r_buf.a);//set 0
|
||||
kv_init(b->k_flag.a);//set 0
|
||||
kv_init(b->sp);//set 0
|
||||
if(!is_ug) b->ab = ha_abuf_init_buf(km);
|
||||
else b->abl = ha_abufl_init_buf(km);
|
||||
if (!b->is_final) {
|
||||
init_Cigar_record_buf(&b->cigar1, km);
|
||||
// init_Graph(&b->POA_Graph);
|
||||
// init_Graph(&b->DAGCon);
|
||||
init_Correct_dumy_buf(&b->correct, km);//set 0
|
||||
InitHaplotypeEvdience_buf(&b->hap, km);
|
||||
init_Round2_alignment_buf(&b->round2, km);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
ha_ovec_buf_t *ha_ovec_init(int is_final, int save_ov)
|
||||
ha_ovec_buf_t *ha_ovec_init(int is_final, int save_ov, int is_ug)
|
||||
{
|
||||
ha_ovec_buf_t *b;
|
||||
CALLOC(b, 1);
|
||||
@@ -452,11 +463,15 @@ ha_ovec_buf_t *ha_ovec_init(int is_final, int save_ov)
|
||||
init_overlap_region_alloc(&b->olist);
|
||||
init_overlap_region_alloc(&b->olist_hp);
|
||||
init_fake_cigar(&(b->tmp_region.f_cigar));
|
||||
memset(&(b->tmp_region.w_list), 0, sizeof(b->tmp_region.w_list));
|
||||
CALLOC(b->tmp_region.w_list.a, 1); b->tmp_region.w_list.n = b->tmp_region.w_list.m = 1;
|
||||
kv_init(b->b_buf.a);
|
||||
kv_init(b->r_buf.a);
|
||||
kv_init(b->k_flag.a);
|
||||
kv_init(b->sp);
|
||||
b->ab = ha_abuf_init();
|
||||
init_bit_extz_t(&(b->exz), 31);
|
||||
if(!is_ug) b->ab = ha_abuf_init();
|
||||
else b->abl = ha_abufl_init();
|
||||
if (!b->is_final) {
|
||||
init_Cigar_record(&b->cigar1);
|
||||
init_Graph(&b->POA_Graph);
|
||||
@@ -476,11 +491,14 @@ void ha_ovec_destroy(ha_ovec_buf_t *b)
|
||||
destory_overlap_region_alloc(&b->olist);
|
||||
destory_overlap_region_alloc(&b->olist_hp);
|
||||
ha_abuf_destroy(b->ab);
|
||||
ha_abufl_destroy(b->abl);
|
||||
destory_fake_cigar(&(b->tmp_region.f_cigar));
|
||||
free(b->tmp_region.w_list.a); free(b->tmp_region.w_list.c.a);
|
||||
kv_destroy(b->b_buf.a);
|
||||
kv_destroy(b->r_buf.a);
|
||||
kv_destroy(b->k_flag.a);
|
||||
kv_destroy(b->sp);
|
||||
destroy_bit_extz_t(&(b->exz));
|
||||
if (!b->is_final) {
|
||||
destory_Cigar_record(&b->cigar1);
|
||||
destory_Graph(&b->POA_Graph);
|
||||
@@ -506,51 +524,97 @@ static int64_t ha_Graph_mem(const Graph *g)
|
||||
return mem;
|
||||
}
|
||||
|
||||
int64_t ha_ovec_mem(const ha_ovec_buf_t *b)
|
||||
int64_t ha_ovec_mem(const ha_ovec_buf_t *b, int64_t *mem_a)
|
||||
{
|
||||
int64_t i, mem = 0, mem_clist, mem_olist;
|
||||
mem_clist = b->clist.size * sizeof(k_mer_hit) + b->clist.chainDP.size * 7 * 4;
|
||||
int64_t i, mem_ab = 0, mem_clist, mem_olist, mem_hap = 0, mem_aux = 0;
|
||||
// mem_clist = b->clist.size * sizeof(k_mer_hit) + b->clist.chainDP.size * 7 * 4;
|
||||
mem_clist = (b->clist.size * sizeof(k_mer_hit)) + ((sizeof((*b->clist.chainDP.score)) + sizeof((*b->clist.chainDP.pre))
|
||||
+ sizeof((*b->clist.chainDP.indels)) + sizeof((*b->clist.chainDP.self_length))
|
||||
+ sizeof((*b->clist.chainDP.occ)) + sizeof((*b->clist.chainDP.tmp))) * b->clist.chainDP.size);
|
||||
mem_clist += sizeof(*(b->b_buf.a.a)) * b->b_buf.a.m;
|
||||
mem_clist += sizeof(*(b->r_buf.a.a)) * b->r_buf.a.m;
|
||||
mem_clist += sizeof(*(b->k_flag.a.a)) * b->k_flag.a.m;
|
||||
mem_clist += sizeof(*(b->sp.a)) * b->sp.m;
|
||||
mem_clist += sizeof(*(b->tmp_region.f_cigar.buffer)) * b->tmp_region.f_cigar.size;
|
||||
mem_clist += sizeof(*(b->tmp_region.w_list.a)) * b->tmp_region.w_list.n;
|
||||
mem_clist += sizeof(*(b->tmp_region.w_list.c.a)) * b->tmp_region.w_list.c.n;
|
||||
|
||||
mem_olist = b->olist.size * sizeof(overlap_region);
|
||||
for (i = 0; i < (int64_t)b->olist.size; ++i) {
|
||||
const overlap_region *r = &b->olist.list[i];
|
||||
mem_olist += r->w_list_size * sizeof(window_list);
|
||||
mem_olist += (r->w_list.n*sizeof(*(r->w_list.a))) + (r->w_list.c.n*sizeof(*(r->w_list.c.a)));
|
||||
mem_olist += r->f_cigar.size * 8;
|
||||
mem_olist += r->boundary_cigars.size * sizeof(window_list);
|
||||
mem_olist += (r->boundary_cigars.n*sizeof(*(r->boundary_cigars.a)))
|
||||
+ (r->boundary_cigars.c.n*sizeof(*(r->boundary_cigars.c.a)));
|
||||
}
|
||||
|
||||
mem_olist += b->olist_hp.size * sizeof(overlap_region);
|
||||
for (i = 0; i < (int64_t)b->olist_hp.size; ++i) {
|
||||
const overlap_region *r = &b->olist_hp.list[i];
|
||||
mem_olist += r->w_list_size * sizeof(window_list);
|
||||
mem_olist += (r->w_list.n*sizeof(*(r->w_list.a))) + (r->w_list.c.n*sizeof(*(r->w_list.c.a)));
|
||||
mem_olist += r->f_cigar.size * 8;
|
||||
mem_olist += r->boundary_cigars.size * sizeof(window_list);
|
||||
mem_olist += (r->boundary_cigars.n*sizeof(*(r->boundary_cigars.a)))
|
||||
+ (r->boundary_cigars.c.n*sizeof(*(r->boundary_cigars.c.a)));
|
||||
}
|
||||
|
||||
mem = ha_abuf_mem(b->ab) + mem_clist + mem_olist;
|
||||
if(b->ab) mem_ab += ha_abuf_mem(b->ab);
|
||||
if(b->abl) mem_ab += ha_abufl_mem(b->abl);
|
||||
|
||||
if (!b->is_final) {
|
||||
mem += sizeof(Cigar_record) + b->cigar1.lost_base_size + b->cigar1.size * 4;
|
||||
mem += sizeof(Correct_dumy) + b->correct.size * 8;
|
||||
mem += sizeof(Round2_alignment) + b->round2.cigar.size * 4 + b->round2.tmp_cigar.size * 4;
|
||||
mem += sizeof(haplotype_evdience_alloc) + b->hap.size * sizeof(haplotype_evdience) + b->hap.snp_matrix_size + b->hap.snp_stat_size * sizeof(SnpStats);
|
||||
mem += ha_Graph_mem(&b->POA_Graph);
|
||||
mem += ha_Graph_mem(&b->DAGCon);
|
||||
mem_hap += sizeof(Cigar_record) + b->cigar1.lost_base_size + b->cigar1.size * 4;
|
||||
mem_hap += sizeof(Correct_dumy) + b->correct.size * 8;
|
||||
mem_hap += sizeof(Round2_alignment) + b->round2.cigar.size * 4 + b->round2.tmp_cigar.size * 4;
|
||||
mem_hap += sizeof(haplotype_evdience_alloc) + b->hap.size * sizeof(haplotype_evdience) + b->hap.snp_matrix_size + b->hap.r_snp_size + b->hap.snp_stat.m * sizeof(SnpStats) + b->hap.snp_srt.m * sizeof(uint64_t);
|
||||
mem_hap += ha_Graph_mem(&b->POA_Graph);
|
||||
mem_hap += ha_Graph_mem(&b->DAGCon);
|
||||
}
|
||||
return mem;
|
||||
|
||||
|
||||
mem_aux += sizeof(*(b->self_read.seq)) * b->self_read.size;
|
||||
mem_aux += sizeof(*(b->ovlp_read.seq)) * b->ovlp_read.size;
|
||||
|
||||
if(mem_a) {
|
||||
mem_a[0] = mem_ab; mem_a[1] = mem_clist; mem_a[2] = mem_olist;
|
||||
mem_a[3] = mem_hap; mem_a[4] = mem_aux;
|
||||
}
|
||||
|
||||
return mem_ab + mem_clist + mem_olist + mem_hap + mem_aux;
|
||||
}
|
||||
|
||||
uint32_t get_het_cnt(haplotype_evdience_alloc *hap)
|
||||
{
|
||||
uint32_t i, cnt;
|
||||
for (i = cnt = 0; i < hap->snp_stat.n; i++) {
|
||||
if(hap->snp_stat.a[i].score == 1 && (!(hap->snp_stat.a[i].occ_0 < 2 || hap->snp_stat.a[i].occ_1 < 2))) {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static void worker_ovec(void *data, long i, int tid)
|
||||
{
|
||||
ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];
|
||||
int fully_cov, abnormal;
|
||||
// if(i != 12578) return;
|
||||
// fprintf(stderr, "[M::%s-beg] rid->%ld\n", __func__, i);
|
||||
// if (memcmp("7897e875-76e5-42c8-bc37-94b370c4cc8d", Get_NAME((R_INF), i), Get_NAME_LENGTH((R_INF),i)) == 0) {
|
||||
// fprintf(stderr, "[M::%s-beg] rid->%ld\n", __func__, i);
|
||||
// } else {
|
||||
// return;
|
||||
// }
|
||||
|
||||
ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist,
|
||||
0.02, asm_opt.max_n_chain, 1, &(b->k_flag), &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
0.02, asm_opt.max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
|
||||
// prt_chain(&b->olist);
|
||||
// return;
|
||||
|
||||
clear_Cigar_record(&b->cigar1);
|
||||
clear_Round2_alignment(&b->round2);
|
||||
|
||||
correct_overlap(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
|
||||
&b->cigar1, &b->hap, &b->round2, 0, 1, &fully_cov, &abnormal);
|
||||
&b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal);
|
||||
|
||||
b->num_read_base += b->self_read.length;
|
||||
b->num_correct_base += b->correct.corrected_base;
|
||||
@@ -579,6 +643,47 @@ static void worker_ovec(void *data, long i, int tid)
|
||||
push_overlaps(&(R_INF.paf[i]), &b->olist, 1, &R_INF, is_rev);
|
||||
push_overlaps(&(R_INF.reverse_paf[i]), &b->olist, 2, &R_INF, is_rev);
|
||||
}
|
||||
|
||||
if(het_cnt) het_cnt[i] = get_het_cnt(&b->hap);
|
||||
// fprintf(stderr, "[M::%s-end] rid->%ld\n", __func__, i);
|
||||
}
|
||||
|
||||
|
||||
static void worker_ovec_cal0(void *data, long i, int tid)
|
||||
{
|
||||
ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];
|
||||
int fully_cov, abnormal;
|
||||
|
||||
ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist,
|
||||
0.02, asm_opt.max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
|
||||
clear_Cigar_record(&b->cigar1);
|
||||
clear_Round2_alignment(&b->round2);
|
||||
|
||||
correct_overlap(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
|
||||
&b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 0/**1***/, &fully_cov, &abnormal);
|
||||
|
||||
b->num_read_base += b->self_read.length;
|
||||
b->num_correct_base += b->correct.corrected_base;
|
||||
b->num_recorrect_base += b->round2.dumy.corrected_base;
|
||||
|
||||
|
||||
// R_INF.paf[i].is_fully_corrected = 0;
|
||||
// R_INF.paf[i].is_abnormal = abnormal;
|
||||
R_INF.trio_flag[i] = AMBIGU;
|
||||
|
||||
// R_INF.paf[i].is_fully_corrected = 0;
|
||||
// if (fully_cov) {
|
||||
// if (get_cigar_errors(&b->cigar1) == 0 && get_cigar_errors(&b->round2.cigar) == 0)
|
||||
// R_INF.paf[i].is_fully_corrected = 1;
|
||||
// }
|
||||
// R_INF.paf[i].is_abnormal = abnormal;
|
||||
// R_INF.trio_flag[i] = AMBIGU;
|
||||
|
||||
push_final_overlaps(&(R_INF.paf[i]), R_INF.reverse_paf, &b->olist, 1);
|
||||
push_final_overlaps(&(R_INF.reverse_paf[i]), R_INF.reverse_paf, &b->olist, 2);
|
||||
|
||||
if(het_cnt) het_cnt[i] = get_het_cnt(&b->hap);
|
||||
}
|
||||
|
||||
|
||||
@@ -599,16 +704,17 @@ static void worker_ovec_related_reads(void *data, long i, int tid)
|
||||
|
||||
if(k < R_INF_FLAG.query_num)
|
||||
{
|
||||
R_INF_FLAG.read_id[k] = i;
|
||||
int fully_cov, abnormal, q_idx = k;
|
||||
|
||||
ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist,
|
||||
0.02, asm_opt.max_n_chain, 1, &(b->k_flag), &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), &(R_INF_FLAG.candidate_count[q_idx]), &(b->sp));
|
||||
0.02, asm_opt.max_n_chain, 1, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), &(R_INF_FLAG.candidate_count[q_idx]), &(b->sp));
|
||||
|
||||
clear_Cigar_record(&b->cigar1);
|
||||
clear_Round2_alignment(&b->round2);
|
||||
|
||||
correct_overlap(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
|
||||
&b->cigar1, &b->hap, &b->round2, 0, 1, &fully_cov, &abnormal);
|
||||
&b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal);
|
||||
|
||||
b->num_read_base += b->self_read.length;
|
||||
b->num_correct_base += b->correct.corrected_base;
|
||||
@@ -665,6 +771,7 @@ static void worker_ovec_related_reads(void *data, long i, int tid)
|
||||
Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
|
||||
}
|
||||
|
||||
/**
|
||||
fprintf(R_INF_FLAG.fp, "***************************unmatched ovlp***************************\n");
|
||||
for (k = 0; k < b->olist.length; k++)
|
||||
{
|
||||
@@ -676,6 +783,7 @@ static void worker_ovec_related_reads(void *data, long i, int tid)
|
||||
b->olist.list[k].y_pos_strand, b->olist.list[k].strong, b->olist.list[k].without_large_indel,
|
||||
Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
|
||||
}
|
||||
**/
|
||||
|
||||
R_INF.trio_flag[i] = AMBIGU;
|
||||
|
||||
@@ -775,16 +883,14 @@ static void worker_ec_save(void *data, long i, int tid)
|
||||
|
||||
void Output_corrected_reads()
|
||||
{
|
||||
long long i;
|
||||
UC_Read g_read;
|
||||
uint64_t i; UC_Read g_read;
|
||||
init_UC_Read(&g_read);
|
||||
char* gfa_name = (char*)malloc(strlen(asm_opt.output_file_name)+35);
|
||||
sprintf(gfa_name, "%s.ec.fa", asm_opt.output_file_name);
|
||||
FILE *output_file = fopen(gfa_name, "w");
|
||||
free(gfa_name);
|
||||
|
||||
for (i = 0; i < (long long)R_INF.total_reads; i++)
|
||||
{
|
||||
for (i = 0; i < R_INF.total_reads; i++) {
|
||||
recover_UC_Read(&g_read, &R_INF, i);
|
||||
fwrite(">", 1, 1, output_file);
|
||||
fwrite(Get_NAME(R_INF, i), 1, Get_NAME_LENGTH(R_INF, i), output_file);
|
||||
@@ -796,6 +902,40 @@ void Output_corrected_reads()
|
||||
fclose(output_file);
|
||||
}
|
||||
|
||||
void Output_corrected_fastq()
|
||||
{
|
||||
uint64_t i, k;
|
||||
UC_Read g_read; asg8_v dv;
|
||||
init_UC_Read(&g_read); kv_init(dv);
|
||||
char* gfa_name = (char*)malloc(strlen(asm_opt.output_file_name)+35);
|
||||
sprintf(gfa_name, "%s.ec.fq", asm_opt.output_file_name);
|
||||
FILE* fp = fopen(gfa_name, "w");
|
||||
free(gfa_name);
|
||||
|
||||
for (i = 0; i < R_INF.tqn; i++) {
|
||||
recover_UC_Read(&g_read, &R_INF, i);
|
||||
fprintf(fp, "@%.*s\n", (int32_t)Get_NAME_LENGTH(R_INF, i), Get_NAME(R_INF, i));
|
||||
fprintf(fp, "%.*s\n", (int32_t)g_read.length, g_read.seq);
|
||||
fprintf(fp, "+\n");
|
||||
retrive_bqual(&dv, NULL, i, -1, -1, 0, sc_bn);
|
||||
for (k = 0; k < dv.n; k++) fprintf(fp, "%c", (char)(sc_tb[dv.a[k]] + 33 - 1));
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
|
||||
for (; i < R_INF.total_reads; i++) {
|
||||
recover_UC_Read(&g_read, &R_INF, i);
|
||||
fprintf(fp, "@%.*s\n", (int32_t)Get_NAME_LENGTH(R_INF, i), Get_NAME(R_INF, i));
|
||||
fprintf(fp, "%.*s\n", (int32_t)g_read.length, g_read.seq);
|
||||
fprintf(fp, "+\n");
|
||||
// retrive_bqual(&dv, NULL, i, -1, -1, 0, sc_bn);
|
||||
// for (k = 0; k < dv.n; k++) fprintf(fp, "%c", (char)(sc_tb[dv.a[k]] + 33 - 1));
|
||||
for (k = 0; k < (uint64_t)g_read.length; k++) fprintf(fp, "%c", (char)(3 + 33 - 1));
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
destory_UC_Read(&g_read); kv_destroy(dv);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void debug_print_pob_regions()
|
||||
{
|
||||
uint64_t i, total = 0;
|
||||
@@ -816,7 +956,7 @@ void rescue_hp_reads(ha_ovec_buf_t **b)
|
||||
int hom_cov, het_cov;
|
||||
ha_flt_tab_hp = ha_idx_hp = NULL;
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT)) {
|
||||
ha_flt_tab_hp = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 1);
|
||||
ha_flt_tab_hp = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 1, 0);
|
||||
}
|
||||
ha_idx_hp = ha_pt_gen(&asm_opt, ha_flt_tab, 1, 1, &R_INF, &hom_cov, &het_cov);
|
||||
|
||||
@@ -834,7 +974,109 @@ void rescue_hp_reads(ha_ovec_buf_t **b)
|
||||
}
|
||||
|
||||
|
||||
void print_het_cnt_log(uint32_t *het_cnt)
|
||||
{
|
||||
if(!het_cnt) return;
|
||||
char* gfa_name = (char*)malloc(strlen(asm_opt.output_file_name)+35);
|
||||
sprintf(gfa_name, "%s.het_cnt.log", asm_opt.output_file_name);
|
||||
FILE* output_file = fopen(gfa_name, "w");
|
||||
fprintf(stderr, "[M::%s::] ==> print cnt of het sites to %s...\n", __func__, gfa_name);
|
||||
free(gfa_name);
|
||||
uint64_t i;
|
||||
for (i = 0; i < R_INF.total_reads; i++){
|
||||
fprintf(output_file, ">%.*s\t%u\n", (int)Get_NAME_LENGTH(R_INF, i), Get_NAME(R_INF, i), het_cnt[i]);
|
||||
}
|
||||
fclose(output_file);
|
||||
}
|
||||
|
||||
void prt_dbg_rs(FILE *fp, Debug_reads* x, uint64_t round)
|
||||
{
|
||||
uint64_t k, id; UC_Read g_read; init_UC_Read(&g_read);
|
||||
for (k = 0; k < R_INF_FLAG.query_num; k++) {
|
||||
id = x->read_id[k];
|
||||
if(id == ((uint64_t)-1)) continue;
|
||||
recover_UC_Read(&g_read, &R_INF, id);
|
||||
fprintf(fp, ">%.*s_r%lu\n", (int)Get_NAME_LENGTH((R_INF), id), Get_NAME((R_INF), id), round);
|
||||
fprintf(fp, "%.*s\n", (int)g_read.length, g_read.seq);
|
||||
}
|
||||
destory_UC_Read(&g_read);
|
||||
}
|
||||
|
||||
void ha_ec(int64_t round, int num_pround, int des_idx, uint64_t *tot_b, uint64_t *tot_e, uint64_t w_tmp)
|
||||
{
|
||||
int hom_cov, het_cov, r_out = 0;
|
||||
ha_flt_tab_hp = ha_idx_hp = NULL; (*tot_b) = (*tot_e) = 0;
|
||||
|
||||
if((ha_idx == NULL)&&(asm_opt.flag & HA_F_VERBOSE_GFA)&&(round == asm_opt.number_of_round - 1)) r_out = 1;
|
||||
|
||||
if(asm_opt.required_read_name) init_Debug_reads(&R_INF_FLAG, asm_opt.required_read_name); // for debugging only
|
||||
|
||||
if(ha_idx) hom_cov = asm_opt.hom_cov;
|
||||
if(ha_idx == NULL) {
|
||||
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, round == 0? 0 : 1, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
asm_opt.hom_cov = hom_cov; asm_opt.het_cov = het_cov;
|
||||
}
|
||||
///debug_adapter(&asm_opt, &R_INF);
|
||||
if (round == 0 && ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
het_cnt = NULL;
|
||||
if(round == asm_opt.number_of_round-1 && asm_opt.is_dbg_het_cnt) CALLOC(het_cnt, R_INF.total_reads);
|
||||
|
||||
if (r_out) {
|
||||
write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name, 0);
|
||||
if((asm_opt.flag & HA_F_VERBOSE_GFA) && (asm_opt.bin_only == 1)) exit(1);///just for debug
|
||||
}
|
||||
if (w_tmp) tmp_pt_pro(&ha_flt_tab, &ha_idx, &R_INF, &scb, &asm_opt, asm_opt.output_file_name, round, asm_opt.number_of_round, 0, 0);
|
||||
|
||||
// Output_corrected_fastq();
|
||||
|
||||
|
||||
cal_ec_r(asm_opt.thread_num, round, num_pround, R_INF.total_reads, (round == (asm_opt.number_of_round-1))?1:0, tot_b, tot_e);
|
||||
|
||||
// exit(1);
|
||||
|
||||
// if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);
|
||||
if(des_idx) {
|
||||
ha_pt_destroy(ha_idx); ha_idx = NULL;
|
||||
}
|
||||
|
||||
|
||||
if(het_cnt) {
|
||||
print_het_cnt_log(het_cnt); free(het_cnt); het_cnt = NULL;
|
||||
}
|
||||
|
||||
// exit(1);
|
||||
|
||||
|
||||
if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r0, &R_INF_FLAG, 0); // for debugging only
|
||||
|
||||
// save corrected reads to R_INF
|
||||
// sl_ec_r(asm_opt.thread_num, R_INF.total_reads);
|
||||
|
||||
if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r1, &R_INF_FLAG, 1); // for debugging only
|
||||
if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
|
||||
///debug_print_pob_regions();
|
||||
|
||||
// Output_corrected_reads();
|
||||
|
||||
// exit(1);
|
||||
}
|
||||
|
||||
|
||||
int ha_ec_dbg(void)
|
||||
{
|
||||
int hom_cov, het_cov;
|
||||
|
||||
ha_idx = ha_pt_gen(&asm_opt, 0, 0, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
asm_opt.hom_cov = hom_cov; asm_opt.het_cov = het_cov;
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
|
||||
cal_ec_r_dbg(asm_opt.thread_num, R_INF.total_reads);
|
||||
|
||||
ha_pt_destroy(ha_idx); ha_idx = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ha_overlap_and_correct(int round)
|
||||
{
|
||||
@@ -852,32 +1094,42 @@ void ha_overlap_and_correct(int round)
|
||||
// overlap and correct reads
|
||||
CALLOC(b, asm_opt.thread_num);
|
||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||
b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1));
|
||||
b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1),0);
|
||||
if(ha_idx) hom_cov = asm_opt.hom_cov;
|
||||
if(ha_idx == NULL) ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, round == 0? 0 : 1, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
///debug_adapter(&asm_opt, &R_INF);
|
||||
if (round == 0 && ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
het_cnt = NULL;
|
||||
if(round == asm_opt.number_of_round-1 && asm_opt.is_dbg_het_cnt) CALLOC(het_cnt, R_INF.total_reads);
|
||||
// fprintf(stderr, "[M::%s-start]\n", __func__);
|
||||
// double tt0 = yak_realtime_0();
|
||||
if (asm_opt.required_read_name)
|
||||
kt_for(asm_opt.thread_num, worker_ovec_related_reads, b, R_INF.total_reads);
|
||||
else
|
||||
kt_for(asm_opt.thread_num, worker_ovec, b, R_INF.total_reads);
|
||||
kt_for(asm_opt.thread_num, worker_ovec, b, R_INF.total_reads);///debug_for_fix
|
||||
// fprintf(stderr, "[M::%s-end]\n", __func__);
|
||||
// fprintf(stderr, "[M::%s::%.3f] ==> chaining\n", __func__, yak_realtime_0()-tt0);
|
||||
// exit(1);
|
||||
|
||||
if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name);
|
||||
if (r_out) write_pt_index(ha_flt_tab, ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name, 0);
|
||||
ha_pt_destroy(ha_idx);
|
||||
ha_idx = NULL;
|
||||
|
||||
if(het_cnt) {
|
||||
print_het_cnt_log(het_cnt); free(het_cnt); het_cnt = NULL;
|
||||
}
|
||||
|
||||
// collect statistics
|
||||
for (i = 0; i < asm_opt.thread_num; ++i) {
|
||||
asm_opt.num_bases += b[i]->num_read_base;
|
||||
asm_opt.num_corrected_bases += b[i]->num_correct_base;
|
||||
asm_opt.num_recorrected_bases += b[i]->num_recorrect_base;
|
||||
asm_opt.mem_buf += ha_ovec_mem(b[i]);
|
||||
asm_opt.mem_buf += ha_ovec_mem(b[i], NULL);
|
||||
ha_ovec_destroy(b[i]);
|
||||
}
|
||||
free(b);
|
||||
|
||||
if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
|
||||
if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r0, &R_INF_FLAG, 0); // for debugging only
|
||||
|
||||
// save corrected reads to R_INF
|
||||
CALLOC(e, asm_opt.thread_num);
|
||||
@@ -894,9 +1146,53 @@ void ha_overlap_and_correct(int round)
|
||||
free(e[i].second_round_read);
|
||||
}
|
||||
free(e);
|
||||
|
||||
if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r1, &R_INF_FLAG, 1); // for debugging only
|
||||
if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
|
||||
///debug_print_pob_regions();
|
||||
}
|
||||
|
||||
void ha_overlap_cal(int round, int read_from_store)
|
||||
{
|
||||
int i, hom_cov, het_cov;
|
||||
ha_ovec_buf_t **b;
|
||||
ha_flt_tab_hp = ha_idx_hp = NULL;
|
||||
|
||||
// overlap and correct reads
|
||||
CALLOC(b, asm_opt.thread_num);
|
||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||
b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1),0);
|
||||
if(ha_idx) hom_cov = asm_opt.hom_cov;
|
||||
if(ha_idx == NULL) ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, ((round == 0)&&(read_from_store == 0))?0:1, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
///debug_adapter(&asm_opt, &R_INF);
|
||||
if (/**round == 0 &&**/ ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
het_cnt = NULL;
|
||||
if(round == asm_opt.number_of_round-1 && asm_opt.is_dbg_het_cnt) CALLOC(het_cnt, R_INF.total_reads);
|
||||
// fprintf(stderr, "[M::%s-start]\n", __func__);
|
||||
kt_for(asm_opt.thread_num, worker_ovec_cal0, b, R_INF.total_reads);///debug_for_fix
|
||||
// fprintf(stderr, "[M::%s-end]\n", __func__);
|
||||
|
||||
ha_pt_destroy(ha_idx);
|
||||
ha_idx = NULL;
|
||||
|
||||
if(het_cnt) {
|
||||
print_het_cnt_log(het_cnt); free(het_cnt); het_cnt = NULL;
|
||||
}
|
||||
|
||||
// collect statistics
|
||||
for (i = 0; i < asm_opt.thread_num; ++i) {
|
||||
asm_opt.num_bases += b[i]->num_read_base;
|
||||
asm_opt.num_corrected_bases += b[i]->num_correct_base;
|
||||
asm_opt.num_recorrected_bases += b[i]->num_recorrect_base;
|
||||
asm_opt.mem_buf += ha_ovec_mem(b[i], NULL);
|
||||
ha_ovec_destroy(b[i]);
|
||||
}
|
||||
free(b);
|
||||
asm_opt.hom_cov = hom_cov;
|
||||
asm_opt.het_cov = het_cov;
|
||||
}
|
||||
|
||||
|
||||
void update_overlaps(overlap_region_alloc* overlap_list, ma_hit_t_alloc* paf,
|
||||
UC_Read* g_read, UC_Read* overlap_read, int is_match, int is_exact)
|
||||
@@ -1294,7 +1590,7 @@ static void worker_ov_final(void *data, long i, int tid)
|
||||
|
||||
//get_new_candidates(i, &g_read, &overlap_list, &array_list, &l, 0.001, 0);
|
||||
ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist, 0.001,
|
||||
asm_opt.max_n_chain, 0, &(b->k_flag), &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
asm_opt.max_n_chain, 0, NULL/**&(b->k_flag)**/, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
|
||||
overlap_region_sort_y_id(b->olist.list, b->olist.length);
|
||||
ma_hit_sort_tn(R_INF.paf[i].buffer, R_INF.paf[i].length);
|
||||
@@ -1355,12 +1651,13 @@ void debug_affine_gap_alignment(overlap_region_alloc *overlap_list, UC_Read* g_r
|
||||
kv_destroy(y_num);
|
||||
}
|
||||
|
||||
/**
|
||||
static void worker_ov_final_high_het(void *data, long i, int tid)
|
||||
{
|
||||
ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];
|
||||
|
||||
ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist, HIGH_HET_ERROR_RATE,
|
||||
asm_opt.max_n_chain, 1, &(b->k_flag), &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
asm_opt.max_n_chain, 1, NULL, &b->r_buf, &(R_INF.paf[i]), &(R_INF.reverse_paf[i]), &(b->tmp_region), NULL, &(b->sp));
|
||||
|
||||
overlap_region_sort_y_id(b->olist.list, b->olist.length);
|
||||
ma_hit_sort_tn(R_INF.paf[i].buffer, R_INF.paf[i].length);
|
||||
@@ -1384,6 +1681,7 @@ static void worker_ov_final_high_het(void *data, long i, int tid)
|
||||
correct_overlap_high_het(&b->olist, &R_INF, &b->self_read, &b->correct, &b->ovlp_read);
|
||||
push_final_overlaps_increment(&(R_INF.reverse_paf[i]), R_INF.reverse_paf, &b->olist, 2);
|
||||
}
|
||||
**/
|
||||
|
||||
void Output_PAF()
|
||||
{
|
||||
@@ -1428,6 +1726,53 @@ void Output_PAF()
|
||||
free(paf_name);
|
||||
fclose(output_file);
|
||||
|
||||
fprintf(stderr, "PAF has been written.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void Output_PAF0(ma_hit_t_alloc* sources, const char *prefix)
|
||||
{
|
||||
fprintf(stderr, "Writing PAF to disk ...... \n");
|
||||
char* paf_name = (char*)malloc(strlen(asm_opt.output_file_name)+strlen(prefix)+50);
|
||||
sprintf(paf_name, "%s.%s.ovlp.paf", asm_opt.output_file_name, prefix);
|
||||
FILE* output_file = fopen(paf_name, "w");
|
||||
uint64_t i, j;
|
||||
|
||||
for (i = 0; i < R_INF.total_reads; i++)
|
||||
{
|
||||
for (j = 0; j < sources[i].length; j++)
|
||||
{
|
||||
fwrite(Get_NAME(R_INF, Get_qn(sources[i].buffer[j])), 1,
|
||||
Get_NAME_LENGTH(R_INF, Get_qn(sources[i].buffer[j])), output_file);
|
||||
fwrite("\t", 1, 1, output_file);
|
||||
fprintf(output_file, "%lu\t", (unsigned long)Get_READ_LENGTH(R_INF, Get_qn(sources[i].buffer[j])));
|
||||
fprintf(output_file, "%d\t", Get_qs(sources[i].buffer[j]));
|
||||
fprintf(output_file, "%d\t", Get_qe(sources[i].buffer[j]));
|
||||
if(sources[i].buffer[j].rev)
|
||||
{
|
||||
fprintf(output_file, "-\t");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(output_file, "+\t");
|
||||
}
|
||||
fwrite(Get_NAME(R_INF, Get_tn(sources[i].buffer[j])), 1,
|
||||
Get_NAME_LENGTH(R_INF, Get_tn(sources[i].buffer[j])), output_file);
|
||||
fwrite("\t", 1, 1, output_file);
|
||||
fprintf(output_file, "%lu\t", (unsigned long)Get_READ_LENGTH(R_INF, Get_tn(sources[i].buffer[j])));
|
||||
fprintf(output_file, "%d\t", Get_ts(sources[i].buffer[j]));
|
||||
fprintf(output_file, "%d\t", Get_te(sources[i].buffer[j]));
|
||||
fprintf(output_file, "%d\t", sources[i].buffer[j].ml);
|
||||
fprintf(output_file, "%d\t", sources[i].buffer[j].bl);
|
||||
fprintf(output_file, "255\n");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
free(paf_name);
|
||||
fclose(output_file);
|
||||
|
||||
fprintf(stderr, "PAF has been written.\n");
|
||||
}
|
||||
|
||||
@@ -1559,7 +1904,7 @@ void hap_recalculate_peaks(char* output_file_name)
|
||||
int hom_cov, het_cov;
|
||||
// construct hash table for high occurrence k-mers
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT)) {
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0);
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
}
|
||||
free(R_INF.read_length);
|
||||
@@ -1588,13 +1933,13 @@ void ha_overlap_final(void)
|
||||
|
||||
CALLOC(b, asm_opt.thread_num);
|
||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||
b[i] = ha_ovec_init(asm_opt.flag & HA_F_HIGH_HET, 1);///b[i] = ha_ovec_init(1, 1);
|
||||
b[i] = ha_ovec_init(asm_opt.flag & HA_F_HIGH_HET, 1,0);///b[i] = ha_ovec_init(1, 1);
|
||||
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, 1, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
if(asm_opt.flag & HA_F_HIGH_HET)
|
||||
{
|
||||
kt_for(asm_opt.thread_num, worker_ov_final_high_het, b, R_INF.total_reads);
|
||||
}
|
||||
else
|
||||
// if(asm_opt.flag & HA_F_HIGH_HET)
|
||||
// {
|
||||
// kt_for(asm_opt.thread_num, worker_ov_final_high_het, b, R_INF.total_reads);
|
||||
// }
|
||||
// else
|
||||
{
|
||||
kt_for(asm_opt.thread_num, worker_ov_final, b, R_INF.total_reads);
|
||||
}
|
||||
@@ -1608,6 +1953,32 @@ void ha_overlap_final(void)
|
||||
asm_opt.het_cov = het_cov;
|
||||
}
|
||||
|
||||
void ha_ec_ff(int renew_idx, int8_t pre_load_idx, uint64_t w_tmp)
|
||||
{
|
||||
int hom_cov, het_cov;
|
||||
ha_flt_tab_hp = ha_idx_hp = NULL;
|
||||
|
||||
if((ha_idx) && (renew_idx) && (!pre_load_idx)) {
|
||||
ha_pt_destroy(ha_idx); ha_idx = NULL;
|
||||
}
|
||||
|
||||
if(!ha_idx) {
|
||||
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, 1, 0, &R_INF, &hom_cov, &het_cov); // build the index
|
||||
asm_opt.hom_cov = hom_cov; asm_opt.het_cov = het_cov;
|
||||
}
|
||||
|
||||
if (w_tmp) tmp_pt_pro(&ha_flt_tab, &ha_idx, &R_INF, &scb, &asm_opt, asm_opt.output_file_name, asm_opt.number_of_round, asm_opt.number_of_round, 0, 1);
|
||||
|
||||
cal_ov_r(asm_opt.thread_num, R_INF.total_reads, renew_idx);
|
||||
|
||||
if(asm_opt.write_pos_idx) {
|
||||
refresh_pt_idx(&ha_flt_tab, &ha_idx, NULL, &asm_opt, asm_opt.output_file_name, 1);
|
||||
// write_pt_index(ha_flt_tab, ha_idx, NULL, &asm_opt, asm_opt.output_file_name);
|
||||
} else {
|
||||
ha_pt_destroy(ha_idx); ha_idx = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void worker_ov_utg(void *data, long i, int tid)
|
||||
{
|
||||
ha_ovec_buf_t *b = ((ha_ovec_buf_t**)data)[tid];
|
||||
@@ -1636,15 +2007,15 @@ void ug_idx_build(ma_ug_t *ug, int hap_n)
|
||||
{
|
||||
int flag = asm_opt.flag&HA_F_NO_HPC, i;
|
||||
asm_opt.flag -= flag;
|
||||
ha_flt_tab = ha_ft_ug_gen(&asm_opt, &(ug->u), hap_n);
|
||||
ha_idx = ha_pt_ug_gen(&asm_opt, ha_flt_tab, &(ug->u), hap_n);
|
||||
// ha_flt_tab = ha_ft_ug_gen(&asm_opt, &(ug->u), hap_n, hap_n);
|
||||
// ha_idx = ha_pt_ug_gen(&asm_opt, ha_flt_tab, &(ug->u), hap_n);
|
||||
|
||||
ha_ovec_buf_t **b = NULL;
|
||||
// overlap and correct reads
|
||||
CALLOC(b, asm_opt.thread_num);
|
||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||
{
|
||||
b[i] = ha_ovec_init(1, 1);
|
||||
b[i] = ha_ovec_init(1, 1, 0);
|
||||
b[i]->ua = &(ug->u);
|
||||
}
|
||||
|
||||
@@ -1660,12 +2031,149 @@ void ug_idx_build(ma_ug_t *ug, int hap_n)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int ha_assemble_ovec(void)
|
||||
{
|
||||
extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
|
||||
int r = 0, hom_cov = -1;
|
||||
|
||||
ha_flt_tab = ha_idx = NULL;
|
||||
|
||||
// construct hash table for high occurrence k-mers
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) {
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
}
|
||||
// error correction
|
||||
assert(asm_opt.number_of_round > 0);
|
||||
ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
|
||||
ha_overlap_cal(r, 0);
|
||||
fprintf(stderr, "[M::%s] size of buffer: %.3fGB\n", __func__, asm_opt.mem_buf / 1073741824.0);
|
||||
|
||||
|
||||
ha_print_ovlp_stat(R_INF.paf, R_INF.reverse_paf, R_INF.total_reads);
|
||||
ha_ft_destroy(ha_flt_tab);
|
||||
|
||||
Output_PAF0(R_INF.paf, "0");
|
||||
Output_PAF0(R_INF.reverse_paf, "1");
|
||||
if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
|
||||
|
||||
destory_All_reads(&R_INF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ha_assemble_ovec_cc(void)
|
||||
{
|
||||
ha_idx = NULL;
|
||||
|
||||
ha_opt_reset_to_round(&asm_opt, 0); // this update asm_opt.roundID and a few other fields
|
||||
ha_ec_dbg();
|
||||
|
||||
// Output_PAF0(R_INF.paf, "0");
|
||||
destory_All_reads(&R_INF);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ha_assemble(void)
|
||||
{
|
||||
// debug_mc_g_t(MC_NAME);
|
||||
// debug_mc_gg_t(MC_NAME, 0, 0);
|
||||
// quick_debug_phasing(MC_NAME);
|
||||
extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
|
||||
int r, hom_cov = -1, ovlp_loaded = 0;
|
||||
int r, r0 = -1, hom_cov = -1, ovlp_loaded = 0; uint64_t tot_b, tot_e; int8_t pre_load_ff = 0;
|
||||
if ((asm_opt.load_index_from_disk) && (asm_opt.dbg_ec_rr < 0) && load_all_data_from_disk(&R_INF.paf, &R_INF.reverse_paf, asm_opt.output_file_name)) {
|
||||
ovlp_loaded = 1;
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> loaded corrected reads and overlaps from disk\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
if (asm_opt.extract_list) {
|
||||
ha_extract_print_list(&R_INF, asm_opt.extract_iter, asm_opt.extract_list);
|
||||
exit(0);
|
||||
}
|
||||
if (asm_opt.flag & HA_F_WRITE_EC) {
|
||||
if(asm_opt.is_sc) Output_corrected_fastq();
|
||||
else Output_corrected_reads();
|
||||
}
|
||||
if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
|
||||
if (asm_opt.het_cov == -1024) hap_recalculate_peaks(asm_opt.output_file_name), ovlp_loaded = 2;
|
||||
}
|
||||
if (!ovlp_loaded) {
|
||||
ha_flt_tab = ha_idx = NULL;
|
||||
if((asm_opt.flag & HA_F_VERBOSE_GFA)) load_pt_index(&ha_flt_tab, &ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name, 0), load_ct_index(&ha_ct_table, asm_opt.output_file_name);
|
||||
r = ha_idx?asm_opt.number_of_round-1:0;
|
||||
if((!ha_idx) && (asm_opt.restart)) {
|
||||
r = asm_opt.number_of_round/** - 1**/;
|
||||
if(asm_opt.dbg_ec_rr >= 0) r = asm_opt.dbg_ec_rr;
|
||||
for (; r >= 0; --r) {
|
||||
if(tmp_pt_pro(&ha_flt_tab, &ha_idx, &R_INF, &scb, &asm_opt, asm_opt.output_file_name, r, asm_opt.number_of_round, 1, ((r==asm_opt.number_of_round)?(1):(0)))) {
|
||||
load_ct_index(&ha_ct_table, asm_opt.output_file_name); r0 = r;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if((asm_opt.dbg_ec_rr >= 0) && (asm_opt.dbg_ec_rr != r)) {
|
||||
fprintf(stderr, "[E::%s] no matching debug error-correction bins found\n", __func__);
|
||||
exit(1);
|
||||
}
|
||||
if(r < 0) {
|
||||
r = 0;
|
||||
} else if(r == asm_opt.number_of_round) {
|
||||
pre_load_ff = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// construct hash table for high occurrence k-mers
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) {
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
}
|
||||
// error correction
|
||||
assert(asm_opt.number_of_round > 0);
|
||||
for (; r < asm_opt.number_of_round; ++r) {
|
||||
ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
|
||||
tot_b = tot_e = 0;
|
||||
// ha_overlap_and_correct(r);
|
||||
ha_ec(r, asm_opt.number_of_pround, (r<asm_opt.number_of_round-1)?1:0, &tot_b, &tot_e, ((r > r0) && (asm_opt.restart))?1:0);
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> corrected reads for round %d\n", __func__, yak_realtime(),
|
||||
yak_cpu_usage(), yak_peakrss_in_gb(), r + 1);
|
||||
fprintf(stderr, "[M::%s] # bases: %lu; # corrected bases: %lu\n", __func__, tot_b, tot_e);
|
||||
// fprintf(stderr, "[M::%s] # bases: %lld; # corrected bases: %lld; # recorrected bases: %lld\n", __func__,
|
||||
// asm_opt.num_bases, asm_opt.num_corrected_bases, asm_opt.num_recorrected_bases);
|
||||
// fprintf(stderr, "[M::%s] size of buffer: %.3fGB\n", __func__, asm_opt.mem_buf / 1073741824.0);
|
||||
if(asm_opt.dbg_ec_rr >= 0) exit(1);
|
||||
}
|
||||
if (asm_opt.flag & HA_F_WRITE_EC) {
|
||||
if(asm_opt.is_sc) Output_corrected_fastq();
|
||||
else Output_corrected_reads();
|
||||
}
|
||||
// overlap between corrected reads
|
||||
ha_opt_reset_to_round(&asm_opt, asm_opt.number_of_round);
|
||||
// ha_overlap_final();
|
||||
ha_ec_ff(1/**0**/, pre_load_ff, ((r > r0) && (asm_opt.restart))?1:0);
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> found overlaps for the final round\n", __func__, yak_realtime(), yak_cpu_usage(), yak_peakrss_in_gb());
|
||||
if(asm_opt.dbg_ec_rr >= 0) exit(1);
|
||||
// fprintf(stderr, "\n[M::%s::%.3f*%.2f@%.3fGB] ==> found overlaps for the final round\n", __func__, yak_realtime(), yak_cpu_usage(), yak_peakrss_in_gb());
|
||||
// ha_print_ovlp_stat(R_INF.paf, R_INF.reverse_paf, R_INF.total_reads);
|
||||
if(!(asm_opt.write_pos_idx)) {
|
||||
ha_ft_destroy(ha_flt_tab); ha_flt_tab = NULL;
|
||||
}
|
||||
if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
|
||||
ha_triobin(&asm_opt);
|
||||
|
||||
// exit(1);
|
||||
}
|
||||
if(ovlp_loaded == 2) ovlp_loaded = 0;
|
||||
ha_opt_update_cov_min(&asm_opt, asm_opt.hom_cov, MIN_N_CHAIN);
|
||||
|
||||
build_string_graph_without_clean(asm_opt.min_overlap_coverage, R_INF.paf, R_INF.reverse_paf,
|
||||
R_INF.total_reads, R_INF.read_length, asm_opt.min_overlap_Len, asm_opt.max_hang_Len, asm_opt.clean_round,
|
||||
asm_opt.gap_fuzz, asm_opt.min_drop_rate, asm_opt.max_drop_rate, asm_opt.output_file_name, asm_opt.large_pop_bubble_size, 0, !ovlp_loaded);
|
||||
destory_All_reads(&R_INF); /**if(asm_opt.dbg_bam)**/ destroy_cc_v(&scb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int ha_assemble_pair(void)
|
||||
{
|
||||
extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
|
||||
int r = 0, hom_cov = -1, ovlp_loaded = 0; memset((&R_INF), 0, sizeof(R_INF));
|
||||
|
||||
if (asm_opt.load_index_from_disk && load_all_data_from_disk(&R_INF.paf, &R_INF.reverse_paf, asm_opt.output_file_name)) {
|
||||
ovlp_loaded = 1;
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> loaded corrected reads and overlaps from disk\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
@@ -1673,45 +2181,51 @@ int ha_assemble(void)
|
||||
ha_extract_print_list(&R_INF, asm_opt.extract_iter, asm_opt.extract_list);
|
||||
exit(0);
|
||||
}
|
||||
if (!(asm_opt.flag & HA_F_SKIP_TRIOBIN) && !(asm_opt.flag & HA_F_VERBOSE_GFA)) ha_triobin(&asm_opt);
|
||||
///if (!(asm_opt.flag & HA_F_SKIP_TRIOBIN)) ha_triobin(&asm_opt), ovlp_loaded = 2;
|
||||
if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads();
|
||||
if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
|
||||
if (asm_opt.het_cov == -1024) hap_recalculate_peaks(asm_opt.output_file_name), ovlp_loaded = 2;
|
||||
}
|
||||
|
||||
|
||||
if (!ovlp_loaded) {
|
||||
ha_flt_tab = ha_idx = NULL;
|
||||
if((asm_opt.flag & HA_F_VERBOSE_GFA)) load_pt_index(&ha_flt_tab, &ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name), load_ct_index(&ha_ct_table, asm_opt.output_file_name);
|
||||
|
||||
if(!append_All_reads(&R_INF, asm_opt.output_file_name, 0)) {
|
||||
fprintf(stderr, "[M::%s::] Cannot load %s.0\n", __func__, asm_opt.output_file_name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if(!append_All_reads(&R_INF, asm_opt.output_file_name, 1)) {
|
||||
fprintf(stderr, "[M::%s::] Cannot load %s.1\n", __func__, asm_opt.output_file_name);
|
||||
exit(1);
|
||||
}
|
||||
// Output_corrected_reads(); exit(0);
|
||||
|
||||
ha_flt_tab = ha_idx = NULL; r = asm_opt.number_of_round - 1;
|
||||
if((asm_opt.flag & HA_F_VERBOSE_GFA)) load_pt_index(&ha_flt_tab, &ha_idx, &R_INF, &asm_opt, asm_opt.output_file_name, 0), load_ct_index(&ha_ct_table, asm_opt.output_file_name);
|
||||
|
||||
// construct hash table for high occurrence k-mers
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL)
|
||||
{
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0);
|
||||
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) {
|
||||
ha_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 1);
|
||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||
}
|
||||
// error correction
|
||||
assert(asm_opt.number_of_round > 0);
|
||||
for (r = ha_idx?asm_opt.number_of_round-1:0; r < asm_opt.number_of_round; ++r) {
|
||||
ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
|
||||
ha_overlap_and_correct(r);
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> corrected reads for round %d\n", __func__, yak_realtime(),
|
||||
yak_cpu_usage(), yak_peakrss_in_gb(), r + 1);
|
||||
fprintf(stderr, "[M::%s] # bases: %lld; # corrected bases: %lld; # recorrected bases: %lld\n", __func__,
|
||||
asm_opt.num_bases, asm_opt.num_corrected_bases, asm_opt.num_recorrected_bases);
|
||||
ha_overlap_cal(r, 1);
|
||||
fprintf(stderr, "[M::%s] size of buffer: %.3fGB\n", __func__, asm_opt.mem_buf / 1073741824.0);
|
||||
}
|
||||
if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads();
|
||||
// overlap between corrected reads
|
||||
ha_opt_reset_to_round(&asm_opt, asm_opt.number_of_round);
|
||||
ha_overlap_final();
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f@%.3fGB] ==> found overlaps for the final round\n", __func__, yak_realtime(),
|
||||
yak_cpu_usage(), yak_peakrss_in_gb());
|
||||
|
||||
|
||||
if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads();
|
||||
ha_print_ovlp_stat(R_INF.paf, R_INF.reverse_paf, R_INF.total_reads);
|
||||
ha_ft_destroy(ha_flt_tab);
|
||||
if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
|
||||
ha_triobin(&asm_opt);
|
||||
|
||||
}
|
||||
if(ovlp_loaded == 2) ovlp_loaded = 0;
|
||||
ha_opt_update_cov_min(&asm_opt, asm_opt.hom_cov, MIN_N_CHAIN);
|
||||
|
||||
build_string_graph_without_clean(asm_opt.min_overlap_coverage, R_INF.paf, R_INF.reverse_paf,
|
||||
R_INF.total_reads, R_INF.read_length, asm_opt.min_overlap_Len, asm_opt.max_hang_Len, asm_opt.clean_round,
|
||||
|
||||
+36
@@ -2,6 +2,9 @@
|
||||
#define __ASSEMBLY__
|
||||
#include "CommandLines.h"
|
||||
#include "Overlaps.h"
|
||||
#include "Process_Read.h"
|
||||
#include "Hash_Table.h"
|
||||
#include "Correct.h"
|
||||
|
||||
#define FORWARD 0
|
||||
#define REVERSE_COMPLEMENT (0x8000000000000000)
|
||||
@@ -14,7 +17,40 @@
|
||||
#define RESEED_LEN 2000
|
||||
#define RESEED_HP_RATE 0.9
|
||||
|
||||
typedef struct {
|
||||
int is_final, save_ov;
|
||||
// chaining and overlapping related buffers
|
||||
UC_Read self_read, ovlp_read;
|
||||
Candidates_list clist;
|
||||
overlap_region_alloc olist;
|
||||
overlap_region_alloc olist_hp;
|
||||
ha_abuf_t *ab;
|
||||
ha_abufl_t *abl;
|
||||
// error correction related buffers
|
||||
int64_t num_read_base, num_correct_base, num_recorrect_base;
|
||||
Cigar_record cigar1;
|
||||
Graph POA_Graph;
|
||||
Graph DAGCon;
|
||||
Correct_dumy correct;
|
||||
haplotype_evdience_alloc hap;
|
||||
Round2_alignment round2;
|
||||
kvec_t_u32_warp b_buf;
|
||||
kvec_t_u64_warp r_buf;
|
||||
kvec_t_u8_warp k_flag;
|
||||
overlap_region tmp_region;
|
||||
ma_utg_v *ua;
|
||||
st_mt_t sp;
|
||||
bit_extz_t exz;
|
||||
} ha_ovec_buf_t;
|
||||
|
||||
int ha_assemble(void);
|
||||
int ha_assemble_pair(void);
|
||||
void ug_idx_build(ma_ug_t *ug, int hap_n);
|
||||
ha_ovec_buf_t *ha_ovec_init(int is_final, int save_ov, int is_ug);
|
||||
ha_ovec_buf_t *ha_ovec_buf_init(void *km, int is_final, int save_ov, int is_ug);
|
||||
void ha_ovec_destroy(ha_ovec_buf_t *b);
|
||||
int64_t ha_ovec_mem(const ha_ovec_buf_t *b, int64_t *mem_a);
|
||||
int ha_assemble_ovec(void);
|
||||
int ha_ec_dbg(void);
|
||||
|
||||
#endif
|
||||
|
||||
+568
-29
@@ -1,3 +1,4 @@
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <zlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -6,8 +7,16 @@
|
||||
#include <sys/time.h>
|
||||
#include "CommandLines.h"
|
||||
#include "ketopt.h"
|
||||
#include "kseq.h"
|
||||
|
||||
KSEQ_INIT(gzFile, gzread)
|
||||
|
||||
#define DEFAULT_OUTPUT "hifiasm.asm"
|
||||
#define RER_H_HiFi 0.06
|
||||
#define RER_H_ONT 0.08
|
||||
#define RER_N_HiFi 0.03
|
||||
#define RER_N_ONT 0.05
|
||||
#define MIN_R_COV 3
|
||||
|
||||
hifiasm_opt_t asm_opt;
|
||||
|
||||
@@ -17,8 +26,8 @@ static ko_longopt_t long_options[] = {
|
||||
{ "write-paf", ko_no_argument, 302 },
|
||||
{ "write-ec", ko_no_argument, 303 },
|
||||
{ "skip-triobin", ko_no_argument, 304 },
|
||||
{ "max-od-ec", ko_no_argument, 305 },
|
||||
{ "max-od-final", ko_no_argument, 306 },
|
||||
{ "max-od-ec", ko_required_argument, 305 },
|
||||
{ "max-od-final", ko_required_argument, 306 },
|
||||
{ "ex-list", ko_required_argument, 307 },
|
||||
{ "ex-iter", ko_required_argument, 308 },
|
||||
{ "hom-cov", ko_required_argument, 309 },
|
||||
@@ -44,6 +53,61 @@ static ko_longopt_t long_options[] = {
|
||||
{ "dp-er", ko_required_argument, 330},
|
||||
{ "max-kocc", ko_required_argument, 331},
|
||||
{ "hg-size", ko_required_argument, 332},
|
||||
{ "ul", ko_required_argument, 333},
|
||||
{ "unskew", ko_no_argument, 334},
|
||||
{ "kpt-rate", ko_required_argument, 335},
|
||||
{ "ul-rate", ko_required_argument, 336},
|
||||
{ "dbg-het-cnt", ko_no_argument, 337},
|
||||
{ "ul-tip", ko_required_argument, 338},
|
||||
{ "low-het", ko_no_argument, 339},
|
||||
{ "s-base", ko_required_argument, 340},
|
||||
{ "bin-only", ko_no_argument, 341},
|
||||
{ "ul-round", ko_required_argument, 342},
|
||||
{ "prt-raw", ko_no_argument, 343},
|
||||
{ "integer-correct", ko_required_argument, 344},
|
||||
{ "dbg-ovec", ko_no_argument, 345},
|
||||
{ "path-max", ko_required_argument, 346},
|
||||
{ "path-min", ko_required_argument, 347},
|
||||
{ "trio-dual", ko_no_argument, 348},
|
||||
{ "ul-cut", ko_required_argument, 349},
|
||||
{ "dual-scaf", ko_no_argument, 350},
|
||||
{ "scaf-gap", ko_required_argument, 351},
|
||||
{ "sec-in", ko_required_argument, 352},
|
||||
{ "somatic-cov", ko_required_argument, 353},
|
||||
{ "telo-m", ko_required_argument, 354},
|
||||
{ "telo-p", ko_required_argument, 355},
|
||||
{ "telo-d", ko_required_argument, 356},
|
||||
{ "telo-s", ko_required_argument, 357},
|
||||
{ "ctg-n", ko_required_argument, 358},
|
||||
{ "ont", ko_no_argument, 359},
|
||||
// { "sc-n", ko_no_argument, 360},
|
||||
{ "chem-c", ko_required_argument, 361},
|
||||
{ "chem-f", ko_required_argument, 362},
|
||||
{ "ul-m", ko_required_argument, 363},
|
||||
{ "rl-cut", ko_required_argument, 364},
|
||||
{ "sc-cut", ko_required_argument, 365},
|
||||
{ "hf", ko_required_argument, 366},
|
||||
{ "cb", ko_required_argument, 367},
|
||||
{ "gpath", ko_no_argument, 368},
|
||||
{ "het-cov", ko_required_argument, 369},
|
||||
{ "resume", ko_no_argument, 370},
|
||||
{ "flt-kocc", ko_required_argument, 371},
|
||||
{ "chn-occ", ko_required_argument, 372},
|
||||
{ "dbg-in1", ko_required_argument, 373},
|
||||
{ "dbg-in2", ko_required_argument, 374},
|
||||
{ "ec-only", ko_no_argument, 375},
|
||||
{ "hyb-syn", ko_required_argument, 376},
|
||||
{ "simd-m", ko_required_argument, 377},
|
||||
{ "del-hf", ko_no_argument, 378},
|
||||
{ "dbg-rr", ko_required_argument, 379},///start from 0/1/2 step of correction
|
||||
{ "re-aln", ko_required_argument, 380},
|
||||
{ "syn", ko_required_argument, 381},
|
||||
{ "rec", ko_required_argument, 382},
|
||||
{ "ref", ko_required_argument, 383},
|
||||
{ "h_rec", ko_required_argument, 384},
|
||||
{ "h_ref", ko_required_argument, 385},
|
||||
{ "ret", ko_no_argument, 386},
|
||||
// { "path-round", ko_required_argument, 348},
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
@@ -54,6 +118,7 @@ double Get_T(void)
|
||||
return t.tv_sec+t.tv_usec/1000000.0;
|
||||
}
|
||||
|
||||
|
||||
void Print_H(hifiasm_opt_t* asm_opt)
|
||||
{
|
||||
fprintf(stderr, "Usage: hifiasm [options] <in_1.fq> <in_2.fq> <...>\n");
|
||||
@@ -63,11 +128,15 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " -t INT number of threads [%d]\n", asm_opt->thread_num);
|
||||
fprintf(stderr, " -h show help information\n");
|
||||
fprintf(stderr, " --version show version number\n");
|
||||
fprintf(stderr, " Preset options:\n");
|
||||
fprintf(stderr, " --ont assemble Oxford Nanopore reads\n");
|
||||
fprintf(stderr, " Overlap/Error correction:\n");
|
||||
fprintf(stderr, " -k INT k-mer length (must be <64) [%d]\n", asm_opt->k_mer_length);
|
||||
fprintf(stderr, " -w INT minimizer window size [%d]\n", asm_opt->mz_win);
|
||||
fprintf(stderr, " -f INT number of bits for bloom filter; 0 to disable [%d]\n", asm_opt->bf_shift);
|
||||
fprintf(stderr, " -D FLOAT drop k-mers occurring >FLOAT*coverage times [%.1f]\n", asm_opt->high_factor);
|
||||
fprintf(stderr, " -D FLOAT drop k-mers occurring >FLOAT*coverage times [%.1f]; work with --flt-kocc or -N\n", asm_opt->high_factor);
|
||||
fprintf(stderr, " --flt-kocc INT\n");
|
||||
fprintf(stderr, " drop k-mers occurring >max(-D*coverage,--flt-kocc) times [%ld]\n", asm_opt->hf_cutoff);
|
||||
fprintf(stderr, " -N INT consider up to max(-D*coverage,-N) overlaps for each oriented read [%d]\n", asm_opt->max_n_chain);
|
||||
fprintf(stderr, " -r INT round of correction [%d]\n", asm_opt->number_of_round);
|
||||
fprintf(stderr, " -z INT length of adapters that should be removed [%d]\n", asm_opt->adapterLen);
|
||||
@@ -75,6 +144,43 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " employ k-mers occurring <INT times to rescue repetitive overlaps [%d]\n", asm_opt->max_kmer_cnt);
|
||||
fprintf(stderr, " --hg-size INT(k, m or g)\n");
|
||||
fprintf(stderr, " estimated haploid genome size used for inferring read coverage [auto]\n");
|
||||
fprintf(stderr, " --resume resume from the previously incomplete assembly [%ld]\n", asm_opt->restart);
|
||||
fprintf(stderr, " --het-cov INT\n");
|
||||
fprintf(stderr, " heterozygous read coverage [auto]; used for error correction and assembly; manual value overrides auto\n");
|
||||
fprintf(stderr, " --hom-cov INT\n");
|
||||
fprintf(stderr, " homozygous read coverage [auto]; used for error correction and assembly; manual value overrides auto\n");
|
||||
fprintf(stderr, " --chn-occ INT\n");
|
||||
fprintf(stderr, " discard overlaps supported by <INT minimizers [%ld]\n", asm_opt->chn_occ);
|
||||
fprintf(stderr, " --ec-only error correction only; disable overlapping and assembly\n");
|
||||
fprintf(stderr, " --simd-m use SIMD acceleration when supported: AVX-512 (2), AVX2 (1), or non-SIMD (0)\n");
|
||||
fprintf(stderr, " --re-aln keep raw reads for error correction [%d]\n", asm_opt->realn_raw);
|
||||
fprintf(stderr, " --syn rescue overlaps for error correction [%d]\n", asm_opt->post_syn);
|
||||
|
||||
|
||||
|
||||
fprintf(stderr, " Recurrent sequencing-error filtering:\n");
|
||||
fprintf(stderr, " --ret enable recurrent sequencing-error filtering; disabled by default\n");
|
||||
fprintf(stderr, " thresholds are controlled by --rec/--ref and --h_rec/--h_ref\n");
|
||||
fprintf(stderr, " --rec/--ref and --h_rec/--h_ref are ignored unless --ret is set\n");
|
||||
fprintf(stderr, " --rec INT\n");
|
||||
fprintf(stderr, " discard candidate variants supported by <INT reads [%ld]\n",
|
||||
asm_opt->recurrent_err_normal_min);
|
||||
fprintf(stderr, " --ref FLOAT\n");
|
||||
fprintf(stderr, " discard candidate variants supported by <FLOAT*coverage reads; -1 to disable\n");
|
||||
fprintf(stderr, " coverage = min(local read coverage, homozygous coverage);\n");
|
||||
fprintf(stderr, " default: %.3g for ONT, %.3g for HiFi\n",
|
||||
RER_N_ONT, RER_N_HiFi);
|
||||
|
||||
fprintf(stderr, " --h_rec INT\n");
|
||||
fprintf(stderr, " discard candidate variants near homopolymers if supported by <INT reads [%ld]\n",
|
||||
asm_opt->recurrent_err_hpc_min);
|
||||
fprintf(stderr, " --h_ref FLOAT\n");
|
||||
fprintf(stderr, " discard candidate variants near homopolymers if supported by <FLOAT*coverage reads; -1 to disable\n");
|
||||
fprintf(stderr, " coverage = min(local read coverage, homozygous coverage);\n");
|
||||
fprintf(stderr, " default: %.3g for ONT, %.3g for HiFi\n",
|
||||
RER_H_ONT, RER_H_HiFi);
|
||||
|
||||
|
||||
fprintf(stderr, " Assembly:\n");
|
||||
fprintf(stderr, " -a INT round of assembly cleaning [%d]\n", asm_opt->clean_round);
|
||||
fprintf(stderr, " -m INT pop bubbles of <INT in size in contig graphs [%lld]\n", asm_opt->large_pop_bubble_size);
|
||||
@@ -83,9 +189,9 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " -x FLOAT max overlap drop ratio [%.2g]\n", asm_opt->max_drop_rate);
|
||||
fprintf(stderr, " -y FLOAT min overlap drop ratio [%.2g]\n", asm_opt->min_drop_rate);
|
||||
fprintf(stderr, " -i ignore saved read correction and overlaps\n");
|
||||
fprintf(stderr, " -u disable post-join step for contigs which may improve N50\n");
|
||||
fprintf(stderr, " --hom-cov INT\n");
|
||||
fprintf(stderr, " homozygous read coverage [auto]\n");
|
||||
fprintf(stderr, " -u post-join step for contigs which may improve N50; 0 to disable; 1 to enable\n");
|
||||
fprintf(stderr, " [%u] and [%u] in default for the UL+HiFi assembly and the HiFi assembly, respectively\n",
|
||||
asm_opt->ul_pst_join, asm_opt->hifi_pst_join);
|
||||
fprintf(stderr, " --lowQ INT\n");
|
||||
fprintf(stderr, " output contig regions with >=INT%% inconsistency in BED format; 0 to disable [%d]\n", asm_opt->bed_inconsist_rate);
|
||||
fprintf(stderr, " --b-cov INT\n");
|
||||
@@ -96,6 +202,10 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " break contigs at positions with <=FLOAT*coverage exact overlaps;\n");
|
||||
fprintf(stderr, " only work with '--b-cov' or '--h-cov'[%.2f]\n", asm_opt->m_rate);
|
||||
fprintf(stderr, " --primary output a primary assembly and an alternate assembly\n");
|
||||
fprintf(stderr, " --ctg-n INT\n");
|
||||
fprintf(stderr, " remove tip contigs composed of <=INT reads [%d]\n", asm_opt->max_contig_tip);
|
||||
fprintf(stderr, " --gpath output the corresponding path of each contig (p_ctg) within the assembly graph (d_utg.noseq.gfa)\n");
|
||||
|
||||
|
||||
// fprintf(stderr, " --pri-range INT1[,INT2]\n");
|
||||
// fprintf(stderr, " keep contigs with coverage in this range in p_ctg.gfa; -1 to disable [auto,inf]\n");
|
||||
@@ -110,10 +220,12 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " --t-occ INT\n");
|
||||
fprintf(stderr, " forcedly remove unitigs with >INT unexpected haplotype-specific reads;\n");
|
||||
fprintf(stderr, " ignore graph topology; [%d]\n", asm_opt->trio_flag_occ_thres);
|
||||
fprintf(stderr, " --trio-dual utilize homology information to correct trio phasing errors\n");
|
||||
|
||||
|
||||
fprintf(stderr, " Purge-dups:\n");
|
||||
fprintf(stderr, " -l INT purge level. 0: no purging; 1: light; 2/3: aggressive [0 for trio; 3 for unzip]\n");
|
||||
fprintf(stderr, " -s FLOAT similarity threshold for duplicate haplotigs [%g for -l1/-l2, %g for -l3]\n",
|
||||
fprintf(stderr, " -s FLOAT similarity threshold for duplicate haplotigs in read-level [%g for -l1/-l2, %g for -l3]\n",
|
||||
asm_opt->purge_simi_rate_l2, asm_opt->purge_simi_rate_l3);
|
||||
fprintf(stderr, " -O INT min number of overlapped reads for duplicate haplotigs [%d]\n",
|
||||
asm_opt->purge_overlap_len);
|
||||
@@ -127,7 +239,9 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " --h1 FILEs file names of Hi-C R1 [r1_1.fq,r1_2.fq,...]\n");
|
||||
fprintf(stderr, " --h2 FILEs file names of Hi-C R2 [r2_1.fq,r2_2.fq,...]\n");
|
||||
fprintf(stderr, " --seed INT RNG seed [%lu]\n", asm_opt->seed);
|
||||
|
||||
fprintf(stderr, " --s-base FLOAT\n");
|
||||
fprintf(stderr, " similarity threshold for homology detection in base-level;\n");
|
||||
fprintf(stderr, " -1 to disable [%.3g]; -s for read-level (see <Purge-dups>)\n", asm_opt->trans_base_rate_sec);
|
||||
|
||||
fprintf(stderr, " --n-weight INT\n");
|
||||
fprintf(stderr, " rounds of reweighting Hi-C links [%d]\n", asm_opt->n_weight);
|
||||
@@ -138,6 +252,63 @@ void Print_H(hifiasm_opt_t* asm_opt)
|
||||
fprintf(stderr, " --l-msjoin INT\n");
|
||||
fprintf(stderr, " detect misjoined unitigs of >=INT in size; 0 to disable [%lu]\n", asm_opt->misjoin_len);
|
||||
|
||||
fprintf(stderr, " Ultra-Long-integration:\n");
|
||||
fprintf(stderr, " --ul FILEs file names of Ultra-Long reads [r1.fq,r2.fq,...]\n");
|
||||
///pending for integration
|
||||
/**
|
||||
fprintf(stderr, " --ul-m INT\n");
|
||||
fprintf(stderr, " hybrid assembly mode. 0: fast and memory efficent; 1: may produce better assembly with ONT R10 [%d]\n", asm_opt->ul_mod);
|
||||
**/
|
||||
fprintf(stderr, " --ul-rate FLOAT\n");
|
||||
fprintf(stderr, " error rate of Ultra-Long reads [%.3g]\n", asm_opt->ul_error_rate);
|
||||
fprintf(stderr, " --ul-tip INT\n");
|
||||
fprintf(stderr, " remove tip unitigs composed of <=INT reads for the UL assembly [%d]\n", asm_opt->max_short_ul_tip);
|
||||
fprintf(stderr, " --path-max FLOAT\n");
|
||||
fprintf(stderr, " max path drop ratio [%.2g]; higher number may make the assembly cleaner\n", asm_opt->max_path_drop_rate);
|
||||
fprintf(stderr, " but may lead to more misassemblies\n");
|
||||
fprintf(stderr, " --path-min FLOAT\n");
|
||||
fprintf(stderr, " min path drop ratio [%.2g]; higher number may make the assembly cleaner\n", asm_opt->min_path_drop_rate);
|
||||
fprintf(stderr, " but may lead to more misassemblies\n");
|
||||
fprintf(stderr, " --ul-cut INT\n");
|
||||
fprintf(stderr, " filter out <INT UL reads during the UL assembly [%d]\n", asm_opt->ul_min_base);
|
||||
// fprintf(stderr, " --low-het enable it for genomes with very low het heterozygosity rate (<0.0001%%)\n");
|
||||
|
||||
fprintf(stderr, " Dual-Scaffolding:\n");
|
||||
fprintf(stderr, " --dual-scaf output scaffolding\n");
|
||||
fprintf(stderr, " --scaf-gap INT\n");
|
||||
fprintf(stderr, " max gap size for scaffolding [%ld]\n", asm_opt->self_scaf_gap_max);
|
||||
|
||||
fprintf(stderr, " Telomere-identification:\n");
|
||||
fprintf(stderr, " --telo-m STR\n");
|
||||
fprintf(stderr, " telomere motif at 5'-end; CCCTAA for human [%s]\n", ((asm_opt->telo_motif)?(asm_opt->telo_motif):("NULL")));///5'-end, check CCCTAA
|
||||
fprintf(stderr, " --telo-p INT\n");
|
||||
fprintf(stderr, " non-telomeric penalty [%ld]\n", asm_opt->telo_pen);
|
||||
fprintf(stderr, " --telo-d INT\n");
|
||||
fprintf(stderr, " max drop [%ld]\n", asm_opt->telo_drop);
|
||||
fprintf(stderr, " --telo-s INT\n");
|
||||
fprintf(stderr, " min score for telomere reads [%ld]\n", asm_opt->telo_mic_sc);
|
||||
|
||||
fprintf(stderr, " ONT Simplex assembly (beta):\n");
|
||||
fprintf(stderr, " --ont assemble ONT Simplex reads in fastq format\n");
|
||||
// fprintf(stderr, " --sc-n consider base qual value for assembly\n");
|
||||
fprintf(stderr, " --chem-c INT\n");
|
||||
// fprintf(stderr, " detect chimeric reads with <=INT other reads support [%lu]\n", asm_opt->chemical_cov);
|
||||
fprintf(stderr, " detect chimeric reads with <=INT other reads support [auto]\n");
|
||||
fprintf(stderr, " --chem-f INT\n");
|
||||
fprintf(stderr, " length of flanking regions for chimeric read detection [%lu]\n", asm_opt->chemical_flank);
|
||||
fprintf(stderr, " --rl-cut INT\n");
|
||||
fprintf(stderr, " filter out ONT Simplex reads shorter than <INT> for assembly [%ld]\n", asm_opt->rl_cut);
|
||||
fprintf(stderr, " --sc-cut INT\n");
|
||||
fprintf(stderr, " filter out ONT Simplex reads with a mean base quality score below <INT> [%ld]\n", asm_opt->sc_cut);
|
||||
fprintf(stderr, " --hf FILEs HiFi read file(s)\n");
|
||||
fprintf(stderr, " --hyb-syn INT\n");
|
||||
fprintf(stderr, " hybrid correction mode (requires --hf) [%d]:\n", asm_opt->hyb_syn);
|
||||
fprintf(stderr, " 1: all-vs-all (ONT<-all, HiFi<-all)\n");
|
||||
fprintf(stderr, " 2: ONT<-all, HiFi<-HiFi\n");
|
||||
fprintf(stderr, " 3: mode 2 + ONT/HiFi sync to reduce bias\n");
|
||||
|
||||
|
||||
|
||||
fprintf(stderr, "Example: ./hifiasm -o NA12878.asm -t 32 NA12878.fq.gz\n");
|
||||
fprintf(stderr, "See `https://hifiasm.readthedocs.io/en/latest/' or `man ./hifiasm.1' for complete documentation.\n");
|
||||
}
|
||||
@@ -155,24 +326,34 @@ void init_opt(hifiasm_opt_t* asm_opt)
|
||||
asm_opt->hic_enzymes = NULL;
|
||||
asm_opt->hic_reads[0] = NULL;
|
||||
asm_opt->hic_reads[1] = NULL;
|
||||
asm_opt->fn_bin_poy = NULL;
|
||||
asm_opt->fn_chr_bin = NULL;
|
||||
asm_opt->ar = NULL;
|
||||
asm_opt->thread_num = 1;
|
||||
asm_opt->k_mer_length = 51;
|
||||
asm_opt->hic_mer_length = 31;
|
||||
asm_opt->ul_mer_length = 19;
|
||||
asm_opt->trans_mer_length = 31;
|
||||
asm_opt->mz_win = 51;
|
||||
asm_opt->ul_mz_win = 19;
|
||||
asm_opt->trans_win = 31;
|
||||
asm_opt->mz_rewin = 1000;
|
||||
asm_opt->ul_mz_rewin = 360;
|
||||
asm_opt->mz_sample_dist = 500;
|
||||
asm_opt->bf_shift = 37;
|
||||
asm_opt->max_kmer_cnt = 2000;
|
||||
asm_opt->high_factor = 5.0;
|
||||
asm_opt->max_ov_diff_ec = 0.04;
|
||||
asm_opt->max_ov_diff_ec_sec = 0.04;
|
||||
asm_opt->max_ov_diff_final = 0.03;
|
||||
asm_opt->hom_cov = 20;
|
||||
asm_opt->het_cov = -1024;
|
||||
asm_opt->max_n_chain = 100;
|
||||
asm_opt->max_n_chain = MIN_N_CHAIN;
|
||||
asm_opt->min_hist_kmer_cnt = 5;
|
||||
asm_opt->load_index_from_disk = 1;
|
||||
asm_opt->write_index_to_disk = 1;
|
||||
asm_opt->number_of_round = 3;
|
||||
asm_opt->number_of_pround = 0/**3**/;
|
||||
asm_opt->adapterLen = 0;
|
||||
asm_opt->clean_round = 4;
|
||||
///asm_opt->small_pop_bubble_size = 100000;
|
||||
@@ -186,12 +367,16 @@ void init_opt(hifiasm_opt_t* asm_opt)
|
||||
asm_opt->min_overlap_Len = 50;
|
||||
asm_opt->min_overlap_coverage = 0;
|
||||
asm_opt->max_short_tip = 3;
|
||||
asm_opt->max_short_ul_tip = 6;
|
||||
asm_opt->max_contig_tip = 3;
|
||||
asm_opt->min_cnt = 2;
|
||||
asm_opt->mid_cnt = 5;
|
||||
asm_opt->purge_level_primary = 3;
|
||||
asm_opt->purge_level_trio = 0;
|
||||
asm_opt->purge_simi_rate_l2 = 0.75;
|
||||
asm_opt->purge_simi_rate_l3 = 0.55;
|
||||
asm_opt->trans_base_rate = 0.93;
|
||||
asm_opt->trans_base_rate_sec = 0.5;
|
||||
asm_opt->purge_overlap_len = 1;
|
||||
///asm_opt->purge_overlap_len_hic = 50;
|
||||
asm_opt->recover_atg_cov_min = -1024;
|
||||
@@ -219,6 +404,105 @@ void init_opt(hifiasm_opt_t* asm_opt)
|
||||
asm_opt->dp_min_len = 2000;
|
||||
asm_opt->dp_e = 0.0025;
|
||||
asm_opt->hg_size = -1;
|
||||
asm_opt->kpt_rate = -1;
|
||||
asm_opt->infor_cov = MIN_R_COV;
|
||||
asm_opt->s_hap_cov = MIN_R_COV;
|
||||
asm_opt->ul_error_rate = 0.2/**0.15**/;
|
||||
asm_opt->ul_error_rate_low = 0.1;
|
||||
asm_opt->ul_error_rate_hpc = 0.2;
|
||||
asm_opt->ul_ec_round = 3;
|
||||
asm_opt->is_dbg_het_cnt = 0;
|
||||
asm_opt->is_low_het_ul = 0;
|
||||
asm_opt->is_base_trans = 1;
|
||||
asm_opt->is_read_trans = 1;
|
||||
asm_opt->is_topo_trans = 1;
|
||||
asm_opt->is_bub_trans = 1;
|
||||
asm_opt->bin_only = 0;
|
||||
asm_opt->ul_clean_round = 1;
|
||||
asm_opt->prt_dbg_gfa = 0;
|
||||
asm_opt->integer_correct_round = 0;
|
||||
asm_opt->dbg_ovec_cal = 0;
|
||||
asm_opt->min_path_drop_rate = 0.2;
|
||||
asm_opt->max_path_drop_rate = 0.6;
|
||||
asm_opt->hifi_pst_join = 1;
|
||||
asm_opt->ul_pst_join = 1;
|
||||
asm_opt->trio_cov_het_ovlp = -1;
|
||||
asm_opt->ul_min_base = 0;
|
||||
asm_opt->self_scaf = 0;
|
||||
asm_opt->self_scaf_min = 250000;
|
||||
asm_opt->self_scaf_reliable_min = 5000000;
|
||||
asm_opt->self_scaf_gap_max = 3000000;
|
||||
asm_opt->sec_in = NULL;
|
||||
asm_opt->somatic_cov = -1;
|
||||
|
||||
asm_opt->telo_motif = NULL;
|
||||
asm_opt->telo_pen = 1;
|
||||
asm_opt->telo_drop = 2000;
|
||||
asm_opt->telo_mic_sc = 500;
|
||||
|
||||
asm_opt->is_ont = 0;
|
||||
asm_opt->is_sc = 0;
|
||||
asm_opt->chemical_cov = -1/**1**/;
|
||||
asm_opt->chemical_flank = 256;
|
||||
asm_opt->ul_mod = 0;
|
||||
|
||||
asm_opt->rl_cut = 1000;
|
||||
asm_opt->sc_cut = 10;
|
||||
|
||||
asm_opt->hf = NULL;
|
||||
|
||||
asm_opt->gpath = 0;
|
||||
|
||||
asm_opt->hf_rate = 4;
|
||||
asm_opt->ont_rate = 1;///must be 1 or 0
|
||||
asm_opt->hf_rate_max = 4;
|
||||
|
||||
asm_opt->het_cov_set = -1;
|
||||
asm_opt->restart = 0;
|
||||
|
||||
asm_opt->hf_cutoff = -1;
|
||||
|
||||
asm_opt->write_pos_idx = 0/**1**/;
|
||||
|
||||
asm_opt->hom_cov_0 = -1;
|
||||
asm_opt->het_cov_0 = -1;
|
||||
asm_opt->max_n_chain_0 = -1;
|
||||
|
||||
|
||||
asm_opt->hmo_cov_ss = -1;
|
||||
asm_opt->het_cov_ss = -1;
|
||||
asm_opt->chn_occ = 2;
|
||||
|
||||
asm_opt->dbg_run_1 = NULL;
|
||||
asm_opt->dbg_run_2 = NULL;
|
||||
|
||||
asm_opt->ec_only = 0;
|
||||
asm_opt->hyb_syn = 1;
|
||||
asm_opt->step_rd = -1/**128**/;
|
||||
|
||||
asm_opt->dbg_bam = 0;
|
||||
|
||||
asm_opt->simd_mm = -1;
|
||||
|
||||
asm_opt->del_hf = 0;
|
||||
|
||||
asm_opt->dbg_ec_rr = -1;
|
||||
|
||||
asm_opt->realn_raw = 0;
|
||||
asm_opt->post_syn = 1;
|
||||
|
||||
asm_opt->recurrent_err_normal_min = MIN_R_COV;
|
||||
asm_opt->recurrent_err_normal_min_set = -1;
|
||||
asm_opt->recurrent_err_normal_rat = RER_N_HiFi;
|
||||
asm_opt->recurrent_err_normal_rat_set = -1;
|
||||
|
||||
asm_opt->recurrent_err_hpc_min = MIN_R_COV;
|
||||
asm_opt->recurrent_err_hpc_min_set = -1;
|
||||
asm_opt->recurrent_err_hpc_rat = RER_H_HiFi;
|
||||
asm_opt->recurrent_err_hpc_rat_set = -1;
|
||||
|
||||
asm_opt->recurrent_err_test = 0;
|
||||
|
||||
}
|
||||
|
||||
void destory_enzyme(enzyme* f)
|
||||
@@ -242,6 +526,7 @@ void destory_opt(hifiasm_opt_t* asm_opt)
|
||||
if(asm_opt->hic_enzymes != NULL) destory_enzyme(asm_opt->hic_enzymes);
|
||||
if(asm_opt->hic_reads[0] != NULL) destory_enzyme(asm_opt->hic_reads[0]);
|
||||
if(asm_opt->hic_reads[1] != NULL) destory_enzyme(asm_opt->hic_reads[1]);
|
||||
if(asm_opt->ar != NULL) destory_enzyme(asm_opt->ar);
|
||||
}
|
||||
|
||||
void ha_opt_reset_to_round(hifiasm_opt_t* asm_opt, int round)
|
||||
@@ -262,6 +547,14 @@ void ha_opt_update_cov(hifiasm_opt_t *opt, int hom_cov)
|
||||
fprintf(stderr, "[M::%s] updated max_n_chain to %d\n", __func__, opt->max_n_chain);
|
||||
}
|
||||
|
||||
void ha_opt_update_cov_min(hifiasm_opt_t *opt, int hom_cov, int min_chain)
|
||||
{
|
||||
int max_n_chain = (int)(hom_cov * opt->high_factor + .499);
|
||||
opt->hom_cov = hom_cov; opt->max_n_chain = max_n_chain;
|
||||
if(opt->max_n_chain < min_chain) opt->max_n_chain = min_chain;
|
||||
fprintf(stderr, "[M::%s] updated max_n_chain to %d\n", __func__, opt->max_n_chain);
|
||||
}
|
||||
|
||||
static int check_file(char* name, const char* opt)
|
||||
{
|
||||
if(!name)
|
||||
@@ -283,14 +576,43 @@ static int check_file(char* name, const char* opt)
|
||||
|
||||
static int check_hic_reads(enzyme* f, const char* opt)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < f->n; i++)
|
||||
{
|
||||
int32_t i;
|
||||
for (i = 0; i < f->n; i++) {
|
||||
if(check_file(f->a[i], opt) == 0) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int check_fq_files(enzyme* f, const char* opt, int32_t is_fq)
|
||||
{
|
||||
int32_t i, ret; gzFile dfp; kseq_t *ks = NULL;
|
||||
for (i = 0; i < f->n; i++) {
|
||||
if(!(f->a[i])) {
|
||||
fprintf(stderr, "[ERROR] input file does not exist (%s)\n", opt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dfp = gzopen(f->a[i], "r");
|
||||
if (dfp == 0) {
|
||||
fprintf(stderr, "[ERROR] Cannot find the input file: %s (%s)\n", f->a[i], opt);
|
||||
return 0;
|
||||
} else if(is_fq){
|
||||
ks = kseq_init(dfp);
|
||||
while (((ret = kseq_read(ks)) >= 0)) {
|
||||
if((ks->qual.l == 0) || (ks->qual.s == NULL)) {
|
||||
fprintf(stderr, "[ERROR] %s is in fasta format rather than fastq format (%s)\n", f->a[i], opt);
|
||||
fprintf(stderr, "[ERROR] set --ul-m 0 for fasta files\n");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
kseq_destroy(ks); ks = NULL;
|
||||
}
|
||||
gzclose(dfp);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int check_option(hifiasm_opt_t* asm_opt)
|
||||
{
|
||||
if(asm_opt->read_file_names == NULL || asm_opt->num_reads == 0)
|
||||
@@ -490,6 +812,13 @@ int check_option(hifiasm_opt_t* asm_opt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->ar != NULL && check_fq_files(asm_opt->ar, "--ul", asm_opt->ul_mod) == 0) return 0;
|
||||
if(asm_opt->ar != NULL && asm_opt->ar->n == 0)
|
||||
{
|
||||
fprintf(stderr, "[ERROR] wrong UL reads (--ul)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->b_low_cov < 0)
|
||||
{
|
||||
fprintf(stderr, "[ERROR] must >= 0 (--b-cov)\n");
|
||||
@@ -532,30 +861,90 @@ int check_option(hifiasm_opt_t* asm_opt)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->ul_mod != 0 && asm_opt->ul_mod != 1) {
|
||||
fprintf(stderr, "[ERROR] must be 0 or 1 (--ul-m)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->telo_motif) {
|
||||
uint64_t k, tlen = strlen((asm_opt->telo_motif)); char c;
|
||||
if(tlen > 32) {
|
||||
fprintf(stderr, "[ERROR] [--telo-m] must be no longer than 32\n");
|
||||
return 0;
|
||||
}
|
||||
for (k = 0; k < tlen; k++) {
|
||||
c = asm_opt->telo_motif[k];
|
||||
if(c != 'A' && c != 'C' && c != 'G' && c != 'T' &&
|
||||
c != 'a' && c != 'c' && c != 'g' && c != 't') {
|
||||
fprintf(stderr, "[ERROR] [--telo-m] must be A/C/G/T\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((asm_opt->hf) && (!(asm_opt->is_ont))) {
|
||||
fprintf(stderr, "[ERROR] [--hf] must work with [--ont]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((asm_opt->hyb_syn != 1) && (asm_opt->hyb_syn != 2) && (asm_opt->hyb_syn != 3)) {
|
||||
fprintf(stderr, "[ERROR] [--hyb-syn] must be 1/2/3\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((asm_opt->realn_raw != 0) && (asm_opt->realn_raw != 1)) {
|
||||
fprintf(stderr, "[ERROR] [--re-aln] must be 0/1\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if((asm_opt->post_syn != 0) && (asm_opt->post_syn != 1)) {
|
||||
fprintf(stderr, "[ERROR] [--syn] must be 0/1\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->recurrent_err_normal_rat > 1.0) {
|
||||
fprintf(stderr, "[ERROR] [--ref] must be >= 0 && <= 1.0; -1 to disable\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(asm_opt->recurrent_err_hpc_rat > 1.0) {
|
||||
fprintf(stderr, "[ERROR] [--h_ref] must be >= 0 && <= 1.0; -1 to disable\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void get_queries(int argc, char *argv[], ketopt_t* opt, hifiasm_opt_t* asm_opt)
|
||||
{
|
||||
if(opt->ind == argc)
|
||||
{
|
||||
if(opt->ind == argc) {
|
||||
return;
|
||||
}
|
||||
|
||||
asm_opt->num_reads = argc - opt->ind;
|
||||
asm_opt->read_file_names = (char**)malloc(sizeof(char*)*asm_opt->num_reads);
|
||||
|
||||
long long i;
|
||||
gzFile dfp;
|
||||
for (i = 0; i < asm_opt->num_reads; i++)
|
||||
{
|
||||
long long i; int ret;
|
||||
gzFile dfp; kseq_t *ks = NULL;
|
||||
for (i = 0; i < asm_opt->num_reads; i++) {
|
||||
asm_opt->read_file_names[i] = argv[i + opt->ind];
|
||||
dfp = gzopen(asm_opt->read_file_names[i], "r");
|
||||
if (dfp == 0)
|
||||
{
|
||||
if (dfp == 0) {
|
||||
fprintf(stderr, "[ERROR] Cannot find the input read file: %s\n",
|
||||
asm_opt->read_file_names[i]);
|
||||
exit(0);
|
||||
} else if(asm_opt->is_sc){
|
||||
ks = kseq_init(dfp);
|
||||
while (((ret = kseq_read(ks)) >= 0)) {
|
||||
if((ks->qual.l == 0) || (ks->qual.s == NULL)) {
|
||||
fprintf(stderr, "[ERROR] %s is in fasta format rather than fastq format\n", asm_opt->read_file_names[i]);
|
||||
asm_opt->is_sc = 0;
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
kseq_destroy(ks); ks = NULL;
|
||||
}
|
||||
gzclose(dfp);
|
||||
}
|
||||
@@ -640,7 +1029,7 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
|
||||
int c;
|
||||
|
||||
while ((c = ketopt(&opt, argc, argv, 1, "hvt:o:k:w:m:n:r:a:b:z:x:y:p:c:d:M:P:if:D:FN:1:2:3:4:l:s:O:eu", long_options)) >= 0) {
|
||||
while ((c = ketopt(&opt, argc, argv, 1, "hvt:o:k:w:m:n:r:a:b:z:x:y:p:c:d:M:P:if:D:FN:1:2:3:4:5:l:s:O:eu:", long_options)) >= 0) {
|
||||
if (c == 'h')
|
||||
{
|
||||
Print_H(asm_opt);
|
||||
@@ -670,13 +1059,20 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
else if (c == '2' || c == 'M') asm_opt->fn_bin_yak[1] = opt.arg;
|
||||
else if (c == '3') asm_opt->fn_bin_list[0] = opt.arg;
|
||||
else if (c == '4') asm_opt->fn_bin_list[1] = opt.arg;
|
||||
else if (c == '5') asm_opt->fn_bin_poy = opt.arg;
|
||||
else if (c == 'x') asm_opt->max_drop_rate = atof(opt.arg);
|
||||
else if (c == 'y') asm_opt->min_drop_rate = atof(opt.arg);
|
||||
else if (c == 'p') asm_opt->small_pop_bubble_size = atoll(opt.arg);
|
||||
else if (c == 'm') asm_opt->large_pop_bubble_size = atoll(opt.arg);
|
||||
else if (c == 'n') asm_opt->max_short_tip = atoll(opt.arg);
|
||||
else if (c == 'e') asm_opt->flag |= HA_F_BAN_ASSEMBLY;
|
||||
else if (c == 'u') asm_opt->flag |= HA_F_BAN_POST_JOIN;
|
||||
else if (c == 'u') {
|
||||
if(atoll(opt.arg)) {
|
||||
asm_opt->hifi_pst_join = asm_opt->ul_pst_join = 1;
|
||||
} else {
|
||||
asm_opt->hifi_pst_join = asm_opt->ul_pst_join = 0;
|
||||
}
|
||||
}
|
||||
else if (c == 301) asm_opt->flag |= HA_F_VERBOSE_GFA;
|
||||
else if (c == 302) asm_opt->flag |= HA_F_WRITE_PAF;
|
||||
else if (c == 303) asm_opt->flag |= HA_F_WRITE_EC;
|
||||
@@ -685,12 +1081,14 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
else if (c == 306) asm_opt->max_ov_diff_final = atof(opt.arg);
|
||||
else if (c == 307) asm_opt->extract_list = opt.arg;
|
||||
else if (c == 308) asm_opt->extract_iter = atoi(opt.arg);
|
||||
else if (c == 309)
|
||||
{
|
||||
asm_opt->hom_global_coverage = atoi(opt.arg);
|
||||
else if (c == 309) {
|
||||
asm_opt->hom_global_coverage = asm_opt->hmo_cov_ss = atoi(opt.arg);
|
||||
asm_opt->hom_global_coverage_set = 1;
|
||||
if(asm_opt->hmo_cov_ss <= 0) {
|
||||
fprintf(stderr, "[ERROR] homozygous read coverage should be > 0 (--hom-cov)");
|
||||
return 1;
|
||||
}
|
||||
else if (c == 310)
|
||||
} else if (c == 310)
|
||||
{
|
||||
char* s = NULL;
|
||||
asm_opt->recover_atg_cov_min = strtol(opt.arg, &s, 10);
|
||||
@@ -722,8 +1120,107 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
else if (c == 330) asm_opt->dp_e = atof(opt.arg);
|
||||
else if (c == 331) asm_opt->max_kmer_cnt = atol(opt.arg);
|
||||
else if (c == 332) asm_opt->hg_size = inter_gsize(opt.arg);
|
||||
else if (c == 'l')
|
||||
{ ///0: disable purge_dup; 1: purge containment; 2: purge overlap
|
||||
else if (c == 333) get_hic_enzymes(opt.arg, &(asm_opt->ar), 0);
|
||||
else if (c == 334) asm_opt->flag |= HA_F_USKEW;
|
||||
else if (c == 335) asm_opt->kpt_rate = atof(opt.arg);
|
||||
else if (c == 336) asm_opt->ul_error_rate = atof(opt.arg);
|
||||
else if (c == 337) asm_opt->is_dbg_het_cnt = 1;
|
||||
else if (c == 338) asm_opt->max_short_ul_tip = atol(opt.arg);
|
||||
else if (c == 339) asm_opt->is_low_het_ul = 1;
|
||||
else if (c == 340) {
|
||||
asm_opt->trans_base_rate_sec = atof(opt.arg);
|
||||
if(asm_opt->trans_base_rate_sec < 0) asm_opt->is_base_trans = 0;
|
||||
}
|
||||
else if (c == 341) asm_opt->bin_only = 1;
|
||||
else if (c == 342) asm_opt->ul_clean_round = atol(opt.arg);
|
||||
else if (c == 343) asm_opt->prt_dbg_gfa = 1;
|
||||
else if (c == 344) asm_opt->integer_correct_round = atol(opt.arg);
|
||||
else if (c == 345) asm_opt->dbg_ovec_cal = 1;
|
||||
else if (c == 346) asm_opt->max_path_drop_rate = atof(opt.arg);
|
||||
else if (c == 347) asm_opt->min_path_drop_rate = atof(opt.arg);
|
||||
else if (c == 348) asm_opt->trio_cov_het_ovlp = 1;
|
||||
else if (c == 349) asm_opt->ul_min_base = atol(opt.arg);
|
||||
else if (c == 350) asm_opt->self_scaf = 1;
|
||||
else if (c == 351) asm_opt->self_scaf_gap_max = atol(opt.arg);
|
||||
else if (c == 352) get_hic_enzymes(opt.arg, &(asm_opt->sec_in), 0);
|
||||
else if (c == 353) asm_opt->somatic_cov = atol(opt.arg);
|
||||
else if (c == 354) asm_opt->telo_motif = opt.arg;
|
||||
else if (c == 355) asm_opt->telo_pen = atol(opt.arg);
|
||||
else if (c == 356) asm_opt->telo_drop = atol(opt.arg);
|
||||
else if (c == 357) asm_opt->telo_mic_sc = atol(opt.arg);
|
||||
else if (c == 358) asm_opt->max_contig_tip = atol(opt.arg);
|
||||
else if (c == 359) {
|
||||
asm_opt->is_ont = 1; asm_opt->max_ov_diff_ec = 0.07; asm_opt->is_sc = 1; ///asm_opt->mz_win = 37; asm_opt->k_mer_length = 37;
|
||||
} /**else if (c == 360) {
|
||||
asm_opt->is_sc = 1;
|
||||
}**/ else if (c == 361) {
|
||||
asm_opt->chemical_cov = atol(opt.arg);
|
||||
} else if (c == 362) {
|
||||
asm_opt->chemical_flank = atol(opt.arg);
|
||||
///pending for integration
|
||||
/**
|
||||
} else if (c == 363) {
|
||||
asm_opt->ul_mod = atol(opt.arg);
|
||||
**/
|
||||
} else if (c == 364) {
|
||||
asm_opt->rl_cut = atol(opt.arg);
|
||||
} else if (c == 365) {
|
||||
asm_opt->sc_cut = atol(opt.arg);
|
||||
} else if (c == 366) {
|
||||
get_hic_enzymes(opt.arg, &(asm_opt->hf), 0);
|
||||
} else if (c == 367) {
|
||||
asm_opt->fn_chr_bin = opt.arg;
|
||||
} else if (c == 368) {
|
||||
asm_opt->gpath = 1;
|
||||
} else if (c == 369) {
|
||||
asm_opt->het_cov_set = asm_opt->het_cov_ss = atoi(opt.arg);
|
||||
if(asm_opt->het_cov_ss <= 0) {
|
||||
fprintf(stderr, "[ERROR] heterozygous read coverage should be > 0 (--het-cov)");
|
||||
return 1;
|
||||
}
|
||||
} else if (c == 370) {
|
||||
asm_opt->restart = 1;
|
||||
} else if (c == 371) {
|
||||
asm_opt->hf_cutoff = atoi(opt.arg);
|
||||
} else if (c == 372) {
|
||||
asm_opt->chn_occ = atoi(opt.arg);
|
||||
if(asm_opt->chn_occ <= 0) {
|
||||
fprintf(stderr, "[ERROR] chain cutoff should be > 0 (--chn-occ)");
|
||||
return 1;
|
||||
}
|
||||
} else if (c == 373) {
|
||||
asm_opt->dbg_run_1 = opt.arg;
|
||||
} else if (c == 374) {
|
||||
asm_opt->dbg_run_2 = opt.arg;
|
||||
} else if (c == 375) {
|
||||
asm_opt->ec_only = 1;
|
||||
} else if (c == 376) {
|
||||
asm_opt->hyb_syn = atoi(opt.arg);
|
||||
} else if (c == 377) {
|
||||
asm_opt->simd_mm = atoi(opt.arg);
|
||||
} else if (c == 378) {
|
||||
asm_opt->del_hf = 1;
|
||||
} else if (c == 379) {
|
||||
asm_opt->dbg_ec_rr = atoi(opt.arg);
|
||||
} else if (c == 380) {
|
||||
asm_opt->realn_raw = atoi(opt.arg);
|
||||
} else if (c == 381) {
|
||||
asm_opt->post_syn = atoi(opt.arg);
|
||||
} else if (c == 382) {
|
||||
asm_opt->recurrent_err_normal_min = atoi(opt.arg);
|
||||
asm_opt->recurrent_err_normal_min_set = 1;
|
||||
} else if (c == 383) {
|
||||
asm_opt->recurrent_err_normal_rat = atof(opt.arg);
|
||||
asm_opt->recurrent_err_normal_rat_set = 1;
|
||||
} else if (c == 384) {
|
||||
asm_opt->recurrent_err_hpc_min = atoi(opt.arg);
|
||||
asm_opt->recurrent_err_hpc_min_set = 1;
|
||||
} else if (c == 385) {
|
||||
asm_opt->recurrent_err_hpc_rat = atof(opt.arg);
|
||||
asm_opt->recurrent_err_hpc_rat_set = 1;
|
||||
} else if (c == 386) {
|
||||
asm_opt->recurrent_err_test = 1;
|
||||
} else if (c == 'l') { ///0: disable purge_dup; 1: purge containment; 2: purge overlap
|
||||
asm_opt->purge_level_primary = asm_opt->purge_level_trio = atoi(opt.arg);
|
||||
}
|
||||
else if (c == 's') asm_opt->purge_simi_rate_l2 = asm_opt->purge_simi_rate_l3 = atof(opt.arg);
|
||||
@@ -743,7 +1240,6 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
if(asm_opt->purge_level_primary > 2) asm_opt->purge_simi_thres = asm_opt->purge_simi_rate_l3;
|
||||
else asm_opt->purge_simi_thres = asm_opt->purge_simi_rate_l2;
|
||||
|
||||
|
||||
if (argc == opt.ind)
|
||||
{
|
||||
Print_H(asm_opt);
|
||||
@@ -752,5 +1248,48 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
|
||||
|
||||
get_queries(argc, argv, &opt, asm_opt);
|
||||
|
||||
c = ((asm_opt->ar)?(asm_opt->ul_pst_join):(asm_opt->hifi_pst_join));
|
||||
if(c) {
|
||||
if((asm_opt->flag&HA_F_BAN_POST_JOIN)) asm_opt->flag-=HA_F_BAN_POST_JOIN;
|
||||
} else {
|
||||
asm_opt->flag |= HA_F_BAN_POST_JOIN;
|
||||
}
|
||||
|
||||
// fprintf(stderr, "[M::%s::] post join::%u\n", __func__, (uint32_t)(!(asm_opt->flag & HA_F_BAN_POST_JOIN)));
|
||||
// exit(1);
|
||||
if(!(asm_opt->is_ont)) {
|
||||
asm_opt->rl_cut = -1; asm_opt->sc_cut = 1;
|
||||
}
|
||||
|
||||
if(asm_opt->recurrent_err_normal_min_set != 1) {
|
||||
asm_opt->recurrent_err_normal_min = MIN_R_COV;
|
||||
}
|
||||
if(asm_opt->recurrent_err_normal_rat_set != 1) {
|
||||
asm_opt->recurrent_err_normal_rat = ((asm_opt->is_ont)?(RER_N_ONT):(RER_N_HiFi));
|
||||
}
|
||||
if(asm_opt->recurrent_err_hpc_min_set != 1) {
|
||||
asm_opt->recurrent_err_hpc_min = MIN_R_COV;
|
||||
}
|
||||
if(asm_opt->recurrent_err_hpc_rat_set != 1) {
|
||||
asm_opt->recurrent_err_hpc_rat = ((asm_opt->is_ont)?(RER_H_ONT):(RER_H_HiFi));
|
||||
}
|
||||
|
||||
if(asm_opt->recurrent_err_normal_min < 0) asm_opt->recurrent_err_normal_min = -1;
|
||||
if(asm_opt->recurrent_err_normal_rat < 0) asm_opt->recurrent_err_normal_rat = -1;
|
||||
if(asm_opt->recurrent_err_hpc_min < 0) asm_opt->recurrent_err_hpc_min = -1;
|
||||
if(asm_opt->recurrent_err_hpc_rat < 0) asm_opt->recurrent_err_hpc_rat = -1;
|
||||
|
||||
if(asm_opt->recurrent_err_test == 0) {
|
||||
asm_opt->recurrent_err_normal_min = -1;
|
||||
asm_opt->recurrent_err_normal_min_set = -1;
|
||||
asm_opt->recurrent_err_normal_rat = -1;
|
||||
asm_opt->recurrent_err_normal_rat_set = -1;
|
||||
|
||||
asm_opt->recurrent_err_hpc_min = -1;
|
||||
asm_opt->recurrent_err_hpc_min_set = -1;
|
||||
asm_opt->recurrent_err_hpc_rat = -1;
|
||||
asm_opt->recurrent_err_hpc_rat_set = -1;
|
||||
}
|
||||
|
||||
return check_option(asm_opt);
|
||||
}
|
||||
|
||||
+112
-1
@@ -1,10 +1,11 @@
|
||||
#ifndef __COMMAND_LINE_PARSER__
|
||||
#define __COMMAND_LINE_PARSER__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define HA_VERSION "0.16.0-r369"
|
||||
#define HA_VERSION "0.25.1-r933"
|
||||
|
||||
#define VERBOSE 0
|
||||
|
||||
@@ -21,8 +22,10 @@
|
||||
#define HA_F_HIGH_HET 0x400
|
||||
#define HA_F_PARTITION 0x800
|
||||
#define HA_F_FAST 0x1000
|
||||
#define HA_F_USKEW 0x2000
|
||||
|
||||
#define HA_MIN_OV_DIFF 0.02 // min sequence divergence in an overlap
|
||||
#define MIN_N_CHAIN 100
|
||||
|
||||
typedef struct{
|
||||
int *l, n;
|
||||
@@ -37,21 +40,32 @@ typedef struct {
|
||||
char* required_read_name;
|
||||
char *fn_bin_yak[2];
|
||||
char *fn_bin_list[2];
|
||||
char *fn_bin_poy;
|
||||
char *fn_chr_bin;
|
||||
char *extract_list;
|
||||
enzyme *hic_reads[2];
|
||||
enzyme *hic_enzymes;
|
||||
enzyme *ar;
|
||||
enzyme *hf;
|
||||
enzyme *sec_in;
|
||||
int extract_iter;
|
||||
int thread_num;
|
||||
int k_mer_length;
|
||||
int hic_mer_length;
|
||||
int ul_mer_length;
|
||||
int trans_mer_length;
|
||||
int bub_mer_length;
|
||||
int mz_win;
|
||||
int ul_mz_win;
|
||||
int trans_win;
|
||||
int mz_rewin;
|
||||
int ul_mz_rewin;
|
||||
int mz_sample_dist;
|
||||
int bf_shift;
|
||||
int max_kmer_cnt;
|
||||
double high_factor; // coverage cutoff set to high_factor*hom_cov
|
||||
double max_ov_diff_ec;
|
||||
double max_ov_diff_ec_sec;
|
||||
double max_ov_diff_final;
|
||||
int hom_cov;
|
||||
int het_cov;
|
||||
@@ -63,6 +77,7 @@ typedef struct {
|
||||
int load_index_from_disk;
|
||||
int write_index_to_disk;
|
||||
int number_of_round;
|
||||
int number_of_pround;
|
||||
int adapterLen;
|
||||
int clean_round;
|
||||
int roundID;
|
||||
@@ -71,6 +86,8 @@ typedef struct {
|
||||
int min_overlap_Len;
|
||||
int min_overlap_coverage;
|
||||
int max_short_tip;
|
||||
int max_short_ul_tip;
|
||||
int max_contig_tip;
|
||||
int min_cnt;
|
||||
int mid_cnt;
|
||||
int purge_level_primary;
|
||||
@@ -91,6 +108,11 @@ typedef struct {
|
||||
float purge_simi_rate_l2;
|
||||
float purge_simi_rate_l3;
|
||||
float purge_simi_thres;
|
||||
float trans_base_rate;
|
||||
float trans_base_rate_sec;
|
||||
float min_path_drop_rate;
|
||||
float max_path_drop_rate;
|
||||
// uint64_t path_clean_round;
|
||||
|
||||
///float purge_simi_rate_hic;
|
||||
|
||||
@@ -114,6 +136,94 @@ typedef struct {
|
||||
int32_t dp_min_len;
|
||||
float dp_e;
|
||||
int64_t hg_size;
|
||||
float kpt_rate;
|
||||
int64_t infor_cov, s_hap_cov, trio_cov_het_ovlp;
|
||||
double ul_error_rate, ul_error_rate_low, ul_error_rate_hpc;
|
||||
int32_t ul_ec_round;
|
||||
int32_t ul_mod;
|
||||
uint8_t is_dbg_het_cnt;
|
||||
uint8_t is_low_het_ul;
|
||||
uint8_t is_base_trans;
|
||||
uint8_t is_read_trans;
|
||||
uint8_t is_topo_trans;
|
||||
uint8_t is_bub_trans;
|
||||
uint8_t bin_only;
|
||||
uint8_t ec_only;
|
||||
int32_t ul_clean_round;
|
||||
int32_t prt_dbg_gfa;
|
||||
int32_t integer_correct_round;
|
||||
uint8_t dbg_ovec_cal;
|
||||
uint8_t hifi_pst_join, ul_pst_join;
|
||||
uint32_t ul_min_base;
|
||||
uint8_t self_scaf;
|
||||
uint64_t self_scaf_min;
|
||||
uint64_t self_scaf_reliable_min;
|
||||
int64_t self_scaf_gap_max;
|
||||
int64_t somatic_cov;
|
||||
|
||||
char *telo_motif;
|
||||
int64_t telo_pen;
|
||||
int64_t telo_drop;
|
||||
int64_t telo_mic_sc;
|
||||
|
||||
uint64_t is_ont;
|
||||
uint64_t is_sc;
|
||||
int64_t chemical_cov;
|
||||
uint64_t chemical_flank;
|
||||
|
||||
int64_t rl_cut;
|
||||
int64_t sc_cut;
|
||||
uint8_t gpath;
|
||||
|
||||
uint64_t hf_rate;///cannot be larger than 128?
|
||||
uint64_t hf_rate_max;///cannot be larger than 128?
|
||||
uint64_t ont_rate;///cannot be 0, should be 1 in anyway
|
||||
|
||||
int64_t het_cov_set;
|
||||
int64_t restart;
|
||||
|
||||
int64_t hf_cutoff;
|
||||
|
||||
uint8_t write_pos_idx;
|
||||
|
||||
int hom_cov_0;
|
||||
int het_cov_0;
|
||||
int max_n_chain_0; // fall-back max number of chains to consider
|
||||
|
||||
int64_t hmo_cov_ss;
|
||||
int64_t het_cov_ss;
|
||||
int64_t chn_occ;
|
||||
|
||||
char *dbg_run_1, *dbg_run_2;
|
||||
|
||||
int32_t hyb_syn;
|
||||
|
||||
int64_t step_rd;
|
||||
|
||||
uint8_t dbg_bam;
|
||||
|
||||
int8_t simd_mm;
|
||||
int8_t del_hf;
|
||||
|
||||
int64_t dbg_ec_rr;
|
||||
|
||||
int8_t realn_raw;
|
||||
int8_t post_syn;
|
||||
|
||||
int64_t recurrent_err_normal_min;
|
||||
int8_t recurrent_err_normal_min_set;
|
||||
|
||||
double recurrent_err_normal_rat;
|
||||
int8_t recurrent_err_normal_rat_set;
|
||||
|
||||
int64_t recurrent_err_hpc_min;
|
||||
int8_t recurrent_err_hpc_min_set;
|
||||
|
||||
double recurrent_err_hpc_rat;
|
||||
int8_t recurrent_err_hpc_rat_set;
|
||||
|
||||
int8_t recurrent_err_test;
|
||||
|
||||
} hifiasm_opt_t;
|
||||
|
||||
extern hifiasm_opt_t asm_opt;
|
||||
@@ -122,6 +232,7 @@ void init_opt(hifiasm_opt_t* asm_opt);
|
||||
void destory_opt(hifiasm_opt_t* asm_opt);
|
||||
void ha_opt_reset_to_round(hifiasm_opt_t* asm_opt, int round);
|
||||
void ha_opt_update_cov(hifiasm_opt_t *opt, int hom_cov);
|
||||
void ha_opt_update_cov_min(hifiasm_opt_t *opt, int hom_cov, int min_chain);
|
||||
int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt);
|
||||
double Get_T(void);
|
||||
|
||||
|
||||
+33625
-1754
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,14 @@
|
||||
#ifndef __CORRECT__
|
||||
#define __CORRECT__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
#include "Hash_Table.h"
|
||||
#include "Levenshtein_distance.h"
|
||||
#include "POA.h"
|
||||
#include "Process_Read.h"
|
||||
#include "Correct.h"
|
||||
#include "kalloc.h"
|
||||
|
||||
//#define CORRECT_THRESHOLD 0.70
|
||||
#define CORRECT_THRESHOLD 0.60
|
||||
@@ -16,6 +19,10 @@
|
||||
#define MISMATCH 1
|
||||
#define INSERTION 2
|
||||
#define DELETION 3
|
||||
#define ERROR_RATE 1.5
|
||||
#define UL_TOPN 50
|
||||
#define SGAP 16
|
||||
#define MAX_LGAP(ql) ((((ql)*0.2)<256)?((ql)*0.2):256)
|
||||
|
||||
#define WINDOW_MAX_SIZE (WINDOW + (int)(1.0 / HA_MIN_OV_DIFF) + 3) // TODO: why 1/max_ov_diff?
|
||||
|
||||
@@ -132,11 +139,15 @@ typedef struct
|
||||
uint32_t overlapSite;
|
||||
///there are several types: 0: equal to read 1: not equal to read, but it is a mismatch 2: is a gap
|
||||
uint8_t type;
|
||||
uint32_t cov;
|
||||
///misbase
|
||||
char misBase;
|
||||
}haplotype_evdience;
|
||||
|
||||
|
||||
#define hh_tp(z) (((z).type&1))
|
||||
#define hh_hp(z) ((((z).type>>1)&1))
|
||||
#define hh_bq(z) ((((z).type>>2))&sc_bm)
|
||||
#define hh_wq(z) ((((z).type>>(sc_bn+2)))&sc_bm)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -229,7 +240,14 @@ DP_matrix;
|
||||
#define Get_SNP_Martix_Size(matrix) (matrix.snp * matrix.overlap)
|
||||
#define Get_SNP_Vector(matrix, i) (matrix.snp_matrix + matrix.overlap * i)
|
||||
#define Get_SNP_Vector_Length(matrix) (matrix.overlap)
|
||||
#define Get_Result_SNP_Vector(matrix) (matrix.snp_matrix + matrix.overlap*matrix.snp)
|
||||
// #define Get_Result_SNP_Vector(matrix) (matrix.snp_matrix + matrix.overlap*matrix.snp)
|
||||
#define Get_Result_SNP_Vector(matrix) (matrix.r_snp)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SnpStats* a;
|
||||
size_t n,m;
|
||||
}kv_SnpStats_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -243,15 +261,22 @@ typedef struct
|
||||
uint8_t flag[WINDOW_MAX_SIZE];
|
||||
/****************************may have bugs********************************/
|
||||
|
||||
uint32_t available_snp;
|
||||
|
||||
uint32_t core_snp;
|
||||
uint32_t snp;
|
||||
uint32_t overlap;
|
||||
int8_t *snp_matrix;
|
||||
uint32_t snp_matrix_size;
|
||||
SnpStats* snp_stat;
|
||||
int8_t *r_snp;
|
||||
uint32_t r_snp_size;
|
||||
SnpStats result_stat;
|
||||
uint32_t snp_stat_size;
|
||||
|
||||
kv_SnpStats_t snp_stat;
|
||||
uint32_t nn_snp;
|
||||
kvec_t(uint64_t) snp_srt;
|
||||
// SnpStats* snp_stat;
|
||||
// uint32_t snp;
|
||||
// uint32_t snp_stat_size;
|
||||
// uint32_t available_snp;
|
||||
|
||||
DP_matrix dp;
|
||||
}
|
||||
@@ -341,9 +366,9 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
small_id = SNPs[i + 1];
|
||||
|
||||
|
||||
if(hap->snp_stat[large_id].site - hap->snp_stat[current_id].site < distance
|
||||
if(hap->snp_stat.a[large_id].site - hap->snp_stat.a[current_id].site < distance
|
||||
||
|
||||
hap->snp_stat[current_id].site - hap->snp_stat[small_id].site < distance)
|
||||
hap->snp_stat.a[current_id].site - hap->snp_stat.a[small_id].site < distance)
|
||||
{
|
||||
(*nearsnp)++;
|
||||
}
|
||||
@@ -352,8 +377,8 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
(*non_nearsnps)++;
|
||||
}
|
||||
|
||||
if(hap->snp_stat[current_id].site > hap->snp_stat[large_id].site ||
|
||||
hap->snp_stat[current_id].site < hap->snp_stat[small_id].site)
|
||||
if(hap->snp_stat.a[current_id].site > hap->snp_stat.a[large_id].site ||
|
||||
hap->snp_stat.a[current_id].site < hap->snp_stat.a[small_id].site)
|
||||
{
|
||||
fprintf(stderr, "error\n");
|
||||
}
|
||||
@@ -362,7 +387,7 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
{
|
||||
current_id= SNPs[i];
|
||||
small_id = SNPs[i + 1];
|
||||
if(hap->snp_stat[current_id].site - hap->snp_stat[small_id].site < distance)
|
||||
if(hap->snp_stat.a[current_id].site - hap->snp_stat.a[small_id].site < distance)
|
||||
{
|
||||
(*nearsnp)++;
|
||||
}
|
||||
@@ -371,7 +396,7 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
(*non_nearsnps)++;
|
||||
}
|
||||
|
||||
if(hap->snp_stat[current_id].site < hap->snp_stat[small_id].site)
|
||||
if(hap->snp_stat.a[current_id].site < hap->snp_stat.a[small_id].site)
|
||||
{
|
||||
fprintf(stderr, "error\n");
|
||||
}
|
||||
@@ -380,7 +405,7 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
{
|
||||
large_id = SNPs[i - 1];
|
||||
current_id= SNPs[i];
|
||||
if(hap->snp_stat[large_id].site - hap->snp_stat[current_id].site < distance)
|
||||
if(hap->snp_stat.a[large_id].site - hap->snp_stat.a[current_id].site < distance)
|
||||
{
|
||||
(*nearsnp)++;
|
||||
}
|
||||
@@ -389,7 +414,7 @@ inline void count_nearby_snps(haplotype_evdience_alloc* hap, uint32_t* SNPs, int
|
||||
(*non_nearsnps)++;
|
||||
}
|
||||
|
||||
if(hap->snp_stat[current_id].site > hap->snp_stat[large_id].site)
|
||||
if(hap->snp_stat.a[current_id].site > hap->snp_stat.a[large_id].site)
|
||||
{
|
||||
fprintf(stderr, "error\n");
|
||||
}
|
||||
@@ -632,46 +657,61 @@ UC_Read* g_read)
|
||||
{
|
||||
if(sub_length <= 0)
|
||||
return;
|
||||
long long i = 0;
|
||||
h->snp_stat[h->available_snp].id = h->available_snp;
|
||||
h->snp_stat[h->available_snp].occ_0 = 0;
|
||||
h->snp_stat[h->available_snp].occ_1 = 0;
|
||||
h->snp_stat[h->available_snp].occ_2 = 0;
|
||||
h->snp_stat[h->available_snp].overlap_num = 0;
|
||||
long long i = 0; SnpStats *p = NULL;
|
||||
kv_pushp(SnpStats, h->snp_stat, &p);
|
||||
|
||||
h->snp_stat[h->available_snp].site = sub_list[0].site;
|
||||
// h->snp_stat[h->available_snp].id = h->available_snp;
|
||||
// h->snp_stat[h->available_snp].occ_0 = 0;
|
||||
// h->snp_stat[h->available_snp].occ_1 = 0;
|
||||
// h->snp_stat[h->available_snp].occ_2 = 0;
|
||||
// h->snp_stat[h->available_snp].overlap_num = 0;
|
||||
// h->snp_stat[h->available_snp].site = sub_list[0].site;
|
||||
// h->snp_stat[h->available_snp].is_homopolymer =
|
||||
// if_is_homopolymer_strict(h->snp_stat[h->available_snp].site, g_read->seq, g_read->length);
|
||||
// int8_t* vector = Get_SNP_Vector((*h), h->available_snp);
|
||||
|
||||
h->snp_stat[h->available_snp].is_homopolymer =
|
||||
if_is_homopolymer_strict(h->snp_stat[h->available_snp].site, g_read->seq, g_read->length);
|
||||
|
||||
int8_t* vector = Get_SNP_Vector((*h), h->available_snp);
|
||||
p->id = h->snp_stat.n-1;
|
||||
p->occ_0 = 0;
|
||||
p->occ_1 = 0;
|
||||
p->occ_2 = 0;
|
||||
p->overlap_num = 0;
|
||||
p->site = sub_list[0].site;
|
||||
p->is_homopolymer = if_is_homopolymer_strict(p->site, g_read->seq, g_read->length);
|
||||
int8_t* vector = Get_SNP_Vector((*h), p->id);
|
||||
for (i = 0; i < sub_length; i++)
|
||||
{
|
||||
if(sub_list[i].type == 0)
|
||||
{
|
||||
vector[sub_list[i].overlapID] = 0;
|
||||
h->snp_stat[h->available_snp].occ_0++;
|
||||
// h->snp_stat[h->available_snp].occ_0++;
|
||||
h->snp_stat.a[p->id].occ_0++;
|
||||
}
|
||||
else if(sub_list[i].type == 1 && sub_list[i].misBase == misBase)
|
||||
{
|
||||
vector[sub_list[i].overlapID] = 1;
|
||||
h->snp_stat[h->available_snp].occ_1++;
|
||||
// h->snp_stat[h->available_snp].occ_1++;
|
||||
h->snp_stat.a[p->id].occ_1++;
|
||||
}
|
||||
else
|
||||
{
|
||||
vector[sub_list[i].overlapID] = 2;
|
||||
h->snp_stat[h->available_snp].occ_2++;
|
||||
// h->snp_stat[h->available_snp].occ_2++;
|
||||
h->snp_stat.a[p->id].occ_2++;
|
||||
}
|
||||
h->snp_stat[h->available_snp].overlap_num++;
|
||||
// h->snp_stat[h->available_snp].overlap_num++;
|
||||
h->snp_stat.a[p->id].overlap_num++;
|
||||
}
|
||||
|
||||
|
||||
int new_occ_0 = h->snp_stat[h->available_snp].occ_0 + 1;
|
||||
int new_occ_1 = h->snp_stat[h->available_snp].occ_1;
|
||||
// int new_occ_0 = h->snp_stat[h->available_snp].occ_0 + 1;
|
||||
// int new_occ_1 = h->snp_stat[h->available_snp].occ_1;
|
||||
int new_occ_0 = h->snp_stat.a[p->id].occ_0 + 1;
|
||||
int new_occ_1 = h->snp_stat.a[p->id].occ_1;
|
||||
|
||||
if(filter_snp(new_occ_0, new_occ_1, new_occ_0 + new_occ_1) == 0)
|
||||
if(filter_snp(new_occ_0, new_occ_1, new_occ_0 + new_occ_1) == 0) ///Fix-attention:definitely wrong
|
||||
{
|
||||
h->snp_stat[h->available_snp].score = -1;
|
||||
// h->snp_stat[h->available_snp].score = -1;
|
||||
h->snp_stat.a[p->id].score = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -682,7 +722,7 @@ UC_Read* g_read)
|
||||
|
||||
consensus = consensus /((double)(new_occ_0 + new_occ_1));
|
||||
|
||||
///50% vs 50%
|
||||
///50% vs 50%///Fix-attention:definitely wrong
|
||||
if(new_occ_0 == new_occ_1)
|
||||
{
|
||||
consensus = consensus + 0.25;
|
||||
@@ -707,12 +747,13 @@ UC_Read* g_read)
|
||||
|
||||
consensus= consensus*((double)(new_occ_0 + new_occ_1));
|
||||
|
||||
h->snp_stat[h->available_snp].score = consensus;
|
||||
// h->snp_stat[h->available_snp].score = consensus;
|
||||
h->snp_stat.a[p->id].score = consensus;
|
||||
}
|
||||
|
||||
|
||||
|
||||
h->available_snp++;
|
||||
// h->available_snp++;
|
||||
}
|
||||
|
||||
|
||||
@@ -760,32 +801,31 @@ inline int calculate_score(int new_occ_0, int new_occ_1)
|
||||
return consensus;
|
||||
}
|
||||
|
||||
inline void SetSnpMatrix(haplotype_evdience_alloc* h, long long snp_num, long long overlap_num)
|
||||
inline void SetSnpMatrix(haplotype_evdience_alloc* h, uint32_t *nn_snp, uint64_t *overlap_num, int32_t set_matrix, void *km)
|
||||
{
|
||||
long long new_size = (snp_num + 1)* overlap_num;
|
||||
if(nn_snp && overlap_num) {
|
||||
if(!km) kv_resize(SnpStats, h->snp_stat, *nn_snp);
|
||||
else kv_resize_km(km, SnpStats, h->snp_stat, *nn_snp);
|
||||
h->snp_stat.n = 0; h->overlap = *overlap_num; h->core_snp = 0;
|
||||
}
|
||||
|
||||
if(h->snp_matrix_size < new_size)
|
||||
{
|
||||
if(set_matrix) {
|
||||
uint64_t n_snp = nn_snp? *nn_snp:h->snp_stat.n;
|
||||
uint64_t n_ovlp = overlap_num? *overlap_num:h->overlap;
|
||||
uint64_t new_size = n_snp* n_ovlp;
|
||||
if(h->snp_matrix_size < new_size) {
|
||||
h->snp_matrix_size = new_size;
|
||||
h->snp_matrix = (int8_t*)realloc(h->snp_matrix, h->snp_matrix_size);
|
||||
if(!km) REALLOC(h->snp_matrix, h->snp_matrix_size);
|
||||
else KREALLOC(km, h->snp_matrix, h->snp_matrix_size);
|
||||
}
|
||||
memset(h->snp_matrix, -1, n_snp * n_ovlp);
|
||||
|
||||
if(h->snp_stat_size < snp_num)
|
||||
{
|
||||
h->snp_stat_size = snp_num;
|
||||
h->snp_stat = (SnpStats*)realloc(h->snp_stat, h->snp_stat_size * sizeof(SnpStats));
|
||||
if(h->r_snp_size < n_ovlp) {
|
||||
h->r_snp_size = n_ovlp;
|
||||
if(!km) REALLOC(h->r_snp, h->r_snp_size);
|
||||
else KREALLOC(km, h->r_snp, h->r_snp_size);
|
||||
}
|
||||
}
|
||||
|
||||
///h->snp may be different with the number of snp vector
|
||||
///since some snps have been filtered
|
||||
h->snp = snp_num;
|
||||
h->overlap = overlap_num;
|
||||
h->available_snp = 0;
|
||||
h->core_snp = 0;
|
||||
|
||||
memset(h->snp_matrix, -1, h->snp * h->overlap);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -897,15 +937,33 @@ inline void init_DP_matrix(DP_matrix* dp, uint32_t snp_num)
|
||||
|
||||
}
|
||||
|
||||
inline void InitHaplotypeEvdience_buf(haplotype_evdience_alloc* h, void *km)
|
||||
{
|
||||
memset(h, 0, sizeof(haplotype_evdience_alloc));
|
||||
/****************************may have bugs********************************/
|
||||
memset(h->flag, 0, WINDOW_MAX_SIZE * sizeof(uint8_t));
|
||||
/****************************may have bugs********************************/
|
||||
// init_SNP_IDs(&(h->dp.SNP_IDs));
|
||||
memset(&(h->dp.SNP_IDs), 0, sizeof(h->dp.SNP_IDs));
|
||||
h->dp.SNP_IDs.max_snp_id = -1;
|
||||
}
|
||||
|
||||
|
||||
inline void InitHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
{
|
||||
h->snp = 0;
|
||||
h->available_snp = 0;
|
||||
|
||||
h->overlap = 0;
|
||||
h->snp_matrix_size = 0;
|
||||
h->snp_stat_size = 0;
|
||||
h->snp_matrix = NULL;
|
||||
h->snp_stat = NULL;
|
||||
h->r_snp_size = 0;
|
||||
h->r_snp = NULL;
|
||||
kv_init(h->snp_stat);
|
||||
kv_init(h->snp_srt);
|
||||
h->nn_snp = 0;
|
||||
// h->snp_stat = NULL;
|
||||
// h->snp = 0;
|
||||
// h->snp_stat_size = 0;
|
||||
// h->available_snp = 0;
|
||||
|
||||
|
||||
h->sub_list_start = 0;
|
||||
@@ -937,7 +995,6 @@ inline void InitHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
h->dp.max_buffer = NULL;
|
||||
|
||||
init_SNP_IDs(&(h->dp.SNP_IDs));
|
||||
|
||||
}
|
||||
|
||||
inline void StarSubListHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
@@ -954,8 +1011,11 @@ inline void EndSubListHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
inline void destoryHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
{
|
||||
free(h->list);
|
||||
free(h->snp_stat);
|
||||
// free(h->snp_stat);
|
||||
kv_destroy(h->snp_stat);
|
||||
kv_destroy(h->snp_srt);
|
||||
free(h->snp_matrix);
|
||||
free(h->r_snp);
|
||||
free(h->dp.backtrack);
|
||||
free(h->dp.max);
|
||||
free(h->dp.max_for_sort);
|
||||
@@ -966,9 +1026,12 @@ inline void destoryHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
destory_SNP_IDs(&(h->dp.SNP_IDs));
|
||||
}
|
||||
|
||||
|
||||
inline void ResizeInitHaplotypeEvdience(haplotype_evdience_alloc* h)
|
||||
{
|
||||
h->snp = 0;
|
||||
// h->snp = 0;
|
||||
h->nn_snp = 0;
|
||||
h->snp_stat.n = 0;
|
||||
h->length = 0;
|
||||
h->sub_list_start = 0;
|
||||
h->sub_list_length = 0;
|
||||
@@ -984,17 +1047,14 @@ inline void RsetInitHaplotypeEvdienceFlag(haplotype_evdience_alloc* h, long long
|
||||
/****************************may have bugs********************************/
|
||||
}
|
||||
|
||||
inline void addHaplotypeEvdience(haplotype_evdience_alloc* h, haplotype_evdience* ev)
|
||||
inline void addHaplotypeEvdience(haplotype_evdience_alloc* h, haplotype_evdience* ev, void *km)
|
||||
{
|
||||
uint32_t new_length = h->length + 1;
|
||||
if(new_length > h->size)
|
||||
{
|
||||
h->size = h->size * 2;
|
||||
if(h->size < new_length)
|
||||
{
|
||||
h->size = new_length;
|
||||
}
|
||||
h->list = (haplotype_evdience*)realloc(h->list, sizeof(haplotype_evdience)*h->size);
|
||||
if(h->length + 1 > h->size){
|
||||
h->size = h->length + 1;
|
||||
kroundup32(h->size);
|
||||
if(!km) REALLOC(h->list, h->size);
|
||||
else KREALLOC(km, h->list, h->size);
|
||||
// h->list = (haplotype_evdience*)realloc(h->list, sizeof(haplotype_evdience)*h->size);
|
||||
}
|
||||
|
||||
h->list[h->length] = (*ev);
|
||||
@@ -1043,24 +1103,36 @@ typedef struct
|
||||
}
|
||||
Round2_alignment;
|
||||
|
||||
void init_Round2_alignment_buf(Round2_alignment* h, void *km);
|
||||
void init_Round2_alignment(Round2_alignment* h);
|
||||
void destory_Round2_alignment(Round2_alignment* h);
|
||||
void clear_Round2_alignment(Round2_alignment* h);
|
||||
|
||||
typedef struct {
|
||||
int32_t c_qs, c_qe, c_ts, c_te; //[c_qs, c_qe) && [c_ts, c_te)
|
||||
int32_t c_wsid, c_weid, c_wsii, c_weii;//[c_wsid, c_weid] && [c_wsii, c_weii)
|
||||
int32_t rev, sfx_e, pfx_e, mid_e, oid;
|
||||
} rtrace_t;
|
||||
|
||||
typedef struct {
|
||||
rtrace_t *a;
|
||||
size_t n, m;
|
||||
} kv_rtrace_t;
|
||||
|
||||
void correct_overlap(overlap_region_alloc* overlap_list, All_reads* R_INF,
|
||||
UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read, Graph* g, Graph* DAGCon,
|
||||
Cigar_record* current_cigar, haplotype_evdience_alloc* hap,
|
||||
Round2_alignment* second_round, int force_repeat, int is_consensus,
|
||||
int* fully_cov, int* abnormal);
|
||||
Round2_alignment* second_round, kvec_t_u64_warp* v_idx, window_list_alloc* win_ciagr_buf,
|
||||
int force_repeat, int is_consensus, int* fully_cov, int* abnormal);
|
||||
void init_Correct_dumy_buf(Correct_dumy* list, void *km);
|
||||
void init_Correct_dumy(Correct_dumy* list);
|
||||
void destory_Correct_dumy(Correct_dumy* list);
|
||||
void clear_Correct_dumy(Correct_dumy* list, overlap_region_alloc* overlap_list);
|
||||
void clear_Correct_dumy(Correct_dumy* list, overlap_region_alloc* overlap_list, void *km);
|
||||
void clear_Correct_dumy_pure(Correct_dumy* list);
|
||||
void get_seq_from_Graph(Graph* backbone, Graph* DAGCon, Correct_dumy* dumy, Cigar_record* current_cigar, char* self_string,
|
||||
char* r_string, long long r_string_length, long long r_string_site);
|
||||
void init_Cigar_record(Cigar_record* dummy);
|
||||
void init_Cigar_record_buf(Cigar_record* dummy, void *km);
|
||||
void destory_Cigar_record(Cigar_record* dummy);
|
||||
void clear_Cigar_record(Cigar_record* dummy);
|
||||
void add_new_cell_to_cigar_record(Cigar_record* dummy, uint32_t len, uint32_t type);
|
||||
@@ -1069,6 +1141,35 @@ void add_new_cell_to_cigar_record_with_different_base(Cigar_record* dummy, uint3
|
||||
void add_existing_cell_to_cigar_record_with_different_base(Cigar_record* dummy, uint32_t len, uint32_t type, char* seq);
|
||||
|
||||
|
||||
void correct_ul_overlap(overlap_region_alloc* overlap_list, const ul_idx_t *uref,
|
||||
UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read,
|
||||
Graph* g, Graph* DAGCon, Cigar_record* current_cigar,
|
||||
haplotype_evdience_alloc* hap, Round2_alignment* second_round,
|
||||
kvec_t_u64_warp* v_idx, window_list_alloc* win_ciagr_buf,
|
||||
int force_repeat, int is_consensus, int* fully_cov, int* abnormal,
|
||||
double max_ov_diff_ec, long long winLen, void *km);
|
||||
void ul_lalign(overlap_region_alloc* ol, Candidates_list *cl, const ul_idx_t *uref, const ug_opt_t *uopt, char *qstr,
|
||||
uint64_t ql, UC_Read* qu, UC_Read* tu, Correct_dumy* dumy, bit_extz_t *exz,
|
||||
haplotype_evdience_alloc* hap, kvec_t_u64_warp* v_idx, overlap_region *aux_o,
|
||||
double e_rate, int64_t wl, kv_ul_ov_t *aln, int64_t sid, uint64_t hpc_k, st_mt_t *stb, idx_emask_t *mm, mask_ul_ov_t *mk, void *km);
|
||||
|
||||
void ul_lalign_old_ed(overlap_region_alloc* ol, Candidates_list *cl, const ul_idx_t *uref, char *qstr,
|
||||
uint64_t ql, UC_Read* qu, UC_Read* tu, Correct_dumy* dumy,
|
||||
haplotype_evdience_alloc* hap, kvec_t_u64_warp* v_idx,
|
||||
double e_rate, int64_t wl, uint64_t is_base, void *km);
|
||||
|
||||
void lchain_align(overlap_region_alloc* overlap_list, const ul_idx_t *uref,
|
||||
UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read,
|
||||
Graph* g, Graph* DAGCon, Cigar_record* current_cigar,
|
||||
haplotype_evdience_alloc* hap, Round2_alignment* second_round,
|
||||
kvec_t_u64_warp* v_idx, window_list_alloc* win_ciagr_buf,
|
||||
int force_repeat, int is_consensus, int* fully_cov, int* abnormal,
|
||||
double max_ov_diff_ec, long long winLen, void *km);
|
||||
|
||||
void ug_lalign(overlap_region_alloc* ol, Candidates_list *cl, const ul_idx_t *uref, const ug_opt_t *uopt,
|
||||
char *qstr, uint64_t ql, UC_Read* qu, UC_Read* tu, Correct_dumy* dumy, bit_extz_t *exz,
|
||||
overlap_region *aux_o, double e_rate, int64_t wl, int64_t sid, uint64_t khit, uint64_t chain_cut,
|
||||
void *km);
|
||||
/***
|
||||
type:
|
||||
0. match
|
||||
@@ -1169,8 +1270,8 @@ long long* max_q_pos, long long* max_t_pos, long long* global_score,
|
||||
long long* extention_score, long long* q_boundary_score, long long* q_boundary_t_coordinate,
|
||||
long long* t_boundary_score, long long* t_boundary_q_coordinate,
|
||||
long long* droped, int mode);
|
||||
void correct_overlap_high_het(overlap_region_alloc* overlap_list, All_reads* R_INF,
|
||||
UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read);
|
||||
// void correct_overlap_high_het(overlap_region_alloc* overlap_list, All_reads* R_INF,
|
||||
// UC_Read* g_read, Correct_dumy* dumy, UC_Read* overlap_read);
|
||||
long long get_affine_gap_score(overlap_region* ovc, UC_Read* g_read, UC_Read* overlap_read, uint8_t* x_num,
|
||||
uint8_t* y_num, uint64_t EstimateXOlen, uint64_t EstimateYOlen);
|
||||
int collect_hp_regions(overlap_region_alloc* olist, All_reads* R_INF, kvec_t_u8_warp* k_flag, float hp_rate, int rlen, FILE* fp);
|
||||
@@ -1187,7 +1288,80 @@ inline int if_exact_match(char* x, long long xLen, char* y, long long yLen, long
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void get_cigar_cell(window_list *idx, window_list_alloc *cc, uint32_t i, uint8_t *c, uint32_t *len)
|
||||
{
|
||||
uint16_t p = cc->c.a[idx->cidx+i];
|
||||
(*c) = (uint8_t)(p>>14); (*len) = (p&((uint16_t)0x3fff));
|
||||
}
|
||||
|
||||
inline void push_cigar_cell(window_list_alloc *res, uint8_t c, uint32_t len)
|
||||
{
|
||||
uint16_t p = c; p <<= 14; p += (uint16_t)len;
|
||||
kv_push(uint16_t, res->c, p);
|
||||
}
|
||||
int64_t get_num_wins(int64_t s, int64_t e, int64_t block_s);
|
||||
void append_unmatched_wins(overlap_region *z, int64_t block_s);
|
||||
|
||||
///[w_s, w_e]
|
||||
inline int64_t get_win_id_by_s(overlap_region *z, int64_t w_s, int64_t block_s, int64_t *w_e)
|
||||
{
|
||||
int64_t n_s = ((z->x_pos_s/block_s)*block_s), wid = (w_s-n_s)/block_s;
|
||||
if(w_e) {
|
||||
(*w_e) = n_s + (wid+1)*block_s - 1;
|
||||
if((*w_e) > z->x_pos_e) (*w_e) = z->x_pos_e;
|
||||
}
|
||||
return wid;
|
||||
}
|
||||
|
||||
///[w_s, w_e]
|
||||
inline int64_t get_win_id_by_e(overlap_region *z, int64_t w_e, int64_t block_s, int64_t *w_s)
|
||||
{
|
||||
int64_t n_s = ((z->x_pos_s/block_s)*block_s), wid = (w_e-n_s)/block_s;
|
||||
if(w_s) {
|
||||
(*w_s) = n_s + wid*block_s;
|
||||
if((*w_s) < z->x_pos_s) (*w_s) = z->x_pos_s;
|
||||
}
|
||||
return wid;
|
||||
}
|
||||
|
||||
///[w_s, w_e]
|
||||
inline void get_win_se_by_normalize_xs(overlap_region *z, int64_t norm_w_s, int64_t block_s, int64_t *w_s, int64_t *w_e)
|
||||
{
|
||||
int64_t n_s = ((z->x_pos_s/block_s)*block_s), wid = (norm_w_s-n_s)/block_s;
|
||||
if(w_s) {
|
||||
(*w_s) = n_s + wid*block_s;
|
||||
if((*w_s) < z->x_pos_s) (*w_s) = z->x_pos_s;
|
||||
}
|
||||
if(w_e) {
|
||||
(*w_e) = n_s + (wid+1)*block_s - 1;
|
||||
if((*w_e) > z->x_pos_e) (*w_e) = z->x_pos_e;
|
||||
}
|
||||
}
|
||||
|
||||
void inline resize_UC_Read(UC_Read *z, int64_t s)
|
||||
{
|
||||
if(z->size < s) {
|
||||
REALLOC(z->seq, s); z->size = s;
|
||||
}
|
||||
}
|
||||
|
||||
void update_sketch_trace(overlap_region_alloc* ol, const ul_idx_t *uref, const ug_opt_t *uopt,
|
||||
All_reads *rref, UC_Read* tu, asg64_v* idx, asg64_v *b0, asg64_v *b1, int64_t ql, int64_t wl,
|
||||
kv_ul_ov_t *aln, uint64_t rid, int64_t max_lgap, double sgap_rate);
|
||||
|
||||
int64_t infer_rovlp(ul_ov_t *li, ul_ov_t *lj, uc_block_t *bi, uc_block_t *bj, All_reads *ridx, ma_ug_t *ug);
|
||||
void convert_ul_ov_t(ul_ov_t *des, overlap_region *src, ma_ug_t *ug);
|
||||
uint64_t check_connect_ug(const ul_idx_t *uref, uint32_t v, uint32_t w, int64_t bw, double diff_ec_ul, int64_t dq);
|
||||
uint64_t check_connect_rg(const ul_idx_t *uref, const ug_opt_t *uopt, uint32_t uv, uint32_t uw, int64_t bw, double diff_ec_ul, int64_t dq);
|
||||
uint32_t govlp_check(const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, ul_ov_t *li, ul_ov_t *lj);
|
||||
void ul_rid_lalign_adv(overlap_region_alloc* ol, Candidates_list *cl, const ul_idx_t *uref, const ug_opt_t *uopt,
|
||||
char *qstr, uint64_t ql, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate,
|
||||
int64_t wl, kv_ul_ov_t *aln, kv_ul_ov_t *cln, kv_rtrace_t *trace, int64_t sid, uint64_t khit, void *km);
|
||||
|
||||
#define copy_asg_arr(des, src) ((des).a = (src).a, (des).n = (src).n, (des).m = (src).m)
|
||||
#define is_ualn_win(a) (((a).error==INT16_MAX)&&((a).clen==0)&&((a).extra_end<0))
|
||||
#define is_exact_aln(a) (((a).error<INT16_MAX)&&((a).clen>0))
|
||||
#define is_est_aln(a) (((a).error<INT16_MAX)&&((a).clen==0))
|
||||
|
||||
#define FORWARD_KSW 0
|
||||
#define BACKWARD_KSW 1
|
||||
@@ -1197,4 +1371,136 @@ inline int if_exact_match(char* x, long long xLen, char* y, long long yLen, long
|
||||
#define GAP_EXT_KSW 2
|
||||
#define Z_DROP_KSW 400
|
||||
#define BAND_KSW 500
|
||||
|
||||
#define set_bit_extz_t(x, z, id) do {\
|
||||
(x).cigar.a = (z).w_list.c.a+(z).w_list.a[(id)].cidx;\
|
||||
(x).cigar.n = (x).cigar.m = (z).w_list.a[(id)].clen;\
|
||||
(x).ts = (z).w_list.a[(id)].x_start;\
|
||||
(x).te = (z).w_list.a[(id)].x_end;\
|
||||
(x).ps = (z).w_list.a[(id)].y_start;\
|
||||
(x).pe = (z).w_list.a[(id)].y_end;\
|
||||
(x).err = (z).w_list.a[(id)].error;\
|
||||
(x).thre = (z).w_list.a[(id)].error;\
|
||||
} while (0)
|
||||
|
||||
typedef struct {
|
||||
int64_t k, q[2], t[2], cq[2], ct[2], ci[2], werr, werr0, cerr;
|
||||
int64_t qoff, f, toff, coff, cur_qoff;
|
||||
} rtrace_iter;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
overlap_region_alloc *ol;
|
||||
Candidates_list *cl;
|
||||
All_reads *rref;
|
||||
UC_Read *qu;
|
||||
UC_Read *tu;
|
||||
bit_extz_t *exz;
|
||||
overlap_region *aux_o, *rse_o;
|
||||
double e_rate[2];
|
||||
int64_t wl[2];
|
||||
int64_t rid;
|
||||
int64_t khit;
|
||||
int64_t move_gap;
|
||||
asg16_v *buf;
|
||||
asg64_v *srt;
|
||||
asg8_v *hpz;
|
||||
ma_hit_t_alloc *in;
|
||||
|
||||
int8_t chem_drop[2];
|
||||
double align_gap_rate[2];
|
||||
int64_t align_gap_max[2];
|
||||
|
||||
uint64_t sec_aln_win;
|
||||
uint64_t sec_aln_cov;
|
||||
double sec_aln_err_rate;
|
||||
double sec_aln_max;
|
||||
asg64_v *kp;
|
||||
|
||||
asg32_v *v32;
|
||||
asg64_v *bp;
|
||||
ha_abuf_t *ab;
|
||||
uint64_t max_n_chain;
|
||||
uint64_t max_n_chain_f;
|
||||
uint64_t chain_cutoff;
|
||||
uint64_t ave_cov_min;
|
||||
uint64_t ocw;
|
||||
|
||||
uint64_t t_cut;
|
||||
|
||||
uint64_t hom_cov_a;
|
||||
} gen_hc_aln_t;
|
||||
int64_t get_rid_backward_cigar_err(rtrace_iter *it, ul_ov_t *aln, kv_rtrace_t *trace, rtrace_t *tc,
|
||||
const ul_idx_t *uref, char* qstr, UC_Read *tu, overlap_region_alloc *ol, overlap_region *o,
|
||||
bit_extz_t *exz, double e_rate, int64_t qs);
|
||||
|
||||
uint64_t gen_hc_r_alin_adp_smp_ff_ec(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, int64_t rid, asg64_v *sp, uint64_t ocw, uint32_t *ocn, uint32_t *osc, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min);
|
||||
uint64_t gen_hc_r_alin_adp_smp(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *sp, uint64_t ocw, uint8_t *hpf, uint32_t *a_cu, uint32_t *a_ci, uint32_t *ocn, uint32_t *osc, uint64_t *idx_cu, uint64_t n_cu, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min, uint8_t set_match, uint8_t is_dedup);
|
||||
uint64_t gen_hc_r_alin_adp_mmp_1(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *sp, uint64_t ocw, uint8_t *hpf, asg32_v *v32, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min, uint8_t set_match);
|
||||
uint64_t gen_hc_r_alin_adp_mmp_0(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *sp, uint64_t ocw, uint8_t *hpf, asg32_v *v32, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min, uint8_t set_match);
|
||||
uint64_t gen_gc_r_alin_adp_mmp_0(overlap_region_alloc* ol, Candidates_list *cl, ul_idx_t *uref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *sp, uint64_t ocw, uint8_t *hpf, asg32_v *v32, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min, uint8_t set_match);
|
||||
void gen_hc_r_alin_adv_adp_smp(gen_hc_aln_t *ez, uint32_t *a_cu, uint32_t *a_ci, uint32_t *ocn, uint32_t *osc, uint64_t *idx_cu, uint64_t n_cu, uint8_t set_match);
|
||||
void gen_hc_r_alin_adv_adp_smp_0(gen_hc_aln_t *ez, uint8_t set_match);
|
||||
void gen_hc_r_alin_adv_adp_smp_1(gen_hc_aln_t *ez, uint8_t set_match);
|
||||
void pp_chn_a(overlap_region *z, Candidates_list *cl, uint8_t is_raw);
|
||||
uint64_t gen_hc_r_alin(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max, asg64_v *kp, uint8_t *hpf);
|
||||
void gen_hc_r_alin_flt(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, overlap_region *aux_b, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *kp, asg64_v *sp, uint64_t ocw, uint8_t *hpf, uint32_t *a_cu, uint32_t *a_ci, uint32_t *ocn, uint32_t *osc, uint64_t *idx_cu, uint64_t n_cu, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min);
|
||||
void gen_hc_r_alin_adp(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, overlap_region *aux_b, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max,
|
||||
asg64_v *kp, asg64_v *sp, uint64_t ocw, uint8_t *hpf, uint32_t *a_cu, uint32_t *a_ci, uint32_t *ocn, uint32_t *osc, uint64_t *idx_cu, uint64_t n_cu, asg64_v *bp, uint64_t max_n_chain, uint64_t max_n_chain_f, uint64_t chain_cutoff, uint64_t ave_cov_min);
|
||||
void gen_hc_r_alin_adv(gen_hc_aln_t *ez);
|
||||
uint64_t gen_hc_r_alin_nec(overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max, uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max, asg64_v *kp, uint8_t *hpf);
|
||||
void gen_hc_r_alin_nec_adv(gen_hc_aln_t *ez);
|
||||
uint64_t gen_hc_r_alin_re(overlap_region* z, Candidates_list *cl, char* qstr, uint64_t ql, char* tstr, uint64_t tl, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf);
|
||||
uint64_t gen_hc_r_alin_self(overlap_region* z, Candidates_list *cl, char* qstr, uint64_t ql, char* tstr, uint64_t tl, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v* buf, asg16_v* scc);
|
||||
void rphase_hc(overlap_region_alloc* ol, All_reads *rref, haplotype_evdience_alloc* hp, UC_Read* qu, asg16_v *qc0, UC_Read* tu, kv_ul_ov_t *c_idx, asg64_v* idx, asg64_v* buf, int64_t bd, int64_t wl, int64_t ql, uint8_t occ_thres/**, uint8_t is_dbg**/, uint64_t rid, uint64_t hpc_len, uint64_t std_bs, Chain_Data *dp, asg8_v *q8, asg8_v *t8, uint8_t lindel, uint64_t tcut, uint64_t site_sc, int64_t h0_w, asg32_v *b32,
|
||||
int64_t hap_cov_match, int64_t hap_cov_unmatch, int64_t het_cov_a, int64_t hom_cov_a, int64_t n_hap, double hf_rate, overlap_region *rchn, int64_t rref_len, int64_t flag_hf_ov_cut, int64_t min_re_cut, double min_re_rt, int64_t min_hpc_re_cut, double min_hpc_re_rt, int8_t is_hpc_flt);
|
||||
void set_exact_exz(bit_extz_t *exz, int64_t qs, int64_t qe, int64_t ts, int64_t te);
|
||||
void push_alnw(overlap_region *aux_o, bit_extz_t *exz);
|
||||
void cal_exz_global(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, bit_extz_t *ez);
|
||||
void get_wqual(uint64_t zid, uint64_t zpos, uint64_t zrev, asg8_v *v, uint8_t *va, uint64_t scw, uint64_t *tqual, uint64_t *wqual);
|
||||
void gen_reseed_re(overlap_region_alloc *ol, Candidates_list *cl, overlap_region *aux_o, overlap_region *rse_o, All_reads *rref, UC_Read* qu, UC_Read *tu, bit_extz_t *exz, kv_ul_ov_t *c_idx, asg64_v *idx, asg64_v *res, int64_t bd, int64_t mzw, int64_t kl, int64_t rid, double err_h, double err_l, asg16_v *b16, uint64_t tqn, uint8_t *hpf);
|
||||
inline uint64_t exact_ec_check(char *qstr, uint64_t ql, char *tstr, uint64_t tl, int64_t qs, int64_t qe, int64_t ts, int64_t te)
|
||||
{
|
||||
if(qe - qs != te - ts) return 0;
|
||||
if(memcmp(qstr + qs, tstr + ts, qe - qs) == 0) return 1;
|
||||
return 0;
|
||||
}
|
||||
// void est_rep_err_rate(overlap_region_alloc* ol, asg64_v *ix, kv_ul_ov_t *c_idx, int64_t ql, int64_t wl, uint64_t *ou_a, uint64_t min_dp, int64_t ph_cov, uint8_t flg_ov, double flg_ov_sec_rate, double flg_cov_rate, uint64_t *ave_e, uint64_t *bd_e, uint64_t *tot_cov);
|
||||
void est_rep_err_rate(overlap_region_alloc* ol, asg64_v *ix, kv_ul_ov_t *c_idx, int64_t ql, int64_t wl, uint64_t *ou_a, uint64_t min_dp, int64_t ph_cov, uint8_t flg_ov, double flg_ov_sec_rate, double flg_cov_rate, uint64_t *ave_e, uint64_t *bd_e, uint64_t *tot_cov);
|
||||
#define ovlp_id(x) ((x).tn)
|
||||
#define ovlp_min_wid(x) ((x).ts)
|
||||
#define ovlp_max_wid(x) ((x).te)
|
||||
#define ovlp_cur_wid(x) ((x).qn)
|
||||
#define ovlp_cur_xoff(x) ((x).qs)
|
||||
#define ovlp_cur_yoff(x) ((x).ts)
|
||||
#define ovlp_cur_ylen(x) ((x).te)
|
||||
#define ovlp_cur_coff(x) ((x).qe)
|
||||
#define ovlp_bd(x) ((x).sec)
|
||||
#define ovlp_um(x) ((x).sec)
|
||||
#define ovlp_hf(x) ((x).el)
|
||||
|
||||
#define HPC_PL 12
|
||||
#define HPC_RR 4
|
||||
#define HPC_CC 2
|
||||
#define HPC_RR_Q 5
|
||||
#define HPC_CC_Q 3
|
||||
#define HC_MF_R 0.5
|
||||
#define HC_AV_MIN 0.7
|
||||
#define GC_MF_N 12
|
||||
|
||||
// #define FORCE_CUT 1
|
||||
|
||||
// overlap_region_alloc* ol, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o,
|
||||
|
||||
// double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v *buf, asg64_v *srt, ma_hit_t_alloc *in, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max,
|
||||
// uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max, asg64_v *kp
|
||||
|
||||
// uint64_t gen_hc_r_alin_ea_hybrid(overlap_region_alloc* ol, uint64_t bi, uint64_t bn, uint64_t tk, Candidates_list *cl, All_reads *rref, UC_Read* qu, UC_Read* tu, bit_extz_t *exz, overlap_region *aux_o, double e_rate, int64_t wl, int64_t rid, int64_t khit, int64_t move_gap, asg16_v *buf, uint8_t ec_filter, ma_hit_t_alloc *in, uint8_t chem_drop, double align_gap_rate, int64_t align_gap_max,
|
||||
// uint64_t sec_aln_win, uint64_t sec_aln_cov, double sec_aln_err_rate, double sec_aln_max, asg64_v *kp)
|
||||
|
||||
#endif
|
||||
|
||||
+2223
-105
File diff suppressed because it is too large
Load Diff
+113
-31
@@ -8,13 +8,30 @@
|
||||
|
||||
#define WINDOW 375
|
||||
#define WINDOW_BOUNDARY 375
|
||||
#define WINDOW_HC 775
|
||||
///ONT high error
|
||||
// #define WINDOW_OHC 475
|
||||
#define WINDOW_OHC 375
|
||||
#define WINDOW_HC_FAST 512
|
||||
///for one side, the first or last WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY bases should not be corrected
|
||||
#define WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY 25
|
||||
#define THRESHOLD 15
|
||||
#define OVERLAP_THRESHOLD_FILTER 0.9
|
||||
#define OVERLAP_THRESHOLD_HIFI_FILTER 0.9
|
||||
#define OVERLAP_THRESHOLD_HIFI_FF_FILTER 0.6
|
||||
#define OVERLAP_THRESHOLD_HIFI_FF_DE_FILTER 0.5
|
||||
#define OVERLAP_THRESHOLD_NOSI_FILTER 0.7
|
||||
#define OVERLAP_THRESHOLD_FILTER_HPC 0.75
|
||||
#define HIGH_HET_OVERLAP_THRESHOLD_FILTER 0.3
|
||||
#define HIGH_HET_ERROR_RATE 0.08
|
||||
#define THRESHOLD_MAX_SIZE 31
|
||||
#define THRESHOLD_UL_MAX 0.2
|
||||
#define WINDOW_UL 75
|
||||
#define WINDOW_UL_H 200
|
||||
// #define WINDOW_UL_H 150
|
||||
#define MIN_UL_ALIN_RATE 0.5
|
||||
#define MIN_UL_ALIN_LEN (WINDOW_UL*6)
|
||||
#define WINDOW_UL_BOUND 48
|
||||
#define WINDOW_UL_BOUND_RATE 0.55
|
||||
|
||||
#define GROUP_SIZE 4
|
||||
///the max cigar likes 10M10D10M10D10M
|
||||
@@ -36,32 +53,21 @@ typedef struct
|
||||
uint64_t end_pos;
|
||||
} k_mer_pos_list;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int C_L[CIGAR_MAX_LENGTH];
|
||||
char C_C[CIGAR_MAX_LENGTH];
|
||||
int length;
|
||||
} CIGAR;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
///the begining and end of a window, instead of the whole overlap
|
||||
uint64_t x_start;
|
||||
uint64_t x_end;
|
||||
int y_end;
|
||||
int y_start;
|
||||
int extra_begin;
|
||||
int extra_end;
|
||||
int error_threshold;
|
||||
int error;
|
||||
CIGAR cigar;
|
||||
int32_t x_start, x_end;
|
||||
int32_t y_start, y_end;
|
||||
int16_t extra_begin, extra_end;
|
||||
int16_t error, error_threshold;
|
||||
uint32_t cidx, clen;
|
||||
} window_list;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
window_list* buffer;
|
||||
int32_t length;
|
||||
int32_t size;
|
||||
size_t n, m;
|
||||
window_list *a;
|
||||
kvec_t(uint16_t) c;
|
||||
} window_list_alloc;
|
||||
|
||||
typedef struct
|
||||
@@ -92,11 +98,12 @@ typedef struct
|
||||
int8_t strong;
|
||||
uint32_t non_homopolymer_errors;
|
||||
|
||||
window_list* w_list;
|
||||
uint32_t w_list_size;
|
||||
uint32_t w_list_length;
|
||||
// window_list* w_list;
|
||||
// uint32_t w_list_size;
|
||||
// uint32_t w_list_length;
|
||||
Fake_Cigar f_cigar;
|
||||
|
||||
window_list_alloc w_list;
|
||||
window_list_alloc boundary_cigars;
|
||||
} overlap_region;
|
||||
|
||||
@@ -136,23 +143,24 @@ typedef struct
|
||||
void init_Candidates_list(Candidates_list* l);
|
||||
void clear_Candidates_list(Candidates_list* l);
|
||||
void destory_Candidates_list(Candidates_list* l);
|
||||
void destory_Candidates_list_buf(void *km, Candidates_list* l, int is_z);
|
||||
|
||||
void init_overlap_region_alloc(overlap_region_alloc* list);
|
||||
void clear_overlap_region_alloc(overlap_region_alloc* list);
|
||||
void destory_overlap_region_alloc(overlap_region_alloc* list);
|
||||
void append_window_list(overlap_region* region, uint64_t x_start, uint64_t x_end, int y_start, int y_end, int error,
|
||||
int extra_begin, int extra_end, int error_threshold);
|
||||
int extra_begin, int extra_end, int error_threshold, int blockLen, void *km);
|
||||
|
||||
void overlap_region_sort_y_id(overlap_region *a, long long n);
|
||||
|
||||
void calculate_overlap_region_by_chaining(Candidates_list* candidates, overlap_region_alloc* overlap_list, kvec_t_u64_warp* chain_idx,
|
||||
uint64_t readID, uint64_t readLength, All_reads* R_INF, double band_width_threshold, int add_beg_end, overlap_region* f_cigar);
|
||||
uint64_t readID, uint64_t readLength, All_reads* R_INF, const ul_idx_t *uref, double band_width_threshold, int add_beg_end, overlap_region* f_cigar, void *km);
|
||||
|
||||
void init_fake_cigar(Fake_Cigar* x);
|
||||
void destory_fake_cigar(Fake_Cigar* x);
|
||||
void clear_fake_cigar(Fake_Cigar* x);
|
||||
void add_fake_cigar(Fake_Cigar* x, uint32_t gap_site, int32_t gap_shift);
|
||||
void resize_fake_cigar(Fake_Cigar* x, uint64_t size);
|
||||
void add_fake_cigar(Fake_Cigar* x, uint32_t gap_site, int32_t gap_shift, void *km);
|
||||
void resize_fake_cigar(Fake_Cigar* x, uint64_t size, void *km);
|
||||
int get_fake_gap_pos(Fake_Cigar* x, int index);
|
||||
int get_fake_gap_shift(Fake_Cigar* x, int index);
|
||||
|
||||
@@ -182,12 +190,86 @@ static inline long long y_start_offset(long long x_start, Fake_Cigar* o)
|
||||
return get_fake_gap_shift(o, i - 1);
|
||||
}
|
||||
|
||||
void resize_Chain_Data(Chain_Data* x, long long size);
|
||||
void resize_Chain_Data(Chain_Data* x, long long size, void *km);
|
||||
void init_window_list_alloc(window_list_alloc* x);
|
||||
void clear_window_list_alloc(window_list_alloc* x);
|
||||
void destory_window_list_alloc(window_list_alloc* x);
|
||||
void resize_window_list_alloc(window_list_alloc* x, long long size);
|
||||
long long chain_DP(k_mer_hit* a, long long a_n, Chain_Data* dp, overlap_region* result, double band_width_threshold, int max_skip, int x_readLen, int y_readLen);
|
||||
void resize_window_list_alloc(window_list_alloc* x, uint64_t size);
|
||||
long long chain_DP(k_mer_hit* a, long long a_n, Chain_Data* dp, overlap_region* result, double band_width_threshold, int max_skip, int x_readLen, int y_readLen, void *km);
|
||||
uint64_t lchain_dp(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp, overlap_region* res,
|
||||
int64_t max_skip, int64_t max_iter, int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
|
||||
int64_t xl, int64_t yl, int64_t quick_check);
|
||||
int ovlp_chain_gen(overlap_region_alloc* ol, overlap_region* t, int64_t xl, int64_t yl, int64_t apend_be, k_mer_hit* hit, int64_t n_hit);
|
||||
void gen_fake_cigar(Fake_Cigar* z, overlap_region *o, int64_t apend_be, k_mer_hit* hit, int64_t n_hit);
|
||||
int append_utg_inexact_overlap_region_alloc(overlap_region_alloc* list, overlap_region* tmp,
|
||||
ma_utg_v *ua, int add_beg_end);
|
||||
ma_utg_v *ua, int add_beg_end, void *km);
|
||||
|
||||
#define kv_pushp_cl(type, v, p) do { \
|
||||
if ((v).length == (v).size) { \
|
||||
(v).size = (v).size? (v).size<<1 : 2; \
|
||||
(v).list = (type*)realloc((v).list, sizeof(type) * (v).size); \
|
||||
} \
|
||||
*(p) = &((v).list[(v).length++]); \
|
||||
} while (0)
|
||||
|
||||
#define kv_resize_cl(type, v, s) do { \
|
||||
if ((v).size < (s)) { \
|
||||
(v).size = (s); \
|
||||
kv_roundup32((v).size); \
|
||||
(v).list = (type*)realloc((v).list, sizeof(type) * (v).size); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define is_alnw(a) (((a).readID) == ((uint32_t)(0x7fffffff)))
|
||||
#define is_pri_aln(a) ((((a).readID) == ((uint32_t)(0x7fffffff)))||((a).cnt >= (a).readID))
|
||||
|
||||
uint64_t lchain_dp_trace(k_mer_hit* a, int64_t a_n, int64_t max_lgap, double sgap_rate, int64_t sgap);
|
||||
uint64_t lchain_qdp(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp, overlap_region* res,
|
||||
int64_t max_skip, int64_t max_iter, int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
|
||||
int64_t xl, int64_t yl, int64_t quick_check);
|
||||
int ovlp_chain_qgen(overlap_region_alloc* ol, overlap_region* t, int64_t xl, int64_t yl, int64_t apend_be, k_mer_hit* hit, int64_t n_hit);
|
||||
uint64_t lchain_refine(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp,
|
||||
int64_t max_skip, int64_t max_iter, int64_t max_dis, int64_t long_gap);
|
||||
uint64_t lchain_qdp_fix(k_mer_hit* a, int64_t a_n, Chain_Data* dp, int64_t max_skip,
|
||||
int64_t max_iter, int64_t max_dis, double chn_pen_gap, double chn_pen_skip,
|
||||
double bw_rate, int64_t xl, int64_t yl, int64_t quick_check,
|
||||
int64_t left_fix, int64_t right_fix);
|
||||
uint64_t lchain_qdp_fix_adv(k_mer_hit* a, int64_t a_n, Chain_Data* dp, int64_t max_skip,
|
||||
int64_t max_iter, int64_t max_dis, double chn_pen_gap, double chn_pen_skip,
|
||||
double bw_rate, int64_t xl, int64_t yl, int64_t quick_check,
|
||||
int64_t left_fix, int64_t right_fix, k_mer_hit *res);
|
||||
uint64_t lchain_simple(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp,
|
||||
int64_t max_skip, int64_t max_iter);
|
||||
uint64_t lchain_simple0(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp, int64_t max_skip, int64_t max_iter);
|
||||
void push_ovlp_chain_qgen(overlap_region* o, uint32_t xid, int64_t xl, int64_t yl, int64_t sc, k_mer_hit *beg, k_mer_hit *end);
|
||||
|
||||
uint64_t lchain_qdp_mcopy(Candidates_list *cl, int64_t a_idx, int64_t a_n, int64_t des_idx,
|
||||
Chain_Data* dp, overlap_region_alloc* res, int64_t max_skip, int64_t max_iter,
|
||||
int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
|
||||
uint32_t xid, int64_t xl, int64_t yl, int64_t quick_check, uint32_t apend_be,
|
||||
int64_t gen_cigar, int64_t enable_mcopy, double mcopy_rate, int64_t mcopy_khit_cutoff,
|
||||
int64_t khit_n);
|
||||
|
||||
uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n, int64_t des_idx,
|
||||
Chain_Data* dp, overlap_region_alloc* res, int64_t max_skip, int64_t max_iter,
|
||||
int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
|
||||
uint32_t xid, int64_t xl, int64_t yl, int64_t quick_check, uint32_t apend_be,
|
||||
int64_t gen_cigar, int64_t enable_mcopy, double mcopy_rate, int64_t mcopy_khit_cutoff,
|
||||
int64_t khit_n);
|
||||
|
||||
uint64_t lchain_qdp_global_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n, int64_t des_idx,
|
||||
Chain_Data* dp, overlap_region_alloc* res, int64_t max_skip, int64_t max_iter,
|
||||
int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
|
||||
uint32_t xid, int64_t xl, int64_t yl, int64_t quick_check, uint32_t apend_be,
|
||||
int64_t gen_cigar, int64_t khit_n);
|
||||
|
||||
#define kv_pushp_ol(type, v, p) do { \
|
||||
if ((v).length == (v).size) { \
|
||||
(v).list = (type*)realloc((v).list, sizeof(type)*((v).size?((v).size<<1):(2))); \
|
||||
memset((v).list+(v).size, 0, sizeof(overlap_region)*(((v).size?((v).size<<1):2)-(v).size));\
|
||||
(v).size = (v).size?((v).size<<1):(2); \
|
||||
} \
|
||||
*(p) = &((v).list[(v).length++]); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
#include "Levenshtein_distance.h"
|
||||
#include <immintrin.h>
|
||||
|
||||
|
||||
#define init_simd_ed4(PSA, PNA, THRE, ABS_DIAG, R_ERR, R_PE, SI, TN, CUT, BD, I, MM, PEQ_MM, LZ, IBD) {\
|
||||
(R_ERR)[(SI)] = INT32_MAX; (R_PE)[(SI)] = -1; (IBD)[(SI)] = ((THRE)<<1) - (ABS_DIAG)[(SI)];\
|
||||
if(((PNA)[(SI)] <= (TN) + (CUT)) && ((TN) <= (PNA)[(SI)] + (CUT))) {\
|
||||
(BD) = (((THRE)<<1)+1)-(ABS_DIAG)[(SI)]; (BD) = (((BD)<=(PNA)[(SI)])?(BD):(PNA)[(SI)]); (LZ) |= (((int32_t)1u) << (SI));\
|
||||
for ((I) = 0, (MM) = (((Word)1)<<((ABS_DIAG)[(SI)])); (I) < (BD); (I)++) {\
|
||||
(PEQ_MM)[seq_nt4_table[(uint8_t)(PSA)[(SI)][(I)]]][(SI)] |= (MM); (MM) <<= 1;\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ed_core_64x4(PEQz, VPz, VNz, Xz, D0z, HNz, HPz) { \
|
||||
/**(X) = (Peq)|(VN);**/\
|
||||
(Xz) = _mm256_or_si256((PEQz), (VNz)); \
|
||||
/**(D0) = (((VP) + ((X)&(VP))) ^ (VP)) | (X);**/\
|
||||
(D0z) = _mm256_or_si256(_mm256_xor_si256(_mm256_add_epi64((VPz), _mm256_and_si256((Xz), (VPz))), (VPz)), (Xz)); \
|
||||
/**(HN) = (VP)&(D0);**/\
|
||||
(HNz) = _mm256_and_si256((VPz), (D0z)); \
|
||||
/**(HP) = (VN) | ~((VP) | (D0));**/\
|
||||
(HPz) = _mm256_or_si256((VNz), _mm256_andnot_si256(_mm256_or_si256((VPz), (D0z)), _mm256_set1_epi64x(-1))); \
|
||||
/**(X) = (D0) >> 1;**/\
|
||||
(Xz) = _mm256_srli_epi64((D0z), 1); \
|
||||
/**(VN) = (X)&(HP);**/\
|
||||
(VNz) = _mm256_and_si256((Xz), (HPz)); \
|
||||
/**(VP) = (HN) | ~((X) | (HP));**/\
|
||||
(VPz) = _mm256_or_si256((HNz), _mm256_andnot_si256(_mm256_or_si256((Xz), (HPz)), _mm256_set1_epi64x(-1))); \
|
||||
}
|
||||
|
||||
#define ed_core_upx4(PEQz, PSA, PNA, IBD, HT, CC, MMK, SI) { \
|
||||
if((HT) & (((int32_t)1u) << (SI))) {\
|
||||
(IBD)[(SI)]++;\
|
||||
if((IBD)[(SI)] < (PNA)[(SI)]) {\
|
||||
(CC) = seq_nt4_table[(uint8_t)(PSA)[(SI)][(IBD)[(SI)]]];\
|
||||
if((CC) < 4) (PEQz)[(CC)] = _mm256_or_si256((PEQz)[(CC)], (MMK)[(SI)]);\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ed_tail_upx4(HT, SI, ST, AI, PNA, ABS_DIAG, K, ERR_MM, VP_MM, VN_MM, THRE, R_ERR, R_PE, BD, I) {\
|
||||
if((HT) & (((int32_t)1u) << (SI))) {\
|
||||
(ST)[(SI)] -= (ABS_DIAG)[(SI)]; (AI)[(SI)] += (PNA)[(SI)] + (ABS_DIAG)[(SI)];\
|
||||
for ((K)[(SI)] = 0; (ST)[(SI)] < 0 && (K)[(SI)] < (AI)[(SI)]; (K)[(SI)]++, (ST)[(SI)]++) {\
|
||||
(ERR_MM)[(SI)] += ((VP_MM)[(SI)]&(1ULL)); (VP_MM)[(SI)]>>=1;\
|
||||
(ERR_MM)[(SI)] -= ((VN_MM)[(SI)]&(1ULL)); (VN_MM)[(SI)]>>=1;\
|
||||
}\
|
||||
if (((ERR_MM)[(SI)] <= (THRE)) && ((ERR_MM)[(SI)] <= (R_ERR)[(SI)])) {\
|
||||
(R_ERR)[(SI)] = (ERR_MM)[(SI)]; (R_PE)[(SI)] = (ST)[(SI)];\
|
||||
}\
|
||||
(ST)[(SI)] -= (K)[(SI)]; (BD)++; (I) = (SI);\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ED_TAIL_LANE(K) do { \
|
||||
if ((ht) & (((int32_t)1u) << (K))) { \
|
||||
st = tn - 1 - abs_diag_a[(K)]; \
|
||||
ai = pna[(K)] - tn + abs_diag_a[(K)]; \
|
||||
for (i = 0, uge = INT64_MAX; st < 0 && i < ai; i++, st++) { \
|
||||
err_mm[(K)] += ((VP_mm[(K)] >> i) & 1ULL); \
|
||||
err_mm[(K)] -= ((VN_mm[(K)] >> i) & 1ULL); \
|
||||
} \
|
||||
if ((err_mm[(K)] <= thre) && (err_mm[(K)] <= r_err[(K)])) { \
|
||||
r_err[(K)] = err_mm[(K)]; \
|
||||
r_pe[(K)] = st; \
|
||||
} \
|
||||
st -= i; \
|
||||
while (i < ai) { \
|
||||
err_mm[(K)] += ((VP_mm[(K)] >> i) & 1ULL); \
|
||||
err_mm[(K)] -= ((VN_mm[(K)] >> i) & 1ULL); \
|
||||
++i; \
|
||||
if ((err_mm[(K)] <= thre) && (err_mm[(K)] <= r_err[(K)])) { \
|
||||
r_err[(K)] = err_mm[(K)]; \
|
||||
r_pe[(K)] = st + i; \
|
||||
} \
|
||||
if (i == thre) uge = err_mm[(K)]; \
|
||||
} \
|
||||
if ((uge <= thre) && (uge == r_err[(K)])) r_pe[(K)] = st + thre; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void ed_band_cal_semi_64_w_absent_diag_avx4(char **psa, int32_t *pna, char *tstr, int32_t tn, int32_t thre, int32_t *abs_diag_a, int64_t *r_err, int64_t *r_pe)
|
||||
{
|
||||
// r_err[0] = r_err[1] = r_err[2] = r_err[3] = r_err[4] = r_err[5] = r_err[6] = r_err[7] = thre+1;
|
||||
// r_pe[0] = r_pe[1] = r_pe[2] = r_pe[3] = r_pe[4] = r_pe[5] = r_pe[6] = r_pe[7] = -1;
|
||||
|
||||
Word mm, Peq_mm[5][AVX_GS2] = {{0}}, *VN_mm = NULL, *VP_mm = NULL, c = 0; __m256i Peq[5], VP, VN, X, D0, HN, HP, lone, E, C, mmk[AVX_GS2];
|
||||
int32_t lz = 0, ht = (((int32_t)1u)<<AVX_GS2)-1; int32_t bd, ibd[AVX_GS2], i, last_high = (thre<<1), tn0 = tn - 1, cut = thre+last_high;
|
||||
|
||||
lone = _mm256_set1_epi64x(1);
|
||||
VP = _mm256_setzero_si256();
|
||||
|
||||
VN_mm = Peq_mm[0];
|
||||
VN_mm[0] = (((Word)1)<<(abs_diag_a[0]))-1; VN_mm[1] = (((Word)1)<<(abs_diag_a[1]))-1; VN_mm[2] = (((Word)1)<<(abs_diag_a[2]))-1; VN_mm[3] = (((Word)1)<<(abs_diag_a[3]))-1;
|
||||
VN = _mm256_loadu_si256((const __m256i *)VN_mm);
|
||||
|
||||
VN_mm[0] = abs_diag_a[0]; VN_mm[1] = abs_diag_a[1]; VN_mm[2] = abs_diag_a[2]; VN_mm[3] = abs_diag_a[3];
|
||||
E = _mm256_loadu_si256((const __m256i *)VN_mm);
|
||||
|
||||
memset(VN_mm, 0, (sizeof((*VN_mm))*AVX_GS2)); VN_mm = NULL;///reset
|
||||
|
||||
init_simd_ed4(psa, pna, thre, abs_diag_a, r_err, r_pe, 0, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed4(psa, pna, thre, abs_diag_a, r_err, r_pe, 1, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed4(psa, pna, thre, abs_diag_a, r_err, r_pe, 2, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed4(psa, pna, thre, abs_diag_a, r_err, r_pe, 3, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
Peq[0] = _mm256_loadu_si256((const __m256i *)Peq_mm[0]);
|
||||
Peq[1] = _mm256_loadu_si256((const __m256i *)Peq_mm[1]);
|
||||
Peq[2] = _mm256_loadu_si256((const __m256i *)Peq_mm[2]);
|
||||
Peq[3] = _mm256_loadu_si256((const __m256i *)Peq_mm[3]);
|
||||
Peq[4] = _mm256_setzero_si256();
|
||||
|
||||
C = _mm256_set1_epi64x(cut + 1);///_mm512_set1_epi64x(cut);
|
||||
|
||||
mm = ((Word)1 << (thre<<1));///for the incoming char/last char**
|
||||
mmk[0] = _mm256_set_epi64x(0, 0, 0, mm);
|
||||
mmk[1] = _mm256_set_epi64x(0, 0, mm, 0);
|
||||
mmk[2] = _mm256_set_epi64x(0, mm, 0, 0);
|
||||
mmk[3] = _mm256_set_epi64x(mm, 0, 0, 0);
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < tn0) {
|
||||
ed_core_64x4(Peq[seq_nt4_table[(uint8_t)tstr[i]]], VP, VN, X, D0, HN, HP);
|
||||
E = _mm256_add_epi64(_mm256_xor_si256(lone, _mm256_and_si256(D0, lone)), E);
|
||||
// ht = _mm512_cmple_epi64_mask(E, C);
|
||||
ht =_mm256_movemask_pd(_mm256_castsi256_pd(_mm256_cmpgt_epi64(C, E)));
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
Peq[0] = _mm256_srli_epi64(Peq[0], 1);
|
||||
Peq[1] = _mm256_srli_epi64(Peq[1], 1);
|
||||
Peq[2] = _mm256_srli_epi64(Peq[2], 1);
|
||||
Peq[3] = _mm256_srli_epi64(Peq[3], 1);
|
||||
i++; ///c = 4;
|
||||
|
||||
ed_core_upx4(Peq, psa, pna, ibd, ht, c, mmk, 0);
|
||||
ed_core_upx4(Peq, psa, pna, ibd, ht, c, mmk, 1);
|
||||
ed_core_upx4(Peq, psa, pna, ibd, ht, c, mmk, 2);
|
||||
ed_core_upx4(Peq, psa, pna, ibd, ht, c, mmk, 3);
|
||||
}
|
||||
|
||||
ed_core_64x4(Peq[seq_nt4_table[(uint8_t)tstr[i]]], VP, VN, X, D0, HN, HP);
|
||||
E = _mm256_add_epi64(_mm256_xor_si256(lone, _mm256_and_si256(D0, lone)), E);
|
||||
// ht = _mm512_cmple_epi64_mask(E, C);
|
||||
ht =_mm256_movemask_pd(_mm256_castsi256_pd(_mm256_cmpgt_epi64(C, E)));
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
int32_t st, ai; int64_t err_mm[AVX_GS2], uge;
|
||||
VN_mm = Peq_mm[0]; VP_mm = Peq_mm[1];
|
||||
_mm256_storeu_si256((__m256i *)VN_mm, VN); _mm256_storeu_si256((__m256i *)VP_mm, VP); _mm256_storeu_si256((__m256i *)err_mm, E);
|
||||
|
||||
ED_TAIL_LANE(0);
|
||||
ED_TAIL_LANE(1);
|
||||
ED_TAIL_LANE(2);
|
||||
ED_TAIL_LANE(3);
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
#include "Levenshtein_distance.h"
|
||||
#include <immintrin.h>
|
||||
|
||||
#define init_simd_ed(PSA, PNA, THRE, ABS_DIAG, R_ERR, R_PE, SI, TN, CUT, BD, I, MM, PEQ_MM, LZ, IBD) {\
|
||||
(R_ERR)[(SI)] = INT32_MAX; (R_PE)[(SI)] = -1; (IBD)[(SI)] = ((THRE)<<1) - (ABS_DIAG)[(SI)];\
|
||||
if(((PNA)[(SI)] <= (TN) + (CUT)) && ((TN) <= (PNA)[(SI)] + (CUT))) {\
|
||||
(BD) = (((THRE)<<1)+1)-(ABS_DIAG)[(SI)]; (BD) = (((BD)<=(PNA)[(SI)])?(BD):(PNA)[(SI)]); (LZ) |= (((__mmask8)1u) << (SI));\
|
||||
for ((I) = 0, (MM) = (((Word)1)<<((ABS_DIAG)[(SI)])); (I) < (BD); (I)++) {\
|
||||
(PEQ_MM)[seq_nt4_table[(uint8_t)(PSA)[(SI)][(I)]]][(SI)] |= (MM); (MM) <<= 1;\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ed_core_64x8(PEQz, VPz, VNz, Xz, D0z, HNz, HPz) { \
|
||||
/**(X) = (Peq)|(VN);**/\
|
||||
(Xz) = _mm512_or_si512((PEQz), (VNz));\
|
||||
/**(D0) = (((VP) + ((X)&(VP))) ^ (VP)) | (X);**/\
|
||||
(D0z) = _mm512_or_si512(_mm512_xor_si512(_mm512_add_epi64((VPz), _mm512_and_si512((Xz), (VPz))), (VPz)), (Xz));\
|
||||
/**(HN) = (VP)&(D0);**/\
|
||||
(HNz) = _mm512_and_si512((VPz), (D0z));\
|
||||
/**(HP) = (VN) | ~((VP) | (D0));**/\
|
||||
(HPz) = _mm512_or_si512((VNz), _mm512_andnot_si512(_mm512_or_si512((VPz), (D0z)), _mm512_set1_epi64(-1)));\
|
||||
/**(X) = (D0) >> 1;**/\
|
||||
(Xz) = _mm512_srli_epi64((D0z), 1);\
|
||||
/**(VN) = (X)&(HP);**/\
|
||||
(VNz) = _mm512_and_si512((Xz), (HPz));\
|
||||
/**(VP) = (HN) | ~((X) | (HP));**/\
|
||||
(VPz) = _mm512_or_si512((HNz), _mm512_andnot_si512(_mm512_or_si512((Xz), (HPz)), _mm512_set1_epi64(-1)));\
|
||||
}
|
||||
|
||||
#define ed_core_upx8(PEQz, PSA, PNA, IBD, HT, CC, MMK, SI) { \
|
||||
if((HT) & (((__mmask8)1u) << (SI))) {\
|
||||
(IBD)[(SI)]++;\
|
||||
if((IBD)[(SI)] < (PNA)[(SI)]) {\
|
||||
(CC) = seq_nt4_table[(uint8_t)(PSA)[(SI)][(IBD)[(SI)]]];\
|
||||
if((CC) < 4) (PEQz)[(CC)] = _mm512_or_si512((PEQz)[(CC)], (MMK)[(SI)]);\
|
||||
}\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ed_tail_upx8(HT, SI, ST, AI, PNA, ABS_DIAG, K, ERR_MM, VP_MM, VN_MM, THRE, R_ERR, R_PE, BD, I) {\
|
||||
if((HT) & (((__mmask8)1u) << (SI))) {\
|
||||
(ST)[(SI)] -= (ABS_DIAG)[(SI)]; (AI)[(SI)] += (PNA)[(SI)] + (ABS_DIAG)[(SI)];\
|
||||
for ((K)[(SI)] = 0; (ST)[(SI)] < 0 && (K)[(SI)] < (AI)[(SI)]; (K)[(SI)]++, (ST)[(SI)]++) {\
|
||||
(ERR_MM)[(SI)] += ((VP_MM)[(SI)]&(1ULL)); (VP_MM)[(SI)]>>=1;\
|
||||
(ERR_MM)[(SI)] -= ((VN_MM)[(SI)]&(1ULL)); (VN_MM)[(SI)]>>=1;\
|
||||
}\
|
||||
if (((ERR_MM)[(SI)] <= (THRE)) && ((ERR_MM)[(SI)] <= (R_ERR)[(SI)])) {\
|
||||
(R_ERR)[(SI)] = (ERR_MM)[(SI)]; (R_PE)[(SI)] = (ST)[(SI)];\
|
||||
}\
|
||||
(ST)[(SI)] -= (K)[(SI)]; (BD)++; (I) = (SI);\
|
||||
}\
|
||||
}
|
||||
|
||||
#define ed_tail_ck8(MBEST, SI, R_PE, ST, K, THRE, UGE_MM, ERR_MM, AI, HT) {\
|
||||
(K)[(SI)]++;\
|
||||
if((MBEST) & (((__mmask8)1u) << (SI))) {\
|
||||
(R_PE)[(SI)] = (ST)[(SI)] + (K)[(SI)];\
|
||||
}\
|
||||
if((K)[(SI)] >= (AI)[(SI)]) (HT) &= ~(((__mmask8)1u) << (SI));\
|
||||
if((K)[(SI)] == (THRE)) (UGE_MM)[(SI)] = (ERR_MM)[(SI)];\
|
||||
}
|
||||
|
||||
|
||||
void ed_band_cal_semi_64_w_absent_diag_avx8(char **psa, int32_t *pna, char *tstr, int32_t tn, int32_t thre, int32_t *abs_diag_a, int64_t *r_err, int64_t *r_pe)
|
||||
{
|
||||
// r_err[0] = r_err[1] = r_err[2] = r_err[3] = r_err[4] = r_err[5] = r_err[6] = r_err[7] = thre+1;
|
||||
// r_pe[0] = r_pe[1] = r_pe[2] = r_pe[3] = r_pe[4] = r_pe[5] = r_pe[6] = r_pe[7] = -1;
|
||||
/**
|
||||
ed_band_cal_semi_64_w_absent_diag_avx4(psa, pna, tstr, tn, thre, abs_diag_a, r_err, r_pe);
|
||||
ed_band_cal_semi_64_w_absent_diag_avx4(psa + 4, pna + 4, tstr, tn, thre, abs_diag_a + 4, r_err + 4, r_pe + 4);
|
||||
return;
|
||||
**/
|
||||
|
||||
|
||||
Word mm, Peq_mm[5][AVX_GS] = {{0}}, *VN_mm = NULL, *VP_mm = NULL, c = 0; __m512i Peq[5], VP, VN, X, D0, HN, HP, lone, E, C, bestE, bestPE, curPE, cutPE, threPE, ugE, mmk[AVX_GS];
|
||||
__mmask8 lz = ((__mmask8)0u), ht = (((__mmask8)1u)<<AVX_GS)-1, mtf, mt, mbest; int32_t bd, ibd[AVX_GS], i, last_high = (thre<<1), tn0 = tn - 1, cut = thre+last_high;
|
||||
|
||||
lone = _mm512_set1_epi64(1);
|
||||
VP = _mm512_setzero_si512();
|
||||
|
||||
VN_mm = Peq_mm[0];
|
||||
VN_mm[0] = (((Word)1)<<(abs_diag_a[0]))-1; VN_mm[1] = (((Word)1)<<(abs_diag_a[1]))-1; VN_mm[2] = (((Word)1)<<(abs_diag_a[2]))-1; VN_mm[3] = (((Word)1)<<(abs_diag_a[3]))-1;
|
||||
VN_mm[4] = (((Word)1)<<(abs_diag_a[4]))-1; VN_mm[5] = (((Word)1)<<(abs_diag_a[5]))-1; VN_mm[6] = (((Word)1)<<(abs_diag_a[6]))-1; VN_mm[7] = (((Word)1)<<(abs_diag_a[7]))-1;
|
||||
VN = _mm512_loadu_si512(VN_mm);
|
||||
|
||||
VN_mm[0] = abs_diag_a[0]; VN_mm[1] = abs_diag_a[1]; VN_mm[2] = abs_diag_a[2]; VN_mm[3] = abs_diag_a[3];
|
||||
VN_mm[4] = abs_diag_a[4]; VN_mm[5] = abs_diag_a[5]; VN_mm[6] = abs_diag_a[6]; VN_mm[7] = abs_diag_a[7];
|
||||
E = _mm512_loadu_si512(VN_mm);
|
||||
|
||||
memset(VN_mm, 0, (sizeof((*VN_mm))*AVX_GS)); VN_mm = NULL;///reset
|
||||
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 0, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 1, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 2, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 3, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 4, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 5, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 6, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
init_simd_ed(psa, pna, thre, abs_diag_a, r_err, r_pe, 7, tn, cut, bd, i, mm, Peq_mm, lz, ibd);
|
||||
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
Peq[0] = _mm512_loadu_si512(Peq_mm[0]);
|
||||
Peq[1] = _mm512_loadu_si512(Peq_mm[1]);
|
||||
Peq[2] = _mm512_loadu_si512(Peq_mm[2]);
|
||||
Peq[3] = _mm512_loadu_si512(Peq_mm[3]);
|
||||
Peq[4] = _mm512_setzero_si512();
|
||||
|
||||
C = _mm512_set1_epi64(cut);
|
||||
|
||||
mm = ((Word)1 << (thre<<1));///for the incoming char/last char**
|
||||
mmk[0] = _mm512_mask_set1_epi64(VP, 1, mm);
|
||||
mmk[1] = _mm512_mask_set1_epi64(VP, 2, mm);
|
||||
mmk[2] = _mm512_mask_set1_epi64(VP, 4, mm);
|
||||
mmk[3] = _mm512_mask_set1_epi64(VP, 8, mm);
|
||||
mmk[4] = _mm512_mask_set1_epi64(VP, 16, mm);
|
||||
mmk[5] = _mm512_mask_set1_epi64(VP, 32, mm);
|
||||
mmk[6] = _mm512_mask_set1_epi64(VP, 64, mm);
|
||||
mmk[7] = _mm512_mask_set1_epi64(VP, 128, mm);
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < tn0) {
|
||||
ed_core_64x8(Peq[seq_nt4_table[(uint8_t)tstr[i]]], VP, VN, X, D0, HN, HP);
|
||||
E = _mm512_add_epi64(_mm512_xor_si512(lone, _mm512_and_si512(D0, lone)), E);
|
||||
ht = _mm512_cmple_epi64_mask(E, C);
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
Peq[0] = _mm512_srli_epi64(Peq[0], 1);
|
||||
Peq[1] = _mm512_srli_epi64(Peq[1], 1);
|
||||
Peq[2] = _mm512_srli_epi64(Peq[2], 1);
|
||||
Peq[3] = _mm512_srli_epi64(Peq[3], 1);
|
||||
i++; ///c = 4;
|
||||
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 0);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 1);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 2);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 3);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 4);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 5);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 6);
|
||||
ed_core_upx8(Peq, psa, pna, ibd, ht, c, mmk, 7);
|
||||
}
|
||||
|
||||
ed_core_64x8(Peq[seq_nt4_table[(uint8_t)tstr[i]]], VP, VN, X, D0, HN, HP);
|
||||
E = _mm512_add_epi64(_mm512_xor_si512(lone, _mm512_and_si512(D0, lone)), E);
|
||||
ht = _mm512_cmple_epi64_mask(E, C);
|
||||
ht &= lz;
|
||||
if(ht == 0) return;
|
||||
|
||||
|
||||
// site = tn - 1 - abs_diag;/**up bound**/
|
||||
// ai = pn - tn + abs_diag; /**in most cases, ai = (thre<<1)**/
|
||||
int32_t st[AVX_GS] = {tn-1, tn-1, tn-1, tn-1, tn-1, tn-1, tn-1, tn-1};
|
||||
int32_t ai[AVX_GS] = {-tn, -tn, -tn, -tn, -tn, -tn, -tn, -tn};
|
||||
int32_t k[AVX_GS] = {0}; i = -1; bd = 0;
|
||||
int64_t err_mm[AVX_GS], uge_mm[AVX_GS] = {INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX};
|
||||
VN_mm = Peq_mm[0]; VP_mm = Peq_mm[1];
|
||||
_mm512_storeu_si512(VN_mm, VN); _mm512_storeu_si512(VP_mm, VP); _mm512_storeu_si512(err_mm, E);
|
||||
|
||||
ed_tail_upx8(ht, 0, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 1, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 2, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 3, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 4, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 5, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 6, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
ed_tail_upx8(ht, 7, st, ai, pna, abs_diag_a, k, err_mm, VP_mm, VN_mm, thre, r_err, r_pe, bd, i);
|
||||
|
||||
if(bd <= 0) return;
|
||||
|
||||
if(bd > 1) {
|
||||
VN = _mm512_loadu_si512(VN_mm); VP = _mm512_loadu_si512(VP_mm); E = _mm512_loadu_si512(err_mm); i = 0;
|
||||
|
||||
bestE = _mm512_loadu_si512(r_err); ///threE = _mm512_set1_epi64(thre);
|
||||
if(k[0] >= ai[0]) ht &= ((__mmask8)(255-1));
|
||||
if(k[1] >= ai[1]) ht &= ((__mmask8)(255-2));
|
||||
if(k[2] >= ai[2]) ht &= ((__mmask8)(255-4));
|
||||
if(k[3] >= ai[3]) ht &= ((__mmask8)(255-8));
|
||||
if(k[4] >= ai[4]) ht &= ((__mmask8)(255-16));
|
||||
if(k[5] >= ai[5]) ht &= ((__mmask8)(255-32));
|
||||
if(k[6] >= ai[6]) ht &= ((__mmask8)(255-64));
|
||||
if(k[7] >= ai[7]) ht &= ((__mmask8)(255-128));
|
||||
|
||||
err_mm[0] = r_pe[0]; err_mm[1] = r_pe[1]; err_mm[2] = r_pe[2]; err_mm[3] = r_pe[3];
|
||||
err_mm[4] = r_pe[4]; err_mm[5] = r_pe[5]; err_mm[6] = r_pe[6]; err_mm[7] = r_pe[7];
|
||||
bestPE = _mm512_loadu_si512(err_mm);
|
||||
err_mm[0] = st[0] + k[0]; err_mm[1] = st[1] + k[1]; err_mm[2] = st[2] + k[2]; err_mm[3] = st[3] + k[3];
|
||||
err_mm[4] = st[4] + k[4]; err_mm[5] = st[5] + k[5]; err_mm[6] = st[6] + k[6]; err_mm[7] = st[7] + k[7];
|
||||
curPE = _mm512_loadu_si512(err_mm);
|
||||
err_mm[0] = st[0] + thre; err_mm[1] = st[1] + thre; err_mm[2] = st[2] + thre; err_mm[3] = st[3] + thre;
|
||||
err_mm[4] = st[4] + thre; err_mm[5] = st[5] + thre; err_mm[6] = st[6] + thre; err_mm[7] = st[7] + thre;
|
||||
threPE = _mm512_loadu_si512(err_mm);
|
||||
err_mm[0] = st[0] + ai[0]; err_mm[1] = st[1] + ai[1]; err_mm[2] = st[2] + ai[2]; err_mm[3] = st[3] + ai[3];
|
||||
err_mm[4] = st[4] + ai[4]; err_mm[5] = st[5] + ai[5]; err_mm[6] = st[6] + ai[6]; err_mm[7] = st[7] + ai[7];
|
||||
cutPE = _mm512_loadu_si512(err_mm);
|
||||
|
||||
ugE = _mm512_loadu_si512(uge_mm);
|
||||
|
||||
// mtf = _mm512_cmpge_epi64_mask(curPE, threPE) | ((__mmask8)(~ht));
|
||||
mtf = _mm512_cmpge_epi64_mask(curPE, threPE);
|
||||
|
||||
while ((ht != 0) && ((mtf|((__mmask8)(~ht))) != (__mmask8)255)) {
|
||||
E = _mm512_add_epi64(E, _mm512_and_si512(VP, lone)); VP = _mm512_srli_epi64(VP, 1);
|
||||
E = _mm512_sub_epi64(E, _mm512_and_si512(VN, lone)); VN = _mm512_srli_epi64(VN, 1);
|
||||
// i++;
|
||||
|
||||
curPE = _mm512_add_epi64(curPE, lone);
|
||||
ht &= _mm512_cmple_epi64_mask(curPE, cutPE);
|
||||
if (ht == 0) break;
|
||||
|
||||
mbest = _mm512_cmple_epi64_mask(E, bestE) & ht;
|
||||
|
||||
bestE = _mm512_mask_mov_epi64(bestE, mbest, E);
|
||||
bestPE = _mm512_mask_mov_epi64(bestPE, mbest, curPE);
|
||||
|
||||
mt = _mm512_cmpeq_epi64_mask(curPE, threPE);
|
||||
ugE = _mm512_mask_mov_epi64(ugE, mt&ht, E);
|
||||
|
||||
mtf |= mt;
|
||||
|
||||
// if(mbest && i < thre) _mm512_storeu_si512(err_mm, E);
|
||||
|
||||
// ed_tail_ck8(mbest, 0, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 1, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 2, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 3, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 4, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 5, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 6, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
// ed_tail_ck8(mbest, 7, r_pe, st, k, thre, uge_mm, err_mm, ai, ht);
|
||||
}
|
||||
|
||||
|
||||
while (ht != 0) {
|
||||
E = _mm512_add_epi64(E, _mm512_and_si512(VP, lone)); VP = _mm512_srli_epi64(VP, 1);
|
||||
E = _mm512_sub_epi64(E, _mm512_and_si512(VN, lone)); VN = _mm512_srli_epi64(VN, 1);
|
||||
// i++;
|
||||
|
||||
curPE = _mm512_add_epi64(curPE, lone);
|
||||
ht &= _mm512_cmple_epi64_mask(curPE, cutPE);
|
||||
if (ht == 0) break;
|
||||
|
||||
mbest = _mm512_cmple_epi64_mask(E, bestE) & ht;
|
||||
|
||||
bestE = _mm512_mask_mov_epi64(bestE, mbest, E);
|
||||
bestPE = _mm512_mask_mov_epi64(bestPE, mbest, curPE);
|
||||
}
|
||||
|
||||
cutPE = _mm512_set1_epi64(thre);
|
||||
ht = _mm512_cmpgt_epi64_mask(bestE, cutPE);
|
||||
bestE = _mm512_mask_set1_epi64(bestE, ht, INT32_MAX);
|
||||
bestPE = _mm512_mask_set1_epi64(bestPE, ht, -1);
|
||||
|
||||
ht = _mm512_cmple_epi64_mask(ugE, cutPE) & _mm512_cmpeq_epi64_mask(ugE, bestE);
|
||||
bestPE = _mm512_mask_mov_epi64(bestPE, ht, threPE);
|
||||
|
||||
_mm512_storeu_si512(r_err, bestE);
|
||||
_mm512_storeu_si512(r_pe, bestPE);
|
||||
_mm512_storeu_si512(uge_mm, ugE);
|
||||
} else {///bd == 1
|
||||
while (k[i] < ai[i]) {
|
||||
err_mm[i] += (VP_mm[i]&(1ULL)); VP_mm[i]>>=1;
|
||||
err_mm[i] -= (VN_mm[i]&(1ULL)); VN_mm[i]>>=1;
|
||||
++k[i];
|
||||
if ((err_mm[i] <= thre) && (err_mm[i] <= r_err[i])) {
|
||||
r_err[i] = err_mm[i]; r_pe[i] = st[i] + k[i];
|
||||
}
|
||||
if(k[i] == thre) uge_mm[i] = err_mm[i];
|
||||
}
|
||||
if((uge_mm[i] <= thre) && (uge_mm[i] == r_err[i])) r_pe[i] = st[i] + thre;
|
||||
}
|
||||
}
|
||||
+3870
-1
File diff suppressed because it is too large
Load Diff
@@ -5,9 +5,9 @@ CFLAGS= $(CXXFLAGS)
|
||||
CPPFLAGS=
|
||||
INCLUDES=
|
||||
OBJS= CommandLines.o Process_Read.o Assembly.o Hash_Table.o \
|
||||
POA.o Correct.o Levenshtein_distance.o Overlaps.o Trio.o kthread.o Purge_Dups.o \
|
||||
htab.o hist.o sketch.o anchor.o extract.o sys.o ksw2_extz2_sse.o hic.o rcut.o horder.o \
|
||||
tovlp.o
|
||||
POA.o Correct.o Levenshtein_distance.o Levenshtein_avx2.o Levenshtein_avx512.o Overlaps.o Trio.o kthread.o Purge_Dups.o \
|
||||
htab.o hist.o sketch.o anchor.o extract.o sys.o hic.o rcut.o horder.o ecovlp.o\
|
||||
tovlp.o inter.o kalloc.o gfa_ut.o gchain_map.o
|
||||
EXE= hifiasm
|
||||
LIBS= -lz -lpthread -lm
|
||||
|
||||
@@ -19,13 +19,22 @@ endif
|
||||
.SUFFIXES:.cpp .c .o
|
||||
.PHONY:all clean depend
|
||||
|
||||
all:$(EXE)
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $< -o $@
|
||||
|
||||
.c.o:
|
||||
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $< -o $@
|
||||
|
||||
all:$(EXE)
|
||||
# compiled only with AVX2
|
||||
Levenshtein_avx2.o: Levenshtein_avx2.cpp Levenshtein_distance.h
|
||||
$(CXX) -c $(CXXFLAGS) -mavx2 $(CPPFLAGS) $(INCLUDES) $< -o $@
|
||||
|
||||
# compiled only with AVX512
|
||||
Levenshtein_avx512.o: Levenshtein_avx512.cpp Levenshtein_distance.h
|
||||
$(CXX) -c $(CXXFLAGS) -mavx512f $(CPPFLAGS) $(INCLUDES) $< -o $@
|
||||
|
||||
|
||||
$(EXE):$(OBJS) main.o
|
||||
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)
|
||||
@@ -40,11 +49,11 @@ depend:
|
||||
|
||||
Assembly.o: Assembly.h CommandLines.h Process_Read.h Overlaps.h kvec.h kdq.h
|
||||
Assembly.o: Hash_Table.h htab.h POA.h Correct.h Levenshtein_distance.h
|
||||
Assembly.o: kthread.h
|
||||
Assembly.o: kthread.h ecovlp.h
|
||||
CommandLines.o: CommandLines.h ketopt.h
|
||||
Correct.o: Correct.h Hash_Table.h htab.h Process_Read.h Overlaps.h kvec.h
|
||||
Correct.o: kdq.h CommandLines.h Levenshtein_distance.h POA.h Assembly.h
|
||||
Correct.o: ksw2.h ksort.h
|
||||
Correct.o: ksort.h
|
||||
Hash_Table.o: Hash_Table.h htab.h Process_Read.h Overlaps.h kvec.h kdq.h
|
||||
Hash_Table.o: CommandLines.h ksort.h
|
||||
Levenshtein_distance.o: Levenshtein_distance.h
|
||||
@@ -58,6 +67,7 @@ Process_Read.o: Process_Read.h Overlaps.h kvec.h kdq.h CommandLines.h
|
||||
Purge_Dups.o: ksort.h Purge_Dups.h kvec.h kdq.h Overlaps.h Hash_Table.h
|
||||
Purge_Dups.o: htab.h Process_Read.h CommandLines.h Correct.h
|
||||
Purge_Dups.o: Levenshtein_distance.h POA.h kthread.h
|
||||
ecovlp.o: Hash_Table.h Process_Read.h Overlaps.h kthread.h
|
||||
Trio.o: khashl.h kthread.h kseq.h Process_Read.h Overlaps.h kvec.h kdq.h
|
||||
Trio.o: CommandLines.h htab.h
|
||||
anchor.o: htab.h Process_Read.h Overlaps.h kvec.h kdq.h CommandLines.h
|
||||
@@ -76,3 +86,7 @@ hic.o: hic.h
|
||||
rcut.o: rcut.h
|
||||
horder.o: horder.h
|
||||
tovlp.o: tovlp.h
|
||||
inter.o: inter.h Process_Read.h
|
||||
kalloc.o: kalloc.h
|
||||
gfa_ut.o: Overlaps.h
|
||||
gchain_map.o: gchain_map.h
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __OUTPUT__
|
||||
#define __OUTPUT__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include<stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
+10069
-639
File diff suppressed because it is too large
Load Diff
+260
-14
@@ -1,10 +1,13 @@
|
||||
#ifndef __OVERLAPS__
|
||||
#define __OVERLAPS__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "kvec.h"
|
||||
#include "kdq.h"
|
||||
#include "ksort.h"
|
||||
#include "CommandLines.h"
|
||||
|
||||
///#define MIN_OVERLAP_LEN 2000
|
||||
///#define MIN_OVERLAP_LEN 500
|
||||
@@ -31,7 +34,8 @@
|
||||
// #define PRIMARY_LABLE 1
|
||||
// #define ALTER_LABLE 2
|
||||
// #define HAP_LABLE 4
|
||||
|
||||
#define ug_ext_len 75000
|
||||
#define UL_COV_THRES 2
|
||||
|
||||
#define Get_qn(RECORD) ((uint32_t)((RECORD).qns>>32))
|
||||
#define Get_qs(RECORD) ((uint32_t)((RECORD).qns))
|
||||
@@ -52,15 +56,68 @@
|
||||
#define TRIM 10
|
||||
#define CUT 11
|
||||
#define CUT_DIF_HAP 12
|
||||
#define SEC_MODE ((uint32_t)(0x3fffffffU))
|
||||
|
||||
///query is the read itself
|
||||
typedef struct {
|
||||
uint32_t qn, qs, qe;
|
||||
uint32_t tn, ts, te;
|
||||
uint32_t sec:30, el:1, rev:1;
|
||||
} ul_ov_t;
|
||||
|
||||
typedef struct {
|
||||
ul_ov_t *a;
|
||||
size_t n, m;
|
||||
} kv_ul_ov_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t tn, rn, el;
|
||||
uint32_t qs, qe, ts, te;
|
||||
uint8_t dir:5, pe:1, full:1, rev:1;
|
||||
} emask_t;
|
||||
|
||||
typedef struct {
|
||||
emask_t *a;
|
||||
size_t n, m;
|
||||
} kv_emask_t;
|
||||
|
||||
typedef struct {
|
||||
kv_emask_t *a;
|
||||
uint32_t n;
|
||||
} idx_emask_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t n, mask;
|
||||
uint8_t *hh;
|
||||
uint64_t tlen, tm;
|
||||
} telo_end_t;
|
||||
|
||||
typedef struct {
|
||||
///off: start idx in mg128_t * a[];
|
||||
///cnt: how many eles in this chain
|
||||
///a[off, off+cnt) saves the eles in this chain
|
||||
int32_t off, cnt:31, inner_pre:1;
|
||||
///ref_id|rev
|
||||
uint32_t v;
|
||||
///chain in ref: [rs, re)
|
||||
///chain in query: [qs, qe)
|
||||
int32_t rs, re, qs, qe;
|
||||
///score: chain score
|
||||
int32_t score, dist_pre;
|
||||
uint32_t hash_pre;
|
||||
} mg_lchain_t;
|
||||
|
||||
typedef struct {
|
||||
mg_lchain_t *a;
|
||||
size_t n, m;
|
||||
}vec_mg_lchain_t;
|
||||
|
||||
///query is the read itself
|
||||
typedef struct {
|
||||
uint64_t qns;
|
||||
uint32_t qe, tn, ts, te;
|
||||
uint32_t ml:31, rev:1;
|
||||
// uint32_t ml:31, rev:1;
|
||||
uint32_t cc:30, ml:1, rev:1;
|
||||
uint32_t bl:31, del:1;
|
||||
uint8_t el;
|
||||
uint8_t no_l_indel;
|
||||
@@ -83,9 +140,7 @@ void add_ma_hit_t_alloc(ma_hit_t_alloc* x, ma_hit_t* element);
|
||||
void ma_hit_sort_tn(ma_hit_t *a, long long n);
|
||||
void ma_hit_sort_qns(ma_hit_t *a, long long n);
|
||||
|
||||
int load_all_data_from_disk(ma_hit_t_alloc **sources, ma_hit_t_alloc **reverse_sources,
|
||||
char* output_file_name);
|
||||
|
||||
int load_all_data_from_disk(ma_hit_t_alloc **sources, ma_hit_t_alloc **reverse_sources, char* output_file_name);
|
||||
|
||||
|
||||
typedef struct {
|
||||
@@ -131,14 +186,17 @@ typedef struct {
|
||||
|
||||
#define u_trans_a(x, id) ((x).a + ((x).idx.a[(id)]>>32))
|
||||
#define u_trans_n(x, id) ((uint32_t)((x).idx.a[(id)]))
|
||||
#define OU_MASK (0x3fffU)
|
||||
|
||||
typedef struct {
|
||||
uint64_t ul;
|
||||
uint32_t v;
|
||||
uint32_t ol:31, del:1;
|
||||
uint8_t strong;
|
||||
uint16_t ou:14, strong:1, no_l_indel:1;
|
||||
uint8_t el;
|
||||
uint8_t no_l_indel;
|
||||
// uint8_t strong;
|
||||
// uint8_t el;
|
||||
// uint8_t no_l_indel;
|
||||
} asg_arc_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -177,6 +235,20 @@ typedef struct {
|
||||
ma_utg_t* F_seq;
|
||||
} asg_t;
|
||||
|
||||
typedef struct {
|
||||
ma_hit_t_alloc* src;
|
||||
int64_t min_ovlp, max_hang, max_hang_rate, need_srt, gap_fuzz;
|
||||
asg_t *g;
|
||||
uint32_t *idx;
|
||||
kvec_t(uint32_t) pi;
|
||||
asg_arc_t *a;
|
||||
size_t n, m;
|
||||
} flex_asg_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t i[2];
|
||||
}flex_asg_e_retrive_t;
|
||||
|
||||
asg_t *asg_init(void);
|
||||
void asg_destroy(asg_t *g);
|
||||
void asg_arc_sort(asg_t *g);
|
||||
@@ -188,9 +260,10 @@ void print_gfa(asg_t *g);
|
||||
|
||||
|
||||
typedef struct { size_t n, m; uint64_t *a; } asg64_v;
|
||||
|
||||
|
||||
typedef struct { size_t n, m; uint32_t *a; } asg32_v;
|
||||
typedef struct { size_t n, m; ma_utg_t *a;} ma_utg_v;
|
||||
typedef struct { asg64_v idx; kv_ul_ov_t srt;} mask_ul_ov_t;
|
||||
typedef struct { uint64_t n, m; char *a; } asgchr_v;
|
||||
|
||||
typedef struct {
|
||||
ma_utg_v u;
|
||||
@@ -202,7 +275,89 @@ typedef struct {
|
||||
uint32_t utg:31, ori:1, start, len;
|
||||
} utg_intv_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t x, s, e;
|
||||
} utg_ct_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t *idx;
|
||||
kvec_t(uint64_t) interval;
|
||||
} ucov_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t u, off, pos;
|
||||
} utg_rid_dt;
|
||||
|
||||
typedef struct {
|
||||
uint32_t *idx;
|
||||
kvec_t(utg_rid_dt) p;
|
||||
asg_t *rg;
|
||||
} utg_rid_t;
|
||||
|
||||
typedef struct {
|
||||
kvec_t(uint64_t) idx;
|
||||
kvec_t(utg_ct_t) rids;
|
||||
kvec_t(uint8_t) is_c;
|
||||
} ul_contain;
|
||||
|
||||
typedef struct {
|
||||
ma_ug_t *ug;
|
||||
asg_t *rg;
|
||||
uint64_t *idx;
|
||||
} cvert_t;
|
||||
|
||||
typedef struct {
|
||||
size_t n, m;
|
||||
uint8_t *a;
|
||||
uint64_t *idx;
|
||||
} hmap_t;
|
||||
|
||||
typedef struct {
|
||||
ma_ug_t *hg;
|
||||
size_t n, m;
|
||||
uint64_t *a;
|
||||
hmap_t *mm;
|
||||
} hpc_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t s, e;
|
||||
uint8_t k;
|
||||
} hpc_ss_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t s, e;
|
||||
} hpc_idx_t;
|
||||
|
||||
typedef struct {
|
||||
size_t n, m;
|
||||
hpc_ss_t *a;
|
||||
hpc_idx_t *idx;
|
||||
uint64_t idx_n;
|
||||
} hpc_re_t;
|
||||
|
||||
#define hpc_len(x, id) ((x).hg->u.a[(id)].len>>1)
|
||||
#define hpc_str(x, id, rev) (((x).hg->u.a[(id)].s)+((rev)?((x).hg->u.a[(id)].len>>1):(0)))
|
||||
|
||||
typedef struct {
|
||||
uint32_t n;
|
||||
uint8_t *a;
|
||||
} bit_mask_t;
|
||||
|
||||
#define set_bit_mask_t(x, i) ((x).a[(i)>>3]|=(((uint8_t)1)<<((i)&((uint32_t)7))))
|
||||
#define get_bit_mask_t(x, i) ((x).a[(i)>>3]&(((uint8_t)1)<<((i)&((uint32_t)7))))
|
||||
|
||||
typedef struct {
|
||||
ma_ug_t *ug;
|
||||
hpc_t *hpc_g;
|
||||
ucov_t *cc;
|
||||
ucov_t *cr;
|
||||
ul_contain *ct;
|
||||
utg_rid_t *r_ug;
|
||||
// cvert_t *nug;
|
||||
// kv_ul_ov_t *ov;
|
||||
} ul_idx_t;
|
||||
|
||||
#define MA_HT_DOUBLE (-1024)
|
||||
#define MA_HT_INT (-1)
|
||||
#define MA_HT_QCONT (-2)
|
||||
#define MA_HT_TCONT (-3)
|
||||
@@ -478,12 +633,12 @@ static inline int count_out_without_del(const asg_t *g, uint32_t v)
|
||||
|
||||
void build_string_graph_without_clean(
|
||||
int min_dp, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources,
|
||||
long long n_read, uint64_t* readLen, long long mini_overlap_length,
|
||||
uint64_t n_read, uint64_t* readLen, long long mini_overlap_length,
|
||||
long long max_hang_length, long long clean_round, long long gap_fuzz,
|
||||
float min_ovlp_drop_ratio, float max_ovlp_drop_ratio, char* output_file_name,
|
||||
long long bubble_dist, int read_graph, int write);
|
||||
|
||||
void debug_info_of_specfic_read(char* name, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, int id, char* command);
|
||||
void debug_info_of_specfic_read(const char* name, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, int id, const char* command);
|
||||
void collect_abnormal_edges(ma_hit_t_alloc* paf, ma_hit_t_alloc* rev_paf, long long readNum);
|
||||
void add_overlaps(ma_hit_t_alloc* source_paf, ma_hit_t_alloc* dest_paf, uint64_t* source_index, long long listLen);
|
||||
void remove_overlaps(ma_hit_t_alloc* source_paf, uint64_t* source_index, long long listLen);
|
||||
@@ -768,6 +923,12 @@ uint32_t get_edge_from_source(ma_hit_t_alloc* sources, ma_sub_t *coverage_cut,
|
||||
R_to_U* ruIndex, int max_hang, int min_ovlp, uint32_t query, uint32_t target, asg_arc_t* t);
|
||||
int unitig_arc_del_short_diploid_by_length(asg_t *g, float drop_ratio);
|
||||
void asg_bub_backtrack_primary(asg_t *g, uint32_t v0, buf_t *b);
|
||||
void set_hom_global_coverage(hifiasm_opt_t *opt, asg_t *sg, ma_sub_t* coverage_cut,
|
||||
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, int max_hang, int min_ovlp);
|
||||
void rescue_bubble_by_chain(asg_t *sg, ma_sub_t *coverage_cut, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources,
|
||||
long long tipsLen, float tip_drop_ratio, long long stops_threshold, R_to_U* ruIndex,
|
||||
float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, uint32_t chainLenThres, long long gap_fuzz,
|
||||
bub_label_t* b_mask_t, long long no_trio_recover, uint8_t *cmk);
|
||||
|
||||
typedef struct{
|
||||
double weight;
|
||||
@@ -891,6 +1052,12 @@ typedef struct {
|
||||
buf_t b0, b1;
|
||||
} utg_trans_t;
|
||||
|
||||
typedef struct {
|
||||
ma_ug_t *ug;
|
||||
kvec_t(uint64_t) idx;
|
||||
kvec_t(uint32_t) dst;
|
||||
} spg_t;
|
||||
|
||||
void init_hc_links(hc_links* link, uint64_t ug_num, trans_chain* t_ch);
|
||||
void destory_hc_links(hc_links* link);
|
||||
uint64_t get_bub_pop_max_dist(asg_t *g, buf_t *b);
|
||||
@@ -907,7 +1074,7 @@ ma_ug_t* copy_untig_graph(ma_ug_t *src);
|
||||
ma_ug_t* output_trio_unitig_graph(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name,
|
||||
uint8_t flag, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources,
|
||||
long long tipsLen, float tip_drop_ratio, long long stops_threshold, R_to_U* ruIndex,
|
||||
float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, int is_bench, bub_label_t* b_mask_t);
|
||||
float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, int gap_fuzz, int is_bench, bub_label_t* b_mask_t, char *f_prefix, uint8_t *kpt_buf, kvec_asg_arc_t_warp *r_edges);
|
||||
asg_t* copy_read_graph(asg_t *src);
|
||||
ma_ug_t *ma_ug_gen(asg_t *g);
|
||||
void ma_ug_destroy(ma_ug_t *ug);
|
||||
@@ -953,14 +1120,30 @@ typedef struct{
|
||||
int min_ovlp;
|
||||
int is_bench;
|
||||
long long gap_fuzz;
|
||||
int64_t min_dp;
|
||||
bub_label_t* b_mask_t;
|
||||
uint64_t* readLen;
|
||||
telo_end_t *te;
|
||||
}ug_opt_t;
|
||||
|
||||
typedef struct{
|
||||
ma_hit_t_alloc **src;
|
||||
ma_hit_t_alloc **r_src;
|
||||
long long *n_read;
|
||||
uint64_t **readLen;
|
||||
asg_t **sg;
|
||||
R_to_U *ruIndex;
|
||||
ma_sub_t **cov;
|
||||
bub_label_t *b_mask_t;
|
||||
int64_t max_hang;
|
||||
int64_t mini_ovlp;
|
||||
}ul_renew_t;
|
||||
|
||||
void adjust_utg_by_trio(ma_ug_t **ug, asg_t* read_g, uint8_t flag, float drop_rate,
|
||||
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, ma_sub_t* coverage_cut,
|
||||
long long tipsLen, float tip_drop_ratio, long long stops_threshold,
|
||||
R_to_U* ruIndex, float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp,
|
||||
kvec_asg_arc_t_warp* new_rtg_edges, bub_label_t* b_mask_t);
|
||||
int gap_fuzz, kvec_asg_arc_t_warp* new_rtg_edges, bub_label_t* b_mask_t);
|
||||
uint32_t cmp_untig_graph(ma_ug_t *src, ma_ug_t *dest);
|
||||
void reduce_hamming_error(asg_t *sg, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut,
|
||||
int max_hang, int min_ovlp, long long gap_fuzz);
|
||||
@@ -1000,9 +1183,72 @@ asg_t *i_read_sg, trans_chain* i_t_ch, uint32_t i_cBeg, uint32_t i_cEnd);
|
||||
void extract_sub_overlaps(uint32_t i_tScur, uint32_t i_tEcur, uint32_t i_tSpre, uint32_t i_tEpre,
|
||||
uint32_t tn, kv_u_trans_hit_t* ktb, uint32_t bn);
|
||||
void clean_u_trans_t_idx(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g);
|
||||
|
||||
void clean_u_trans_t_idx_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g);
|
||||
void clean_u_trans_t_idx_filter_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, double sc_sec_rate, uint64_t uniform_only);
|
||||
uint32_t test_dbug(ma_ug_t* ug, FILE* fp);
|
||||
void write_dbug(ma_ug_t* ug, FILE* fp);
|
||||
int asg_arc_identify_simple_bubbles_multi(asg_t *g, bub_label_t* x, int check_cross);
|
||||
uint8_t get_tip_trio_infor(asg_t *sg, uint32_t begNode);
|
||||
int asg_topocut_aux(asg_t *g, uint32_t v, int max_ext);
|
||||
int asg_topocut_aux_pg(asg_t *g, uint32_t v, int max_ext, uint32_t *rv);
|
||||
int asg_arc_del_triangular_directly(asg_t *g, long long min_edge_length,
|
||||
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex);
|
||||
int asg_arc_del_short_diploid_by_exact(asg_t *g, int max_ext, ma_hit_t_alloc* sources);
|
||||
uint32_t print_debug_gfa(asg_t *read_g, ma_ug_t *ug, ma_sub_t* coverage_cut, const char* output_file_name,
|
||||
ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp, int is_update_ou, int is_check_alter_lable, int is_seq);
|
||||
void debug_info_of_specfic_node(const char* name, asg_t *g, R_to_U* ruIndex, const char* command);
|
||||
ma_ug_t *gen_polished_ug(const ug_opt_t *uopt, asg_t *sg);
|
||||
void output_unitig_graph(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name,
|
||||
ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp);
|
||||
void flat_soma_v(asg_t *sg, ma_hit_t_alloc* sources, R_to_U* ruIndex);
|
||||
void hic_clean(asg_t* read_g);
|
||||
int64_t count_edges_v_w(asg_t *g, uint32_t v, uint32_t w);
|
||||
void renew_utg(ma_ug_t **ug, asg_t* read_g, kvec_asg_arc_t_warp* edge);
|
||||
void merge_unitig_content(ma_utg_t* collection, ma_ug_t* ug, asg_t* read_g, kvec_asg_arc_t_warp* edge);
|
||||
void reset_bub_label_t(bub_label_t* x, asg_t *g, uint64_t bub_dist, uint32_t check_cross);
|
||||
void set_reverse_overlap(ma_hit_t* dest, ma_hit_t* source);
|
||||
// void break_ug_contig(ma_ug_t **ug, asg_t *read_g, All_reads *RNF, ma_sub_t *coverage_cut,
|
||||
// ma_hit_t_alloc* sources, R_to_U* ruIndex, kvec_asg_arc_t_warp* edge, int max_hang, int min_ovlp,
|
||||
// int* b_low_cov, int* b_high_cov, double m_rate);
|
||||
void ma_hit_contained_advance(ma_hit_t_alloc* sources, long long n_read, ma_sub_t *coverage_cut,
|
||||
R_to_U* ruIndex, int max_hang, int min_ovlp);
|
||||
void hic_clean_adv(asg_t *sg, ug_opt_t *uopt);
|
||||
void update_ug_ou(ma_ug_t *ug, asg_t *sg);
|
||||
int asg_arc_del_trans_ul(asg_t *g, int fuzz);
|
||||
|
||||
#define JUNK_COV 5
|
||||
#define DISCARD_RATE 0.8
|
||||
|
||||
typedef struct {
|
||||
uint32_t n, m, a;
|
||||
} mmhap_status_t;
|
||||
|
||||
typedef struct {
|
||||
kvec_t(mmhap_status_t) h;
|
||||
kvec_t(uint32_t) a;
|
||||
} mmhap_t;
|
||||
|
||||
typedef struct { // global data structure for kt_pipeline()
|
||||
ma_ug_t *ug;
|
||||
asg_t *rg;
|
||||
uint64_t *idx;
|
||||
asg64_v cov;
|
||||
uint64_t hom_min, hom_max, hom_cov, het_cov;
|
||||
} ug_rid_cov_t;
|
||||
|
||||
ug_rid_cov_t* gen_ug_rid_cov_t(ma_ug_t *ug, asg_t *rg, ma_hit_t_alloc *src);
|
||||
void destory_ug_rid_cov_t(ug_rid_cov_t *p);
|
||||
uint32_t append_cov_line_ug_rid_cov_t(uint64_t uid, uint64_t *qcc, u_trans_t *p, ug_rid_cov_t *idx, uint64_t hom_cut, double cut_rate);
|
||||
uint64_t infer_mmhap_copy(ma_ug_t *ug, asg_t *sg, ma_hit_t_alloc *src, uint8_t *ff, uint64_t uid, uint64_t het_cov, uint64_t n_hap);
|
||||
uint64_t trans_sec_cut0(kv_u_trans_t *ta, asg64_v *srt, uint32_t id, double sec_rate, uint64_t bd, ma_ug_t *ug);
|
||||
void clean_u_trans_t_idx_filter_mmhap_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, ma_hit_t_alloc* src, ug_rid_cov_t *in);
|
||||
void gen_ug_rid_cov_t_by_ovlp(kv_u_trans_t *ta, ug_rid_cov_t *cc);
|
||||
void rescue_chimeric_reads_aggressive(ma_ug_t *i_ug, asg_t *rg, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut,
|
||||
R_to_U* ruIndex, int max_hang, int min_ovlp, uint32_t chainLenThres, uint32_t is_bubble_check, uint32_t is_primary_check, kvec_asg_arc_t_warp* new_rtg_edges,
|
||||
kvec_t_u32_warp* new_rtg_nodes, bub_label_t* b_mask_t, uint8_t *cmk);
|
||||
|
||||
#define UC_Read_resize(v, s) do {\
|
||||
if ((v).size<(s)) {REALLOC((v).seq,(s));(v).size=(s);}\
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
@@ -307,66 +307,53 @@ void addUnmatchedSeqToGraph(Graph* g, char* g_read_seq, long long g_read_length,
|
||||
}
|
||||
|
||||
void addmatchedSeqToGraph(Graph* backbone, long long currentNodeID, char* x_string, long long x_length,
|
||||
char* y_string, long long y_length, CIGAR* cigar, long long backbone_start, long long backbone_end)
|
||||
char* y_string, long long y_length, window_list *cigar_idx, window_list_alloc *cigar_s, long long backbone_start, long long backbone_end)
|
||||
{
|
||||
|
||||
int x_i, y_i, cigar_i;
|
||||
x_i = 0;
|
||||
y_i = 0;
|
||||
cigar_i = 0;
|
||||
int operation;
|
||||
int operationLen;
|
||||
int i;
|
||||
int last_operation = -1;
|
||||
|
||||
int64_t x_i = 0, y_i = 0, c_i = 0, c_n = cigar_idx->clen;
|
||||
uint32_t i, operLen; uint8_t oper; int8_t last_oper = -1;
|
||||
// if(currentNodeID == 366 && x_length == 9 && y_length == 9) {
|
||||
// fprintf(stderr, "[M::%s] currentNodeID::%lld, x_length::%lld, c_n::%ld, cidx::%u, cigar_s_n::%lld\n", __func__,
|
||||
// currentNodeID, x_length, c_n, cigar_idx->cidx, (long long)cigar_s->c.n);
|
||||
// }
|
||||
|
||||
///note that node 0 is the start node
|
||||
///0 is match, 1 is mismatch, 2 is up, 3 is left
|
||||
///2 mean y has more bases, while 3 means x has more bases
|
||||
while (cigar_i < cigar->length)
|
||||
{
|
||||
operation = cigar->C_C[cigar_i];
|
||||
operationLen = cigar->C_L[cigar_i];
|
||||
for (c_i = 0; c_i < c_n; c_i++) {
|
||||
get_cigar_cell(cigar_idx, cigar_s, c_i, &oper, &operLen);
|
||||
|
||||
///match/mismatch
|
||||
if (operation == 0 || operation == 1)
|
||||
{
|
||||
// if(currentNodeID == 366 && x_length == 9 && y_length == 9) {
|
||||
// fprintf(stderr, "[M::%s] c_i::%ld, oper::%u, operLen::%u, last_oper::%d\n", __func__, c_i, oper, operLen, last_oper);
|
||||
// }
|
||||
|
||||
for (i = 0; i < operationLen; i++)
|
||||
{
|
||||
if (oper == 0 || oper == 1) { ///match/mismatch
|
||||
for (i = 0; i < operLen; i++) {
|
||||
///if the previous node is insertion, this node might be mismatch/match
|
||||
add_mismatchEdge_weight(backbone, currentNodeID, y_string[y_i], last_operation);
|
||||
x_i++;
|
||||
y_i++;
|
||||
currentNodeID++;
|
||||
add_mismatchEdge_weight(backbone, currentNodeID, y_string[y_i], last_oper);
|
||||
x_i++; y_i++; currentNodeID++;
|
||||
}
|
||||
}///insertion
|
||||
else if (operation == 2)
|
||||
{
|
||||
} else if (oper == 2) { ///insertion
|
||||
///the begin and end of cigar cannot be 2, so -1 is right here
|
||||
///if (operationLen <= CORRECT_INDEL_LENGTH)
|
||||
{
|
||||
add_insertionEdge_weight(backbone, currentNodeID, y_string + y_i, operationLen);
|
||||
add_insertionEdge_weight(backbone, currentNodeID, y_string + y_i, operLen);
|
||||
backbone->g_nodes.list[currentNodeID].num_insertions++;
|
||||
}
|
||||
y_i += operationLen;
|
||||
}
|
||||
else if (operation == 3)
|
||||
{
|
||||
y_i += operLen;
|
||||
} else if (oper == 3) {
|
||||
///3 means x has more bases, that means backbone has more bases
|
||||
///like a mismatch (-)
|
||||
///if (operationLen <= CORRECT_INDEL_LENGTH)
|
||||
{
|
||||
add_deletionEdge_weight(backbone, currentNodeID, operationLen);
|
||||
add_deletionEdge_weight(backbone, currentNodeID, operLen);
|
||||
}
|
||||
|
||||
|
||||
currentNodeID += operationLen;
|
||||
x_i += operationLen;
|
||||
currentNodeID += operLen;
|
||||
x_i += operLen;
|
||||
}
|
||||
|
||||
last_operation = operation;
|
||||
|
||||
cigar_i++;
|
||||
last_oper = oper;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifndef __POA_PARSER__
|
||||
#define __POA_PARSER__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
#include "Hash_Table.h"
|
||||
#include "Process_Read.h"
|
||||
@@ -431,7 +433,7 @@ uint64_t* get_Topo_Sort_Order(Node_alloc* list, int need_sort);
|
||||
void init_Graph(Graph* g);
|
||||
void addUnmatchedSeqToGraph(Graph* g, char* g_read_seq, long long g_read_length, long long* startID, long long* endID);
|
||||
void addmatchedSeqToGraph(Graph* backbone, long long currentNodeID, char* x_string, long long x_length,
|
||||
char* y_string, long long y_length, CIGAR* cigar, long long backbone_start, long long backbone_end);
|
||||
char* y_string, long long y_length, window_list *cigar_idx, window_list_alloc *cigar_s, long long backbone_start, long long backbone_end);
|
||||
void destory_Graph(Graph* g);
|
||||
void clear_Graph(Graph* g);
|
||||
void Perform_POA(Graph* g, overlap_region_alloc* overlap_list, All_reads* R_INF, UC_Read* g_read);
|
||||
|
||||
+1724
-87
File diff suppressed because it is too large
Load Diff
+113
-3
@@ -1,12 +1,14 @@
|
||||
#ifndef __READ__
|
||||
#define __READ__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include<stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
#include "Overlaps.h"
|
||||
#include "CommandLines.h"
|
||||
#include "Levenshtein_distance.h"
|
||||
///#include "Hash_Table.h"
|
||||
|
||||
#define READ_INIT_NUMBER 1000
|
||||
@@ -21,21 +23,25 @@
|
||||
#define Get_NAME_LENGTH(R_INF, ID) ((R_INF).name_index[(ID)+1] - (R_INF).name_index[(ID)])
|
||||
///#define Get_READ(R_INF, ID) R_INF.read + (R_INF.index[ID]>>2) + ID
|
||||
#define Get_READ(R_INF, ID) (R_INF).read_sperate[(ID)]
|
||||
#define Get_QUAL(R_INF, ID) (R_INF).rsc[(ID)]
|
||||
#define Get_NAME(R_INF, ID) ((R_INF).name + (R_INF).name_index[(ID)])
|
||||
#define CHECK_BY_NAME(R_INF, NAME, ID) (Get_NAME_LENGTH((R_INF),(ID))==strlen((NAME)) && \
|
||||
memcmp((NAME), Get_NAME((R_INF), (ID)), Get_NAME_LENGTH((R_INF),(ID))) == 0)
|
||||
#define IS_SCAF_READ(R_INF, ID) ((R_INF).read_sperate[(ID)] == NULL)
|
||||
|
||||
extern uint8_t seq_nt6_table[256];
|
||||
extern char bit_t_seq_table[256][4];
|
||||
extern char bit_t_seq_table_rc[256][4];
|
||||
extern char s_H[5];
|
||||
extern char rc_Table[5];
|
||||
extern char rc_Table[6];
|
||||
|
||||
|
||||
#define RC_CHAR(x) rc_Table[seq_nt6_table[(uint8_t)x]]
|
||||
|
||||
void init_aux_table();
|
||||
|
||||
typedef struct { size_t n, m; uint8_t *a; } asg8_v;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t x_id;
|
||||
@@ -105,6 +111,8 @@ typedef struct
|
||||
#define CHAIN_MATCH 1
|
||||
#define CHAIN_UNMATCH 0.334
|
||||
|
||||
#define NEC 1
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint64_t** N_site;
|
||||
@@ -115,6 +123,7 @@ typedef struct
|
||||
uint64_t* read_length;
|
||||
uint64_t* read_size;
|
||||
uint8_t* trio_flag;
|
||||
uint8_t** rsc;
|
||||
|
||||
///seq start pos in uint8_t* read
|
||||
///do not need it
|
||||
@@ -125,8 +134,10 @@ typedef struct
|
||||
uint64_t* name_index;
|
||||
uint64_t name_index_size;
|
||||
uint64_t total_reads;
|
||||
uint64_t tqn;
|
||||
uint64_t total_reads_bases;
|
||||
uint64_t total_name_length;
|
||||
uint64_t tr[2];
|
||||
|
||||
Compressed_Cigar_record* cigars;
|
||||
Compressed_Cigar_record* second_round_cigar;
|
||||
@@ -134,11 +145,16 @@ typedef struct
|
||||
ma_hit_t_alloc* paf;
|
||||
ma_hit_t_alloc* reverse_paf;
|
||||
|
||||
uint8_t is_syn;
|
||||
|
||||
///kvec_t_u64_warp* pb_regions;
|
||||
} All_reads;
|
||||
|
||||
extern All_reads R_INF;
|
||||
|
||||
typedef struct {size_t n, m; asg16_v *a; uint8_t *f; uint16_t *er; uint64_t bid;} cc_v;
|
||||
extern cc_v scb;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* seq;
|
||||
@@ -150,27 +166,121 @@ typedef struct
|
||||
typedef struct
|
||||
{
|
||||
char** read_name;
|
||||
uint64_t *read_id;
|
||||
uint64_t query_num;
|
||||
kvec_t_u64_warp* candidate_count;
|
||||
FILE* fp;
|
||||
FILE *fp, *fp_r0, *fp_r1;
|
||||
pthread_mutex_t OutputMutex;
|
||||
} Debug_reads;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t hid;
|
||||
uint32_t qs, qe, ts, te; uint32_t pidx, pdis, aidx;///TODO: enable pdis
|
||||
uint8_t pchain:5, rev:1, base:1, el:1;
|
||||
} uc_block_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t *a;
|
||||
size_t n, m;
|
||||
} N_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *a; uint32_t n;
|
||||
} nid_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
kvec_t(uint8_t) r_base;
|
||||
uint32_t rlen;
|
||||
|
||||
kvec_t(uc_block_t) bb;
|
||||
N_t N_site;
|
||||
|
||||
uint8_t dd;
|
||||
} ul_vec_t;
|
||||
|
||||
typedef struct{
|
||||
kvec_t(uint32_t) idx;
|
||||
kvec_t(uint64_t) occ;
|
||||
} ul_vec_rid_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
kvec_t(nid_t) nid;
|
||||
ul_vec_rid_t ridx;
|
||||
ul_vec_t *a;
|
||||
size_t n, m;
|
||||
All_reads *hR;
|
||||
// idx_emask_t *mm;
|
||||
// uint32_t mm;
|
||||
} all_ul_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
ul_vec_t *a;
|
||||
size_t n, m;
|
||||
uint8_t dd;
|
||||
} scaf_res_t;
|
||||
|
||||
extern all_ul_t UL_INF;
|
||||
extern all_ul_t ULG_INF;
|
||||
// extern uint32_t *het_cnt;
|
||||
// extern uint32_t debug_out;
|
||||
|
||||
void init_All_reads(All_reads* r);
|
||||
void malloc_All_reads(All_reads* r);
|
||||
void ha_insert_read_len(All_reads *r, int read_len, int name_len);
|
||||
void ha_compress_base(uint8_t* dest, char* src, uint64_t src_l, uint64_t** N_site_lis, uint64_t N_site_occ);
|
||||
void ha_compress_qual(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitn, uint64_t sc_off);
|
||||
void init_UC_Read(UC_Read* r);
|
||||
void recover_UC_Read(UC_Read* r, const All_reads *R_INF, uint64_t ID);
|
||||
void recover_UC_Read_RC(UC_Read* r, All_reads* R_INF, uint64_t ID);
|
||||
void recover_UC_Read_sub_region(char* r, long long start_pos, long long length, uint8_t strand, All_reads* R_INF, long long ID);
|
||||
void recover_UC_Read_sub_region(char* r, int64_t start_pos, int64_t length, uint8_t strand, All_reads* R_INF, int64_t ID);
|
||||
void destory_UC_Read(UC_Read* r);
|
||||
void reverse_complement(char* pattern, uint64_t length);
|
||||
void write_All_reads(All_reads* r, char* read_file_name);
|
||||
int load_All_reads(All_reads* r, char* read_file_name);
|
||||
uint8_t load_cc_v(cc_v* r, char* read_file_name);
|
||||
void write_cc_v(cc_v* r, char* read_file_name);
|
||||
int append_All_reads(All_reads* r, char *idx, uint32_t id);
|
||||
void destory_All_reads(All_reads* r);
|
||||
int destory_read_bin(All_reads* r);
|
||||
void init_Debug_reads(Debug_reads* x, const char* file);
|
||||
void destory_Debug_reads(Debug_reads* x);
|
||||
void recover_UC_sub_Read(UC_Read* i_r, long long start_pos, long long length, uint8_t strand, All_reads* R_INF, long long ID);
|
||||
|
||||
void init_all_ul_t(all_ul_t *x, All_reads *hR);
|
||||
void destory_all_ul_t(all_ul_t *x);
|
||||
void append_ul_t(all_ul_t *x, uint64_t *rid, char* id, int64_t id_l, char* str, int64_t str_l, ul_ov_t *o, int64_t on, float p_chain_rate, const ug_opt_t *uopt, uint32_t save_bases);
|
||||
void retrieve_ul_t(UC_Read* i_r, char *i_s, all_ul_t *ref, uint64_t ID, uint8_t strand, int64_t s, int64_t l);
|
||||
void retrieve_u_seq(UC_Read* i_r, char* i_s, ma_utg_t *u, uint8_t strand, int64_t s, int64_t l, void *km);
|
||||
void debug_retrieve_rc_sub(const ug_opt_t *uopt, all_ul_t *ref, const All_reads *R_INF, ul_idx_t *ul, uint32_t n_step);
|
||||
uint32_t retrieve_u_cov(const ul_idx_t *ul, uint64_t id, uint8_t strand, uint64_t pos, uint8_t dir, int64_t *pi);
|
||||
uint64_t retrieve_u_cov_region(const ul_idx_t *ul, uint64_t id, uint8_t strand, uint64_t s, uint64_t e, int64_t *pi);
|
||||
uint64_t retrieve_r_cov_region(const ul_idx_t *ul, uint64_t id, uint8_t strand, uint64_t s, uint64_t e, int64_t *pi);
|
||||
void append_ul_t_back(all_ul_t *x, uint64_t *rid, char* id, int64_t id_l, char* str, int64_t str_l, ul_ov_t *o, int64_t on, float p_chain_rate);
|
||||
void write_compress_base_disk(FILE *fp, uint64_t ul_rid, char *str, uint32_t len, ul_vec_t *buf);
|
||||
int64_t load_compress_base_disk(FILE *fp, uint64_t *ul_rid, char *dest, uint32_t *len, ul_vec_t *buf);
|
||||
scaf_res_t *init_scaf_res_t(uint32_t n);
|
||||
void destroy_scaf_res_t(scaf_res_t *p);
|
||||
void read_ma(ma_hit_t* x, FILE* fp);
|
||||
void retrieve_u_seq_fast(UC_Read* i_r, char* i_s, ma_utg_t *u, uint8_t strand, int64_t s, int64_t l, void *km);
|
||||
|
||||
const uint64_t sc_tb[8] = {
|
||||
10, 20, 30, 40, 50, 60, 70, 80
|
||||
};
|
||||
|
||||
#define sc_bn 2
|
||||
#define sc_bm ((((uint64_t)1)<<sc_bn)-1)
|
||||
#define sc_wn 5
|
||||
|
||||
void convert_qual(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitu, uint64_t rev, uint64_t sc_off);
|
||||
int64_t retrive_bqual(asg8_v *dv, uint8_t *ds, uint64_t id, int64_t s, int64_t e, uint8_t rev, int64_t bitn);
|
||||
void print_fastq(FILE *fp, char *id, char *bs, char *qual, uint64_t bitu, uint64_t sc_off);
|
||||
void ha_compress_qual_bit(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitn);
|
||||
|
||||
#endif
|
||||
|
||||
+296
-30
@@ -51,7 +51,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
hap_alignment_struct* buf;
|
||||
uint32_t num_threads;
|
||||
|
||||
uint8_t *hh;
|
||||
ma_ug_t *ug;
|
||||
asg_t *read_g;
|
||||
ma_hit_t_alloc* sources;
|
||||
@@ -471,6 +471,30 @@ void destory_hap_alignment_struct(hap_alignment_struct* x)
|
||||
kv_destroy(x->u_can.a);
|
||||
}
|
||||
|
||||
uint8_t *init_pip_hh(asg_t *rg, ma_hit_t_alloc* reverse_sources, ma_sub_t *coverage_cut, long long sc)
|
||||
{
|
||||
uint8_t *c = NULL; CALLOC(c, rg->n_seq);
|
||||
ma_hit_t *h = NULL;
|
||||
uint32_t i, k;
|
||||
long long R_Base, C_Base;
|
||||
for (i = 0; i < rg->n_seq; i++) {
|
||||
if(sc <= 0){
|
||||
c[i] = 1;
|
||||
continue;
|
||||
}
|
||||
R_Base = (coverage_cut[i].e - coverage_cut[i].s);
|
||||
for (k = 0, C_Base = 0; k < reverse_sources[i].length; k++){
|
||||
h = &(reverse_sources[i].buffer[k]);
|
||||
C_Base += (Get_qe((*h)) - Get_qs((*h)));
|
||||
}
|
||||
C_Base = (R_Base!=0?(C_Base/R_Base):0);
|
||||
C_Base /= sc;
|
||||
c[i] = 1;
|
||||
if(C_Base < REV_W) c[i] = REV_W - C_Base;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
void init_hap_alignment_struct_pip(hap_alignment_struct_pip* x, uint32_t num_threads, uint32_t n_seq,
|
||||
ma_ug_t *ug, asg_t *read_g, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, ma_sub_t *coverage_cut,
|
||||
uint64_t* position_index, float Hap_rate, int max_hang, int min_ovlp, float chain_rate, hap_overlaps_list* all_ovlp, hap_cov_t *cov)
|
||||
@@ -496,6 +520,17 @@ uint64_t* position_index, float Hap_rate, int max_hang, int min_ovlp, float chai
|
||||
x->chain_rate = chain_rate;
|
||||
x->all_ovlp = all_ovlp;
|
||||
x->cov = cov;
|
||||
long long sc = -1;
|
||||
if(asm_opt.hom_global_coverage_set) {
|
||||
sc = asm_opt.hom_global_coverage*1.75;
|
||||
}
|
||||
else {
|
||||
if(asm_opt.hom_global_coverage > 0){
|
||||
sc = ((int)(((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE)))*1.75;
|
||||
}
|
||||
}
|
||||
if(sc <= 0) sc = -1;
|
||||
x->hh = init_pip_hh(read_g, reverse_sources, coverage_cut, sc);
|
||||
}
|
||||
|
||||
|
||||
@@ -508,6 +543,7 @@ void destory_hap_alignment_struct_pip(hap_alignment_struct_pip* x)
|
||||
}
|
||||
|
||||
free(x->buf);
|
||||
free(x->hh);
|
||||
}
|
||||
|
||||
void init_hap_overlaps_list(hap_overlaps_list* x, uint32_t num)
|
||||
@@ -677,15 +713,9 @@ void deduplicate_edge(kvec_asg_arc_t_offset* u_buffer)
|
||||
long long i = u_buffer->a.n - 1, k, i_off;
|
||||
uint32_t v = u_buffer->a.a[i].x.ul>>33, m;
|
||||
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
if((u_buffer->a.a[i].x.ul>>33) != v)
|
||||
{
|
||||
break;
|
||||
for (; i >= 0; i--) {
|
||||
if((u_buffer->a.a[i].x.ul>>33) != v) break;
|
||||
}
|
||||
}
|
||||
|
||||
///fprintf(stderr, "u_buffer->a.n: %u, i: %lld\n", u_buffer->a.n, i);
|
||||
|
||||
i = i + 1;
|
||||
for (m = i; i < (long long)u_buffer->a.n; i++)
|
||||
@@ -960,7 +990,7 @@ ma_hit_t_alloc* reverse_sources, asg_t *read_g, R_to_U* ruIndex, double* Match,
|
||||
uint32_t i, j, qn, tn, is_Unitig, uId, min_count = 0, max_count = 0, cutoff = 0;;
|
||||
for (i = 0; i < Len; i++)
|
||||
{
|
||||
if(cutoff > CUTOFF_THRES)
|
||||
if(cutoff > CUTOFF_THRES && cutoff > (Len>>1))
|
||||
{
|
||||
max_count = 0;
|
||||
min_count = Len;
|
||||
@@ -1758,7 +1788,7 @@ void chain_trans_ovlp(hap_cov_t *cover, utg_trans_t *o, ma_ug_t *ug, asg_t *read
|
||||
}
|
||||
|
||||
p_v = v; len += l;
|
||||
if(len >= targetBaseLen)
|
||||
if(len >= targetBaseLen)///might be not right for centromeres
|
||||
{
|
||||
xOcc = aOcc;
|
||||
break;
|
||||
@@ -2254,6 +2284,7 @@ uint32_t* xBeg, uint32_t* xEnd, uint32_t* yBeg, uint32_t* yEnd)
|
||||
|
||||
#define generic_key(x) (x)
|
||||
KRADIX_SORT_INIT(i32, int32_t, generic_key, sizeof(int32_t))
|
||||
KRADIX_SORT_INIT(ru32, uint32_t, generic_key, sizeof(uint32_t))
|
||||
|
||||
long long get_chain_score(ma_utg_t *xReads, asg_t *read_g, kvec_asg_arc_t_offset* u_buffer, kvec_t_i32_warp* tailIndex, kvec_t_i32_warp* idx,
|
||||
ma_hit_t_alloc* reverse_sources, long long xBegPos, long long xEndPos)
|
||||
@@ -2820,7 +2851,7 @@ long long y_readLen)
|
||||
{
|
||||
u_can->a.n = 0;
|
||||
if(u_buffer->a.n == 0) return;
|
||||
uint32_t i = 0, anchor_i = 0, m = 1, break_point = (uint32_t)-1, is_merge;
|
||||
uint32_t i = 0, /**anchor_i = 0, **/m = 1, break_point = (uint32_t)-1, is_merge;
|
||||
|
||||
qsort(u_buffer->a.a, u_buffer->a.n, sizeof(asg_arc_t_offset), cmp_hap_alignment_chaining);
|
||||
|
||||
@@ -2832,14 +2863,14 @@ long long y_readLen)
|
||||
if(u_buffer->a.a[m-1].x.el == u_buffer->a.a[i].x.el)
|
||||
{
|
||||
if(u_buffer->a.a[m-1].Off == u_buffer->a.a[i].Off) is_merge = 1;
|
||||
if(is_merge == 0 && (Get_xOff(u_buffer->a.a[m-1].Off)==Get_xOff(u_buffer->a.a[i].Off)))
|
||||
{
|
||||
if((Get_yOff(u_buffer->a.a[i].Off)-(Get_yOff(u_buffer->a.a[m-1].Off))) ==
|
||||
(i-anchor_i))///not sure why, does it use for tolerate indels in overlaps?
|
||||
{
|
||||
is_merge = 1;
|
||||
}
|
||||
}
|
||||
///I think we don't need the following merging
|
||||
// if(is_merge == 0 && (Get_xOff(u_buffer->a.a[m-1].Off)==Get_xOff(u_buffer->a.a[i].Off)))
|
||||
// {
|
||||
// if((Get_yOff(u_buffer->a.a[i].Off)-(Get_yOff(u_buffer->a.a[m-1].Off))) == (i-anchor_i))///not sure why, does it use for tolerate indels in overlaps?
|
||||
// {
|
||||
// is_merge = 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
if(is_merge)
|
||||
{
|
||||
@@ -2848,7 +2879,7 @@ long long y_readLen)
|
||||
}
|
||||
}
|
||||
u_buffer->a.a[m] = u_buffer->a.a[i];
|
||||
anchor_i = i;
|
||||
// anchor_i = i;
|
||||
if(u_buffer->a.a[m].x.el != u_buffer->a.a[m-1].x.el) break_point = m;
|
||||
m++;
|
||||
}
|
||||
@@ -2957,6 +2988,7 @@ static void hap_alignment_advance_worker(void *_data, long eid, int tid)
|
||||
kvec_t_u8_warp* flag_vec = &(hap_buf->buf[tid].u_buffer_flag);
|
||||
uint64_t cov_threshold = hap_buf->cov_threshold;
|
||||
hap_cov_t *cov = hap_buf->cov;
|
||||
uint8_t *hh = hap_buf->hh, hhc;
|
||||
if(hap_buf->cov_threshold < 0) cov_threshold = (uint64_t)-1;
|
||||
ma_utg_t *xReads = NULL, *yReads = NULL;
|
||||
ma_hit_t_alloc *xR = NULL;
|
||||
@@ -3036,7 +3068,7 @@ static void hap_alignment_advance_worker(void *_data, long eid, int tid)
|
||||
for (k = 0; k < xReads->n; k++)
|
||||
{
|
||||
xR = &(reverse_sources[xReads->a[k]>>33]);
|
||||
|
||||
hhc = hh[xReads->a[k]>>33];
|
||||
for (j = 0; j < xR->length; j++)
|
||||
{
|
||||
h = &(xR->buffer[j]);
|
||||
@@ -3078,7 +3110,7 @@ static void hap_alignment_advance_worker(void *_data, long eid, int tid)
|
||||
if(((t_offset.Off>>32) == (uint32_t)-1) || (((uint32_t)t_offset.Off) == (uint32_t)-1)) continue;
|
||||
|
||||
t_offset.x = t;
|
||||
t_offset.weight = 1;
|
||||
t_offset.weight = hhc;
|
||||
|
||||
kv_push(asg_arc_t_offset, u_buffer->a, t_offset);
|
||||
}
|
||||
@@ -5255,6 +5287,243 @@ void collect_purge_trans_cov(ma_ug_t *ug, hap_overlaps_list* ha, hap_cov_t *cov,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
typedef struct {
|
||||
uint32_t qn, qs, qe;
|
||||
uint32_t tn, ts, te;
|
||||
uint32_t oid;
|
||||
uint8_t rev;
|
||||
}scg_hits;
|
||||
|
||||
typedef struct {
|
||||
scg_hits *a;
|
||||
size_t n,m;
|
||||
kvec_t(uint64_t) idx;
|
||||
}scg_hits_v;
|
||||
|
||||
#define scg_key_qtn(a) ((((uint64_t)(a).qn)<<32)|((uint64_t)(a).tn))
|
||||
KRADIX_SORT_INIT(scg_qtn, scg_hits, scg_key_qtn, 8)
|
||||
#define scg_key_qts(a) ((((uint64_t)(a).qs)<<32)|((uint64_t)(a).ts))
|
||||
KRADIX_SORT_INIT(scg_qts, scg_hits, scg_key_qts, 8)
|
||||
#define scg_key_qte(a) ((((uint64_t)(a).qe)<<32)|((uint64_t)(a).te))
|
||||
KRADIX_SORT_INIT(scg_qte, scg_hits, scg_key_qte, 8)
|
||||
#define scg_key_rev(a) ((a).rev)
|
||||
KRADIX_SORT_INIT(scg_rev, scg_hits, scg_key_rev, member_size(scg_hits, rev))
|
||||
|
||||
inline void rev_scg_hits(scg_hits *p, spg_t *scg)
|
||||
{
|
||||
if(p->rev){
|
||||
uint32_t t;
|
||||
p->ts = scg->ug->u.a[p->tn].len - p->ts - 1;
|
||||
p->te = scg->ug->u.a[p->tn].len - (p->te - 1) - 1;
|
||||
t = p->ts; p->ts = p->te; p->te = t; p->te++;
|
||||
}
|
||||
}
|
||||
|
||||
#define arc_first(g, v) ((g)->arc[(g)->idx[(v)]>>32])
|
||||
scg_hits_v *get_scg_hits_v(scg_hits_v *vp, spg_t *scg)
|
||||
{
|
||||
scg_hits_v *hh = NULL; CALLOC(hh, 1);
|
||||
ma_utg_v *u = &(scg->ug->u);
|
||||
uint32_t i, mn, *ma = NULL;
|
||||
uint64_t offset, *idx = NULL;
|
||||
|
||||
for (i = 0; i < scg->idx.n; i++) {
|
||||
mn = (uint32_t)scg->idx.a[i];
|
||||
ma = scg->dst.a + (scg->idx.a[i]>>32);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return hh;
|
||||
}
|
||||
|
||||
void refine_scg(spg_t *scg, ma_ug_t *lug, hap_overlaps_list *ha, hap_cov_t *cov, uint64_t* position_index)
|
||||
{
|
||||
scg_hits_v vp; kv_init(vp);
|
||||
uint32_t v, i, k, st, c[2];
|
||||
hap_overlaps *x = NULL;
|
||||
u_trans_t *z = NULL;
|
||||
scg_hits *p = NULL;
|
||||
|
||||
for (v = 0; v < cov->t_ch->k_trans.n; v++){
|
||||
z = &(cov->t_ch->k_trans.a[v]);
|
||||
if(z->del) continue;
|
||||
kv_pushp(scg_hits, vp, &p);
|
||||
p->rev = z->rev; p->oid = (uint32_t)-1;
|
||||
p->qn = z->qn; p->qs = z->qs; p->qe = z->qe;
|
||||
p->tn = z->tn; p->ts = z->ts; p->te = z->te;
|
||||
// rev_scg_hits(p, scg);
|
||||
kv_pushp(scg_hits, vp, &p);
|
||||
p->rev = z->rev; p->oid = (uint32_t)-1;
|
||||
p->qn = z->tn; p->qs = z->ts; p->qe = z->te;
|
||||
p->tn = z->qn; p->ts = z->qs; p->te = z->qe;
|
||||
// rev_scg_hits(p, scg);
|
||||
}
|
||||
|
||||
for (v = 0; v < ha->num; v++){
|
||||
for (i = 0; i < ha->x[v].a.n; i++){
|
||||
x = &(ha->x[v].a.a[i]);
|
||||
st = cov->t_ch->k_trans.n;
|
||||
chain_origin_trans_uid_by_purge(x, lug, cov, position_index);
|
||||
for (k = st; k < cov->t_ch->k_trans.n; k++){
|
||||
z = &(cov->t_ch->k_trans.a[k]);
|
||||
if(z->del) continue;
|
||||
kv_pushp(scg_hits, vp, &p);
|
||||
p->rev = z->rev; p->oid = v;
|
||||
p->qn = z->qn; p->qs = z->qs; p->qe = z->qe;
|
||||
p->tn = z->tn; p->ts = z->ts; p->te = z->te;
|
||||
// rev_scg_hits(p, scg);
|
||||
kv_pushp(scg_hits, vp, &p);
|
||||
p->rev = z->rev; p->oid = v;
|
||||
p->qn = z->tn; p->qs = z->ts; p->qe = z->te;
|
||||
p->tn = z->qn; p->ts = z->qs; p->te = z->qe;
|
||||
// rev_scg_hits(p, scg);
|
||||
}
|
||||
cov->t_ch->k_trans.n = st;
|
||||
}
|
||||
}
|
||||
|
||||
///two scg_hits might be totally equal; must remove first
|
||||
radix_sort_scg_qtn(vp.a, vp.a + vp.n);
|
||||
for (st = 0, i = 1; i <= vp.n; ++i){
|
||||
if (i == vp.n || vp.a[i].qn != vp.a[st].qn || vp.a[i].tn != vp.a[st].tn){
|
||||
if(i - st > 1) radix_sort_scg_rev(vp.a+st, vp.a+i);
|
||||
for (v = st, c[0] = c[1] = 0; v < i; v++) c[vp.a[v].rev]++;
|
||||
if(c[0]>1) radix_sort_scg_qts(vp.a+st, vp.a+st+c[0]);
|
||||
if(c[1]>1) radix_sort_scg_qts(vp.a+st+c[0], vp.a+st+c[0]+c[1]);
|
||||
st = i;
|
||||
}
|
||||
}
|
||||
for (st = 0, i = 1; i <= vp.n; ++i){
|
||||
if (i == vp.n || vp.a[i].rev != vp.a[st].rev ||
|
||||
vp.a[i].qn != vp.a[st].qn || vp.a[i].tn != vp.a[st].tn ||
|
||||
vp.a[i].qs != vp.a[st].qs || vp.a[i].ts != vp.a[st].ts)
|
||||
{
|
||||
if(i - st > 1) radix_sort_scg_qte(vp.a+st, vp.a+i);
|
||||
st = i;
|
||||
}
|
||||
}
|
||||
for (st = 0, i = 1, k = 0; i <= vp.n; ++i){
|
||||
if (i == vp.n || vp.a[i].rev != vp.a[st].rev ||
|
||||
vp.a[i].qn != vp.a[st].qn || vp.a[i].tn != vp.a[st].tn ||
|
||||
vp.a[i].qs != vp.a[st].qs || vp.a[i].ts != vp.a[st].ts ||
|
||||
vp.a[i].qe != vp.a[st].qe || vp.a[i].te != vp.a[st].te)
|
||||
{
|
||||
vp.a[k] = vp.a[st];
|
||||
k++;
|
||||
st = i;
|
||||
}
|
||||
}
|
||||
///build idx
|
||||
vp.n = k; kv_resize(uint64_t, vp.idx, scg->ug->u.n); vp.idx.n = scg->ug->u.n;
|
||||
memset(vp.idx.a, 0, vp.idx.n*sizeof(uint64_t));
|
||||
for (st = 0, i = 1; i <= vp.n; ++i)
|
||||
{
|
||||
if (i == vp.n || vp.a[i].qn != vp.a[st].qn)
|
||||
{
|
||||
vp.idx.a[vp.a[st].qn] = (uint64_t)st << 32 | (i - st);
|
||||
st = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
kv_destroy(vp); kv_destroy(vp.idx);
|
||||
}
|
||||
**/
|
||||
uint32_t seed_uid(ma_utg_t *vu, uint64_t* ps_idx, R_to_U* ruIndex, ma_ug_t *rug)
|
||||
{
|
||||
int64_t v_i, v, w, w_i, wb, we, vb, ve, k;
|
||||
uint32_t uid, is_u;
|
||||
ma_utg_t *wu = NULL;
|
||||
for (v_i = 0; v_i < vu->n; v_i++) {
|
||||
v = vu->a[v_i]>>32;
|
||||
get_R_to_U(ruIndex, v>>1, &uid, &is_u);
|
||||
if(is_u == 0 || uid == (uint32_t)-1 || ps_idx[v>>1] == (uint64_t)-1) continue;
|
||||
w_i = (uint32_t)ps_idx[v>>1];
|
||||
wu = &(rug->u.a[uid]);
|
||||
w = wu->a[w_i]>>32;
|
||||
if((v>>1)!=(w>>1)) continue;
|
||||
vb = 0; ve = vu->n; ///[vb, ve)
|
||||
if(v == w){ ///[wb, we)
|
||||
wb = w_i - v_i;
|
||||
we = wb + vu->n;
|
||||
if(wb < 0 || we > wu->n) continue;
|
||||
for (k = 0; k < vu->n; k++){
|
||||
if((vu->a[k+vb]>>32) != (wu->a[k+wb]>>32)) break;
|
||||
}
|
||||
if(k >= vu->n) return uid;
|
||||
} else {
|
||||
wb = w_i + 1 - (ve - v_i);
|
||||
we = wb + vu->n;
|
||||
if(wb < 0 || we > wu->n) continue;
|
||||
for (k = 0; k < vu->n; k++){
|
||||
if((vu->a[k+vb]>>32) != ((wu->a[we-k-1]>>32)^1)) break;
|
||||
}
|
||||
if(k >= vu->n) return uid;
|
||||
}
|
||||
}
|
||||
return (uint32_t)-1;
|
||||
}
|
||||
|
||||
void filter_ovlp_vecs(hap_overlaps_list* ha, uint32_t *a, uint32_t a_n)
|
||||
{
|
||||
uint32_t st, k, i, m, v, w;
|
||||
int idx;
|
||||
radix_sort_ru32(a, a + a_n);
|
||||
for (st = 0, m = 0, k = 1; k <= a_n; k++){
|
||||
if(k == a_n || a[k] != a[st]){
|
||||
a[m++] = a[st];
|
||||
st = k;
|
||||
}
|
||||
}
|
||||
a_n = m;
|
||||
if(a_n < 2) return;
|
||||
for (k = 0; k < a_n; k++){
|
||||
v = a[k];
|
||||
for (i = k+1; i < a_n; i++) {
|
||||
w = a[i];
|
||||
idx = get_specific_hap_overlap(&(ha->x[v]), v, w);
|
||||
if(idx != -1) ha->x[v].a.a[idx].status = DELETE;
|
||||
idx = get_specific_hap_overlap(&(ha->x[w]), w, v);
|
||||
if(idx != -1) ha->x[w].a.a[idx].status = DELETE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void filter_ovlp_scg(hap_overlaps_list* ha, uint64_t* ps_idx, R_to_U* ruIndex, ma_ug_t *rug, spg_t *scg)
|
||||
{
|
||||
uint32_t i, k, v, *ma = NULL, mn, luid;
|
||||
ma_utg_v *pp = &(scg->ug->u);
|
||||
kvec_t(uint32_t) vv; kv_init(vv);
|
||||
for (i = 0; i < scg->idx.n; i++){
|
||||
ma = scg->dst.a + (scg->idx.a[i]>>32);
|
||||
mn = (uint64_t)scg->idx.a[i];
|
||||
if(mn < 2) continue;
|
||||
for (k = 0, vv.n = 0; k < mn; k++){
|
||||
luid = seed_uid(&(pp->a[ma[k]>>1]), ps_idx, ruIndex, rug);
|
||||
if(luid == (uint32_t)-1) {
|
||||
fprintf(stderr, "ERROR-scg\n");
|
||||
continue;
|
||||
}
|
||||
kv_push(uint32_t, vv, luid);
|
||||
}
|
||||
if(vv.n < 2) continue;
|
||||
filter_ovlp_vecs(ha, vv.a, vv.n);
|
||||
}
|
||||
|
||||
for (v = 0; v < ha->num; v++){
|
||||
for (i = 0, k = 0; i < ha->x[v].a.n; i++){
|
||||
if(ha->x[v].a.a[i].status == DELETE) continue;
|
||||
ha->x[v].a.a[k++] = ha->x[v].a.a[i];
|
||||
}
|
||||
ha->x[v].a.n = k;
|
||||
}
|
||||
|
||||
kv_destroy(vv);
|
||||
}
|
||||
|
||||
void purge_dups(ma_ug_t *ug, asg_t *read_g, ma_sub_t* coverage_cut, ma_hit_t_alloc* sources,
|
||||
ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, kvec_asg_arc_t_warp* edge, float density,
|
||||
uint32_t purege_minLen, int max_hang, int min_ovlp, float drop_ratio, uint32_t just_contain,
|
||||
@@ -5343,7 +5612,9 @@ uint32_t just_coverage, hap_cov_t *cov, uint32_t collect_p_trans, uint32_t colle
|
||||
///if(debug_enable) print_all_purge_ovlp(ug, &all_ovlp);
|
||||
filter_hap_overlaps_by_length(&all_ovlp, purege_minLen);
|
||||
|
||||
normalize_hap_overlaps_advance(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex);
|
||||
// normalize_hap_overlaps_advance(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex);
|
||||
pg = init_p_g_t(ug, cov, read_g);
|
||||
normalize_hap_overlaps_advance_by_p_g_t(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex, pg, cov, 0.8);
|
||||
|
||||
if(collect_p_trans && collect_p_trans_f == 0)
|
||||
{
|
||||
@@ -5352,7 +5623,7 @@ uint32_t just_coverage, hap_cov_t *cov, uint32_t collect_p_trans, uint32_t colle
|
||||
|
||||
if(asm_opt.polyploidy <= 2)
|
||||
{
|
||||
mc_solve(&all_ovlp, cov->t_ch, NULL, ug, read_g, 0.8, R_INF.trio_flag, 1, NULL, 1, NULL, NULL);
|
||||
mc_solve(&all_ovlp, cov->t_ch, NULL, ug, read_g, 0.8, R_INF.trio_flag, 1, NULL, 1, NULL, NULL, 1, 0);
|
||||
}
|
||||
|
||||
if(collect_p_trans && collect_p_trans_f == 1)
|
||||
@@ -5360,11 +5631,6 @@ uint32_t just_coverage, hap_cov_t *cov, uint32_t collect_p_trans, uint32_t colle
|
||||
collect_purge_trans_cov(ug, &all_ovlp, cov, position_index);
|
||||
}
|
||||
|
||||
pg = init_p_g_t(ug, cov, read_g);
|
||||
|
||||
normalize_hap_overlaps_advance_by_p_g_t(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources,
|
||||
ruIndex, pg, cov, 0.8);
|
||||
|
||||
///normalize_hap_overlaps_advance(&all_ovlp, &back_all_ovlp, ug, read_g, reverse_sources, ruIndex);
|
||||
///debug_hap_overlaps(&all_ovlp, &back_all_ovlp);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifndef __PURGEDUPS__
|
||||
#define __PURGEDUPS__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "kvec.h"
|
||||
@@ -12,6 +14,7 @@
|
||||
#define ALTER_COV_THRES 0.9
|
||||
#define REAL_ALTER_THRES 0.25
|
||||
#define CHAIN_FILTER_RATE 0.7
|
||||
#define REV_W 8
|
||||
|
||||
#define SELF_EXIST 0
|
||||
#define REVE_EXIST 1
|
||||
|
||||
@@ -15,6 +15,9 @@ hifiasm -o CHM13.asm -t32 -l0 CHM13-HiFi.fa.gz 2> CHM13.asm.log
|
||||
# Assemble heterozygous genomes with built-in duplication purging
|
||||
hifiasm -o HG002.asm -t32 HG002-file1.fq.gz HG002-file2.fq.gz
|
||||
|
||||
# Assemble genomes with ONT R10 reads rather than PacBio HiFi reads using the latest release of hifiasm (>0.21.0-r686)
|
||||
hifiasm -o HG002.asm --ont -t32 HG002-ont.fq.gz
|
||||
|
||||
# Hi-C phasing with paired-end short reads in two FASTQ files
|
||||
hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
|
||||
|
||||
@@ -22,6 +25,19 @@ hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
|
||||
yak count -b37 -t16 -o pat.yak <(cat pat_1.fq.gz pat_2.fq.gz) <(cat pat_1.fq.gz pat_2.fq.gz)
|
||||
yak count -b37 -t16 -o mat.yak <(cat mat_1.fq.gz mat_2.fq.gz) <(cat mat_1.fq.gz mat_2.fq.gz)
|
||||
hifiasm -o HG002.asm -t32 -1 pat.yak -2 mat.yak HG002-HiFi.fa.gz
|
||||
|
||||
# Improve contiguity for diploid genome assembly by self-scaffolding (`--dual-scaf`)
|
||||
hifiasm -o HG002.asm --dual-scaf --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
|
||||
|
||||
# Preserve more telomeres for human genomes (`--telo-m CCCTAA`)
|
||||
hifiasm -o HG002.asm --telo-m CCCTAA --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
|
||||
|
||||
# Hybrid assembly with HiFi, ultralong and Hi-C reads
|
||||
hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz --ul ul.fq.gz HG002-HiFi.fq.gz
|
||||
|
||||
# Single-sample telomere-to-telomere assembly for diploid human genomes
|
||||
hifiasm -o HG002.asm --dual-scaf --telo-m CCCTAA --h1 read1.fq.gz --h2 read2.fq.gz --ul ul.fq.gz HG002-HiFi.fq.gz
|
||||
|
||||
```
|
||||
See [tutorial][tutorial] for more details.
|
||||
|
||||
@@ -32,8 +48,10 @@ See [tutorial][tutorial] for more details.
|
||||
- [Why Hifiasm?](#why)
|
||||
- [Usage](#use)
|
||||
- [Assembling HiFi reads without additional data types](#hifionly)
|
||||
- [Assembling ONT reads](#ontonly)
|
||||
- [Hi-C integration](#hic)
|
||||
- [Trio binning](#trio)
|
||||
- [Ultra-long ONT integration](#ul)
|
||||
- [Output files](#output)
|
||||
- [Results](#results)
|
||||
- [Getting Help](#help)
|
||||
@@ -42,15 +60,12 @@ See [tutorial][tutorial] for more details.
|
||||
|
||||
## <a name="intro"></a>Introduction
|
||||
|
||||
Hifiasm is a fast haplotype-resolved de novo assembler for PacBio HiFi reads.
|
||||
It can assemble a human genome in several hours and assemble a ~30Gb California
|
||||
redwood genome in a few days. Hifiasm emits partially phased assemblies of
|
||||
quality competitive with the best assemblers. Given parental short reads or
|
||||
Hi-C data, it produces arguably the best haplotype-resolved assemblies so far.
|
||||
Hifiasm is a fast haplotype-resolved de novo assembler initially designed for PacBio HiFi reads.
|
||||
Its latest release could support the telomere-to-telomere assembly by utilizing ultralong Oxford Nanopore reads. Hifiasm produces arguably the best single-sample telomere-to-telomere assemblies combing HiFi, ultralong and Hi-C reads, and it is one of the best haplotype-resolved assemblers for the trio-binning assembly given parental short reads. For a human genome, hifiasm can produce the telomere-to-telomere assembly in one day.
|
||||
|
||||
## <a name="why"></a>Why Hifiasm?
|
||||
|
||||
* Hifiasm delivers high-quality assemblies. It tends to generate longer contigs
|
||||
* Hifiasm delivers high-quality telomere-to-telomere assemblies. It tends to generate longer contigs
|
||||
and resolve more segmental duplications than other assemblers.
|
||||
|
||||
* Given Hi-C reads or short reads from the parents, hifiasm can produce overall the best
|
||||
@@ -105,6 +120,16 @@ bloom filter which takes 16GB memory at the beginning. For genomes much larger
|
||||
than human, applying `-f38` or even `-f39` is preferred to save memory on k-mer
|
||||
counting.
|
||||
|
||||
### <a name="ontonly"></a>Assembling ONT reads
|
||||
|
||||
Since version 0.21.0 (r686), hifiasm can support ONT assembly using ONT simplex R10 reads.
|
||||
To enable this feature, add the `--ont` option as shown below:
|
||||
```sh
|
||||
hifiasm -t64 --ont -o ONT.asm ONT.read.fastq.gz
|
||||
```
|
||||
Please note that this module requires input reads in FASTQ format.
|
||||
|
||||
|
||||
### <a name="hic"></a>Hi-C integration
|
||||
|
||||
Hifiasm can generate a pair of haplotype-resolved assemblies with paired-end
|
||||
@@ -143,6 +168,39 @@ hifiasm -o NA12878.asm -t 32 -1 pat.yak -2 mat.yak /dev/null 2> NA12878.asm.trio
|
||||
```
|
||||
The second command line will run much faster than the first.
|
||||
|
||||
### <a name="ul"></a>Ultra-long ONT integration
|
||||
|
||||
Hifiasm could integrate ultra-long ONT reads to produce the telomere-to-telomere assembly:
|
||||
```sh
|
||||
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz HiFi-reads.fq.gz
|
||||
```
|
||||
For the single-sample telomere-to-telomere assembly with Hi-C reads:
|
||||
```sh
|
||||
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz --h1 read1.fq.gz --h2 read2.fq.gz HiFi-reads.fq.gz
|
||||
```
|
||||
For the trio-binning telomere-to-telomere assembly:
|
||||
```sh
|
||||
hifiasm -o NA12878.asm -t32 --ul ul.fq.gz -1 pat.yak -2 mat.yak HiFi-reads.fq.gz
|
||||
```
|
||||
|
||||
### <a name="ul"></a>Self-scaffolding
|
||||
|
||||
For diploid haplotype-resolved genome assembly, hifiasm can further enhance assembly contiguity
|
||||
by introducing scaffolding. It leverages the assemblies of the two haplotypes to scaffold each other.
|
||||
Specifically, if there is a gap within the haplotype 1 assembly, hifiasm will use the corresponding
|
||||
homologous region in haplotype 2 to scaffold haplotype 1. Below is an example using the `--dual-scaf` option.
|
||||
```sh
|
||||
hifiasm -o NA12878.asm -t32 --dual-scaf HiFi-reads.fq.gz
|
||||
```
|
||||
|
||||
### <a name="ul"></a>Preserve more telomeres for T2T assemblies
|
||||
|
||||
Hifiasm can preserve more telomeres by specifying the telomere motif using the `--telo-m` option.
|
||||
Below is an example applied to human genome assembly.
|
||||
```sh
|
||||
hifiasm -o NA12878.asm -t32 --telo-m CCCTAA HiFi-reads.fq.gz
|
||||
```
|
||||
|
||||
### <a name="output"></a>Output files
|
||||
|
||||
Hifiasm generates different types of assemblies based on the input data.
|
||||
@@ -226,3 +284,13 @@ If you use hifiasm in your work, please cite:
|
||||
> Haplotype-resolved de novo assembly using phased assembly graphs with
|
||||
> hifiasm. *Nat Methods*, **18**:170-175.
|
||||
> https://doi.org/10.1038/s41592-020-01056-5
|
||||
|
||||
> Cheng, H., Jarvis, E.D., Fedrigo, O., Koepfli, K.P., Urban, L., Gemmell, N.J., Li, H. (2022)
|
||||
> Haplotype-resolved assembly of diploid genomes without parental data.
|
||||
> *Nature Biotechnology*, **40**:1332–1335.
|
||||
> https://doi.org/10.1038/s41587-022-01261-x
|
||||
|
||||
> Cheng, H., Asri, M., Lucas, J., Koren, S., Li, H. (2024)
|
||||
> Scalable telomere-to-telomere assembly for diploid and polyploid genomes with double graph.
|
||||
> *Nat Methods*, **21**:967-970.
|
||||
> https://doi.org/10.1038/s41592-024-02269-8
|
||||
|
||||
@@ -349,6 +349,197 @@ static void ha_triobin_list(const hifiasm_opt_t *opt)
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> partitioned reads with external lists\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
}
|
||||
|
||||
uint32_t test_yak_binning(char* fn, char *cmd)
|
||||
{
|
||||
gzFile fp; kstream_t *ks; kstring_t str = {0,0,0};
|
||||
int dret, eq = 0; fp = gzopen(fn, "r");
|
||||
if (fp == 0) return eq;
|
||||
ks = ks_init(fp);
|
||||
if(ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) {
|
||||
uint64_t sl = strlen(str.s), z;
|
||||
for (z = 0; (z < sl) && (str.s[z]!='\t'); z++);
|
||||
if(((z+1)<sl) && (str.s[z]=='\t')) {
|
||||
if((strlen(str.s+z+1)==strlen(cmd)) && (!memcmp(str.s+z+1, cmd, strlen(cmd)))) {
|
||||
eq = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(str.s);
|
||||
ks_destroy(ks);
|
||||
gzclose(fp);
|
||||
return eq;
|
||||
}
|
||||
|
||||
inline void phrase_hstatus(char *s, char **rname, uint32_t *hid)
|
||||
{
|
||||
char *p = NULL, *id = NULL; *rname = NULL; *hid = (uint32_t)-1;
|
||||
uint32_t tot;
|
||||
for (p = s, tot = 0; *p; ++p){
|
||||
if (*p == '\t' || *p == ' '){
|
||||
*p = 0;
|
||||
if(!tot) *rname = p+1;
|
||||
else break;
|
||||
tot++;
|
||||
}
|
||||
}
|
||||
for (p = s, tot = 0; *p; ++p){
|
||||
if (*p == '_') id = p + 1;
|
||||
}
|
||||
*hid = atoi(id);
|
||||
}
|
||||
|
||||
inline void phrase_hchar(char *s, char **rname, uint32_t *hid)
|
||||
{
|
||||
*rname = NULL; *hid = (uint32_t)-1;
|
||||
uint32_t tot = 0, k, l, z, sl = strlen(s);
|
||||
for (k = 1, l = 0; k <= sl; k++) {
|
||||
if((k == sl) || (s[k] == '\t') || (s[k] == ' ')) {
|
||||
if(k > l) {
|
||||
s[k] = 0;
|
||||
if(tot == 0) {
|
||||
*rname = s + l;
|
||||
} else if(tot == 1) {
|
||||
for (z = l; (z < k) && (s[z] >= '0') && (s[z] <= '9'); ++z);
|
||||
if(z < k) {
|
||||
fprintf(stderr, "ERROR: wrong hap id\n");
|
||||
return;
|
||||
}
|
||||
*hid = atoi(s + l);
|
||||
}
|
||||
tot++;
|
||||
}
|
||||
l = k + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t *ha_polybin_list(const hifiasm_opt_t *opt)
|
||||
{
|
||||
int64_t i;
|
||||
khint_t k;
|
||||
cstr_ht_t *h;
|
||||
assert(R_INF.total_reads < (uint32_t)-1);
|
||||
h = cstr_ht_init();
|
||||
for (i = 0; i < (int64_t)R_INF.total_reads; ++i) {
|
||||
int absent;
|
||||
char *str = (char*)calloc(Get_NAME_LENGTH(R_INF, i) + 1, 1);
|
||||
strncpy(str, Get_NAME(R_INF, i), Get_NAME_LENGTH(R_INF, i));
|
||||
k = cstr_ht_put(h, str, &absent);
|
||||
if (absent) kh_val(h, k) = i;
|
||||
}
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] created the hash table for read names\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
|
||||
gzFile fp;
|
||||
kstream_t *ks;
|
||||
kstring_t str = {0,0,0};
|
||||
char *rname = NULL;
|
||||
uint32_t hid, *ss = NULL;
|
||||
int dret;
|
||||
int64_t n_tot = 0, n_bin = 0;
|
||||
fp = gzopen(opt->fn_bin_poy, "r");
|
||||
if (fp == 0) {
|
||||
fprintf(stderr, "ERROR: failed to open file '%s'\n", opt->fn_bin_poy);
|
||||
for (k = 0; k < kh_end(h); ++k)
|
||||
if (kh_exist(h, k))
|
||||
free((char*)kh_key(h, k));
|
||||
cstr_ht_destroy(h);
|
||||
return NULL;
|
||||
}
|
||||
CALLOC(ss, R_INF.total_reads);
|
||||
ks = ks_init(fp);
|
||||
while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) {
|
||||
khint_t k; ++n_tot;
|
||||
phrase_hstatus(str.s, &rname, &hid);
|
||||
if((!(*rname)) || hid == (uint32_t)-1) {
|
||||
fprintf(stderr, "ERROR: wrong hap status\n");
|
||||
continue;
|
||||
}
|
||||
k = cstr_ht_get(h, rname);
|
||||
if (k != kh_end(h)) {
|
||||
ss[kh_val(h, k)] |= (((uint32_t)1)<<(hid-1));
|
||||
++n_bin;
|
||||
}
|
||||
}
|
||||
free(str.s);
|
||||
ks_destroy(ks);
|
||||
gzclose(fp);
|
||||
|
||||
for (k = 0; k < kh_end(h); ++k)
|
||||
if (kh_exist(h, k))
|
||||
free((char*)kh_key(h, k));
|
||||
cstr_ht_destroy(h);
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> partitioned reads with external lists\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
return ss;
|
||||
}
|
||||
|
||||
uint32_t *ha_charbin_list(const hifiasm_opt_t *opt, uint8_t **idx, uint32_t *idx_n)
|
||||
{
|
||||
int64_t i;
|
||||
khint_t k;
|
||||
cstr_ht_t *h; (*idx) = NULL; *idx_n = 0;
|
||||
assert(R_INF.total_reads < (uint32_t)-1);
|
||||
h = cstr_ht_init();
|
||||
for (i = 0; i < (int64_t)R_INF.total_reads; ++i) {
|
||||
int absent;
|
||||
char *str = (char*)calloc(Get_NAME_LENGTH(R_INF, i) + 1, 1);
|
||||
strncpy(str, Get_NAME(R_INF, i), Get_NAME_LENGTH(R_INF, i));
|
||||
k = cstr_ht_put(h, str, &absent);
|
||||
if (absent) kh_val(h, k) = i;
|
||||
}
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] created the hash table for read names\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
|
||||
gzFile fp;
|
||||
kstream_t *ks;
|
||||
kstring_t str = {0,0,0};
|
||||
char *rname = NULL;
|
||||
uint32_t hid, mhid = 0, *ss = NULL;
|
||||
int dret;
|
||||
int64_t n_tot = 0, n_bin = 0;
|
||||
fp = gzopen(opt->fn_chr_bin, "r");
|
||||
if (fp == 0) {
|
||||
fprintf(stderr, "ERROR: failed to open file '%s'\n", opt->fn_chr_bin);
|
||||
for (k = 0; k < kh_end(h); ++k)
|
||||
if (kh_exist(h, k))
|
||||
free((char*)kh_key(h, k));
|
||||
cstr_ht_destroy(h);
|
||||
return NULL;
|
||||
}
|
||||
MALLOC(ss, R_INF.total_reads); memset(ss, -1, sizeof((*ss))*R_INF.total_reads);
|
||||
ks = ks_init(fp);
|
||||
while (ks_getuntil(ks, KS_SEP_LINE, &str, &dret) >= 0) {
|
||||
khint_t k; ++n_tot;
|
||||
phrase_hchar(str.s, &rname, &hid);
|
||||
if((!(*rname)) || hid == (uint32_t)-1) {
|
||||
fprintf(stderr, "ERROR: wrong hap id\n");
|
||||
continue;
|
||||
}
|
||||
k = cstr_ht_get(h, rname);
|
||||
if (k != kh_end(h)) {
|
||||
ss[kh_val(h, k)] = hid;
|
||||
if(hid > mhid) mhid = hid;
|
||||
++n_bin;
|
||||
// fprintf(stderr, "%s\t%u\trid::%ld\n", rname, hid, kh_val(h, k));
|
||||
}
|
||||
}
|
||||
free(str.s);
|
||||
ks_destroy(ks);
|
||||
gzclose(fp);
|
||||
|
||||
for (k = 0; k < kh_end(h); ++k)
|
||||
if (kh_exist(h, k))
|
||||
free((char*)kh_key(h, k));
|
||||
cstr_ht_destroy(h);
|
||||
|
||||
mhid++; CALLOC((*idx), mhid);
|
||||
for (i = 0; i < (int64_t)R_INF.total_reads; ++i) {
|
||||
if(ss[i] >= mhid) continue;
|
||||
(*idx)[ss[i]] = 1;
|
||||
}
|
||||
*idx_n = mhid;
|
||||
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> partitioned reads with external lists\n", __func__, yak_realtime(), yak_cpu_usage());
|
||||
return ss;
|
||||
}
|
||||
|
||||
void ha_triobin(const hifiasm_opt_t *opt)
|
||||
{
|
||||
memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t));
|
||||
|
||||
+3719
-16
File diff suppressed because it is too large
Load Diff
+10859
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,24 @@
|
||||
#ifndef __ECOVLP_PARSER__
|
||||
#define __ECOVLP_PARSER__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
#include "Hash_Table.h"
|
||||
#include "Process_Read.h"
|
||||
#include "kdq.h"
|
||||
|
||||
|
||||
void prt_chain(overlap_region_alloc *o);
|
||||
void cal_ec_r(uint64_t n_thre, uint64_t round, uint64_t n_round, uint64_t n_a, uint64_t is_sv, uint64_t *tot_b, uint64_t *tot_e);
|
||||
void sl_ec_r(uint64_t n_thre, uint64_t n_a);
|
||||
void cal_ov_r(uint64_t n_thre, uint64_t n_a, uint64_t new_idx);
|
||||
void handle_chemical_r(uint64_t n_thre, uint64_t n_a);
|
||||
void handle_chemical_arc(uint64_t n_thre, uint64_t n_a);
|
||||
uint8_t* gen_chemical_arc_rf(uint64_t n_thre, uint64_t n_a);
|
||||
void cal_ec_r_dbg(uint64_t n_thre, uint64_t n_a);
|
||||
void write_ec_reads(const char *suffix_ou, cc_v *cvt, uint8_t is_rev);
|
||||
void destroy_cc_v(cc_v *z);
|
||||
void gen_gfa_bam(ma_ug_t *ug, uint64_t n_a);
|
||||
void clean_arc_rf(uint64_t n_thre, uint64_t n_a);
|
||||
|
||||
#endif
|
||||
+204
@@ -0,0 +1,204 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <zlib.h>
|
||||
#include <math.h>
|
||||
#include "kseq.h" // FASTA/Q parser
|
||||
#include "kavl.h"
|
||||
#include "khash.h"
|
||||
#include "kalloc.h"
|
||||
#include "kthread.h"
|
||||
#include "inter.h"
|
||||
#include "Overlaps.h"
|
||||
#include "CommandLines.h"
|
||||
#include "htab.h"
|
||||
#include "Hash_Table.h"
|
||||
#include "Correct.h"
|
||||
#include "Process_Read.h"
|
||||
#include "Assembly.h"
|
||||
#include "gchain_map.h"
|
||||
KSEQ_INIT(gzFile, gzread)
|
||||
void ul_map_lchain(ha_abufl_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, const ul_idx_t *uref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres,
|
||||
int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, overlap_region* f_cigar, kvec_t_u64_warp* dbg_ct, st_mt_t *sp, uint32_t *high_occ, uint32_t *low_occ, uint32_t is_accurate, uint32_t gen_off, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut);
|
||||
|
||||
typedef struct { // global data structure for kt_pipeline()
|
||||
const void *ha_flt_tab;
|
||||
const ha_pt_t *ha_idx;
|
||||
const mg_idxopt_t *opt;
|
||||
const ma_ug_t *ug;
|
||||
const asg_t *rg;
|
||||
const ug_opt_t *uopt;
|
||||
const ul_idx_t *uu;
|
||||
ucr_file_t *ucr_s;
|
||||
kseq_t *ks;
|
||||
int64_t chunk_size;
|
||||
uint64_t n_thread;
|
||||
uint64_t total_base;
|
||||
uint64_t total_pair;
|
||||
uint64_t num_bases, num_corrected_bases, num_recorrected_bases;
|
||||
uint64_t remap, mini_cut;
|
||||
} gmap_t;
|
||||
|
||||
typedef struct { // data structure for each step in kt_pipeline()
|
||||
const mg_idxopt_t *opt;
|
||||
const void *ha_flt_tab;
|
||||
const ha_pt_t *ha_idx;
|
||||
const ma_ug_t *ug;
|
||||
const asg_t *rg;
|
||||
const ug_opt_t *uopt;
|
||||
const ul_idx_t *uu;
|
||||
int n, m, sum_len;
|
||||
uint64_t *len, id;
|
||||
char **seq;
|
||||
// ha_mzl_v *mzs;///useless
|
||||
// st_mt_t *sps;///useless
|
||||
// mg_gchains_t **gcs;///useless
|
||||
mg_tbuf_t **buf;///useless
|
||||
ha_ovec_buf_t **hab;
|
||||
kv_ul_ov_t *res;
|
||||
// glchain_t *ll;
|
||||
// gdpchain_t *gdp;
|
||||
// glchain_t *sec_ll;
|
||||
uint64_t num_bases, num_corrected_bases, num_recorrected_bases, mini_cut;
|
||||
int64_t n_thread;
|
||||
} sstep_t;
|
||||
|
||||
/**
|
||||
static void worker_ul_map(void *data, long i, int tid) // callback for kt_for()
|
||||
{
|
||||
sstep_t *s = (sstep_t*)data;
|
||||
ha_ovec_buf_t *b = s->hab[tid];
|
||||
kv_ul_ov_t *res = (s->res?(&(s->res[tid])):(NULL));
|
||||
mg_tbuf_t *buf = (s->buf?s->buf[tid]:NULL);
|
||||
int64_t winLen = MIN((((double)THRESHOLD_MAX_SIZE)/s->opt->diff_ec_ul), WINDOW);
|
||||
int fully_cov, abnormal;
|
||||
assert(UL_INF.a[s->id+i].rlen == s->len[i]);
|
||||
// if(s->id+i!=43) return;
|
||||
|
||||
ul_map_lchain(b->abl, i, s->seq[i], s->len[i], s->opt->w, s->opt->k, s->uu, &b->olist, &b->olist_hp, &b->clist, s->opt->bw_thres,
|
||||
s->opt->max_n_chain, 1, NULL, &(b->tmp_region), NULL, &(b->sp), s->mini_cut, 0);
|
||||
|
||||
clear_Cigar_record(&b->cigar1);
|
||||
clear_Round2_alignment(&b->round2);
|
||||
|
||||
b->self_read.seq = s->seq[i]; b->self_read.length = s->len[i]; b->self_read.size = 0;
|
||||
lchain_align(&b->olist, s->uu, &b->self_read, &b->correct, &b->ovlp_read, &b->POA_Graph, &b->DAGCon,
|
||||
&b->cigar1, &b->hap, &b->round2, &b->r_buf, &(b->tmp_region.w_list), 0, 1, &fully_cov, &abnormal, s->opt->diff_ec_ul, winLen, NULL);
|
||||
|
||||
// gl_chain_refine(&b->olist, &b->correct, &b->hap, bl, s->uu, s->opt->diff_ec_ul, winLen, s->len[i], km);
|
||||
gl_chain_refine_advance_combine(s->buf[tid], &(UL_INF.a[s->id+i]), &b->olist, &b->correct, &b->hap, &(s->sps[tid]), bl, &(s->gdp[tid]), s->uu, s->opt->diff_ec_ul, winLen, s->len[i], s->uopt, s->id+i, tid, NULL);
|
||||
|
||||
memset(&b->self_read, 0, sizeof(b->self_read));
|
||||
if(UL_INF.a[s->id+i].dd) {
|
||||
free(s->seq[i]); s->seq[i] = NULL; b->num_correct_base++;
|
||||
}
|
||||
s->hab[tid]->num_read_base++;
|
||||
}
|
||||
|
||||
static void *worker_gmap_work_ovec_pip(void *data, int step, void *in) // callback for kt_pipeline()
|
||||
{
|
||||
gmap_t *p = (gmap_t*)data;
|
||||
if (step == 0) { // step 1: read a block of sequences
|
||||
int32_t ret; uint64_t l; sstep_t *s; CALLOC(s, 1);
|
||||
s->ha_flt_tab = p->ha_flt_tab; s->ha_idx = p->ha_idx; s->id = p->total_pair;
|
||||
s->opt = p->opt; s->uu = p->uu; s->uopt = p->uopt; s->rg = p->rg; s->mini_cut = p->mini_cut;///need set
|
||||
while ((ret = kseq_read(p->ks)) >= 0) {
|
||||
if (p->ks->seq.l < (uint64_t)p->opt->k) continue;
|
||||
if (s->n == s->m) {
|
||||
s->m = s->m < 16? 16 : s->m + (s->n>>1);
|
||||
REALLOC(s->len, s->m);
|
||||
REALLOC(s->seq, s->m);
|
||||
}
|
||||
if(!(p->remap)) {
|
||||
append_ul_t(&UL_INF, NULL, p->ks->name.s, p->ks->name.l, NULL, 0, NULL, 0, P_CHAIN_COV, s->uopt, 0);
|
||||
}
|
||||
l = p->ks->seq.l;
|
||||
MALLOC(s->seq[s->n], l);
|
||||
s->sum_len += l;
|
||||
memcpy(s->seq[s->n], p->ks->seq.s, l);
|
||||
s->len[s->n++] = l;
|
||||
if (s->sum_len >= p->chunk_size) break;
|
||||
}
|
||||
p->total_pair += s->n;
|
||||
if (s->sum_len == 0) free(s);
|
||||
else return s;
|
||||
}
|
||||
else if (step == 1) { // step 2: alignment
|
||||
sstep_t *s = (sstep_t*)in; uint64_t i;
|
||||
CALLOC(s->hab, p->n_thread);
|
||||
CALLOC(s->buf, p->n_thread);
|
||||
if(!(p->remap)) CALLOC(s->res, p->n_thread);//for results
|
||||
for (i = 0; i < p->n_thread; ++i) {
|
||||
s->hab[i] = ha_ovec_init(0, 0, 1); s->buf[i] = mg_tbuf_init();
|
||||
}
|
||||
// kt_for(p->n_thread, worker_for_ul_scall_alignment, s, s->n);
|
||||
|
||||
for (i = 0; i < p->n_thread; ++i) {
|
||||
s->num_bases += s->hab[i]->num_read_base;
|
||||
s->num_corrected_bases += s->hab[i]->num_correct_base;
|
||||
s->num_recorrected_bases += s->hab[i]->num_recorrect_base;
|
||||
ha_ovec_destroy(s->hab[i]); mg_tbuf_destroy(s->buf[i]);
|
||||
}
|
||||
free(s->hab); free(s->buf);
|
||||
return s;
|
||||
}
|
||||
else if (step == 2) { // step 3: dump
|
||||
sstep_t *s = (sstep_t*)in;
|
||||
uint64_t i, rid, sn = s->n;
|
||||
p->num_bases += s->num_bases;
|
||||
p->num_corrected_bases += s->num_corrected_bases;
|
||||
p->num_recorrected_bases += s->num_recorrected_bases;
|
||||
if(!(p->remap)) {
|
||||
for (i = 0; i < p->n_thread; ++i) {
|
||||
push_uc_block_t(s->uopt, &(s->res[i]), s->seq, s->len, s->id);
|
||||
kv_destroy(s->res[i]);
|
||||
}
|
||||
free(s->res);
|
||||
|
||||
for (i = 0; i < sn; ++i) {
|
||||
rid = s->id + i;
|
||||
if((UL_INF.n <= rid) || (UL_INF.n > rid && UL_INF.a[rid].rlen != s->len[i])) {///reads without alignment
|
||||
append_ul_t(&UL_INF, &rid, NULL, 0, s->seq[i], s->len[i], NULL, 0, P_CHAIN_COV, s->uopt, 0);
|
||||
}
|
||||
free(s->seq[i]);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < sn; ++i) {
|
||||
rid = s->id + i;
|
||||
if(UL_INF.a[rid].dd == 0 && p->ucr_s && p->ucr_s->flag == 1) {
|
||||
assert(s->seq[i]);
|
||||
///for debug interval
|
||||
write_compress_base_disk(p->ucr_s->fp, rid, s->seq[i], s->len[i], &(p->ucr_s->u));
|
||||
}
|
||||
free(s->seq[i]);
|
||||
}
|
||||
}
|
||||
free(s->len); free(s->seq); free(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
**/
|
||||
|
||||
// int gmap_work_ovec(gmap_t* sl, const enzyme *fn)
|
||||
// {
|
||||
// double index_time = yak_realtime();
|
||||
// int i;
|
||||
|
||||
// init_all_ul_t(&UL_INF, &R_INF);
|
||||
// for (i = 0; i < fn->n; i++){
|
||||
// gzFile fp;
|
||||
// if ((fp = gzopen(fn->a[i], "r")) == 0) return 0;
|
||||
// sl->ks = kseq_init(fp);
|
||||
// kt_pipeline(3, worker_gmap_work_ovec_pip, sl, 3);
|
||||
// kseq_destroy(sl->ks);
|
||||
// gzclose(fp);
|
||||
// }
|
||||
// sl->hits.total_base = sl->total_base;
|
||||
// sl->hits.total_pair = sl->total_pair;
|
||||
// fprintf(stderr, "[M::%s::%.3f] ==> Qualification\n", __func__, yak_realtime()-index_time);
|
||||
// fprintf(stderr, "[M::%s::] ==> # reads: %lu, # bases: %lu\n", __func__, UL_INF.n, sl->total_base);
|
||||
// fprintf(stderr, "[M::%s::] ==> # bases: %lu; # corrected bases: %lu; # recorrected bases: %lu\n",
|
||||
// __func__, sl->num_bases, sl->num_corrected_bases, sl->num_recorrected_bases);
|
||||
// gen_ul_vec_rid_t(&UL_INF, &R_INF, NULL);
|
||||
// return 1;
|
||||
// }
|
||||
@@ -0,0 +1,6 @@
|
||||
#ifndef __INTER__
|
||||
#define __INTER__
|
||||
#include "Overlaps.h"
|
||||
#include "Process_Read.h"
|
||||
|
||||
#endif
|
||||
+18413
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
#ifndef __GFA_UT__
|
||||
#define __GFA_UT__
|
||||
#include "Overlaps.h"
|
||||
#include "hic.h"
|
||||
|
||||
#define is_contain_r(ri, z) (((z)<(ri).len)&&((ri).index[(z)]!=(uint32_t)(-1))&&(!((ri).index[(z)]>>31)))
|
||||
|
||||
typedef struct {
|
||||
asg_t *g;
|
||||
ma_hit_t_alloc *src;
|
||||
ma_sub_t *cov;
|
||||
R_to_U* ruIndex;
|
||||
int64_t max_hang;
|
||||
int64_t min_ovlp;
|
||||
int64_t ul_occ;
|
||||
} sset_aux;
|
||||
|
||||
void ul_clean_gfa(ug_opt_t *uopt, asg_t *sg, ma_hit_t_alloc *src, ma_hit_t_alloc *rev, R_to_U* rI, int64_t clean_round, double min_ovlp_drop_ratio, double max_ovlp_drop_ratio,
|
||||
double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, int32_t is_ou, int32_t is_trio, uint32_t ou_thres, uint8_t *cmk, char *o_file);
|
||||
uint32_t asg_arc_cut_tips(asg_t *g, uint32_t max_ext, asg64_v *in, uint32_t is_ou, R_to_U *ru, telo_end_t *te);
|
||||
void asg_iterative_semi_circ(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, uint32_t normal_len, uint32_t pop_chimer, asg64_v *dbg, telo_end_t *te);
|
||||
void asg_arc_cut_chimeric(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, uint32_t ou_thres, telo_end_t *te);
|
||||
void asg_arc_cut_inexact(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, int32_t max_ext, uint32_t is_ou, uint32_t is_trio, uint32_t min_diff, float ou_rat/**, asg64_v *dbg**/);
|
||||
void asg_arc_cut_length(asg_t *g, asg64_v *in, int32_t max_ext, float len_rat, float ou_rat, uint32_t is_ou, uint32_t is_trio,
|
||||
uint32_t is_topo, uint32_t min_diff, uint32_t min_ou, ma_hit_t_alloc *rev, R_to_U* rI, uint32_t *max_drop_len);
|
||||
void asg_arc_cut_bub_links(asg_t *g, asg64_v *in, float len_rat, float sec_len_rat, float ou_rat, uint32_t is_ou, uint64_t check_dist, ma_hit_t_alloc *rev, R_to_U* rI, int32_t max_ext);
|
||||
void asg_arc_cut_complex_bub_links(asg_t *g, asg64_v *in, float len_rat, float ou_rat, uint32_t is_ou, bub_label_t *b_mask_t);
|
||||
uint32_t asg_cut_large_indel(asg_t *g, asg64_v *in, int32_t max_ext, float ou_rat, uint32_t is_ou, uint32_t min_diff);
|
||||
uint32_t asg_cut_semi_circ(asg_t *g, uint32_t lim_len, uint32_t is_clean);
|
||||
void ul_realignment_gfa(ug_opt_t *uopt, asg_t *sg, int64_t clean_round, double min_ovlp_drop_ratio,
|
||||
double max_ovlp_drop_ratio, int64_t max_tip, int64_t max_ul_tip, bub_label_t *b_mask_t, uint32_t is_trio, char *o_file, ul_renew_t *ropt, const char *bin_file, uint64_t free_uld, uint64_t is_bridg, uint64_t deep_clean);
|
||||
void recover_contain_g(asg_t *g, ma_hit_t_alloc *src, R_to_U* ruIndex, int64_t max_hang, int64_t min_ovlp, int64_t ul_occ);
|
||||
void normalize_gou(asg_t *g);
|
||||
void prt_specfic_sge(asg_t *g, uint32_t src, uint32_t dst, const char* cmd);
|
||||
asg_t *gen_ng(ma_ug_t *ug, asg_t *sg, ug_opt_t *uopt, ma_sub_t **cov, R_to_U *ruI, uint64_t scaffold_len);
|
||||
void post_rescue(ug_opt_t *uopt, asg_t *sg, ma_hit_t_alloc *src, ma_hit_t_alloc *rev, R_to_U* rI, bub_label_t *b_mask_t, long long no_trio_recover, uint8_t *cmk);
|
||||
// void print_raw_u2rgfa_seq(all_ul_t *aln, R_to_U* rI, uint32_t is_detail);
|
||||
bubble_type *gen_bubble_chain(asg_t *sg, ma_ug_t *ug, ug_opt_t *uopt, uint8_t **ir_het, uint8_t avoid_het);
|
||||
void filter_sg_by_ug(asg_t *rg, ma_ug_t *ug, ug_opt_t *uopt);
|
||||
void ug_ext_gfa(ug_opt_t *uopt, asg_t *sg, uint32_t max_len);
|
||||
void update_sg_uo(asg_t *g, ma_hit_t_alloc *src);
|
||||
uint32_t get_arcs(asg_t *g, uint32_t v, uint32_t* idx, uint32_t idx_n);
|
||||
uint64_t ug_occ_w(uint64_t is, uint64_t ie, ma_utg_t *u);
|
||||
void hc_dbg_prt_ma_hit_t(const char *ids0[], uint64_t n0, const uint64_t iids0[], uint64_t ni0, const char* cmd, ma_hit_t_alloc *paf, R_to_U* ruIndex, ma_sub_t* cov, asg_t* g);
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifndef __HIC__
|
||||
#define __HIC__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
#include "Overlaps.h"
|
||||
|
||||
@@ -8,6 +10,7 @@
|
||||
#define RC_0 0
|
||||
#define RC_1 1
|
||||
#define RC_2 2
|
||||
#define RC_3 3
|
||||
|
||||
hc_edge* get_hc_edge(hc_links* link, uint64_t src, uint64_t dest, uint64_t dir);
|
||||
hc_edge* push_hc_edge(hc_linkeage* x, uint64_t uID, double weight, int dir, uint64_t* d);
|
||||
@@ -75,6 +78,7 @@ typedef struct{
|
||||
}pdq;
|
||||
|
||||
|
||||
|
||||
#define P_het(B) ((B).num.n)
|
||||
#define M_het(B) ((B).num.n + 1)
|
||||
// #define IF_BUB(ID, B) ((B).index[(ID)] < (B).num.n)
|
||||
@@ -89,6 +93,10 @@ int load_hc_links(hc_links* link, const char *fn);
|
||||
void write_hc_links(hc_links* link, const char *fn);
|
||||
void destory_bubbles(bubble_type* bub);
|
||||
void identify_bubbles(ma_ug_t* ug, bubble_type* bub, uint8_t *r_het_flag, kv_u_trans_t *ref);
|
||||
void identify_bubbles_recal(asg_t* sg, ma_ug_t* ug, bubble_type* bub, uint8_t *r_het_flag, ma_hit_t_alloc* sources, R_to_U* ruIndex,
|
||||
kv_u_trans_t *ref);
|
||||
void identify_bubbles_recal_poy(asg_t* sg, ma_ug_t* ug, bubble_type* bub, uint8_t *r_het_flag, ma_hit_t_alloc* sources, R_to_U* ruIndex,
|
||||
kv_u_trans_t *ref);
|
||||
void resolve_bubble_chain_tangle(ma_ug_t* ug, bubble_type* bub);
|
||||
uint32_t connect_bub_occ(bubble_type* bub, uint32_t root_id, uint32_t check_het);
|
||||
void get_bub_id(bubble_type* bub, uint32_t root, uint64_t* id0, uint64_t* id1, uint32_t check_het);
|
||||
@@ -105,6 +113,10 @@ pdq* pqw, uint32_t* path_w, buf_t *resw, asg_t *sg, uint8_t *dest, uint8_t df, u
|
||||
long long *dis);
|
||||
void set_utg_by_dis(uint32_t v, pdq* pq, asg_t *g, kvec_t_u32_warp *res, uint32_t dis);
|
||||
void dedup_hits(kvec_pe_hit* hits, uint64_t is_dup);
|
||||
void hic_analysis(ma_ug_t *ug, asg_t* read_g, trans_chain* t_ch, ug_opt_t *opt, uint32_t is_poy, kvec_pe_hit **rhits);
|
||||
void hic_analysis(ma_ug_t *ug, asg_t* read_g, trans_chain* t_ch, ug_opt_t *opt, mmhap_t **rh, kvec_pe_hit **rhits);
|
||||
spg_t *hic_pre_analysis(ma_ug_t *ug, asg_t* read_g, trans_chain* t_ch, ug_opt_t *opt, kvec_pe_hit **rhits);
|
||||
void prt_bubble_gfa_adv(FILE *fp, bubble_type *bub, const char* utg_pre, const char* bub_pre, const char* chain_pre);
|
||||
void bp_solve(ug_opt_t *opt, kv_u_trans_t *ref, ma_ug_t *ug, asg_t *sg, bubble_type *bub, double cis_rate);
|
||||
void trio_phasing_refine(ma_ug_t *ug, asg_t* sg, kv_u_trans_t *ta, ug_opt_t *opt);
|
||||
|
||||
#endif
|
||||
|
||||
+753
-120
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,10 @@
|
||||
#ifndef __HORDER__
|
||||
#define __HORDER__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
#include "hic.h"
|
||||
#include "rcut.h"
|
||||
|
||||
#define get_hit_srev(x, k) ((x).a.a[(k)].s>>63)
|
||||
#define get_hit_slen(x, k) ((x).a.a[(k)].len>>32)
|
||||
@@ -67,4 +70,10 @@ kvec_pe_hit *get_r_hits_order(kvec_pe_hit *uhits, uint64_t hits_uid_bits, uint64
|
||||
asg_t *rg, ma_ug_t* ug, bubble_type* bub);
|
||||
void ha_aware_order(kvec_pe_hit *r_hits, asg_t *rg, ma_ug_t *ug_fa, ma_ug_t *ug_mo, kv_u_trans_t *ref,
|
||||
ug_opt_t *opt, uint32_t round);
|
||||
spg_t *horder_utg(kvec_pe_hit *i_hits, uint64_t i_hits_uid_bits, uint64_t i_hits_pos_mode,
|
||||
asg_t *i_rg, ma_ug_t* i_ug, bubble_type* bub, ug_opt_t *opt);
|
||||
void layout_mc_clus_t(const mc_match_t *ma, uint32_t *a, uint32_t an, scg_t *sg, uint32_t *buf, uint64_t *idx, ma_ug_t* ug,
|
||||
double min_cut, double max_cut, uint64_t cut_round);
|
||||
void osg_destroy(osg_t *g);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "CommandLines.h"
|
||||
|
||||
typedef struct {
|
||||
int n, m;
|
||||
size_t n, m;
|
||||
uint64_t *a;
|
||||
} st_mt_t;
|
||||
|
||||
@@ -25,16 +25,14 @@ typedef struct { uint32_t n, m; ha_mz1_t *a; } ha_mz1_v;
|
||||
|
||||
typedef struct {
|
||||
uint64_t x; ///x is the hash key
|
||||
///rid is the read id, pos is the end pos of this minimizer, rev is the direction
|
||||
///span is the length of this k-mer. For non-HPC k-mer, span may not be equal to k
|
||||
uint64_t rid:30, pos:34;
|
||||
uint16_t rev:1, span:15;
|
||||
uint64_t rid:31, rev:1, pos:32;
|
||||
uint8_t span;
|
||||
} ha_mzl_t;
|
||||
|
||||
typedef struct {
|
||||
uint64_t rid:30, pos:34;
|
||||
uint16_t rev:1, span:15;
|
||||
} ha_mzl_idxpos_t;
|
||||
uint64_t rid:31, rev:1, pos:32;
|
||||
uint8_t span;
|
||||
} ha_idxposl_t;
|
||||
|
||||
typedef struct { uint32_t n, m; ha_mzl_t *a; } ha_mzl_v;
|
||||
|
||||
@@ -64,6 +62,9 @@ typedef struct ha_pt_s ha_pt_t;
|
||||
struct ha_abuf_s;
|
||||
typedef struct ha_abuf_s ha_abuf_t;
|
||||
|
||||
struct ha_abufl_s;
|
||||
typedef struct ha_abufl_s ha_abufl_t;
|
||||
|
||||
extern const unsigned char seq_nt4_table[256];
|
||||
extern void *ha_flt_tab;
|
||||
extern ha_pt_t *ha_idx;
|
||||
@@ -71,42 +72,63 @@ extern void *ha_flt_tab_hp;
|
||||
extern ha_pt_t *ha_idx_hp;
|
||||
extern void *ha_ct_table;
|
||||
|
||||
void *ha_ft_ug_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int hap_n);
|
||||
void *ha_ft_gen(const hifiasm_opt_t *asm_opt, All_reads *rs, int *hom_cov, int is_hp_mode);
|
||||
void *ha_ft_ul_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int k, int w, int cutoff, int max_cutoff);
|
||||
void *ha_ft_ug_gen(hifiasm_opt_t *asm_opt, ma_utg_v *us, int is_HPC, int k, int w, int min_freq, int max_freq);
|
||||
void *ha_ft_gen(const hifiasm_opt_t *asm_opt, All_reads *rs, int *hom_cov, int is_hp_mode, int read_from_store);
|
||||
int32_t ha_ft_cnt(const void *hh, uint64_t y);
|
||||
void ha_ft_destroy(void *h);
|
||||
|
||||
ha_pt_t *ha_pt_ug_gen(const hifiasm_opt_t *asm_opt, const void *flt_tab, ma_utg_v *us, int hap_n);
|
||||
ha_pt_t *ha_pt_ul_gen(const hifiasm_opt_t *asm_opt, const void *flt_tab, ma_utg_v *us, int k, int w, int cutoff);
|
||||
ha_pt_t *ha_pt_ug_gen(const hifiasm_opt_t *asm_opt, const void *flt_tab, ma_utg_v *us, int is_HPC, int k, int w, int min_freq);
|
||||
ha_pt_t *ha_pt_gen(const hifiasm_opt_t *asm_opt, const void *flt_tab, int read_from_store, int is_hp_mode, All_reads *rs, int *hom_cov, int *het_cov);
|
||||
void ha_pt_destroy(ha_pt_t *h);
|
||||
const ha_idxpos_t *ha_pt_get(const ha_pt_t *h, uint64_t hash, int *n);
|
||||
const ha_idxposl_t *ha_ptl_get(const ha_pt_t *h, uint64_t hash, int *n);
|
||||
const int ha_pt_cnt(const ha_pt_t *h, uint64_t hash);
|
||||
|
||||
int write_pt_index(void *flt_tab, ha_pt_t *ha_idx, All_reads* r, hifiasm_opt_t* opt, char* file_name);
|
||||
int load_pt_index(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads* r, hifiasm_opt_t* opt, char* file_name);
|
||||
int write_pt_index(void *flt_tab, ha_pt_t *ha_idx, All_reads* r, hifiasm_opt_t* opt, char* file_name, uint8_t force_rpaf_load);
|
||||
int load_pt_index(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads* r, hifiasm_opt_t* opt, char* file_name, uint8_t force_rpaf_load);
|
||||
void refresh_pt_idx(void **flt_tab, ha_pt_t **ha_idx, All_reads *r, hifiasm_opt_t *opt, char *file_name, uint8_t is_w);
|
||||
int uidx_write(void *flt_tab, ha_pt_t *ha_idx, char* file_name, ma_ug_t *ug);
|
||||
int uidx_load(void **r_flt_tab, ha_pt_t **r_ha_idx, char* file_name, ma_ug_t *ug);
|
||||
int write_ct_index(void *ct_idx, char* file_name);
|
||||
int load_ct_index(void **ct_idx, char* file_name);
|
||||
int query_ct_index(void* ct_idx, uint64_t hash);
|
||||
uint64_t tmp_pt_pro(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads *r, cc_v* rcc, hifiasm_opt_t *opt, char *file_name, uint64_t rr, uint64_t tot_rr, uint64_t is_load, uint8_t force_rpaf_load);
|
||||
|
||||
ha_abuf_t *ha_abuf_init_buf(void *km);
|
||||
ha_abufl_t *ha_abufl_init_buf(void *km);
|
||||
void ha_abuf_destroy_buf(void *km, ha_abuf_t *ab);
|
||||
void ha_abufl_destroy_buf(void *km, ha_abufl_t *ab);
|
||||
void ha_abufl_free_buf(void *km, ha_abufl_t *ab, int is_z);
|
||||
ha_abuf_t *ha_abuf_init(void);
|
||||
void ha_abuf_destroy(ha_abuf_t *ab);
|
||||
uint64_t ha_abuf_mem(const ha_abuf_t *ab);
|
||||
ha_abufl_t *ha_abufl_init(void);
|
||||
void ha_abufl_destroy(ha_abufl_t *ab);
|
||||
uint64_t ha_abufl_mem(const ha_abufl_t *ab);
|
||||
|
||||
double yak_cputime(void);
|
||||
void yak_reset_realtime(void);
|
||||
double yak_realtime_0(void);
|
||||
double yak_realtime(void);
|
||||
long yak_peakrss(void);
|
||||
double yak_peakrss_in_gb(void);
|
||||
double yak_cpu_usage(void);
|
||||
|
||||
void ha_triobin(const hifiasm_opt_t *opt);
|
||||
uint32_t test_yak_binning(char* fn, char *cmd);
|
||||
uint32_t *ha_polybin_list(const hifiasm_opt_t *opt);
|
||||
uint32_t *ha_charbin_list(const hifiasm_opt_t *opt, uint8_t **idx, uint32_t *idx_n);
|
||||
|
||||
void ha_sketch(const char *str, int len, int w, int k, uint32_t rid, int is_hpc, ha_mz1_v *p, const void *hf, int sample_dist, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* dbg_ct, ha_pt_t *pt, int min_freq, int32_t dp_min_len, float dp_e, st_mt_t *mt, int32_t ws);
|
||||
void mz1_ha_sketch(const char *str, int len, int w, int k, uint32_t rid, int is_hpc, ha_mz1_v *p, const void *hf, int sample_dist, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* dbg_ct, ha_pt_t *pt, int min_freq, int32_t dp_min_len, float dp_e, st_mt_t *mt, int32_t ws, int32_t is_unique, void *km);
|
||||
void mz2_ha_sketch(const char *str, int len, int w, int k, uint32_t rid, int is_hpc, ha_mzl_v *p, const void *hf, int sample_dist, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* dbg_ct, ha_pt_t *pt, int min_freq, int32_t dp_min_len, float dp_e, st_mt_t *mt, int32_t ws, int32_t is_unique, void *km);
|
||||
int ha_analyze_count(int n_cnt, int start_cnt, int m_peak_hom, const int64_t *cnt, int *peak_het);
|
||||
int adj_m_peak_hom(int m_peak_hom, int max_i, int max2_i, int max3_i, int *peak_het);
|
||||
void print_hist_lines(int n_cnt, int start_cnt, const int64_t *cnt);
|
||||
void debug_adapter(const hifiasm_opt_t *asm_opt, All_reads *rs);
|
||||
|
||||
|
||||
inline int mz_low_b(int peak_hom, int peak_het)
|
||||
{
|
||||
int low_freq = 2;
|
||||
@@ -147,9 +169,10 @@ static inline uint64_t yak_hash_long(uint64_t x[4])
|
||||
return yak_hash64_64(x[j<<1|0]) + yak_hash64_64(x[j<<1|1]);
|
||||
}
|
||||
|
||||
#define CALLOC(ptr, len) ((ptr) = (__typeof__(ptr))calloc((len), sizeof(*(ptr))))
|
||||
#define CALLOC(ptr, len) ((ptr) = ((((len)*sizeof(*(ptr))) <= 9223372036854775807)?((__typeof__(ptr))calloc((len), sizeof(*(ptr)))):(NULL)))
|
||||
#define MALLOC(ptr, len) ((ptr) = (__typeof__(ptr))malloc((len) * sizeof(*(ptr))))
|
||||
#define REALLOC(ptr, len) ((ptr) = (__typeof__(ptr))realloc((ptr), (len) * sizeof(*(ptr))))
|
||||
#define MEMCPY(dest, src, len) (memcpy((dest), (src), (len) * sizeof(*(src))))
|
||||
|
||||
#ifndef kroundup32
|
||||
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
#ifndef __INTER__
|
||||
#define __INTER__
|
||||
#include "Overlaps.h"
|
||||
#include "Process_Read.h"
|
||||
#include "hic.h"
|
||||
|
||||
#define G_CHAIN_BW 16//128
|
||||
#define FLANK_M (0x7fffU)
|
||||
#define P_CHAIN_COV 0.985
|
||||
#define P_FRAGEMENT_CHAIN_COV 0.20
|
||||
#define P_FRAGEMENT_PRIMARY_CHAIN_COV 0.70
|
||||
#define P_FRAGEMENT_PRIMARY_SECOND_COV 0.25
|
||||
#define P_CHAIN_SCORE 0.6
|
||||
#define G_CHAIN_GAP 0.1
|
||||
#define UG_SKIP 5
|
||||
#define RG_SKIP 25
|
||||
#define UG_SKIP_GRAPH_N 72
|
||||
#define UG_SKIP_N 100
|
||||
#define UG_ITER_N 5000
|
||||
#define UG_DIS_N 50000
|
||||
// #define UG_TRANS_W 2
|
||||
#define UG_TRANS_W 2
|
||||
// #define UG_TRANS_ERR_W 512
|
||||
#define UG_TRANS_ERR_W 64
|
||||
#define G_CHAIN_TRANS_RATE 0.25
|
||||
#define G_CHAIN_TRANS_WEIGHT -1
|
||||
#define G_CHAIN_INDEL 128
|
||||
#define W_CHN_PEN_GAP 0.1
|
||||
#define N_GCHAIN_RATE 0.04
|
||||
#define PRIMARY_UL_CHAIN_MIN 75000
|
||||
|
||||
typedef struct {
|
||||
int w, k, bw, max_gap, is_HPC, hap_n, occ_weight, max_gap_pre, max_gc_seq_ext, seed;
|
||||
int max_lc_skip, max_lc_iter, min_lc_cnt, min_lc_score, max_gc_skip, ref_bonus;
|
||||
int min_gc_cnt, min_gc_score, sub_diff, best_n;
|
||||
float chn_pen_gap, mask_level, pri_ratio;
|
||||
///base-alignment
|
||||
double bw_thres, diff_ec_ul, diff_ec_ul_low, diff_ec_ul_hpc; int max_n_chain, ec_ul_round;
|
||||
} mg_idxopt_t;
|
||||
|
||||
struct mg_tbuf_s {
|
||||
void *km;
|
||||
int frag_gap;
|
||||
};
|
||||
typedef struct mg_tbuf_s mg_tbuf_t;
|
||||
|
||||
|
||||
mg_tbuf_t *mg_tbuf_init(void);
|
||||
|
||||
void mg_tbuf_destroy(mg_tbuf_t *b);
|
||||
|
||||
void *mg_tbuf_get_km(mg_tbuf_t *b);
|
||||
|
||||
typedef struct {
|
||||
FILE *fp;
|
||||
ul_vec_t u;
|
||||
uint64_t flag;
|
||||
} ucr_file_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t off, cnt;
|
||||
uint32_t v;
|
||||
int32_t score;
|
||||
} mg_llchain_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t id, parent;
|
||||
int32_t off, cnt;
|
||||
int32_t n_anchor, score;
|
||||
int32_t qs, qe;
|
||||
int32_t plen, ps, pe;
|
||||
int32_t blen, mlen;
|
||||
float div;
|
||||
uint32_t hash;
|
||||
int32_t subsc, n_sub;
|
||||
uint32_t mapq:8, flt:1, dummy:23;
|
||||
} mg_gchain_t;
|
||||
|
||||
typedef struct {
|
||||
size_t n,m;
|
||||
uint64_t *a, tl;
|
||||
kvec_t(char) cc;
|
||||
} mg_dbn_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t cnt;
|
||||
uint32_t v;
|
||||
int32_t score;
|
||||
uint32_t qs, qe, ts, te;
|
||||
} mg_lres_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t n_gc, n_lc;
|
||||
mg_gchain_t *gc;///g_chain; idx in l_chains
|
||||
mg_lres_t *lc;///l_chain
|
||||
uint64_t qid, qlen;
|
||||
} mg_gres_t;
|
||||
|
||||
typedef struct {
|
||||
size_t n,m;
|
||||
mg_gres_t *a;
|
||||
uint64_t total_base;
|
||||
uint64_t total_pair;
|
||||
} mg_gres_a;
|
||||
|
||||
void push_uc_block_t(const ug_opt_t *uopt, kv_ul_ov_t *z, char **seq, uint64_t *len, uint64_t b_id);
|
||||
void ul_resolve(ma_ug_t *ug, const asg_t *rg, const ug_opt_t *uopt, int hap_n);
|
||||
void ul_load(const ug_opt_t *uopt);
|
||||
uint64_t* get_hifi2ul_list(all_ul_t *x, uint64_t hid, uint64_t* a_n);
|
||||
uint64_t ul_refine_alignment(const ug_opt_t *uopt, asg_t *sg);
|
||||
ma_ug_t *ul_realignment(const ug_opt_t *uopt, asg_t *sg, uint32_t double_check_cache, const char *bin_file);
|
||||
int32_t write_all_ul_t(all_ul_t *x, char* file_name, ma_ug_t *ug);
|
||||
int32_t load_all_ul_t(all_ul_t *x, char* file_name, All_reads *hR, ma_ug_t *ug);
|
||||
uint32_t ugl_cover_check(uint64_t is, uint64_t ie, ma_utg_t *u);
|
||||
void filter_ul_ug(ma_ug_t *ug);
|
||||
void gen_ul_vec_rid_t(all_ul_t *x, All_reads *rdb, ma_ug_t *ug);
|
||||
void update_ug_arch_ul_mul(ma_ug_t *ug);
|
||||
void print_ul_alignment(ma_ug_t *ug, all_ul_t *aln, uint32_t id, const char* cmd);
|
||||
void clear_all_ul_t(all_ul_t *x);
|
||||
void trans_base_infer(ma_ug_t *ug, asg_t *sg, ug_opt_t *uopt, kv_u_trans_t *res, bubble_type *bub);
|
||||
hpc_re_t *gen_hpc_re_t(ma_ug_t *ug);
|
||||
idx_emask_t* graph_ovlp_binning(ma_ug_t *ug, asg_t *sg, const ug_opt_t *uopt);
|
||||
uint32_t gen_src_shared_interval_simple(uint32_t src, ma_ug_t *ug, uint64_t *flt, uint64_t flt_n, kv_ul_ov_t *res);
|
||||
uint64_t check_ul_ov_t_consist(ul_ov_t *x, ul_ov_t *y, int64_t ql, int64_t tl, double diff);
|
||||
uint32_t infer_se(uint32_t qs, uint32_t qe, uint32_t ts, uint32_t te, uint32_t rev,
|
||||
uint32_t rqs, uint32_t rqe, uint32_t *rts, uint32_t *rte);
|
||||
uint32_t clean_contain_g(const ug_opt_t *uopt, asg_t *sg, uint32_t push_trans);
|
||||
void dedup_contain_g(const ug_opt_t *uopt, asg_t *sg);
|
||||
void trans_base_mmhap_infer(ma_ug_t *ug, asg_t *sg, ug_opt_t *uopt, kv_u_trans_t *res);
|
||||
scaf_res_t *gen_contig_path(const ug_opt_t *uopt, asg_t *sg, ma_ug_t *ctg, ma_ug_t *ref);
|
||||
void gen_contig_trans(const ug_opt_t *uopt, asg_t *sg, ma_ug_t *qry, scaf_res_t *qry_sc, ma_ug_t *ref, scaf_res_t *ref_sc, ma_ug_t *gfa, kv_u_trans_t *ta, uint32_t qoff, uint32_t toff, bubble_type *bu, kv_u_trans_t *res);
|
||||
void gen_contig_self(const ug_opt_t *uopt, asg_t *sg, ma_ug_t *db, scaf_res_t *db_sc, ma_ug_t *gfa, kv_u_trans_t *ta, uint64_t soff, bubble_type *bu, kv_u_trans_t *res, uint32_t is_exact);
|
||||
void order_contig_trans(kv_u_trans_t *in);
|
||||
void sort_uc_block_qe(uc_block_t* a, uint64_t a_n);
|
||||
|
||||
#endif
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "kalloc.h"
|
||||
|
||||
/* In kalloc, a *core* is a large chunk of contiguous memory. Each core is
|
||||
* associated with a master header, which keeps the size of the current core
|
||||
* and the pointer to next core. Kalloc allocates small *blocks* of memory from
|
||||
* the cores and organizes free memory blocks in a circular single-linked list.
|
||||
*
|
||||
* In the following diagram, "@" stands for the header of a free block (of type
|
||||
* header_t), "#" for the header of an allocated block (of type size_t), "-"
|
||||
* for free memory, and "+" for allocated memory.
|
||||
*
|
||||
* master This region is core 1. master This region is core 2.
|
||||
* | |
|
||||
* *@-------#++++++#++++++++++++@-------- *@----------#++++++++++++#+++++++@------------
|
||||
* | | | |
|
||||
* p=p->ptr->ptr->ptr->ptr p->ptr p->ptr->ptr p->ptr->ptr->ptr
|
||||
*/
|
||||
typedef struct header_t {
|
||||
size_t size;
|
||||
struct header_t *ptr;
|
||||
} header_t;
|
||||
|
||||
typedef struct {
|
||||
void *par;
|
||||
size_t min_core_size;
|
||||
header_t base, *loop_head, *core_head; /* base is a zero-sized block always kept in the loop */
|
||||
} kmem_t;
|
||||
|
||||
static void panic(const char *s)
|
||||
{
|
||||
fprintf(stderr, "%s\n", s);
|
||||
abort();
|
||||
}
|
||||
|
||||
void *km_init2(void *km_par, size_t min_core_size)
|
||||
{
|
||||
kmem_t *km;
|
||||
km = (kmem_t*)kcalloc(km_par, 1, sizeof(kmem_t));
|
||||
km->par = km_par;
|
||||
km->min_core_size = min_core_size > 0? min_core_size : 0x80000;
|
||||
return (void*)km;
|
||||
}
|
||||
|
||||
void *km_init(void) { return km_init2(0, 0); }
|
||||
|
||||
void km_destroy(void *_km)
|
||||
{
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
void *km_par;
|
||||
header_t *p, *q;
|
||||
if (km == NULL) return;
|
||||
km_par = km->par;
|
||||
for (p = km->core_head; p != NULL;) {
|
||||
q = p->ptr;
|
||||
kfree(km_par, p);
|
||||
p = q;
|
||||
}
|
||||
kfree(km_par, km);
|
||||
}
|
||||
|
||||
static header_t *morecore(kmem_t *km, size_t nu)
|
||||
{
|
||||
header_t *q;
|
||||
size_t bytes, *p;
|
||||
nu = (nu + 1 + (km->min_core_size - 1)) / km->min_core_size * km->min_core_size; /* the first +1 for core header */
|
||||
bytes = nu * sizeof(header_t);
|
||||
q = (header_t*)kmalloc(km->par, bytes);
|
||||
if (!q) panic("[morecore] insufficient memory");
|
||||
q->ptr = km->core_head, q->size = nu, km->core_head = q;
|
||||
p = (size_t*)(q + 1);
|
||||
*p = nu - 1; /* the size of the free block; -1 because the first unit is used for the core header */
|
||||
kfree(km, p + 1); /* initialize the new "core"; NB: the core header is not looped. */
|
||||
return km->loop_head;
|
||||
}
|
||||
|
||||
void kfree(void *_km, void *ap) /* kfree() also adds a new core to the circular list */
|
||||
{
|
||||
header_t *p, *q;
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
|
||||
if (!ap) return;
|
||||
if (km == NULL) {
|
||||
free(ap);
|
||||
return;
|
||||
}
|
||||
p = (header_t*)((size_t*)ap - 1);
|
||||
p->size = *((size_t*)ap - 1);
|
||||
/* Find the pointer that points to the block to be freed. The following loop can stop on two conditions:
|
||||
*
|
||||
* a) "p>q && p<q->ptr": @------#++++++++#+++++++@------- @---------------#+++++++@-------
|
||||
* (can also be in | | | -> | |
|
||||
* two cores) q p q->ptr q q->ptr
|
||||
*
|
||||
* @-------- #+++++++++@-------- @-------- @------------------
|
||||
* | | | -> | |
|
||||
* q p q->ptr q q->ptr
|
||||
*
|
||||
* b) "q>=q->ptr && (p>q || p<q->ptr)": @-------#+++++ @--------#+++++++ @-------#+++++ @----------------
|
||||
* | | | -> | |
|
||||
* q->ptr q p q->ptr q
|
||||
*
|
||||
* #+++++++@----- #++++++++@------- @------------- #++++++++@-------
|
||||
* | | | -> | |
|
||||
* p q->ptr q q->ptr q
|
||||
*/
|
||||
for (q = km->loop_head; !(p > q && p < q->ptr); q = q->ptr)
|
||||
if (q >= q->ptr && (p > q || p < q->ptr)) break;
|
||||
if (p + p->size == q->ptr) { /* two adjacent blocks, merge p and q->ptr (the 2nd and 4th cases) */
|
||||
p->size += q->ptr->size;
|
||||
p->ptr = q->ptr->ptr;
|
||||
} else if (p + p->size > q->ptr && q->ptr >= p) {
|
||||
panic("[kfree] The end of the allocated block enters a free block.");
|
||||
} else p->ptr = q->ptr; /* backup q->ptr */
|
||||
|
||||
if (q + q->size == p) { /* two adjacent blocks, merge q and p (the other two cases) */
|
||||
q->size += p->size;
|
||||
q->ptr = p->ptr;
|
||||
km->loop_head = q;
|
||||
} else if (q + q->size > p && p >= q) {
|
||||
panic("[kfree] The end of a free block enters the allocated block.");
|
||||
} else km->loop_head = p, q->ptr = p; /* in two cores, cannot be merged; create a new block in the list */
|
||||
}
|
||||
|
||||
void *kmalloc(void *_km, size_t n_bytes)
|
||||
{
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
size_t n_units;
|
||||
header_t *p, *q;
|
||||
|
||||
if (n_bytes == 0) return 0;
|
||||
if (km == NULL) return malloc(n_bytes);
|
||||
n_units = (n_bytes + sizeof(size_t) + sizeof(header_t) - 1) / sizeof(header_t); /* header+n_bytes requires at least this number of units */
|
||||
|
||||
if (!(q = km->loop_head)) /* the first time when kmalloc() is called, intialize it */
|
||||
q = km->loop_head = km->base.ptr = &km->base;
|
||||
for (p = q->ptr;; q = p, p = p->ptr) { /* search for a suitable block */
|
||||
if (p->size >= n_units) { /* p->size if the size of current block. This line means the current block is large enough. */
|
||||
if (p->size == n_units) q->ptr = p->ptr; /* no need to split the block */
|
||||
else { /* split the block. NB: memory is allocated at the end of the block! */
|
||||
p->size -= n_units; /* reduce the size of the free block */
|
||||
p += p->size; /* p points to the allocated block */
|
||||
*(size_t*)p = n_units; /* set the size */
|
||||
}
|
||||
km->loop_head = q; /* set the end of chain */
|
||||
return (size_t*)p + 1;
|
||||
}
|
||||
if (p == km->loop_head) { /* then ask for more "cores" */
|
||||
if ((p = morecore(km, n_units)) == 0) return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *kcalloc(void *_km, size_t count, size_t size)
|
||||
{
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
void *p;
|
||||
if (size == 0 || count == 0) return 0;
|
||||
if (km == NULL) return calloc(count, size);
|
||||
p = kmalloc(km, count * size);
|
||||
memset(p, 0, count * size);
|
||||
return p;
|
||||
}
|
||||
|
||||
void *krealloc(void *_km, void *ap, size_t n_bytes) // TODO: this can be made more efficient in principle
|
||||
{
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
size_t cap, *p, *q;
|
||||
|
||||
if (n_bytes == 0) {
|
||||
kfree(km, ap); return 0;
|
||||
}
|
||||
if (km == NULL) return realloc(ap, n_bytes);
|
||||
if (ap == NULL) return kmalloc(km, n_bytes);
|
||||
p = (size_t*)ap - 1;
|
||||
cap = (*p) * sizeof(header_t) - sizeof(size_t);
|
||||
if (cap >= n_bytes) return ap; /* TODO: this prevents shrinking */
|
||||
q = (size_t*)kmalloc(km, n_bytes);
|
||||
memcpy(q, ap, cap);
|
||||
kfree(km, ap);
|
||||
return q;
|
||||
}
|
||||
|
||||
void km_stat(const void *_km, km_stat_t *s)
|
||||
{
|
||||
kmem_t *km = (kmem_t*)_km;
|
||||
header_t *p;
|
||||
memset(s, 0, sizeof(km_stat_t));
|
||||
if (km == NULL || km->loop_head == NULL) return;
|
||||
for (p = km->loop_head;; p = p->ptr) {
|
||||
s->available += p->size * sizeof(header_t);
|
||||
if (p->size != 0) ++s->n_blocks; /* &kmem_t::base is always one of the cores. It is zero-sized. */
|
||||
if (p->ptr > p && p + p->size > p->ptr)
|
||||
panic("[km_stat] The end of a free block enters another free block.");
|
||||
if (p->ptr == km->loop_head) break;
|
||||
}
|
||||
for (p = km->core_head; p != NULL; p = p->ptr) {
|
||||
size_t size = p->size * sizeof(header_t);
|
||||
++s->n_cores;
|
||||
s->capacity += size;
|
||||
s->largest = s->largest > size? s->largest : size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef _KALLOC_H_
|
||||
#define _KALLOC_H_
|
||||
|
||||
#include <stddef.h> /* for size_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
size_t capacity, available, n_blocks, n_cores, largest;
|
||||
} km_stat_t;
|
||||
|
||||
void *kmalloc(void *km, size_t size);
|
||||
void *krealloc(void *km, void *ptr, size_t size);
|
||||
void *kcalloc(void *km, size_t count, size_t size);
|
||||
void kfree(void *km, void *ptr);
|
||||
|
||||
void *km_init(void);
|
||||
void *km_init2(void *km_par, size_t min_core_size);
|
||||
void km_destroy(void *km);
|
||||
void km_stat(const void *_km, km_stat_t *s);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define KMALLOC(km, ptr, len) ((ptr) = (__typeof__(ptr))kmalloc((km), (len) * sizeof(*(ptr))))
|
||||
#define KCALLOC(km, ptr, len) ((ptr) = (__typeof__(ptr))kcalloc((km), (len), sizeof(*(ptr))))
|
||||
#define KREALLOC(km, ptr, len) ((ptr) = (__typeof__(ptr))krealloc((km), (ptr), (len) * sizeof(*(ptr))))
|
||||
|
||||
#define KEXPAND(km, a, m) do { \
|
||||
(m) = (m) >= 4? (m) + ((m)>>1) : 16; \
|
||||
KREALLOC((km), (a), (m)); \
|
||||
} while (0)
|
||||
|
||||
#define kv_resize_km(km, type, v, s) do { \
|
||||
if ((v).m < (s)) { \
|
||||
(v).m = (s); \
|
||||
kv_roundup32((v).m); \
|
||||
KREALLOC((km), (v).a, (v).m); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define kv_copy_km(km, type, v1, v0) do { \
|
||||
if ((v1).m < (v0).n) kv_resize_km((km), type, v1, (v0).n); \
|
||||
(v1).n = (v0).n; \
|
||||
memcpy((v1).a, (v0).a, sizeof(type) * (v0).n); \
|
||||
} while (0) \
|
||||
|
||||
#define kv_push_km(km, type, v, x) do { \
|
||||
if ((v).n == (v).m) { \
|
||||
(v).m = (v).m? (v).m<<1 : 2; \
|
||||
KREALLOC((km), (v).a, (v).m); \
|
||||
} \
|
||||
(v).a[(v).n++] = (x); \
|
||||
} while (0)
|
||||
|
||||
#define kv_pushp_km(km, type, v, p) do { \
|
||||
if ((v).n == (v).m) { \
|
||||
(v).m = (v).m? (v).m<<1 : 2; \
|
||||
KREALLOC((km), (v).a, (v).m); \
|
||||
} \
|
||||
*(p) = &(v).a[(v).n++]; \
|
||||
} while (0)
|
||||
|
||||
#ifndef klib_unused
|
||||
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
|
||||
#define klib_unused __attribute__ ((__unused__))
|
||||
#else
|
||||
#define klib_unused
|
||||
#endif
|
||||
#endif /* klib_unused */
|
||||
|
||||
// adapted from klist.h
|
||||
#define KALLOC_POOL_INIT2(SCOPE, name, kmptype_t) \
|
||||
typedef struct { \
|
||||
size_t cnt, n, max; \
|
||||
kmptype_t **buf; \
|
||||
void *km; \
|
||||
} kmp_##name##_t; \
|
||||
SCOPE kmp_##name##_t *kmp_init_##name(void *km) { \
|
||||
kmp_##name##_t *mp; \
|
||||
KCALLOC(km, mp, 1); \
|
||||
mp->km = km; \
|
||||
return mp; \
|
||||
} \
|
||||
SCOPE void kmp_destroy_##name(kmp_##name##_t *mp) { \
|
||||
size_t k; \
|
||||
for (k = 0; k < mp->n; ++k) kfree(mp->km, mp->buf[k]); \
|
||||
kfree(mp->km, mp->buf); kfree(mp->km, mp); \
|
||||
} \
|
||||
SCOPE kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \
|
||||
++mp->cnt; \
|
||||
if (mp->n == 0) return (kmptype_t*)kcalloc(mp->km, 1, sizeof(kmptype_t)); \
|
||||
return mp->buf[--mp->n]; \
|
||||
} \
|
||||
SCOPE void kmp_free_##name(kmp_##name##_t *mp, kmptype_t *p) { \
|
||||
--mp->cnt; \
|
||||
if (mp->n == mp->max) KEXPAND(mp->km, mp->buf, mp->max); \
|
||||
mp->buf[mp->n++] = p; \
|
||||
}
|
||||
|
||||
#define KALLOC_POOL_INIT(name, kmptype_t) \
|
||||
KALLOC_POOL_INIT2(static inline klib_unused, name, kmptype_t)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,414 @@
|
||||
/* The MIT License
|
||||
|
||||
Copyright (c) 2018 by Attractive Chaos <attractor@live.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/* An example:
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "kavl.h"
|
||||
|
||||
struct my_node {
|
||||
char key;
|
||||
KAVL_HEAD(struct my_node) head;
|
||||
};
|
||||
#define my_cmp(p, q) (((q)->key < (p)->key) - ((p)->key < (q)->key))
|
||||
KAVL_INIT(my, struct my_node, head, my_cmp)
|
||||
|
||||
int main(void) {
|
||||
const char *str = "MNOLKQOPHIA"; // from wiki, except a duplicate
|
||||
struct my_node *root = 0;
|
||||
int i, l = strlen(str);
|
||||
for (i = 0; i < l; ++i) { // insert in the input order
|
||||
struct my_node *q, *p = malloc(sizeof(*p));
|
||||
p->key = str[i];
|
||||
q = kavl_insert(my, &root, p, 0);
|
||||
if (p != q) free(p); // if already present, free
|
||||
}
|
||||
kavl_itr_t(my) itr;
|
||||
kavl_itr_first(my, root, &itr); // place at first
|
||||
do { // traverse
|
||||
const struct my_node *p = kavl_at(&itr);
|
||||
putchar(p->key);
|
||||
free((void*)p); // free node
|
||||
} while (kavl_itr_next(my, &itr));
|
||||
putchar('\n');
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef KAVL_H
|
||||
#define KAVL_H
|
||||
|
||||
#ifdef __STRICT_ANSI__
|
||||
#define inline __inline__
|
||||
#endif
|
||||
|
||||
#define KAVL_MAX_DEPTH 64
|
||||
|
||||
#define kavl_size(head, p) ((p)? (p)->head.size : 0)
|
||||
#define kavl_size_child(head, q, i) ((q)->head.p[(i)]? (q)->head.p[(i)]->head.size : 0)
|
||||
|
||||
#define KAVL_HEAD(__type) \
|
||||
struct { \
|
||||
__type *p[2]; \
|
||||
signed char balance; /* balance factor */ \
|
||||
unsigned size; /* #elements in subtree */ \
|
||||
}
|
||||
|
||||
#define __KAVL_FIND(suf, __scope, __type, __head, __cmp) \
|
||||
__scope __type *kavl_find_##suf(const __type *root, const __type *x, unsigned *cnt_) { \
|
||||
const __type *p = root; \
|
||||
unsigned cnt = 0; \
|
||||
while (p != 0) { \
|
||||
int cmp; \
|
||||
cmp = __cmp(x, p); \
|
||||
if (cmp >= 0) cnt += kavl_size_child(__head, p, 0) + 1; \
|
||||
if (cmp < 0) p = p->__head.p[0]; \
|
||||
else if (cmp > 0) p = p->__head.p[1]; \
|
||||
else break; \
|
||||
} \
|
||||
if (cnt_) *cnt_ = cnt; \
|
||||
return (__type*)p; \
|
||||
} \
|
||||
__scope __type *kavl_interval_##suf(const __type *root, const __type *x, __type **lower, __type **upper) { \
|
||||
const __type *p = root, *l = 0, *u = 0; \
|
||||
while (p != 0) { \
|
||||
int cmp; \
|
||||
cmp = __cmp(x, p); \
|
||||
if (cmp < 0) u = p, p = p->__head.p[0]; \
|
||||
else if (cmp > 0) l = p, p = p->__head.p[1]; \
|
||||
else { l = u = p; break; } \
|
||||
} \
|
||||
if (lower) *lower = (__type*)l; \
|
||||
if (upper) *upper = (__type*)u; \
|
||||
return (__type*)p; \
|
||||
}
|
||||
|
||||
#define __KAVL_ROTATE(suf, __type, __head) \
|
||||
/* one rotation: (a,(b,c)q)p => ((a,b)p,c)q */ \
|
||||
static inline __type *kavl_rotate1_##suf(__type *p, int dir) { /* dir=0 to left; dir=1 to right */ \
|
||||
int opp = 1 - dir; /* opposite direction */ \
|
||||
__type *q = p->__head.p[opp]; \
|
||||
unsigned size_p = p->__head.size; \
|
||||
p->__head.size -= q->__head.size - kavl_size_child(__head, q, dir); \
|
||||
q->__head.size = size_p; \
|
||||
p->__head.p[opp] = q->__head.p[dir]; \
|
||||
q->__head.p[dir] = p; \
|
||||
return q; \
|
||||
} \
|
||||
/* two consecutive rotations: (a,((b,c)r,d)q)p => ((a,b)p,(c,d)q)r */ \
|
||||
static inline __type *kavl_rotate2_##suf(__type *p, int dir) { \
|
||||
int b1, opp = 1 - dir; \
|
||||
__type *q = p->__head.p[opp], *r = q->__head.p[dir]; \
|
||||
unsigned size_x_dir = kavl_size_child(__head, r, dir); \
|
||||
r->__head.size = p->__head.size; \
|
||||
p->__head.size -= q->__head.size - size_x_dir; \
|
||||
q->__head.size -= size_x_dir + 1; \
|
||||
p->__head.p[opp] = r->__head.p[dir]; \
|
||||
r->__head.p[dir] = p; \
|
||||
q->__head.p[dir] = r->__head.p[opp]; \
|
||||
r->__head.p[opp] = q; \
|
||||
b1 = dir == 0? +1 : -1; \
|
||||
if (r->__head.balance == b1) q->__head.balance = 0, p->__head.balance = -b1; \
|
||||
else if (r->__head.balance == 0) q->__head.balance = p->__head.balance = 0; \
|
||||
else q->__head.balance = b1, p->__head.balance = 0; \
|
||||
r->__head.balance = 0; \
|
||||
return r; \
|
||||
}
|
||||
|
||||
#define __KAVL_INSERT(suf, __scope, __type, __head, __cmp) \
|
||||
__scope __type *kavl_insert_##suf(__type **root_, __type *x, unsigned *cnt_) { \
|
||||
unsigned char stack[KAVL_MAX_DEPTH]; \
|
||||
__type *path[KAVL_MAX_DEPTH]; \
|
||||
__type *bp, *bq; \
|
||||
__type *p, *q, *r = 0; /* _r_ is potentially the new root */ \
|
||||
int i, which = 0, top, b1, path_len; \
|
||||
unsigned cnt = 0; \
|
||||
bp = *root_, bq = 0; \
|
||||
/* find the insertion location */ \
|
||||
for (p = bp, q = bq, top = path_len = 0; p; q = p, p = p->__head.p[which]) { \
|
||||
int cmp; \
|
||||
cmp = __cmp(x, p); \
|
||||
if (cmp >= 0) cnt += kavl_size_child(__head, p, 0) + 1; \
|
||||
if (cmp == 0) { \
|
||||
if (cnt_) *cnt_ = cnt; \
|
||||
return p; \
|
||||
} \
|
||||
if (p->__head.balance != 0) \
|
||||
bq = q, bp = p, top = 0; \
|
||||
stack[top++] = which = (cmp > 0); \
|
||||
path[path_len++] = p; \
|
||||
} \
|
||||
if (cnt_) *cnt_ = cnt; \
|
||||
x->__head.balance = 0, x->__head.size = 1, x->__head.p[0] = x->__head.p[1] = 0; \
|
||||
if (q == 0) *root_ = x; \
|
||||
else q->__head.p[which] = x; \
|
||||
if (bp == 0) return x; \
|
||||
for (i = 0; i < path_len; ++i) ++path[i]->__head.size; \
|
||||
for (p = bp, top = 0; p != x; p = p->__head.p[stack[top]], ++top) /* update balance factors */ \
|
||||
if (stack[top] == 0) --p->__head.balance; \
|
||||
else ++p->__head.balance; \
|
||||
if (bp->__head.balance > -2 && bp->__head.balance < 2) return x; /* no re-balance needed */ \
|
||||
/* re-balance */ \
|
||||
which = (bp->__head.balance < 0); \
|
||||
b1 = which == 0? +1 : -1; \
|
||||
q = bp->__head.p[1 - which]; \
|
||||
if (q->__head.balance == b1) { \
|
||||
r = kavl_rotate1_##suf(bp, which); \
|
||||
q->__head.balance = bp->__head.balance = 0; \
|
||||
} else r = kavl_rotate2_##suf(bp, which); \
|
||||
if (bq == 0) *root_ = r; \
|
||||
else bq->__head.p[bp != bq->__head.p[0]] = r; \
|
||||
return x; \
|
||||
}
|
||||
|
||||
#define __KAVL_ERASE(suf, __scope, __type, __head, __cmp) \
|
||||
__scope __type *kavl_erase_##suf(__type **root_, const __type *x, unsigned *cnt_) { \
|
||||
__type *p, *path[KAVL_MAX_DEPTH], fake; \
|
||||
unsigned char dir[KAVL_MAX_DEPTH]; \
|
||||
int i, d = 0, cmp; \
|
||||
unsigned cnt = 0; \
|
||||
fake.__head.p[0] = *root_, fake.__head.p[1] = 0; \
|
||||
if (cnt_) *cnt_ = 0; \
|
||||
if (x) { \
|
||||
for (cmp = -1, p = &fake; cmp; cmp = __cmp(x, p)) { \
|
||||
int which = (cmp > 0); \
|
||||
if (cmp > 0) cnt += kavl_size_child(__head, p, 0) + 1; \
|
||||
dir[d] = which; \
|
||||
path[d++] = p; \
|
||||
p = p->__head.p[which]; \
|
||||
if (p == 0) { \
|
||||
if (cnt_) *cnt_ = 0; \
|
||||
return 0; \
|
||||
} \
|
||||
} \
|
||||
cnt += kavl_size_child(__head, p, 0) + 1; /* because p==x is not counted */ \
|
||||
} else { \
|
||||
for (p = &fake, cnt = 1; p; p = p->__head.p[0]) \
|
||||
dir[d] = 0, path[d++] = p; \
|
||||
p = path[--d]; \
|
||||
} \
|
||||
if (cnt_) *cnt_ = cnt; \
|
||||
for (i = 1; i < d; ++i) --path[i]->__head.size; \
|
||||
if (p->__head.p[1] == 0) { /* ((1,.)2,3)4 => (1,3)4; p=2 */ \
|
||||
path[d-1]->__head.p[dir[d-1]] = p->__head.p[0]; \
|
||||
} else { \
|
||||
__type *q = p->__head.p[1]; \
|
||||
if (q->__head.p[0] == 0) { /* ((1,2)3,4)5 => ((1)2,4)5; p=3 */ \
|
||||
q->__head.p[0] = p->__head.p[0]; \
|
||||
q->__head.balance = p->__head.balance; \
|
||||
path[d-1]->__head.p[dir[d-1]] = q; \
|
||||
path[d] = q, dir[d++] = 1; \
|
||||
q->__head.size = p->__head.size - 1; \
|
||||
} else { /* ((1,((.,2)3,4)5)6,7)8 => ((1,(2,4)5)3,7)8; p=6 */ \
|
||||
__type *r; \
|
||||
int e = d++; /* backup _d_ */\
|
||||
for (;;) { \
|
||||
dir[d] = 0; \
|
||||
path[d++] = q; \
|
||||
r = q->__head.p[0]; \
|
||||
if (r->__head.p[0] == 0) break; \
|
||||
q = r; \
|
||||
} \
|
||||
r->__head.p[0] = p->__head.p[0]; \
|
||||
q->__head.p[0] = r->__head.p[1]; \
|
||||
r->__head.p[1] = p->__head.p[1]; \
|
||||
r->__head.balance = p->__head.balance; \
|
||||
path[e-1]->__head.p[dir[e-1]] = r; \
|
||||
path[e] = r, dir[e] = 1; \
|
||||
for (i = e + 1; i < d; ++i) --path[i]->__head.size; \
|
||||
r->__head.size = p->__head.size - 1; \
|
||||
} \
|
||||
} \
|
||||
while (--d > 0) { \
|
||||
__type *q = path[d]; \
|
||||
int which, other, b1 = 1, b2 = 2; \
|
||||
which = dir[d], other = 1 - which; \
|
||||
if (which) b1 = -b1, b2 = -b2; \
|
||||
q->__head.balance += b1; \
|
||||
if (q->__head.balance == b1) break; \
|
||||
else if (q->__head.balance == b2) { \
|
||||
__type *r = q->__head.p[other]; \
|
||||
if (r->__head.balance == -b1) { \
|
||||
path[d-1]->__head.p[dir[d-1]] = kavl_rotate2_##suf(q, which); \
|
||||
} else { \
|
||||
path[d-1]->__head.p[dir[d-1]] = kavl_rotate1_##suf(q, which); \
|
||||
if (r->__head.balance == 0) { \
|
||||
r->__head.balance = -b1; \
|
||||
q->__head.balance = b1; \
|
||||
break; \
|
||||
} else r->__head.balance = q->__head.balance = 0; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
*root_ = fake.__head.p[0]; \
|
||||
return p; \
|
||||
}
|
||||
|
||||
#define kavl_free(__type, __head, __root, __free) do { \
|
||||
__type *_p, *_q; \
|
||||
for (_p = __root; _p; _p = _q) { \
|
||||
if (_p->__head.p[0] == 0) { \
|
||||
_q = _p->__head.p[1]; \
|
||||
__free(_p); \
|
||||
} else { \
|
||||
_q = _p->__head.p[0]; \
|
||||
_p->__head.p[0] = _q->__head.p[1]; \
|
||||
_q->__head.p[1] = _p; \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define __KAVL_ITR(suf, __scope, __type, __head, __cmp) \
|
||||
struct kavl_itr_##suf { \
|
||||
const __type *stack[KAVL_MAX_DEPTH], **top; \
|
||||
}; \
|
||||
__scope void kavl_itr_first_##suf(const __type *root, struct kavl_itr_##suf *itr) { \
|
||||
const __type *p; \
|
||||
for (itr->top = itr->stack - 1, p = root; p; p = p->__head.p[0]) \
|
||||
*++itr->top = p; \
|
||||
} \
|
||||
__scope int kavl_itr_find_##suf(const __type *root, const __type *x, struct kavl_itr_##suf *itr) { \
|
||||
const __type *p = root; \
|
||||
itr->top = itr->stack - 1; \
|
||||
while (p != 0) { \
|
||||
int cmp; \
|
||||
*++itr->top = p; \
|
||||
cmp = __cmp(x, p); \
|
||||
if (cmp < 0) p = p->__head.p[0]; \
|
||||
else if (cmp > 0) p = p->__head.p[1]; \
|
||||
else break; \
|
||||
} \
|
||||
return p? 1 : 0; \
|
||||
} \
|
||||
__scope int kavl_itr_next_bidir_##suf(struct kavl_itr_##suf *itr, int dir) { \
|
||||
const __type *p; \
|
||||
if (itr->top < itr->stack) return 0; \
|
||||
dir = !!dir; \
|
||||
p = (*itr->top)->__head.p[dir]; \
|
||||
if (p) { /* go down */ \
|
||||
for (; p; p = p->__head.p[!dir]) \
|
||||
*++itr->top = p; \
|
||||
return 1; \
|
||||
} else { /* go up */ \
|
||||
do { \
|
||||
p = *itr->top--; \
|
||||
} while (itr->top >= itr->stack && p == (*itr->top)->__head.p[dir]); \
|
||||
return itr->top < itr->stack? 0 : 1; \
|
||||
} \
|
||||
} \
|
||||
|
||||
/**
|
||||
* Insert a node to the tree
|
||||
*
|
||||
* @param suf name suffix used in KAVL_INIT()
|
||||
* @param proot pointer to the root of the tree (in/out: root may change)
|
||||
* @param x node to insert (in)
|
||||
* @param cnt number of nodes smaller than or equal to _x_; can be NULL (out)
|
||||
*
|
||||
* @return _x_ if not present in the tree, or the node equal to x.
|
||||
*/
|
||||
#define kavl_insert(suf, proot, x, cnt) kavl_insert_##suf(proot, x, cnt)
|
||||
|
||||
/**
|
||||
* Find a node in the tree
|
||||
*
|
||||
* @param suf name suffix used in KAVL_INIT()
|
||||
* @param root root of the tree
|
||||
* @param x node value to find (in)
|
||||
* @param cnt number of nodes smaller than or equal to _x_; can be NULL (out)
|
||||
*
|
||||
* @return node equal to _x_ if present, or NULL if absent
|
||||
*/
|
||||
#define kavl_find(suf, root, x, cnt) kavl_find_##suf(root, x, cnt)
|
||||
#define kavl_interval(suf, root, x, lower, upper) kavl_interval_##suf(root, x, lower, upper)
|
||||
|
||||
/**
|
||||
* Delete a node from the tree
|
||||
*
|
||||
* @param suf name suffix used in KAVL_INIT()
|
||||
* @param proot pointer to the root of the tree (in/out: root may change)
|
||||
* @param x node value to delete; if NULL, delete the first node (in)
|
||||
*
|
||||
* @return node removed from the tree if present, or NULL if absent
|
||||
*/
|
||||
#define kavl_erase(suf, proot, x, cnt) kavl_erase_##suf(proot, x, cnt)
|
||||
#define kavl_erase_first(suf, proot) kavl_erase_##suf(proot, 0, 0)
|
||||
|
||||
#define kavl_itr_t(suf) struct kavl_itr_##suf
|
||||
|
||||
/**
|
||||
* Place the iterator at the smallest object
|
||||
*
|
||||
* @param suf name suffix used in KAVL_INIT()
|
||||
* @param root root of the tree
|
||||
* @param itr iterator
|
||||
*/
|
||||
#define kavl_itr_first(suf, root, itr) kavl_itr_first_##suf(root, itr)
|
||||
|
||||
/**
|
||||
* Place the iterator at the object equal to or greater than the query
|
||||
*
|
||||
* @param suf name suffix used in KAVL_INIT()
|
||||
* @param root root of the tree
|
||||
* @param x query (in)
|
||||
* @param itr iterator (out)
|
||||
*
|
||||
* @return 1 if find; 0 otherwise. kavl_at(itr) is NULL if and only if query is
|
||||
* larger than all objects in the tree
|
||||
*/
|
||||
#define kavl_itr_find(suf, root, x, itr) kavl_itr_find_##suf(root, x, itr)
|
||||
|
||||
/**
|
||||
* Move to the next object in order
|
||||
*
|
||||
* @param itr iterator (modified)
|
||||
*
|
||||
* @return 1 if there is a next object; 0 otherwise
|
||||
*/
|
||||
#define kavl_itr_next(suf, itr) kavl_itr_next_bidir_##suf(itr, 1)
|
||||
#define kavl_itr_prev(suf, itr) kavl_itr_next_bidir_##suf(itr, 0)
|
||||
|
||||
/**
|
||||
* Return the pointer at the iterator
|
||||
*
|
||||
* @param itr iterator
|
||||
*
|
||||
* @return pointer if present; NULL otherwise
|
||||
*/
|
||||
#define kavl_at(itr) ((itr)->top < (itr)->stack? 0 : *(itr)->top)
|
||||
|
||||
#define KAVL_INIT2(suf, __scope, __type, __head, __cmp) \
|
||||
__KAVL_FIND(suf, __scope, __type, __head, __cmp) \
|
||||
__KAVL_ROTATE(suf, __type, __head) \
|
||||
__KAVL_INSERT(suf, __scope, __type, __head, __cmp) \
|
||||
__KAVL_ERASE(suf, __scope, __type, __head, __cmp) \
|
||||
__KAVL_ITR(suf, __scope, __type, __head, __cmp)
|
||||
|
||||
#define KAVL_INIT(suf, __type, __head, __cmp) \
|
||||
KAVL_INIT2(suf,, __type, __head, __cmp)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,635 @@
|
||||
/* The MIT License
|
||||
|
||||
Copyright (c) 2008, 2009, 2011 by Attractive Chaos <attractor@live.co.uk>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
An example:
|
||||
|
||||
#include "khash.h"
|
||||
KHASH_MAP_INIT_INT(32, char)
|
||||
int main() {
|
||||
int ret, is_missing;
|
||||
khiter_t k;
|
||||
khash_t(32) *h = kh_init(32);
|
||||
k = kh_put(32, h, 5, &ret);
|
||||
kh_value(h, k) = 10;
|
||||
k = kh_get(32, h, 10);
|
||||
is_missing = (k == kh_end(h));
|
||||
k = kh_get(32, h, 5);
|
||||
kh_del(32, h, k);
|
||||
for (k = kh_begin(h); k != kh_end(h); ++k)
|
||||
if (kh_exist(h, k)) kh_value(h, k) = 1;
|
||||
kh_destroy(32, h);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
2013-05-02 (0.2.8):
|
||||
|
||||
* Use quadratic probing. When the capacity is power of 2, stepping function
|
||||
i*(i+1)/2 guarantees to traverse each bucket. It is better than double
|
||||
hashing on cache performance and is more robust than linear probing.
|
||||
|
||||
In theory, double hashing should be more robust than quadratic probing.
|
||||
However, my implementation is probably not for large hash tables, because
|
||||
the second hash function is closely tied to the first hash function,
|
||||
which reduce the effectiveness of double hashing.
|
||||
|
||||
Reference: http://research.cs.vt.edu/AVresearch/hashing/quadratic.php
|
||||
|
||||
2011-12-29 (0.2.7):
|
||||
|
||||
* Minor code clean up; no actual effect.
|
||||
|
||||
2011-09-16 (0.2.6):
|
||||
|
||||
* The capacity is a power of 2. This seems to dramatically improve the
|
||||
speed for simple keys. Thank Zilong Tan for the suggestion. Reference:
|
||||
|
||||
- http://code.google.com/p/ulib/
|
||||
- http://nothings.org/computer/judy/
|
||||
|
||||
* Allow to optionally use linear probing which usually has better
|
||||
performance for random input. Double hashing is still the default as it
|
||||
is more robust to certain non-random input.
|
||||
|
||||
* Added Wang's integer hash function (not used by default). This hash
|
||||
function is more robust to certain non-random input.
|
||||
|
||||
2011-02-14 (0.2.5):
|
||||
|
||||
* Allow to declare global functions.
|
||||
|
||||
2009-09-26 (0.2.4):
|
||||
|
||||
* Improve portability
|
||||
|
||||
2008-09-19 (0.2.3):
|
||||
|
||||
* Corrected the example
|
||||
* Improved interfaces
|
||||
|
||||
2008-09-11 (0.2.2):
|
||||
|
||||
* Improved speed a little in kh_put()
|
||||
|
||||
2008-09-10 (0.2.1):
|
||||
|
||||
* Added kh_clear()
|
||||
* Fixed a compiling error
|
||||
|
||||
2008-09-02 (0.2.0):
|
||||
|
||||
* Changed to token concatenation which increases flexibility.
|
||||
|
||||
2008-08-31 (0.1.2):
|
||||
|
||||
* Fixed a bug in kh_get(), which has not been tested previously.
|
||||
|
||||
2008-08-31 (0.1.1):
|
||||
|
||||
* Added destructor
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __AC_KHASH_H
|
||||
#define __AC_KHASH_H
|
||||
|
||||
/*!
|
||||
@header
|
||||
|
||||
Generic hash table library.
|
||||
*/
|
||||
|
||||
#define AC_VERSION_KHASH_H "0.2.8"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "kalloc.h"
|
||||
|
||||
/* compiler specific configuration */
|
||||
|
||||
#if UINT_MAX == 0xffffffffu
|
||||
typedef unsigned int khint32_t;
|
||||
#elif ULONG_MAX == 0xffffffffu
|
||||
typedef unsigned long khint32_t;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX == ULLONG_MAX
|
||||
typedef unsigned long khint64_t;
|
||||
#else
|
||||
typedef unsigned long long khint64_t;
|
||||
#endif
|
||||
|
||||
#ifndef kh_inline
|
||||
#ifdef _MSC_VER
|
||||
#define kh_inline __inline
|
||||
#else
|
||||
#define kh_inline inline
|
||||
#endif
|
||||
#endif /* kh_inline */
|
||||
|
||||
#ifndef klib_unused
|
||||
#if (defined __clang__ && __clang_major__ >= 3) || (defined __GNUC__ && __GNUC__ >= 3)
|
||||
#define klib_unused __attribute__ ((__unused__))
|
||||
#else
|
||||
#define klib_unused
|
||||
#endif
|
||||
#endif /* klib_unused */
|
||||
|
||||
typedef khint32_t khint_t;
|
||||
typedef khint_t khiter_t;
|
||||
|
||||
#define __ac_isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
|
||||
#define __ac_isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1)
|
||||
#define __ac_iseither(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&3)
|
||||
#define __ac_set_isdel_false(flag, i) (flag[i>>4]&=~(1ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isempty_false(flag, i) (flag[i>>4]&=~(2ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isboth_false(flag, i) (flag[i>>4]&=~(3ul<<((i&0xfU)<<1)))
|
||||
#define __ac_set_isdel_true(flag, i) (flag[i>>4]|=1ul<<((i&0xfU)<<1))
|
||||
|
||||
#define __ac_fsize(m) ((m) < 16? 1 : (m)>>4)
|
||||
|
||||
#ifndef kroundup32
|
||||
#define kroundup32(x) (--(x), (x)|=(x)>>1, (x)|=(x)>>2, (x)|=(x)>>4, (x)|=(x)>>8, (x)|=(x)>>16, ++(x))
|
||||
#endif
|
||||
|
||||
static const double __ac_HASH_UPPER = 0.77;
|
||||
|
||||
#define __KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
typedef struct kh_##name##_s { \
|
||||
khint_t n_buckets, size, n_occupied, upper_bound; \
|
||||
khint32_t *flags; \
|
||||
khkey_t *keys; \
|
||||
khval_t *vals; \
|
||||
void *km; \
|
||||
} kh_##name##_t;
|
||||
|
||||
#define __KHASH_PROTOTYPES(name, khkey_t, khval_t) \
|
||||
extern kh_##name##_t *kh_init_##name(void); \
|
||||
extern void kh_destroy_##name(kh_##name##_t *h); \
|
||||
extern void kh_clear_##name(kh_##name##_t *h); \
|
||||
extern khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
|
||||
extern int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
|
||||
extern khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
|
||||
extern void kh_del_##name(kh_##name##_t *h, khint_t x);
|
||||
|
||||
#define __KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
SCOPE kh_##name##_t *kh_init2_##name(void *km) { \
|
||||
kh_##name##_t *h; \
|
||||
h = (kh_##name##_t*)kcalloc(km, 1, sizeof(kh_##name##_t)); \
|
||||
h->km = km; \
|
||||
return h; \
|
||||
} \
|
||||
SCOPE kh_##name##_t *kh_init_##name(void) { return kh_init2_##name(0); } \
|
||||
SCOPE void kh_destroy_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h) { \
|
||||
void *km = h->km; \
|
||||
kfree(km, (void *)h->keys); kfree(km, h->flags); \
|
||||
kfree(km, (void *)h->vals); \
|
||||
kfree(km, h); \
|
||||
} \
|
||||
} \
|
||||
SCOPE void kh_clear_##name(kh_##name##_t *h) \
|
||||
{ \
|
||||
if (h && h->flags) { \
|
||||
memset(h->flags, 0xaa, __ac_fsize(h->n_buckets) * sizeof(khint32_t)); \
|
||||
h->size = h->n_occupied = 0; \
|
||||
} \
|
||||
} \
|
||||
SCOPE khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key) \
|
||||
{ \
|
||||
if (h->n_buckets) { \
|
||||
khint_t k, i, last, mask, step = 0; \
|
||||
mask = h->n_buckets - 1; \
|
||||
k = __hash_func(key); i = k & mask; \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) return h->n_buckets; \
|
||||
} \
|
||||
return __ac_iseither(h->flags, i)? h->n_buckets : i; \
|
||||
} else return 0; \
|
||||
} \
|
||||
SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
|
||||
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
|
||||
khint32_t *new_flags = 0; \
|
||||
khint_t j = 1; \
|
||||
{ \
|
||||
kroundup32(new_n_buckets); \
|
||||
if (new_n_buckets < 4) new_n_buckets = 4; \
|
||||
if (h->size >= (khint_t)(new_n_buckets * __ac_HASH_UPPER + 0.5)) j = 0; /* requested size is too small */ \
|
||||
else { /* hash table size to be changed (shrink or expand); rehash */ \
|
||||
new_flags = (khint32_t*)kmalloc(h->km, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (!new_flags) return -1; \
|
||||
memset(new_flags, 0xaa, __ac_fsize(new_n_buckets) * sizeof(khint32_t)); \
|
||||
if (h->n_buckets < new_n_buckets) { /* expand */ \
|
||||
khkey_t *new_keys = (khkey_t*)krealloc(h->km, (void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (!new_keys) { kfree(h->km, new_flags); return -1; } \
|
||||
h->keys = new_keys; \
|
||||
if (kh_is_map) { \
|
||||
khval_t *new_vals = (khval_t*)krealloc(h->km, (void *)h->vals, new_n_buckets * sizeof(khval_t)); \
|
||||
if (!new_vals) { kfree(h->km, new_flags); return -1; } \
|
||||
h->vals = new_vals; \
|
||||
} \
|
||||
} /* otherwise shrink */ \
|
||||
} \
|
||||
} \
|
||||
if (j) { /* rehashing is needed */ \
|
||||
for (j = 0; j != h->n_buckets; ++j) { \
|
||||
if (__ac_iseither(h->flags, j) == 0) { \
|
||||
khkey_t key = h->keys[j]; \
|
||||
khval_t val; \
|
||||
khint_t new_mask; \
|
||||
new_mask = new_n_buckets - 1; \
|
||||
if (kh_is_map) val = h->vals[j]; \
|
||||
__ac_set_isdel_true(h->flags, j); \
|
||||
while (1) { /* kick-out process; sort of like in Cuckoo hashing */ \
|
||||
khint_t k, i, step = 0; \
|
||||
k = __hash_func(key); \
|
||||
i = k & new_mask; \
|
||||
while (!__ac_isempty(new_flags, i)) i = (i + (++step)) & new_mask; \
|
||||
__ac_set_isempty_false(new_flags, i); \
|
||||
if (i < h->n_buckets && __ac_iseither(h->flags, i) == 0) { /* kick out the existing element */ \
|
||||
{ khkey_t tmp = h->keys[i]; h->keys[i] = key; key = tmp; } \
|
||||
if (kh_is_map) { khval_t tmp = h->vals[i]; h->vals[i] = val; val = tmp; } \
|
||||
__ac_set_isdel_true(h->flags, i); /* mark it as deleted in the old hash table */ \
|
||||
} else { /* write the element and jump out of the loop */ \
|
||||
h->keys[i] = key; \
|
||||
if (kh_is_map) h->vals[i] = val; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (h->n_buckets > new_n_buckets) { /* shrink the hash table */ \
|
||||
h->keys = (khkey_t*)krealloc(h->km, (void *)h->keys, new_n_buckets * sizeof(khkey_t)); \
|
||||
if (kh_is_map) h->vals = (khval_t*)krealloc(h->km, (void *)h->vals, new_n_buckets * sizeof(khval_t)); \
|
||||
} \
|
||||
kfree(h->km, h->flags); /* free the working space */ \
|
||||
h->flags = new_flags; \
|
||||
h->n_buckets = new_n_buckets; \
|
||||
h->n_occupied = h->size; \
|
||||
h->upper_bound = (khint_t)(h->n_buckets * __ac_HASH_UPPER + 0.5); \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
SCOPE khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret) \
|
||||
{ \
|
||||
khint_t x; \
|
||||
if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
|
||||
if (h->n_buckets > (h->size<<1)) { \
|
||||
if (kh_resize_##name(h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \
|
||||
*ret = -1; return h->n_buckets; \
|
||||
} \
|
||||
} else if (kh_resize_##name(h, h->n_buckets + 1) < 0) { /* expand the hash table */ \
|
||||
*ret = -1; return h->n_buckets; \
|
||||
} \
|
||||
} /* TODO: to implement automatically shrinking; resize() already support shrinking */ \
|
||||
{ \
|
||||
khint_t k, i, site, last, mask = h->n_buckets - 1, step = 0; \
|
||||
x = site = h->n_buckets; k = __hash_func(key); i = k & mask; \
|
||||
if (__ac_isempty(h->flags, i)) x = i; /* for speed up */ \
|
||||
else { \
|
||||
last = i; \
|
||||
while (!__ac_isempty(h->flags, i) && (__ac_isdel(h->flags, i) || !__hash_equal(h->keys[i], key))) { \
|
||||
if (__ac_isdel(h->flags, i)) site = i; \
|
||||
i = (i + (++step)) & mask; \
|
||||
if (i == last) { x = site; break; } \
|
||||
} \
|
||||
if (x == h->n_buckets) { \
|
||||
if (__ac_isempty(h->flags, i) && site != h->n_buckets) x = site; \
|
||||
else x = i; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
if (__ac_isempty(h->flags, x)) { /* not present at all */ \
|
||||
h->keys[x] = key; \
|
||||
__ac_set_isboth_false(h->flags, x); \
|
||||
++h->size; ++h->n_occupied; \
|
||||
*ret = 1; \
|
||||
} else if (__ac_isdel(h->flags, x)) { /* deleted */ \
|
||||
h->keys[x] = key; \
|
||||
__ac_set_isboth_false(h->flags, x); \
|
||||
++h->size; \
|
||||
*ret = 2; \
|
||||
} else *ret = 0; /* Don't touch h->keys[x] if present and not deleted */ \
|
||||
return x; \
|
||||
} \
|
||||
SCOPE void kh_del_##name(kh_##name##_t *h, khint_t x) \
|
||||
{ \
|
||||
if (x != h->n_buckets && !__ac_iseither(h->flags, x)) { \
|
||||
__ac_set_isdel_true(h->flags, x); \
|
||||
--h->size; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define KHASH_DECLARE(name, khkey_t, khval_t) \
|
||||
__KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
__KHASH_PROTOTYPES(name, khkey_t, khval_t)
|
||||
|
||||
#define KHASH_INIT2(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
__KHASH_TYPE(name, khkey_t, khval_t) \
|
||||
__KHASH_IMPL(name, SCOPE, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
|
||||
|
||||
#define KHASH_INIT(name, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal) \
|
||||
KHASH_INIT2(name, static kh_inline klib_unused, khkey_t, khval_t, kh_is_map, __hash_func, __hash_equal)
|
||||
|
||||
/* --- BEGIN OF HASH FUNCTIONS --- */
|
||||
|
||||
/*! @function
|
||||
@abstract Integer hash function
|
||||
@param key The integer [khint32_t]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_int_hash_func(key) (khint32_t)(key)
|
||||
/*! @function
|
||||
@abstract Integer comparison function
|
||||
*/
|
||||
#define kh_int_hash_equal(a, b) ((a) == (b))
|
||||
/*! @function
|
||||
@abstract 64-bit integer hash function
|
||||
@param key The integer [khint64_t]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_int64_hash_func(key) (khint32_t)((key)>>33^(key)^(key)<<11)
|
||||
/*! @function
|
||||
@abstract 64-bit integer comparison function
|
||||
*/
|
||||
#define kh_int64_hash_equal(a, b) ((a) == (b))
|
||||
/*! @function
|
||||
@abstract const char* hash function
|
||||
@param s Pointer to a null terminated string
|
||||
@return The hash value
|
||||
*/
|
||||
static kh_inline khint_t __ac_X31_hash_string(const char *s)
|
||||
{
|
||||
khint_t h = (khint_t)*s;
|
||||
if (h) for (++s ; *s; ++s) h = (h << 5) - h + (khint_t)*s;
|
||||
return h;
|
||||
}
|
||||
/*! @function
|
||||
@abstract Another interface to const char* hash function
|
||||
@param key Pointer to a null terminated string [const char*]
|
||||
@return The hash value [khint_t]
|
||||
*/
|
||||
#define kh_str_hash_func(key) __ac_X31_hash_string(key)
|
||||
/*! @function
|
||||
@abstract Const char* comparison function
|
||||
*/
|
||||
#define kh_str_hash_equal(a, b) (strcmp(a, b) == 0)
|
||||
|
||||
static kh_inline khint_t __ac_Wang_hash(khint_t key)
|
||||
{
|
||||
key += ~(key << 15);
|
||||
key ^= (key >> 10);
|
||||
key += (key << 3);
|
||||
key ^= (key >> 6);
|
||||
key += ~(key << 11);
|
||||
key ^= (key >> 16);
|
||||
return key;
|
||||
}
|
||||
#define kh_int_hash_func2(key) __ac_Wang_hash((khint_t)key)
|
||||
|
||||
static kh_inline khint64_t __ac_Wang_hash64(khint64_t key)
|
||||
{
|
||||
key = ~key + (key << 21);
|
||||
key = key ^ key >> 24;
|
||||
key = (key + (key << 3)) + (key << 8);
|
||||
key = key ^ key >> 14;
|
||||
key = (key + (key << 2)) + (key << 4);
|
||||
key = key ^ key >> 28;
|
||||
key = key + (key << 31);
|
||||
return key;
|
||||
}
|
||||
#define kh_int_hash64_func2(key) __ac_Wang_hash64((khint64_t)key)
|
||||
|
||||
/* --- END OF HASH FUNCTIONS --- */
|
||||
|
||||
/* Other convenient macros... */
|
||||
|
||||
/*!
|
||||
@abstract Type of the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define khash_t(name) kh_##name##_t
|
||||
|
||||
/*! @function
|
||||
@abstract Initiate a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@return Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_init(name) kh_init_##name()
|
||||
#define kh_init2(name, km) kh_init2_##name(km)
|
||||
|
||||
/*! @function
|
||||
@abstract Destroy a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_destroy(name, h) kh_destroy_##name(h)
|
||||
|
||||
/*! @function
|
||||
@abstract Reset a hash table without deallocating memory.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
*/
|
||||
#define kh_clear(name, h) kh_clear_##name(h)
|
||||
|
||||
/*! @function
|
||||
@abstract Resize a hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param s New size [khint_t]
|
||||
*/
|
||||
#define kh_resize(name, h, s) kh_resize_##name(h, s)
|
||||
|
||||
/*! @function
|
||||
@abstract Insert a key to the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Key [type of keys]
|
||||
@param r Extra return code: -1 if the operation failed;
|
||||
0 if the key is present in the hash table;
|
||||
1 if the bucket is empty (never used); 2 if the element in
|
||||
the bucket has been deleted [int*]
|
||||
@return Iterator to the inserted element [khint_t]
|
||||
*/
|
||||
#define kh_put(name, h, k, r) kh_put_##name(h, k, r)
|
||||
|
||||
/*! @function
|
||||
@abstract Retrieve a key from the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Key [type of keys]
|
||||
@return Iterator to the found element, or kh_end(h) if the element is absent [khint_t]
|
||||
*/
|
||||
#define kh_get(name, h, k) kh_get_##name(h, k)
|
||||
|
||||
/*! @function
|
||||
@abstract Remove a key from the hash table.
|
||||
@param name Name of the hash table [symbol]
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param k Iterator to the element to be deleted [khint_t]
|
||||
*/
|
||||
#define kh_del(name, h, k) kh_del_##name(h, k)
|
||||
|
||||
/*! @function
|
||||
@abstract Test whether a bucket contains data.
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return 1 if containing data; 0 otherwise [int]
|
||||
*/
|
||||
#define kh_exist(h, x) (!__ac_iseither((h)->flags, (x)))
|
||||
|
||||
/*! @function
|
||||
@abstract Get key given an iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return Key [type of keys]
|
||||
*/
|
||||
#define kh_key(h, x) ((h)->keys[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Get value given an iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param x Iterator to the bucket [khint_t]
|
||||
@return Value [type of values]
|
||||
@discussion For hash sets, calling this results in segfault.
|
||||
*/
|
||||
#define kh_val(h, x) ((h)->vals[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Alias of kh_val()
|
||||
*/
|
||||
#define kh_value(h, x) ((h)->vals[x])
|
||||
|
||||
/*! @function
|
||||
@abstract Get the start iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return The start iterator [khint_t]
|
||||
*/
|
||||
#define kh_begin(h) (khint_t)(0)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the end iterator
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return The end iterator [khint_t]
|
||||
*/
|
||||
#define kh_end(h) ((h)->n_buckets)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the number of elements in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return Number of elements in the hash table [khint_t]
|
||||
*/
|
||||
#define kh_size(h) ((h)->size)
|
||||
|
||||
/*! @function
|
||||
@abstract Get the number of buckets in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@return Number of buckets in the hash table [khint_t]
|
||||
*/
|
||||
#define kh_n_buckets(h) ((h)->n_buckets)
|
||||
|
||||
/*! @function
|
||||
@abstract Iterate over the entries in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param kvar Variable to which key will be assigned
|
||||
@param vvar Variable to which value will be assigned
|
||||
@param code Block of code to execute
|
||||
*/
|
||||
#define kh_foreach(h, kvar, vvar, code) { khint_t __i; \
|
||||
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
|
||||
if (!kh_exist(h,__i)) continue; \
|
||||
(kvar) = kh_key(h,__i); \
|
||||
(vvar) = kh_val(h,__i); \
|
||||
code; \
|
||||
} }
|
||||
|
||||
/*! @function
|
||||
@abstract Iterate over the values in the hash table
|
||||
@param h Pointer to the hash table [khash_t(name)*]
|
||||
@param vvar Variable to which value will be assigned
|
||||
@param code Block of code to execute
|
||||
*/
|
||||
#define kh_foreach_value(h, vvar, code) { khint_t __i; \
|
||||
for (__i = kh_begin(h); __i != kh_end(h); ++__i) { \
|
||||
if (!kh_exist(h,__i)) continue; \
|
||||
(vvar) = kh_val(h,__i); \
|
||||
code; \
|
||||
} }
|
||||
|
||||
/* More conenient interfaces */
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash set containing integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_INT(name) \
|
||||
KHASH_INIT(name, khint32_t, char, 0, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_INT(name, khval_t) \
|
||||
KHASH_INIT(name, khint32_t, khval_t, 1, kh_int_hash_func, kh_int_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing 64-bit integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_INT64(name) \
|
||||
KHASH_INIT(name, khint64_t, char, 0, kh_int64_hash_func, kh_int64_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing 64-bit integer keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_INT64(name, khval_t) \
|
||||
KHASH_INIT(name, khint64_t, khval_t, 1, kh_int64_hash_func, kh_int64_hash_equal)
|
||||
|
||||
typedef const char *kh_cstr_t;
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing const char* keys
|
||||
@param name Name of the hash table [symbol]
|
||||
*/
|
||||
#define KHASH_SET_INIT_STR(name) \
|
||||
KHASH_INIT(name, kh_cstr_t, char, 0, kh_str_hash_func, kh_str_hash_equal)
|
||||
|
||||
/*! @function
|
||||
@abstract Instantiate a hash map containing const char* keys
|
||||
@param name Name of the hash table [symbol]
|
||||
@param khval_t Type of values [type]
|
||||
*/
|
||||
#define KHASH_MAP_INIT_STR(name, khval_t) \
|
||||
KHASH_INIT(name, kh_cstr_t, khval_t, 1, kh_str_hash_func, kh_str_hash_equal)
|
||||
|
||||
#endif /* __AC_KHASH_H */
|
||||
@@ -52,6 +52,17 @@ typedef struct {
|
||||
} \
|
||||
l[i] = tmp; \
|
||||
} \
|
||||
void ks_heapup_##name(size_t n, type_t l[]) \
|
||||
{ \
|
||||
size_t i, k = n - 1; \
|
||||
type_t tmp = l[k]; \
|
||||
while (k) { \
|
||||
i = (k - 1) >> 1; \
|
||||
if (__sort_lt(tmp, l[i])) break; \
|
||||
l[k] = l[i]; k = i; \
|
||||
} \
|
||||
l[k] = tmp; \
|
||||
} \
|
||||
void ks_heapmake_##name(size_t lsize, type_t l[]) \
|
||||
{ \
|
||||
size_t i; \
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef KSW2_H_
|
||||
#define KSW2_H_
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdint.h>
|
||||
|
||||
#define KSW_NEG_INF -0x40000000
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
|
||||
@@ -8,16 +8,103 @@
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// setvbuf(stderr, NULL, _IONBF, 0);
|
||||
int i, ret;
|
||||
yak_reset_realtime();
|
||||
init_opt(&asm_opt);
|
||||
if (!CommandLine_process(argc, argv, &asm_opt)) return 0;
|
||||
ret = ha_assemble();
|
||||
|
||||
// bit_extz_t exz, exz64; init_bit_extz_t(&exz, 2); init_bit_extz_t(&exz64, 2);
|
||||
|
||||
// char *pstr = "GACCCAG", *tsrt = "GTTGTTAATTCCAT"; int32_t thre = 14; clear_align(exz); clear_align(exz64);
|
||||
// ed_band_cal_extension_64_0_w_trace((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz);
|
||||
// // // ed_band_cal_semi_64_w_absent_diag((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, 0, &exz);
|
||||
// fprintf(stderr, "\n[M::%s::] exz.err::%d, exz.ps::%d, exz.pe::%d, exz.ts::%d, exz.te::%d\n", __func__,
|
||||
// exz.err, exz.ps, exz.pe, exz.ts, exz.te);
|
||||
// cigar_check((char*)pstr, (char*)tsrt, &(exz));
|
||||
// ed_band_cal_extension_64_0_w((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz);
|
||||
// fprintf(stderr, "\n[M::%s::] exz.err::%d, exz.ps::%d, exz.pe::%d, exz.ts::%d, exz.te::%d\n", __func__,
|
||||
// exz.err, exz.ps, exz.pe, exz.ts, exz.te);
|
||||
// ed_band_cal_semi_infi_w((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, NULL, &exz);
|
||||
// ed_band_cal_semi_64_w((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz64);
|
||||
// fprintf(stderr, "\n[M::%s::] exz.err::%d, exz64.err::%d, exz.ps::%d, exz64.ps::%d, exz.pe::%d, exz64.pe::%d, exz.ts::%d, exz64.ts::%d, exz.te::%d, exz64.te::%d\n", __func__,
|
||||
// exz.err, exz64.err, exz.ps, exz64.ps, exz.pe, exz64.pe, exz.ts, exz64.ts, exz.te, exz64.te);
|
||||
// ed_band_cal_semi_64_w_trace((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz64);
|
||||
// cigar_check((char*)pstr, (char*)tsrt, &(exz64));
|
||||
|
||||
|
||||
// char *pstr = "TGT", *tsrt = "CTGT"; int32_t thre = 1;
|
||||
// ed_band_cal_global_infi_w((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, NULL, &exz);
|
||||
// ed_band_cal_global_64_w((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz64);
|
||||
// ed_band_cal_global_64_w_trace((char*)pstr, strlen(pstr), (char*)tsrt, strlen(tsrt), thre, &exz64);
|
||||
// fprintf(stderr, "\n[M::%s::] exz.err::%d, exz64.err::%d, exz.ps::%d, exz64.ps::%d, exz.pe::%d, exz64.pe::%d, exz.ts::%d, exz64.ts::%d, exz.te::%d, exz64.te::%d\n", __func__,
|
||||
// exz.err, exz64.err, exz.ps, exz64.ps, exz.pe, exz64.pe, exz.ts, exz64.ts, exz.te, exz64.te);
|
||||
// cigar_check((char*)pstr, (char*)tsrt, &(exz64));
|
||||
|
||||
// ed_band_cal_extension_infi0_w((char *)"AAT", 3, (char *)"ACTTTTTT", 8, 2, NULL, &exz);
|
||||
// ed_band_cal_extension_64_w((char *)"AAT", 3, (char *)"ACTTTTTT", 8, 2, &exz64);
|
||||
// fprintf(stderr, "\n[M::%s::] exz.err::%d, exz64.err::%d, exz.ps::%d, exz64.ps::%d, exz.pe::%d, exz64.pe::%d, exz.ts::%d, exz64.ts::%d, exz.te::%d, exz64.te::%d\n", __func__,
|
||||
// exz.err, exz64.err, exz.ps, exz64.ps, exz.pe, exz64.pe, exz.ts, exz64.ts, exz.te, exz64.te);
|
||||
|
||||
//bit_extz_t exz; ///ed_band_cal_global_128bit(t_string+r_ts, t_end+1-r_ts, q_string, ql, thres, &exz);
|
||||
// ed_band_cal_extension_128bit((char *)"AAGTTTA", 7, (char *)"CCTTTTTT", 8, 4, &exz);
|
||||
// ed_band_cal_extension_128bit((char *)"AA", 2, (char *)"ACTTTTTT", 8, 1, &exz);
|
||||
// fprintf(stderr, "ed_extension::%d, pe::%d, te::%d\n", exz.err, exz.pe, exz.te);
|
||||
// exit(1);
|
||||
|
||||
|
||||
|
||||
// fprintf(stderr, "[M::%s::] ed_global::%d, ed_global_128bit::%d\n", __func__,
|
||||
// ed_band_cal_global((char *)"ACT", 3, (char *)"AAT", 3, 1),
|
||||
// ed_band_cal_global_128bit((char *)"ACT", 3, (char *)"AAT", 3, 1));
|
||||
|
||||
// fprintf(stderr, "[M::%s::] ed_global::%d, ed_global_128bit::%d\n", __func__,
|
||||
// ed_band_cal_global((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3),
|
||||
// ed_band_cal_global_128bit((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3));
|
||||
// exit(1);
|
||||
|
||||
int8_t simd_auto = 0;
|
||||
#if defined(__x86_64__) || defined(__i386__)
|
||||
__builtin_cpu_init();
|
||||
if (__builtin_cpu_supports("avx512f")) simd_auto = 2;
|
||||
else if (__builtin_cpu_supports("avx2")) simd_auto = 1;
|
||||
else simd_auto = 0;
|
||||
#endif
|
||||
|
||||
if (simd_auto) {
|
||||
fprintf(stderr, "[M::%s::auto] detected CPU support for %s\n", __func__, (simd_auto == 2) ? "AVX-512" : "AVX2");
|
||||
} else {
|
||||
fprintf(stderr, "[M::%s::auto] no supported SIMD extension detected; falling back to non-SIMD\n", __func__);
|
||||
}
|
||||
|
||||
if (asm_opt.simd_mm == 0 || asm_opt.simd_mm == 1 || asm_opt.simd_mm == 2) {
|
||||
fprintf(stderr, "[M::%s::user] user requested %s mode\n", __func__, (asm_opt.simd_mm == 2) ? "AVX-512" : ((asm_opt.simd_mm == 1) ? "AVX2" : "non-SIMD"));
|
||||
if(asm_opt.simd_mm > simd_auto) asm_opt.simd_mm = simd_auto;
|
||||
} else {
|
||||
asm_opt.simd_mm = simd_auto;
|
||||
if(asm_opt.simd_mm >= 1) asm_opt.simd_mm = 1; ///use avx2 rather than avx512, looks like avx512 still has issues right now
|
||||
}
|
||||
|
||||
fprintf(stderr, "[M::%s::final] using %s mode\n", __func__, (asm_opt.simd_mm == 2) ? "AVX-512" : ((asm_opt.simd_mm == 1) ? "AVX2" : "non-SIMD"));
|
||||
|
||||
fprintf(stderr, "[M::%s::]\traw_aln::%d\tpost_syn::%d\n", __func__, asm_opt.realn_raw, asm_opt.post_syn);
|
||||
|
||||
if(asm_opt.recurrent_err_test) {
|
||||
fprintf(stderr, "[M::%s::] Enable recurrent sequencing-error filtering\n", __func__);
|
||||
} else {
|
||||
fprintf(stderr, "[M::%s::] Disable recurrent sequencing-error filtering\n", __func__);
|
||||
}
|
||||
|
||||
|
||||
if(asm_opt.sec_in) ret = ha_assemble_pair();
|
||||
else if(asm_opt.dbg_ovec_cal) ret = ha_ec_dbg();
|
||||
else ret = ha_assemble();
|
||||
|
||||
destory_opt(&asm_opt);
|
||||
fprintf(stderr, "[M::%s] Version: %s\n", __func__, HA_VERSION);
|
||||
fprintf(stderr, "[M::%s] CMD:", __func__);
|
||||
for (i = 0; i < argc; ++i)
|
||||
fprintf(stderr, " %s", argv[i]);
|
||||
fprintf(stderr, "\n[M::%s] Real time: %.3f sec; CPU: %.3f sec; Peak RSS: %.3f GB\n", __func__, yak_realtime(), yak_cputime(), yak_peakrss_in_gb());
|
||||
fprintf(stderr, "\n[M::%s] Real time: %.3f sec; CPU: %.3f sec; Peak RSS: %.3f GB; SIMD: %u\n", __func__, yak_realtime(), yak_cputime(), yak_peakrss_in_gb(), asm_opt.simd_mm);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#ifndef __RCUT__
|
||||
#define __RCUT__
|
||||
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include "kvec.h"
|
||||
@@ -118,11 +120,12 @@ static inline double kr_drand_r(uint64_t *x)
|
||||
return u.d - 1.0;
|
||||
}
|
||||
|
||||
void mc_solve(hap_overlaps_list* ovlp, trans_chain* t_ch, kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, double f_rate, uint8_t* trio_flag, uint32_t renew_s, int8_t *s, uint32_t is_sys, bubble_type* bub, kv_u_trans_t *ref);
|
||||
void mc_solve(hap_overlaps_list* ovlp, trans_chain* t_ch, kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, double f_rate, uint8_t* trio_flag, uint32_t renew_s, int8_t *s, uint32_t is_sys, bubble_type* bub, kv_u_trans_t *ref, int clean_ov, int is_dump);
|
||||
void debug_mc_g_t(const char* name);
|
||||
void mc_solve_general(kv_u_trans_t *ta, uint32_t un, kv_gg_status *s, uint16_t hapN, uint16_t update_ta, uint16_t write_dump);
|
||||
kv_gg_status *init_mc_gg_status(ma_ug_t *ug, asg_t *read_g, ma_sub_t* coverage_cut,
|
||||
ma_hit_t_alloc* sources, R_to_U* ruIndex, uint64_t t_cov, uint16_t hapN);
|
||||
void destory_mc_gg_t(mc_gg_t **p);
|
||||
void debug_mc_gg_t(const char* fn, uint32_t update_ta, uint32_t convert_mc_g_t);
|
||||
void quick_debug_phasing(const char* fn);
|
||||
#endif
|
||||
+403
-659
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,12 @@ double yak_realtime(void)
|
||||
return yak_realtime_core() - yak_realtime0;
|
||||
}
|
||||
|
||||
double yak_realtime_0(void)
|
||||
{
|
||||
return yak_realtime_core();
|
||||
}
|
||||
|
||||
|
||||
long yak_peakrss(void)
|
||||
{
|
||||
struct rusage r;
|
||||
|
||||
@@ -968,7 +968,7 @@ pdq *pq_p, pdq *pq_a, uint8_t fp, uint8_t fa, long long *d)
|
||||
for (i = 0; i < ns; i++)
|
||||
{
|
||||
if(as[i].del || as[i].v == sv) continue;
|
||||
nc = dfs_set(g, as[i].v, s>>1, stack, tt, vis, fa);
|
||||
nc = dfs_set(g, as[i].v, s>>1, stack, tt, vis, fa);///nc > 0 means as[i].v and sv have common suffix
|
||||
if(nc && check_trans_relation_by_path(sv, as[i].v, pq_p, NULL, NULL, pq_a, NULL, NULL, g,
|
||||
vis, fp+fa, nc, 0.45, d))
|
||||
{
|
||||
@@ -1100,11 +1100,12 @@ int get_min_dec(clean_mul_t *cl, uint32_t positive_flag, uint32_t negative_flag,
|
||||
clean_t *p = NULL;
|
||||
(*v) = (uint32_t)-1;
|
||||
for (i = 0; i < cl->n; i++) cl->a[i].is_b = 0, cl->a[i].min_v = (uint32_t)-1;
|
||||
kt_for(cl->n, bub_iden_worker, cl, cl->g->n_seq<<1);
|
||||
kt_for(cl->n, bub_iden_worker, cl, cl->g->n_seq<<1);///fast check if there are bubbles in graph
|
||||
for (i = 0; i < cl->n; i++)
|
||||
{
|
||||
if(cl->a[i].is_b) ///pop bubble
|
||||
{
|
||||
///pop all bubbles
|
||||
n_pop = asg_pop_bubble_primary_trio(cl->g, cl->ug, cl->bs_flag, &(cl->a[i].b),
|
||||
cl->max_dist, positive_flag, negative_flag, o);
|
||||
if(n_pop ==0) fprintf(stderr, "ERROR-n_pop\n");
|
||||
@@ -1116,6 +1117,7 @@ int get_min_dec(clean_mul_t *cl, uint32_t positive_flag, uint32_t negative_flag,
|
||||
{
|
||||
if(cl->a[i].min_v == (uint32_t)-1) continue;
|
||||
// if(b->min_v == (uint32_t)-1 || (b->min_d > d) || (b->min_d == d && b->min_v < eid))
|
||||
///looks like select the minum node, and back
|
||||
if(!p || p->min_d > cl->a[i].min_d ||
|
||||
(p->min_d == cl->a[i].min_d && cl->g->seq[p->min_v>>1].len > cl->g->seq[cl->a[i].min_v>>1].len) ||
|
||||
(p->min_d == cl->a[i].min_d && cl->g->seq[p->min_v>>1].len == cl->g->seq[cl->a[i].min_v>>1].len && p->min_v > cl->a[i].min_v))
|
||||
|
||||
Reference in New Issue
Block a user