Compare commits

..
31 Commits
Author SHA1 Message Date
chhylp123 bca2394b69 unsucessful hpc mark 2026-05-15 19:02:16 -04:00
chhylp123 7884b5ad88 regen_scb 2026-05-03 03:34:23 -04:00
chhylp123 f5078f7b23 seperate phase dp to ont/hifi 2026-04-15 11:59:09 -04:00
chhylp123 6b026f0caa fast dp hybrid 2026-04-14 14:31:02 -04:00
chhylp123 ba8627fb23 phasing speedup 2026-04-11 22:33:18 -04:00
chhylp123 815d709fb9 fall back to avx2 2026-04-01 22:28:54 -04:00
chhylp123 a137a6b06f r878 2026-03-28 11:02:52 -04:00
chhylp123 e53fc786bd fix slow running time vs r726 2026-03-27 15:37:44 -04:00
chhylp123 aa4d12b1c6 simd version 0 2026-03-24 17:54:36 -04:00
chhylp123 9a2884f518 backup avx 2026-03-20 16:06:06 -04:00
chhylp123 5e5a1568ed error est funcion 2026-03-17 17:27:48 -04:00
chhylp123 c0478830e6 err_estimate 2026-03-01 08:51:53 -05:00
chhylp123 2fa4ef224f updating final overlapping 2026-02-17 18:07:49 -05:00
chhylp123 86311effb9 running time bug fixed 2026-02-16 10:46:28 -05:00
chhylp123 53e1b150c3 bug fixed for memory leak 2026-02-12 16:47:32 -05:00
chhylp123 67877deed3 r852 -> hybrid correction 2026-02-11 16:38:57 -05:00
chhylp123 d6ba102d42 r852 -> hybrid correction 2026-02-11 16:38:27 -05:00
chhylp123 ec9a8b222d add new options for ont assembly 2025-03-18 12:29:48 -04:00
chhylp123 b3b18ab1d0 r721 2025-03-14 01:40:21 -04:00
chhylp123 a96191560e eliminate SVs 2025-03-10 16:09:02 -04:00
chhylp123 79387d081f update readme 2025-01-31 20:34:12 -05:00
chhylp123 4733ef5011 update readme for ont 2025-01-31 20:27:22 -05:00
chhylp123 2c77b3c87e ont overlapping 2024-12-21 03:17:17 -05:00
chhylp123 3067771783 update for low coverge data 2024-12-16 06:25:31 -05:00
chhylp123 4889f1c6d8 fix high-coverage issue for ONT 2024-12-07 20:02:57 -05:00
chhylp123 dbdef7ff63 fix Print_H 2024-12-06 05:29:19 -05:00
chhylp123 184eb0a9fe fix the memory issue 2024-12-06 05:17:30 -05:00
chhylp123 676385cf8e ont simplex support 2024-11-27 13:27:13 -05:00
chhylp123 80fa5ed436 ONT EC 2024-11-12 23:53:29 -05:00
chhylp123 6de4e14782 update before fly HPC 2024-10-29 14:59:52 -04:00
chhylp123 ade800990e update for reference read hpc 2024-10-27 13:22:06 -04:00
75 changed files with 202171 additions and 175384 deletions
+127 -25
View File
@@ -883,16 +883,14 @@ static void worker_ec_save(void *data, long i, int tid)
void Output_corrected_reads() void Output_corrected_reads()
{ {
long long i; uint64_t i; UC_Read g_read;
UC_Read g_read;
init_UC_Read(&g_read); init_UC_Read(&g_read);
char* gfa_name = (char*)malloc(strlen(asm_opt.output_file_name)+35); char* gfa_name = (char*)malloc(strlen(asm_opt.output_file_name)+35);
sprintf(gfa_name, "%s.ec.fa", asm_opt.output_file_name); sprintf(gfa_name, "%s.ec.fa", asm_opt.output_file_name);
FILE* output_file = fopen(gfa_name, "w"); FILE *output_file = fopen(gfa_name, "w");
free(gfa_name); 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); recover_UC_Read(&g_read, &R_INF, i);
fwrite(">", 1, 1, output_file); fwrite(">", 1, 1, output_file);
fwrite(Get_NAME(R_INF, i), 1, Get_NAME_LENGTH(R_INF, i), output_file); fwrite(Get_NAME(R_INF, i), 1, Get_NAME_LENGTH(R_INF, i), output_file);
@@ -904,6 +902,40 @@ void Output_corrected_reads()
fclose(output_file); 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() void debug_print_pob_regions()
{ {
uint64_t i, total = 0; uint64_t i, total = 0;
@@ -970,7 +1002,7 @@ void prt_dbg_rs(FILE *fp, Debug_reads* x, uint64_t round)
destory_UC_Read(&g_read); 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) 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; int hom_cov, het_cov, r_out = 0;
ha_flt_tab_hp = ha_idx_hp = NULL; (*tot_b) = (*tot_e) = 0; ha_flt_tab_hp = ha_idx_hp = NULL; (*tot_b) = (*tot_e) = 0;
@@ -990,7 +1022,14 @@ void ha_ec(int64_t round, int num_pround, int des_idx, uint64_t *tot_b, uint64_t
het_cnt = NULL; 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(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); 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); 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);
@@ -1024,6 +1063,21 @@ void ha_ec(int64_t round, int num_pround, int des_idx, uint64_t *tot_b, uint64_t
} }
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) void ha_overlap_and_correct(int round)
{ {
int i, hom_cov, het_cov, r_out = 0; int i, hom_cov, het_cov, r_out = 0;
@@ -1058,7 +1112,7 @@ void ha_overlap_and_correct(int round)
// fprintf(stderr, "[M::%s::%.3f] ==> chaining\n", __func__, yak_realtime_0()-tt0); // fprintf(stderr, "[M::%s::%.3f] ==> chaining\n", __func__, yak_realtime_0()-tt0);
// exit(1); // 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_pt_destroy(ha_idx);
ha_idx = NULL; ha_idx = NULL;
@@ -1673,6 +1727,7 @@ void Output_PAF()
fclose(output_file); fclose(output_file);
fprintf(stderr, "PAF has been written.\n"); fprintf(stderr, "PAF has been written.\n");
exit(1);
} }
@@ -1898,12 +1953,12 @@ void ha_overlap_final(void)
asm_opt.het_cov = het_cov; asm_opt.het_cov = het_cov;
} }
void ha_ec_ff(int renew_idx) void ha_ec_ff(int renew_idx, int8_t pre_load_idx, uint64_t w_tmp)
{ {
int hom_cov, het_cov; int hom_cov, het_cov;
ha_flt_tab_hp = ha_idx_hp = NULL; ha_flt_tab_hp = ha_idx_hp = NULL;
if(ha_idx && renew_idx) { if((ha_idx) && (renew_idx) && (!pre_load_idx)) {
ha_pt_destroy(ha_idx); ha_idx = NULL; ha_pt_destroy(ha_idx); ha_idx = NULL;
} }
@@ -1912,9 +1967,16 @@ void ha_ec_ff(int renew_idx)
asm_opt.hom_cov = hom_cov; asm_opt.het_cov = het_cov; 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); 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; ha_pt_destroy(ha_idx); ha_idx = NULL;
}
} }
static void worker_ov_utg(void *data, long i, int tid) static void worker_ov_utg(void *data, long i, int tid)
@@ -1977,8 +2039,7 @@ int ha_assemble_ovec(void)
ha_flt_tab = ha_idx = NULL; ha_flt_tab = ha_idx = NULL;
// construct hash table for high occurrence k-mers // construct hash table for high occurrence k-mers
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) 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_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
ha_opt_update_cov(&asm_opt, hom_cov); ha_opt_update_cov(&asm_opt, hom_cov);
} }
@@ -2000,57 +2061,98 @@ int ha_assemble_ovec(void)
return 0; 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) int ha_assemble(void)
{ {
// debug_mc_g_t(MC_NAME); // debug_mc_g_t(MC_NAME);
// debug_mc_gg_t(MC_NAME, 0, 0); // debug_mc_gg_t(MC_NAME, 0, 0);
// quick_debug_phasing(MC_NAME); // quick_debug_phasing(MC_NAME);
extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o); extern void ha_extract_print_list(const All_reads *rs, int n_rounds, const char *o);
int r, hom_cov = -1, ovlp_loaded = 0; uint64_t tot_b, tot_e; 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 && load_all_data_from_disk(&R_INF.paf, &R_INF.reverse_paf, asm_opt.output_file_name)) { 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; ovlp_loaded = 1;
fprintf(stderr, "[M::%s::%.3f*%.2f] ==> loaded corrected reads and overlaps from disk\n", __func__, yak_realtime(), yak_cpu_usage()); 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) { if (asm_opt.extract_list) {
ha_extract_print_list(&R_INF, asm_opt.extract_iter, asm_opt.extract_list); ha_extract_print_list(&R_INF, asm_opt.extract_iter, asm_opt.extract_list);
exit(0); exit(0);
} }
if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads(); 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.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 (asm_opt.het_cov == -1024) hap_recalculate_peaks(asm_opt.output_file_name), ovlp_loaded = 2;
} }
if (!ovlp_loaded) { if (!ovlp_loaded) {
ha_flt_tab = ha_idx = NULL; 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((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 // construct hash table for high occurrence k-mers
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) 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_flt_tab = ha_ft_gen(&asm_opt, &R_INF, &hom_cov, 0, 0);
ha_opt_update_cov(&asm_opt, hom_cov); ha_opt_update_cov(&asm_opt, hom_cov);
} }
// error correction // error correction
assert(asm_opt.number_of_round > 0); 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) { 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 ha_opt_reset_to_round(&asm_opt, r); // this update asm_opt.roundID and a few other fields
tot_b = tot_e = 0; tot_b = tot_e = 0;
// ha_overlap_and_correct(r); // 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); 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(), 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); 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: %lu; # corrected bases: %lu\n", __func__, tot_b, tot_e);
// fprintf(stderr, "[M::%s] # bases: %lld; # corrected bases: %lld; # recorrected bases: %lld\n", __func__, // 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); // 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); // 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();
} }
if (asm_opt.flag & HA_F_WRITE_EC) Output_corrected_reads();
// overlap between corrected reads // overlap between corrected reads
ha_opt_reset_to_round(&asm_opt, asm_opt.number_of_round); ha_opt_reset_to_round(&asm_opt, asm_opt.number_of_round);
// ha_overlap_final(); // ha_overlap_final();
ha_ec_ff(1/**0**/); 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()); 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()); // 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); // ha_print_ovlp_stat(R_INF.paf, R_INF.reverse_paf, R_INF.total_reads);
ha_ft_destroy(ha_flt_tab); 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(); if (asm_opt.flag & HA_F_WRITE_PAF) Output_PAF();
ha_triobin(&asm_opt); ha_triobin(&asm_opt);
@@ -2062,7 +2164,7 @@ int ha_assemble(void)
build_string_graph_without_clean(asm_opt.min_overlap_coverage, R_INF.paf, R_INF.reverse_paf, 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, 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); 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); destory_All_reads(&R_INF); /**if(asm_opt.dbg_bam)**/ destroy_cc_v(&scb);
return 0; return 0;
} }
@@ -2099,7 +2201,7 @@ int ha_assemble_pair(void)
// Output_corrected_reads(); exit(0); // Output_corrected_reads(); exit(0);
ha_flt_tab = ha_idx = NULL; r = asm_opt.number_of_round - 1; 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), load_ct_index(&ha_ct_table, asm_opt.output_file_name); 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 // construct hash table for high occurrence k-mers
if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) { if (!(asm_opt.flag & HA_F_NO_KMER_FLT) && ha_flt_tab == NULL) {
+1
View File
@@ -51,5 +51,6 @@ 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); void ha_ovec_destroy(ha_ovec_buf_t *b);
int64_t ha_ovec_mem(const ha_ovec_buf_t *b, int64_t *mem_a); int64_t ha_ovec_mem(const ha_ovec_buf_t *b, int64_t *mem_a);
int ha_assemble_ovec(void); int ha_assemble_ovec(void);
int ha_ec_dbg(void);
#endif #endif
+369 -22
View File
@@ -7,8 +7,16 @@
#include <sys/time.h> #include <sys/time.h>
#include "CommandLines.h" #include "CommandLines.h"
#include "ketopt.h" #include "ketopt.h"
#include "kseq.h"
KSEQ_INIT(gzFile, gzread)
#define DEFAULT_OUTPUT "hifiasm.asm" #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; hifiasm_opt_t asm_opt;
@@ -71,6 +79,34 @@ static ko_longopt_t long_options[] = {
{ "telo-d", ko_required_argument, 356}, { "telo-d", ko_required_argument, 356},
{ "telo-s", ko_required_argument, 357}, { "telo-s", ko_required_argument, 357},
{ "ctg-n", ko_required_argument, 358}, { "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}, // { "path-round", ko_required_argument, 348},
{ 0, 0, 0 } { 0, 0, 0 }
}; };
@@ -82,6 +118,7 @@ double Get_T(void)
return t.tv_sec+t.tv_usec/1000000.0; return t.tv_sec+t.tv_usec/1000000.0;
} }
void Print_H(hifiasm_opt_t* asm_opt) void Print_H(hifiasm_opt_t* asm_opt)
{ {
fprintf(stderr, "Usage: hifiasm [options] <in_1.fq> <in_2.fq> <...>\n"); fprintf(stderr, "Usage: hifiasm [options] <in_1.fq> <in_2.fq> <...>\n");
@@ -91,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, " -t INT number of threads [%d]\n", asm_opt->thread_num);
fprintf(stderr, " -h show help information\n"); fprintf(stderr, " -h show help information\n");
fprintf(stderr, " --version show version number\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, " Overlap/Error correction:\n");
fprintf(stderr, " -k INT k-mer length (must be <64) [%d]\n", asm_opt->k_mer_length); 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, " -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, " -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, " -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, " -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); fprintf(stderr, " -z INT length of adapters that should be removed [%d]\n", asm_opt->adapterLen);
@@ -103,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, " 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, " --hg-size INT(k, m or g)\n");
fprintf(stderr, " estimated haploid genome size used for inferring read coverage [auto]\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, " Assembly:\n");
fprintf(stderr, " -a INT round of assembly cleaning [%d]\n", asm_opt->clean_round); 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); fprintf(stderr, " -m INT pop bubbles of <INT in size in contig graphs [%lld]\n", asm_opt->large_pop_bubble_size);
@@ -114,8 +192,6 @@ void Print_H(hifiasm_opt_t* asm_opt)
fprintf(stderr, " -u post-join step for contigs which may improve N50; 0 to disable; 1 to enable\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", 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); asm_opt->ul_pst_join, asm_opt->hifi_pst_join);
fprintf(stderr, " --hom-cov INT\n");
fprintf(stderr, " homozygous read coverage [auto]\n");
fprintf(stderr, " --lowQ INT\n"); 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, " 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"); fprintf(stderr, " --b-cov INT\n");
@@ -128,6 +204,7 @@ void Print_H(hifiasm_opt_t* asm_opt)
fprintf(stderr, " --primary output a primary assembly and an alternate assembly\n"); fprintf(stderr, " --primary output a primary assembly and an alternate assembly\n");
fprintf(stderr, " --ctg-n INT\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, " 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, " --pri-range INT1[,INT2]\n");
@@ -177,6 +254,11 @@ void Print_H(hifiasm_opt_t* asm_opt)
fprintf(stderr, " Ultra-Long-integration:\n"); fprintf(stderr, " Ultra-Long-integration:\n");
fprintf(stderr, " --ul FILEs file names of Ultra-Long reads [r1.fq,r2.fq,...]\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, " --ul-rate FLOAT\n");
fprintf(stderr, " error rate of Ultra-Long reads [%.3g]\n", asm_opt->ul_error_rate); fprintf(stderr, " error rate of Ultra-Long reads [%.3g]\n", asm_opt->ul_error_rate);
fprintf(stderr, " --ul-tip INT\n"); fprintf(stderr, " --ul-tip INT\n");
@@ -206,6 +288,26 @@ void Print_H(hifiasm_opt_t* asm_opt)
fprintf(stderr, " --telo-s INT\n"); fprintf(stderr, " --telo-s INT\n");
fprintf(stderr, " min score for telomere reads [%ld]\n", asm_opt->telo_mic_sc); 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, "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"); fprintf(stderr, "See `https://hifiasm.readthedocs.io/en/latest/' or `man ./hifiasm.1' for complete documentation.\n");
@@ -225,6 +327,7 @@ void init_opt(hifiasm_opt_t* asm_opt)
asm_opt->hic_reads[0] = NULL; asm_opt->hic_reads[0] = NULL;
asm_opt->hic_reads[1] = NULL; asm_opt->hic_reads[1] = NULL;
asm_opt->fn_bin_poy = NULL; asm_opt->fn_bin_poy = NULL;
asm_opt->fn_chr_bin = NULL;
asm_opt->ar = NULL; asm_opt->ar = NULL;
asm_opt->thread_num = 1; asm_opt->thread_num = 1;
asm_opt->k_mer_length = 51; asm_opt->k_mer_length = 51;
@@ -241,6 +344,7 @@ void init_opt(hifiasm_opt_t* asm_opt)
asm_opt->max_kmer_cnt = 2000; asm_opt->max_kmer_cnt = 2000;
asm_opt->high_factor = 5.0; asm_opt->high_factor = 5.0;
asm_opt->max_ov_diff_ec = 0.04; 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->max_ov_diff_final = 0.03;
asm_opt->hom_cov = 20; asm_opt->hom_cov = 20;
asm_opt->het_cov = -1024; asm_opt->het_cov = -1024;
@@ -301,8 +405,8 @@ void init_opt(hifiasm_opt_t* asm_opt)
asm_opt->dp_e = 0.0025; asm_opt->dp_e = 0.0025;
asm_opt->hg_size = -1; asm_opt->hg_size = -1;
asm_opt->kpt_rate = -1; asm_opt->kpt_rate = -1;
asm_opt->infor_cov = 3; asm_opt->infor_cov = MIN_R_COV;
asm_opt->s_hap_cov = 3; asm_opt->s_hap_cov = MIN_R_COV;
asm_opt->ul_error_rate = 0.2/**0.15**/; asm_opt->ul_error_rate = 0.2/**0.15**/;
asm_opt->ul_error_rate_low = 0.1; asm_opt->ul_error_rate_low = 0.1;
asm_opt->ul_error_rate_hpc = 0.2; asm_opt->ul_error_rate_hpc = 0.2;
@@ -335,6 +439,70 @@ void init_opt(hifiasm_opt_t* asm_opt)
asm_opt->telo_pen = 1; asm_opt->telo_pen = 1;
asm_opt->telo_drop = 2000; asm_opt->telo_drop = 2000;
asm_opt->telo_mic_sc = 500; 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) void destory_enzyme(enzyme* f)
@@ -408,14 +576,43 @@ static int check_file(char* name, const char* opt)
static int check_hic_reads(enzyme* f, const char* opt) static int check_hic_reads(enzyme* f, const char* opt)
{ {
int i; int32_t i;
for (i = 0; i < f->n; i++) for (i = 0; i < f->n; i++) {
{
if(check_file(f->a[i], opt) == 0) return 0; if(check_file(f->a[i], opt) == 0) return 0;
} }
return 1; 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) int check_option(hifiasm_opt_t* asm_opt)
{ {
if(asm_opt->read_file_names == NULL || asm_opt->num_reads == 0) if(asm_opt->read_file_names == NULL || asm_opt->num_reads == 0)
@@ -615,7 +812,7 @@ int check_option(hifiasm_opt_t* asm_opt)
return 0; return 0;
} }
if(asm_opt->ar != NULL && check_hic_reads(asm_opt->ar, "UL") == 0) 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) if(asm_opt->ar != NULL && asm_opt->ar->n == 0)
{ {
fprintf(stderr, "[ERROR] wrong UL reads (--ul)\n"); fprintf(stderr, "[ERROR] wrong UL reads (--ul)\n");
@@ -664,6 +861,11 @@ int check_option(hifiasm_opt_t* asm_opt)
return 0; 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) { if(asm_opt->telo_motif) {
uint64_t k, tlen = strlen((asm_opt->telo_motif)); char c; uint64_t k, tlen = strlen((asm_opt->telo_motif)); char c;
if(tlen > 32) { if(tlen > 32) {
@@ -680,30 +882,69 @@ int check_option(hifiasm_opt_t* asm_opt)
} }
} }
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; return 1;
} }
void get_queries(int argc, char *argv[], ketopt_t* opt, hifiasm_opt_t* asm_opt) void get_queries(int argc, char *argv[], ketopt_t* opt, hifiasm_opt_t* asm_opt)
{ {
if(opt->ind == argc) if(opt->ind == argc) {
{
return; return;
} }
asm_opt->num_reads = argc - opt->ind; asm_opt->num_reads = argc - opt->ind;
asm_opt->read_file_names = (char**)malloc(sizeof(char*)*asm_opt->num_reads); asm_opt->read_file_names = (char**)malloc(sizeof(char*)*asm_opt->num_reads);
long long i; long long i; int ret;
gzFile dfp; gzFile dfp; kseq_t *ks = NULL;
for (i = 0; i < asm_opt->num_reads; i++) for (i = 0; i < asm_opt->num_reads; i++) {
{
asm_opt->read_file_names[i] = argv[i + opt->ind]; asm_opt->read_file_names[i] = argv[i + opt->ind];
dfp = gzopen(asm_opt->read_file_names[i], "r"); 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", fprintf(stderr, "[ERROR] Cannot find the input read file: %s\n",
asm_opt->read_file_names[i]); asm_opt->read_file_names[i]);
exit(0); 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); gzclose(dfp);
} }
@@ -840,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 == 306) asm_opt->max_ov_diff_final = atof(opt.arg);
else if (c == 307) asm_opt->extract_list = 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 == 308) asm_opt->extract_iter = atoi(opt.arg);
else if (c == 309) else if (c == 309) {
{ asm_opt->hom_global_coverage = asm_opt->hmo_cov_ss = atoi(opt.arg);
asm_opt->hom_global_coverage = atoi(opt.arg);
asm_opt->hom_global_coverage_set = 1; 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; char* s = NULL;
asm_opt->recover_atg_cov_min = strtol(opt.arg, &s, 10); asm_opt->recover_atg_cov_min = strtol(opt.arg, &s, 10);
@@ -906,7 +1149,78 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
else if (c == 356) asm_opt->telo_drop = 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 == 357) asm_opt->telo_mic_sc = atol(opt.arg);
else if (c == 358) asm_opt->max_contig_tip = atol(opt.arg); else if (c == 358) asm_opt->max_contig_tip = atol(opt.arg);
else if (c == 'l') { ///0: disable purge_dup; 1: purge containment; 2: purge overlap 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); 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); else if (c == 's') asm_opt->purge_simi_rate_l2 = asm_opt->purge_simi_rate_l3 = atof(opt.arg);
@@ -943,6 +1257,39 @@ int CommandLine_process(int argc, char *argv[], hifiasm_opt_t* asm_opt)
// fprintf(stderr, "[M::%s::] post join::%u\n", __func__, (uint32_t)(!(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); // 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); return check_option(asm_opt);
} }
+65 -1
View File
@@ -5,7 +5,7 @@
#include <pthread.h> #include <pthread.h>
#include <stdint.h> #include <stdint.h>
#define HA_VERSION "0.20.0-r639" #define HA_VERSION "0.25.1-r933"
#define VERBOSE 0 #define VERBOSE 0
@@ -41,10 +41,12 @@ typedef struct {
char *fn_bin_yak[2]; char *fn_bin_yak[2];
char *fn_bin_list[2]; char *fn_bin_list[2];
char *fn_bin_poy; char *fn_bin_poy;
char *fn_chr_bin;
char *extract_list; char *extract_list;
enzyme *hic_reads[2]; enzyme *hic_reads[2];
enzyme *hic_enzymes; enzyme *hic_enzymes;
enzyme *ar; enzyme *ar;
enzyme *hf;
enzyme *sec_in; enzyme *sec_in;
int extract_iter; int extract_iter;
int thread_num; int thread_num;
@@ -63,6 +65,7 @@ typedef struct {
int max_kmer_cnt; int max_kmer_cnt;
double high_factor; // coverage cutoff set to high_factor*hom_cov double high_factor; // coverage cutoff set to high_factor*hom_cov
double max_ov_diff_ec; double max_ov_diff_ec;
double max_ov_diff_ec_sec;
double max_ov_diff_final; double max_ov_diff_final;
int hom_cov; int hom_cov;
int het_cov; int het_cov;
@@ -137,6 +140,7 @@ typedef struct {
int64_t infor_cov, s_hap_cov, trio_cov_het_ovlp; int64_t infor_cov, s_hap_cov, trio_cov_het_ovlp;
double ul_error_rate, ul_error_rate_low, ul_error_rate_hpc; double ul_error_rate, ul_error_rate_low, ul_error_rate_hpc;
int32_t ul_ec_round; int32_t ul_ec_round;
int32_t ul_mod;
uint8_t is_dbg_het_cnt; uint8_t is_dbg_het_cnt;
uint8_t is_low_het_ul; uint8_t is_low_het_ul;
uint8_t is_base_trans; uint8_t is_base_trans;
@@ -144,6 +148,7 @@ typedef struct {
uint8_t is_topo_trans; uint8_t is_topo_trans;
uint8_t is_bub_trans; uint8_t is_bub_trans;
uint8_t bin_only; uint8_t bin_only;
uint8_t ec_only;
int32_t ul_clean_round; int32_t ul_clean_round;
int32_t prt_dbg_gfa; int32_t prt_dbg_gfa;
int32_t integer_correct_round; int32_t integer_correct_round;
@@ -160,6 +165,65 @@ typedef struct {
int64_t telo_pen; int64_t telo_pen;
int64_t telo_drop; int64_t telo_drop;
int64_t telo_mic_sc; 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; } hifiasm_opt_t;
extern hifiasm_opt_t asm_opt; extern hifiasm_opt_t asm_opt;
+16875 -279
View File
File diff suppressed because it is too large Load Diff
+102 -6
View File
@@ -144,7 +144,10 @@ typedef struct
char misBase; char misBase;
}haplotype_evdience; }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 typedef struct
{ {
@@ -1384,19 +1387,91 @@ typedef struct {
int64_t k, q[2], t[2], cq[2], ct[2], ci[2], werr, werr0, cerr; int64_t k, q[2], t[2], cq[2], ct[2], ci[2], werr, werr0, cerr;
int64_t qoff, f, toff, coff, cur_qoff; int64_t qoff, f, toff, coff, cur_qoff;
} rtrace_iter; } 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, 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, 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); bit_extz_t *exz, double e_rate, int64_t qs);
void 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); 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);
void 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); 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_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);
void rphase_hc(overlap_region_alloc* ol, All_reads *rref, haplotype_evdience_alloc* hp, UC_Read* qu, 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 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 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 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 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_id(x) ((x).tn)
#define ovlp_min_wid(x) ((x).ts) #define ovlp_min_wid(x) ((x).ts)
#define ovlp_max_wid(x) ((x).te) #define ovlp_max_wid(x) ((x).te)
@@ -1406,5 +1481,26 @@ void cal_exz_global(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre
#define ovlp_cur_ylen(x) ((x).te) #define ovlp_cur_ylen(x) ((x).te)
#define ovlp_cur_coff(x) ((x).qe) #define ovlp_cur_coff(x) ((x).qe)
#define ovlp_bd(x) ((x).sec) #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 #endif
+552 -20
View File
@@ -1540,6 +1540,63 @@ inline int32_t comput_sc_ch_ec(const k_mer_hit *ai, const k_mer_hit *aj, double
return sc; return sc;
} }
inline int32_t comput_sc_ch_ec_global(const k_mer_hit *ai, const k_mer_hit *aj, double bw_rate, double chn_pen_gap, double chn_pen_skip, int64_t sl, int64_t ol, uint8_t no_adj)
{
///ai is the suffix of aj
int32_t dq, dr, dd, dg, q_span, sc; double dg_of;
dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
if((dq < 0) || (dr < 0)) return INT32_MIN;
if((no_adj) && ((dq == 0) || (dr == 0))) return INT32_MIN;
dd = dr > dq? dr - dq : dq - dr;//gap
if((dd > 16) && (dd > cal_bw(ai, aj, bw_rate, sl, ol))) return INT32_MIN;
dg = dr < dq? dr : dq;//len
q_span = ai->cnt&(0xffu);
sc = q_span < dg? q_span : dg;
sc = normal_w(sc, ((int32_t)(ai->cnt>>8)));
if (dd || (dg > q_span && dg > 0)) {
double lin_pen, a_pen;
lin_pen = (chn_pen_gap*(double)dd);
dg_of = (dg>0)?((double)dg):(0.333333);
a_pen = ((double)(sc))*((((double)dd)/dg_of)/bw_rate);
///for long gap
// if(lin_pen > a_pen) lin_pen = a_pen;
if(dd < 4) lin_pen = ((lin_pen > a_pen)?(a_pen):(lin_pen));
else lin_pen = ((lin_pen < a_pen)?(a_pen):(lin_pen));
lin_pen += (chn_pen_skip*dg_of);
sc -= (int32_t)lin_pen;
}
return sc;
}
inline int32_t comput_sc_ff_adv(const k_mer_hit *ai, const k_mer_hit *aj, double bw_rate, double chn_pen_gap, double chn_pen_skip, int64_t sl, int64_t ol)
{
///ai is the suffix of aj
int32_t dq, dr, dd, dg, q_span, sc;
dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
if(dq < 0) return INT32_MIN;
dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
if(dr < 0) return INT32_MIN;
dd = dr > dq? dr - dq : dq - dr;//gap
// if((dd > 16) && (dd > cal_bw(ai, aj, bw_rate, sl, ol))) return INT32_MIN;
dg = dr < dq? dr : dq;//len
if(dg <= 0) return INT32_MIN;
q_span = ai->cnt&(0xffu);
sc = q_span < dg? q_span : dg;
sc = normal_w(sc, ((int32_t)(ai->cnt>>8)));
if (dd || (dg > q_span && dg > 0)) {
double lin_pen, a_pen;
lin_pen = (chn_pen_gap*(double)dd);
a_pen = ((double)(sc))*((((double)dd)/((double)dg))/bw_rate);
if(lin_pen > a_pen) lin_pen = a_pen;
lin_pen += (chn_pen_skip*(double)dg);
sc -= (int32_t)lin_pen;
}
return sc;
}
inline int32_t comput_sc_ff(const k_mer_hit *ai, const k_mer_hit *aj, double bw_rate, double chn_pen_gap, double chn_pen_skip, int64_t sl, int64_t ol) inline int32_t comput_sc_ff(const k_mer_hit *ai, const k_mer_hit *aj, double bw_rate, double chn_pen_gap, double chn_pen_skip, int64_t sl, int64_t ol)
{ {
///ai is the suffix of aj ///ai is the suffix of aj
@@ -1749,18 +1806,7 @@ uint64_t lchain_qdp(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp, o
return cL; return cL;
} }
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)
#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)
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)
{ {
int64_t xr, yr; int64_t xr, yr;
o->x_id = xid; o->y_id = beg->readID; o->x_id = xid; o->y_id = beg->readID;
@@ -2118,9 +2164,9 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ; t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ;
a = cl->list + a_idx; des = cl->list + des_idx; a = cl->list + a_idx; des = cl->list + des_idx;
// if(a_n && a[0].readID == 0) { // if(a_n && (a[0].readID == 27105 || a[0].readID == 7603)) {///r833
// fprintf(stderr, "---[M::%s::utg%.6dl::%c]\n", // fprintf(stderr, "---[M::%s::rid->%u::%c]\ta_n::%ld\n",
// __func__, (int32_t)a[0].readID+1, "+-"[a[0].strand]); // __func__, a[0].readID, "+-"[a[0].strand], a_n);
// } // }
if(quick_check) { if(quick_check) {
quick_ck_lchain(a, a_n, xl, yl, chn_pen_gap, chn_pen_skip, bw_rate, p, t, f, ii, &plus, &msc, &msc_i, &movl, &si, &ei); quick_ck_lchain(a, a_n, xl, yl, chn_pen_gap, chn_pen_skip, bw_rate, p, t, f, ii, &plus, &msc, &msc_i, &movl, &si, &ei);
@@ -2128,7 +2174,7 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
msc = msc_i = INT32_MIN; movl = INT32_MAX; plus = 0; si = 0; ei = a_n; msc = msc_i = INT32_MIN; movl = INT32_MAX; plus = 0; si = 0; ei = a_n;
memset(t, 0, (a_n*sizeof((*t)))); memset(t, 0, (a_n*sizeof((*t))));
} }
// if(a_n && a[0].readID == 3125488) { // if(a_n && a[0].readID == 4412344) {
// fprintf(stderr, "[M::%s::] si::%ld, ei::%ld, a_n::%ld\n", __func__, si, ei, a_n); // fprintf(stderr, "[M::%s::] si::%ld, ei::%ld, a_n::%ld\n", __func__, si, ei, a_n);
// } // }
for (i = st = si, max_ii = -1; i < ei; ++i) { for (i = st = si, max_ii = -1; i < ei; ++i) {
@@ -2178,17 +2224,19 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
} }
if(f[i] < plus) plus = f[i]; if(f[i] < plus) plus = f[i];
ii[i] = 0;///for mcopy, not here ii[i] = 0;///for mcopy, not here
// if(a_n && a[0].readID == 0) { // if(a_n && (a[0].readID == 27105 || a[0].readID == 7603)) {///r833
// fprintf(stderr, "i::%ld[M::%s::utg%.6dl::%c] x::%u, y::%u, st::%ld, max_ii::%ld, f[i]::%d, p[i]::%ld, msc_i::%ld, msc::%ld, movl::%ld\n", // fprintf(stderr, "i::%ld[M::%s::rid->%u::%c] q::%u, t::%u, st::%ld, max_ii::%ld, f[i]::%d, p[i]::%ld, msc_i::%ld, msc::%ld, movl::%ld\n",
// i, __func__, (int32_t)a[i].readID+1, "+-"[a[i].strand], // i, __func__, a[i].readID, "+-"[a[i].strand],
// a[i].self_offset, a[i].offset, st, max_ii, f[i], p[i], msc_i, msc, movl); // a[i].self_offset, a[i].offset, st, max_ii, f[i], p[i], msc_i, msc, movl);
// } // }
} }
for (i = msc_i, cL = 0; i >= 0; i = p[i]) { ii[i] = 1; t[cL++] = i;}///label the best chain for (i = msc_i, cL = 0; i >= 0; i = p[i]) { ii[i] = 1; t[cL++] = i;}///label the best chain
if(mcopy_num > 1) { if(mcopy_num > 1) {
// if(a[0].readID == 4412344) {
// fprintf(stderr, "[M::%s::] msc::%ld, cL::%ld\n", __func__, msc, cL);
// }
if(cL >= mcopy_khit_cutoff) {///if there are too few k-mers, disable mcopy if(cL >= mcopy_khit_cutoff) {///if there are too few k-mers, disable mcopy
msc -= plus; min_sc = msc*mcopy_rate/**0.2**/; ii[msc_i] = 0; msc -= plus; min_sc = msc*mcopy_rate/**0.2**/; ii[msc_i] = 0;
for (i = ch_n = 0; i < a_n; ++i) {///make all f[] positive for (i = ch_n = 0; i < a_n; ++i) {///make all f[] positive
@@ -2197,6 +2245,9 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
t[ch_n] = ((uint64_t)f[i])<<32; t[ch_n] += (i<<1); ch_n++; t[ch_n] = ((uint64_t)f[i])<<32; t[ch_n] += (i<<1); ch_n++;
} }
} }
// if(a[0].readID == 4412344) {
// fprintf(stderr, "[M::%s::] msc::%ld, min_sc::%ld, cL::%ld, ch_n::%ld, mcopy_num::%ld\n", __func__, msc, min_sc, cL, ch_n, mcopy_num);
// }
if(ch_n > 1) { if(ch_n > 1) {
int64_t n_v, n_v0, ni, n_u, n_u0 = res->length; int64_t n_v, n_v0, ni, n_u, n_u0 = res->length;
radix_sort_hc64i(t, t + ch_n); radix_sort_hc64i(t, t + ch_n);
@@ -2207,9 +2258,15 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
} }
if(n_v0 == n_v) continue; if(n_v0 == n_v) continue;
sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i])); sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));
// if(a[0].readID == 4412344) {
// fprintf(stderr, "+[M::%s::] sc::%ld, n_a::%ld\n", __func__, sc, n_v-n_v0);
// }
if(sc >= min_sc) { if(sc >= min_sc) {
kv_pushp_ol(overlap_region, (*res), &z); kv_pushp_ol(overlap_region, (*res), &z);
push_ovlp_chain_qgen(z, xid, xl, yl, sc+plus, &(a[ii[n_v-1]]), &(a[ii[n_v0]])); push_ovlp_chain_qgen(z, xid, xl, yl, sc+plus, &(a[ii[n_v-1]]), &(a[ii[n_v0]]));
// if(a[0].readID == 4412344) {
// fprintf(stderr, "-[M::%s::] sc::%ld, n_a::%ld, q::[%u,%u), t::[%u,%u), %c\n", __func__, sc, n_v-n_v0, z->x_pos_s, z->x_pos_e + 1, z->y_pos_s, z->y_pos_e + 1, "+-"[z->y_pos_strand]);
// }
///mcopy_khit_cutoff <= 1: disable the mcopy_khit_cutoff filtering, for the realignment ///mcopy_khit_cutoff <= 1: disable the mcopy_khit_cutoff filtering, for the realignment
// if((mcopy_khit_cutoff <= 1) || ((z->x_pos_e+1-z->x_pos_s) <= (movl<<2))) { // if((mcopy_khit_cutoff <= 1) || ((z->x_pos_e+1-z->x_pos_s) <= (movl<<2))) {
if((!n_u) || (n_v - n_v0 > 1)) { if((!n_u) || (n_v - n_v0 > 1)) {
@@ -2283,6 +2340,315 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
} }
/**
void quick_ck_lchain_global(k_mer_hit* a, int64_t a_n, int64_t xl, int64_t yl, double chn_pen_gap, double chn_pen_skip, double bw_rate,
int64_t *p, int64_t *t, int32_t *f, int32_t *ii, int32_t *gf, int64_t *gp, int64_t *si, int64_t *ei)
{
*si = 0; *ei = a_n; gf[0] = gf[1] = gp[0] = gp[1] = INT32_MIN;
if((a_n <= 0) || (xl <= 0) || (yl <= 0)) return;
int64_t l, k, is_srt = 1, z; k_mer_hit *ai, *aj, ft, fz;
int64_t dq, dr, dd, dg, q_span, sc, csc, ddt; uint8_t ff; double lin_pen, a_pen, dg_of;
ft.cnt = fz.cnt = 0xFFFFFF00u; ft.readID = fz.readID = a[0].readID;
ft.offset = ft.self_offset = 0; fz.offset = yl-1; fz.self_offset = xl-1;
for (k = 1, l = 0; k <= a_n; k++) {
if(k == a_n || a[k].strand != a[l].strand) {
t[k-1] = 0; ii[k-1] = 0;
if(is_srt) {
ddt = 0; ff = 0; p[l] = f[l] = INT32_MIN;
ft.strand = a[l].strand;
aj = &ft; z = l; ai = &a[z];
dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
dd = dr > dq? dr - dq : dq - dr;//gap
if((dd > 16) && (dd > cal_bw(ai, aj, bw_rate, xl, yl))) ff = 1;
if(!ff) {
dg = dr < dq? dr : dq;//len
q_span = ai->cnt&(0xffu);
sc = q_span < dg? q_span : dg;
sc = normal_w(sc, ((int32_t)(ai->cnt>>8)));
if (dd || (dg > q_span && dg > 0)) {
lin_pen = (chn_pen_gap*(double)dd);
dg_of = ((dg>0)?(dg):(0.333333));
a_pen = ((double)(sc))*((((double)dd)/dg_of)/bw_rate);
///for long gap
// if(lin_pen > a_pen) lin_pen = a_pen;
if(dd < 4) lin_pen = ((lin_pen > a_pen)?(a_pen):(lin_pen));
else lin_pen = ((lin_pen < a_pen)?(a_pen):(lin_pen));
lin_pen += (chn_pen_skip*dg_of);
sc -= (int32_t)lin_pen;
}
csc = a[z].cnt&(0xffu); if(sc < csc) ff = 1;
if(!ff) {
p[z] = -1; f[z] = sc; ddt += dd;
}
}
if(!ff) {
for (z = l + 1; z < k; z++) {
///roughly same to comput_sc_ch(&a[z], &a[z-1])
ai = &a[z]; aj = &a[z-1];
dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
if(dq <= 0) break;
dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
if(dr <= 0) break;
dd = dr > dq? dr - dq : dq - dr;//gap
if((dd > 16) && (dd > cal_bw(&(a[z]), &(a[z-1]), bw_rate, xl, yl))) break;
dg = dr < dq? dr : dq;//len
q_span = ai->cnt&(0xffu);
sc = q_span < dg? q_span : dg;
sc = normal_w(sc, ((int32_t)(ai->cnt>>8)));
if (dd || (dg > q_span && dg > 0)) {
lin_pen = (chn_pen_gap*(double)dd);
dg_of = ((dg>0)?(dg):(0.333333));
a_pen = ((double)(sc))*((((double)dd)/dg_of)/bw_rate);
///for long gap
// if(lin_pen > a_pen) lin_pen = a_pen;
if(dd < 4) lin_pen = ((lin_pen > a_pen)?(a_pen):(lin_pen));
else lin_pen = ((lin_pen < a_pen)?(a_pen):(lin_pen));
lin_pen += (chn_pen_skip*dg_of);
sc -= (int32_t)lin_pen;
}
sc += f[z-1]; csc = a[z].cnt&(0xffu); if(sc < csc) break;
p[z] = z - 1; f[z] = sc; ddt += dd;
}
if(z < k) ff = 1;
}
if(!ff) {
fz.strand = a[l].strand;
ai = &fz; aj = &(a[k-1]);
dq = (int64_t)(ai->self_offset) - (int64_t)(aj->self_offset);
dr = (int64_t)(ai->offset) - (int64_t)(aj->offset);
dd = dr > dq? dr - dq : dq - dr;//gap
if(((dd > 16) && (dd > cal_bw(ai, aj, bw_rate, xl, yl)))||
(((ddt + dd) > 16) && ((ddt + dd) > cal_bw(&fz, &ft, bw_rate, xl, yl)))) {
ff = 1;
} else {
dg = dr < dq? dr : dq;//len
sc = q_span = 0;
if (dd || (dg > q_span && dg > 0)) {
lin_pen = (chn_pen_gap*(double)dd);
dg_of = ((dg>0)?(dg):(0.333333));
a_pen = ((double)(sc))*((((double)dd)/dg_of)/bw_rate);
///for long gap
// if(lin_pen > a_pen) lin_pen = a_pen;
if(dd < 4) lin_pen = ((lin_pen > a_pen)?(a_pen):(lin_pen));
else lin_pen = ((lin_pen < a_pen)?(a_pen):(lin_pen));
lin_pen += (chn_pen_skip*dg_of);
sc -= (int32_t)lin_pen;
}
sc += f[k-1]; ///csc = a[z].cnt&(0xffu); if(sc < csc) break;
gp[fz.strand] = k-1; gf[fz.strand] = sc; ///ddt += dd;
if((*ei) > k) {
(*si) = k;
} else {
(*ei) = l;
}
}
}
}
l = k; is_srt = 1;
} else {
if((a[k].self_offset <= a[k-1].self_offset) || (a[k].offset <= a[k-1].offset)) is_srt = 0;
t[k-1] = 0; ii[k-1] = 0;
}
}
}
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)
{
if(a_n <= 0) return 0;
int64_t *p, *t, *gp, max_f, n_skip, st, max_j, end_j, sc, max_ii, ovl, min_sc, ch_n, si, ei;
int32_t *f, max, tmp, *ii, *gf; int64_t i, k, j, cL = 0; k_mer_hit* a; k_mer_hit* des; k_mer_hit *swap, ft; overlap_region *z;
resize_Chain_Data(dp, a_n + 2, NULL); ch_n = 1;
t = dp->tmp; f = dp->score; p = dp->pre; ii = dp->occ; gp = p + a_n; gf = f + a_n; gf[0] = gf[1] = gp[0] = gp[1] = INT32_MIN;
a = cl->list + a_idx; des = cl->list + des_idx;
if(quick_check) {
quick_ck_lchain_global(a, a_n, xl, yl, chn_pen_gap, chn_pen_skip, bw_rate, p, t, f, ii, gf, gp, &si, &ei);
} else {
si = 0; ei = a_n; memset(t, 0, (a_n*sizeof((*t))));
}
ft.cnt = 0xFFFFFF00u; ft.readID = a[0].readID; ft.strand = 0; ft.offset = ft.self_offset = 0;
for (i = st = si, max_ii = -1; i < ei; ++i) {
///max_f = a[i].cnt&(0xffu);
ft.strand = a[i].strand;
n_skip = 0; max_j = end_j = -1;
if ((i-st) > max_iter) st = i-max_iter;
while (a[i].strand != a[st].strand) ++st;
for (j = i - 1; j >= st; --j) {
sc = comput_sc_ch_ec_global(&a[i], &a[j], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
if (sc == INT32_MIN) continue;
sc += f[j];
if (sc > max_f) {
max_f = sc, max_j = j;
if (n_skip > 0) --n_skip;
} else if (t[j] == (int32_t)i) {
if (++n_skip > max_skip)
break;
}
if (p[j] >= 0) t[p[j]] = i;
}
end_j = j;
if ((max_ii<0) || (a[i].self_offset>a[max_ii].self_offset+max_dis) || (a[i].strand!=a[max_ii].strand)) {
max = INT32_MIN; max_ii = -1;
for (j=i-1; (j>=st) && (a[i].self_offset<=max_dis+a[j].self_offset)&&(a[i].strand==a[j].strand); --j) {
if (max < f[j]) {
max = f[j], max_ii = j;
}
}
}
if ((max_ii >= 0) && (max_ii < end_j) && (a[i].strand == a[max_ii].strand)) {///just have a try with a[i]<->a[max_ii]
tmp = comput_sc_ch_ec(&a[i], &a[max_ii], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
if (tmp != INT32_MIN && max_f < tmp + f[max_ii])
max_f = tmp + f[max_ii], max_j = max_ii;
}
f[i] = max_f; p[i] = max_j;
if ((max_ii < 0) || ((a[i].self_offset<=max_dis+a[max_ii].self_offset)&&(a[i].strand==a[max_ii].strand)&&(f[max_ii]<f[i]))) {
max_ii = i;
}
if(f[i] >= msc) {
ovl = get_chainLen(a[i].self_offset, a[i].self_offset, xl, a[i].offset, a[i].offset, yl);
if(f[i] > msc || ovl < movl) {
msc = f[i]; msc_i = i; movl = ovl;
}
}
if(f[i] < plus) plus = f[i];
ii[i] = 0;///for mcopy, not here
// if(a_n && (a[0].readID == 27105 || a[0].readID == 7603)) {///r833
// fprintf(stderr, "i::%ld[M::%s::rid->%u::%c] q::%u, t::%u, st::%ld, max_ii::%ld, f[i]::%d, p[i]::%ld, msc_i::%ld, msc::%ld, movl::%ld\n",
// i, __func__, a[i].readID, "+-"[a[i].strand],
// a[i].self_offset, a[i].offset, st, max_ii, f[i], p[i], msc_i, msc, movl);
// }
}
for (i = msc_i, cL = 0; i >= 0; i = p[i]) { ii[i] = 1; t[cL++] = i;}///label the best chain
if(mcopy_num > 1) {
// if(a[0].readID == 4412344) {
// fprintf(stderr, "[M::%s::] msc::%ld, cL::%ld\n", __func__, msc, cL);
// }
if(cL >= mcopy_khit_cutoff) {///if there are too few k-mers, disable mcopy
msc -= plus; min_sc = msc*mcopy_rate; ii[msc_i] = 0;
for (i = ch_n = 0; i < a_n; ++i) {///make all f[] positive
f[i] -= plus; if(i >= ch_n) t[i] = 0;
if((!(ii[i])) && (f[i] >= min_sc)) {///!(ii[i]): skip the best chain
t[ch_n] = ((uint64_t)f[i])<<32; t[ch_n] += (i<<1); ch_n++;
}
}
// if(a[0].readID == 4412344) {
// fprintf(stderr, "[M::%s::] msc::%ld, min_sc::%ld, cL::%ld, ch_n::%ld, mcopy_num::%ld\n", __func__, msc, min_sc, cL, ch_n, mcopy_num);
// }
if(ch_n > 1) {
int64_t n_v, n_v0, ni, n_u, n_u0 = res->length;
radix_sort_hc64i(t, t + ch_n);
for (k = ch_n-1, n_v = n_u = 0; k >= 0 && n_u < mcopy_num; --k) {
n_v0 = n_v;
for (i = ((uint32_t)t[k])>>1; i >= 0 && (t[i]&1) == 0; ) {
ii[n_v++] = i; t[i] |= 1; i = p[i];
}
if(n_v0 == n_v) continue;
sc = (i<0?(t[k]>>32):((t[k]>>32)-f[i]));
// if(a[0].readID == 4412344) {
// fprintf(stderr, "+[M::%s::] sc::%ld, n_a::%ld\n", __func__, sc, n_v-n_v0);
// }
if(sc >= min_sc) {
kv_pushp_ol(overlap_region, (*res), &z);
push_ovlp_chain_qgen(z, xid, xl, yl, sc+plus, &(a[ii[n_v-1]]), &(a[ii[n_v0]]));
// if(a[0].readID == 4412344) {
// fprintf(stderr, "-[M::%s::] sc::%ld, n_a::%ld, q::[%u,%u), t::[%u,%u), %c\n", __func__, sc, n_v-n_v0, z->x_pos_s, z->x_pos_e + 1, z->y_pos_s, z->y_pos_e + 1, "+-"[z->y_pos_strand]);
// }
///mcopy_khit_cutoff <= 1: disable the mcopy_khit_cutoff filtering, for the realignment
// if((mcopy_khit_cutoff <= 1) || ((z->x_pos_e+1-z->x_pos_s) <= (movl<<2))) {
if((!n_u) || (n_v - n_v0 > 1)) {
z->align_length = n_v-n_v0; z->x_id = n_v0;
n_u++;
} else {///non-best is tiny
res->length--; n_v = n_v0;
}
} else {
n_v = n_v0;
}
}
// if(n_u > 1) ks_introsort_or_sss(n_u, res->list + n_u0);
// res->length = n_u0 + filter_non_ovlp_xchains(res->list + n_u0, n_u, &n_v);
n_u = res->length;
if(n_u > n_u0 + 1) {
kv_resize_cl(k_mer_hit, (*cl), (n_v+cl->length));
a = cl->list + a_idx; des = cl->list + des_idx; swap = cl->list + cl->length;
for (k = n_u0, i = n_v0 = n_v = 0; k < n_u; k++) {
z = &(res->list[k]);
z->non_homopolymer_errors = des_idx + i;
n_v0 = z->x_id; ni = z->align_length;
for (j = 0; j < ni; j++, i++) {
///k0 + (ni - j - 1)
swap[i] = a[ii[n_v0 + (ni- j - 1)]];
swap[i].readID = k;
}
z->x_id = xid;
if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, swap+i-ni, ni);
if(!khit_n) z->align_length = 0;
}
memcpy(des, swap, i*sizeof((*swap))); //assert(i == ch_n);
// fprintf(stderr, "[M::%s::msc->%ld] msc_k_hits::%u, cL::%ld, min_sc::%ld, best_sc::%ld, n_u0_sc::%d, mcopy_rate::%f, # chains::%ld\n",
// __func__, msc, res->list[n_u0].align_length, cL, min_sc, msc+plus, res->list[n_u0].shared_seed,
// mcopy_rate, n_u-n_u0);
} else if(n_u == n_u0 + 1) {
z = &(res->list[n_u0]); k = n_u0; i = 0;
z->non_homopolymer_errors = des_idx + i;
n_v0 = z->x_id; ni = z->align_length;
for (j = 0; j < ni; j++, i++) {
///k0 + (ni - j - 1)
des[i] = a[ii[n_v0 + (ni- j - 1)]];
des[i].readID = k;
}
z->x_id = xid;
if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, des+i-ni, ni);
if(!khit_n) z->align_length = 0;
}
return i;
} else {
msc += plus; i = msc_i; cL = 0;
while (i >= 0) {t[cL++] = i; i = p[i];}
}
}
}
///a[] has been sorted by self_offset
// i = msc_i; cL = 0;
// while (i >= 0) {t[cL++] = i; i = p[i];}
kv_pushp_ol(overlap_region, (*res), &z);
push_ovlp_chain_qgen(z, xid, xl, yl, msc, &(a[t[cL-1]]), &(a[t[0]]));
for (i = 0; i < cL; i++) {des[i] = a[t[cL-i-1]]; des[i].readID = res->length-1;}
z->non_homopolymer_errors = des_idx;
if(gen_cigar) gen_fake_cigar(&(z->f_cigar), z, apend_be, des, cL);
if(khit_n) z->align_length = cL;
return cL;
}
**/
#define rev_khit(an, xl, yl) do { \ #define rev_khit(an, xl, yl) do { \
(an).self_offset = (xl)-1-((an).self_offset+1-((an).cnt&((uint32_t)(0xffu)))); \ (an).self_offset = (xl)-1-((an).self_offset+1-((an).cnt&((uint32_t)(0xffu)))); \
(an).offset = (yl)-1-((an).offset+1-((an).cnt&((uint32_t)(0xffu))));\ (an).offset = (yl)-1-((an).offset+1-((an).cnt&((uint32_t)(0xffu))));\
@@ -2453,6 +2819,121 @@ uint64_t lchain_qdp_fix(k_mer_hit* a, int64_t a_n, Chain_Data* dp, int64_t max_s
} }
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)
{
if(a_n <= 0) return 0;
int64_t *p, *t, max_f, n_skip, st, max_j, end_j, sc, msc, msc_i, bw, max_ii, ovl, movl;
int32_t *f, max, tmp; int64_t i, j, ret, cL = 0;
resize_Chain_Data(dp, a_n, NULL);
t = dp->tmp; f = dp->score; p = dp->pre;
bw = ((xl < yl)?xl:yl); bw *= bw_rate;
msc = msc_i = -1; movl = INT32_MAX;
if(quick_check) {
ret = lchain_qcheck(a, a_n, dp, bw_rate);
if (ret > 0) {
a_n = ret; msc_i = a_n-1; msc = f[msc_i];
goto skip_ldp;
}
}
memset(t, 0, (a_n*sizeof((*t))));
for (i = st = 0, max_ii = -1; i < a_n; ++i) {
max_f = a[i].cnt&(0xffu); if(left_fix && i > 0) max_f = INT32_MIN;
n_skip = 0; max_j = end_j = -1;
if ((i-st) > max_iter) st = i-max_iter;
for (j = i - 1; j >= 0; --j) {
if(left_fix && f[j] == INT32_MIN)continue;
sc = comput_sc_ff_adv(&a[i], &a[j], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
if (sc == INT32_MIN) continue;
sc += f[j];
if (sc > max_f) {
max_f = sc, max_j = j;
if (n_skip > 0) --n_skip;
} else if (t[j] == (int32_t)i) {
if ((++n_skip) > max_skip) {
if((max_j != -1) || (left_fix == 0)) break;
}
}
if (p[j] >= 0) t[p[j]] = i;
///put it here will allow at least one prefix no matter max_dis
///this is special for gap filling, not for chaining
if (a[i].self_offset > (max_dis + a[j].self_offset)) {
if((max_j != -1)) break;
}
if (j < st) {
if((max_j != -1) || (left_fix == 0)) break;
}
}
end_j = j;
if (max_ii < 0 || ((int64_t)a[i].self_offset) - ((int64_t)a[max_ii].self_offset) > max_dis) {
max = INT32_MIN; max_ii = -1;
for (j = i - 1; (j >= st) && ((((int64_t)a[i].self_offset)-((int64_t)a[j].self_offset))<=max_dis); --j) {
if ((f[j] != INT32_MIN) && (max < f[j])) {
max = f[j], max_ii = j;
}
}
}
if ((max_ii >= 0) && (max_ii < end_j) && (f[max_ii] != INT32_MIN)) {///just have a try with a[i]<->a[max_ii]
tmp = comput_sc_ff_adv(&a[i], &a[max_ii], bw_rate, chn_pen_gap, chn_pen_skip, xl, yl);
if (tmp != INT32_MIN && max_f < tmp + f[max_ii])
max_f = tmp + f[max_ii], max_j = max_ii;
}
p[i] = max_j; f[i] = max_f;
if ((max_ii < 0) || (((((int64_t)a[i].self_offset)-((int64_t)a[max_ii].self_offset))<=max_dis) && (f[max_ii]<f[i]))) {
max_ii = i;
}
if(f[i] >= msc) {
ovl = get_chainLen(a[i].self_offset, a[i].self_offset, xl, a[i].offset, a[i].offset, yl);
if(f[i] > msc || ovl < movl) {
msc = f[i]; msc_i = i; movl = ovl;
}
}
}
skip_ldp:
if(right_fix && f[a_n-1] == INT32_MIN) return 0;
if(right_fix) msc_i = a_n-1;
///a[] has been sorted by self_offset
i = msc_i; cL = 0;
while (i >= 0) {
t[cL++] = i; msc_i = i; i = p[i];
}
n_skip = cL>>1;
for (i = 0; i < n_skip; i++) {
msc_i = t[i]; t[i] = t[cL-i-1]; t[cL-i-1] = msc_i;
}
if((cL > 0) && (right_fix) && (t[cL-1] != (a_n-1))) {
cL = 0;
}
if((cL > 0) && (left_fix) && (t[0] != 0)) {
cL = 0;
}
if(cL > 0 && res) {
for (i = 0; i < cL; i++) {
res[i] = a[t[i]];
}
}
return cL;
}
uint64_t lchain_refine(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp, 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) int64_t max_skip, int64_t max_iter, int64_t max_dis, int64_t long_gap)
{ {
@@ -2603,6 +3084,57 @@ uint64_t lchain_simple(k_mer_hit* a, int64_t a_n, k_mer_hit* des, Chain_Data* dp
return cL; return cL;
} }
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)
{
if(a_n <= 0) return 0;
int64_t *p, *t, max_f, n_skip, st, max_j, sc, msc, msc_i;
int32_t *f; int64_t i, j, cL = 0;
resize_Chain_Data(dp, a_n, NULL);
t = dp->tmp; f = dp->score; p = dp->pre; msc = msc_i = -1;
memset(t, 0, (a_n*sizeof((*t))));
f[0]=a[0].cnt; p[0]=-1; msc = f[0]; msc_i = 0;
for (i = 1, st = 0; i < a_n; ++i) {
max_f = INT32_MIN; n_skip = 0; max_j = -1;
if ((i-st) > max_iter) st = i-max_iter;
///[st, i-2]
for (j=i-1; j >= st; --j) {
if((a[i].self_offset > a[j].self_offset)&&(a[i].offset > a[j].offset)) {
sc = f[j]+a[i].cnt;
if (sc > max_f) {
max_f = sc, max_j = j;
if (n_skip > 0) --n_skip;
} else if (t[j] == (int32_t)i) {
if (++n_skip > max_skip)
break;
}
if (p[j] >= 0) t[p[j]] = i;
}
}
f[i] = max_f; p[i] = max_j;
if(f[i] > msc) {
msc = f[i]; msc_i = i;
}
}
///a[] has been sorted by self_offset
i = msc_i;
cL = 0;
while (i >= 0) {
t[cL++] = i; i = p[i];
}
n_skip = cL>>1;
for (i = 0; i < n_skip; i++) {
msc_i = t[i]; t[i] = t[cL-i-1]; t[cL-i-1] = msc_i;
}
if(des) {
for (i = 0; i < cL; i++) des[i] = a[t[i]];
}
return cL;
}
inline int64_t hit_long_gap(k_mer_hit *a, k_mer_hit *b, int64_t max_lgap, double small_bw_rate, int64_t min_small_bw) inline int64_t hit_long_gap(k_mer_hit *a, k_mer_hit *b, int64_t max_lgap, double small_bw_rate, int64_t min_small_bw)
{ {
int64_t dq, dr, dd, dm; int64_t dq, dr, dd, dm;
+27
View File
@@ -9,11 +9,16 @@
#define WINDOW 375 #define WINDOW 375
#define WINDOW_BOUNDARY 375 #define WINDOW_BOUNDARY 375
#define WINDOW_HC 775 #define WINDOW_HC 775
///ONT high error
// #define WINDOW_OHC 475
#define WINDOW_OHC 375
#define WINDOW_HC_FAST 512 #define WINDOW_HC_FAST 512
///for one side, the first or last WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY bases should not be corrected ///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 WINDOW_UNCORRECT_SINGLE_SIDE_BOUNDARY 25
#define THRESHOLD 15 #define THRESHOLD 15
#define OVERLAP_THRESHOLD_HIFI_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_NOSI_FILTER 0.7
#define OVERLAP_THRESHOLD_FILTER_HPC 0.75 #define OVERLAP_THRESHOLD_FILTER_HPC 0.75
#define HIGH_HET_OVERLAP_THRESHOLD_FILTER 0.3 #define HIGH_HET_OVERLAP_THRESHOLD_FILTER 0.3
@@ -229,8 +234,15 @@ uint64_t lchain_qdp_fix(k_mer_hit* a, int64_t a_n, Chain_Data* dp, int64_t max_s
int64_t max_iter, int64_t max_dis, double chn_pen_gap, double chn_pen_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, double bw_rate, int64_t xl, int64_t yl, int64_t quick_check,
int64_t left_fix, int64_t right_fix); 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, 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); 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, 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, 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, int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate,
@@ -245,4 +257,19 @@ uint64_t lchain_qdp_mcopy_fast(Candidates_list *cl, int64_t a_idx, int64_t a_n,
int64_t gen_cigar, int64_t enable_mcopy, double mcopy_rate, int64_t mcopy_khit_cutoff, int64_t gen_cigar, int64_t enable_mcopy, double mcopy_rate, int64_t mcopy_khit_cutoff,
int64_t khit_n); 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 #endif
+162
View File
@@ -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);
}
+276
View File
@@ -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;
}
}
+32 -4
View File
@@ -12,6 +12,9 @@
#include <stdio.h> #include <stdio.h>
#include "kvec.h" #include "kvec.h"
#define AVX_GS 8
#define AVX_GS2 4
extern const unsigned char seq_nt4_table[256]; extern const unsigned char seq_nt4_table[256];
typedef uint64_t Word; typedef uint64_t Word;
typedef uint32_t Word_32; typedef uint32_t Word_32;
@@ -709,7 +712,14 @@ inline uint32_t pop_trace_bp_f(asg16_v *res, uint32_t i, uint16_t *c, uint16_t *
inline int64_t pop_trace_bp_rev_f(asg16_v *res, int64_t i, uint16_t *c, uint16_t *bq, uint16_t *bt, uint32_t *len) inline int64_t pop_trace_bp_rev_f(asg16_v *res, int64_t i, uint16_t *c, uint16_t *bq, uint16_t *bt, uint32_t *len)
{ {
(*c) = (res->a[i]>>14); (*bq) = (*bt) = (uint16_t)-1; uint32_t sl = 1;
(*c) = (*bq) = (*bt) = (uint16_t)-1; (*len) = 0;
if(i >= ((int64_t)res->n)) {
i = ((int64_t)res->n) - 1; sl = 0;
}
if(i >= 0) {
(*c) = (res->a[i]>>14);
(*bq) = (*bt) = (uint16_t)-1;
if((*c) == 2 || (*c) == 3) { if((*c) == 2 || (*c) == 3) {
(*bt) = ((res->a[i]>>12)&3); (*bt) = ((res->a[i]>>12)&3);
(*len) = (res->a[i]&(0xfff)); (*len) = (res->a[i]&(0xfff));
@@ -720,8 +730,12 @@ inline int64_t pop_trace_bp_rev_f(asg16_v *res, int64_t i, uint16_t *c, uint16_t
} else { } else {
(*len) = (res->a[i]&(0x3fff)); (*len) = (res->a[i]&(0x3fff));
} }
}
if(sl == 0) {
(*len) = 0; i = res->n;
}
uint32_t sl; uint16_t sbq, sbt; uint16_t sbq, sbt;
for (i--; (i >= 0) && ((*c) == (res->a[i]>>14)); i--) { for (i--; (i >= 0) && ((*c) == (res->a[i]>>14)); i--) {
sbq = sbt = (uint16_t)-1; sbq = sbt = (uint16_t)-1;
if((*c) == 2 || (*c) == 3) { if((*c) == 2 || (*c) == 3) {
@@ -796,7 +810,7 @@ inline uint32_t cigar_check(char *pstr, char *tstr, bit_extz_t *ez)
if(c == 0) { if(c == 0) {
for (k=0;(k<cl)&&(pstr[pi]==tstr[ti]);k++,pi++,ti++); for (k=0;(k<cl)&&(pstr[pi]==tstr[ti]);k++,pi++,ti++);
if(k!=cl) { if(k!=cl) {
fprintf(stderr, "ERROR-d-0, pi::%d, ti::%d\n", pi, ti); fprintf(stderr, "ERROR-d-0, pi::%d, ti::%d, ci::%u\n", pi, ti, ci);
return 0; return 0;
} }
} else { } else {
@@ -804,7 +818,7 @@ inline uint32_t cigar_check(char *pstr, char *tstr, bit_extz_t *ez)
if(c == 1) { if(c == 1) {
for (k=0;(k<cl)&&(pstr[pi]!=tstr[ti]);k++,pi++,ti++); for (k=0;(k<cl)&&(pstr[pi]!=tstr[ti]);k++,pi++,ti++);
if(k!=cl) { if(k!=cl) {
fprintf(stderr, "ERROR-d-1, pi::%d, ti::%d\n", pi, ti); fprintf(stderr, "ERROR-d-1, pi::%d, ti::%d, ci::%u\n", pi, ti, ci);
return 0; return 0;
} }
} else if(c == 2) {///more p } else if(c == 2) {///more p
@@ -814,10 +828,20 @@ inline uint32_t cigar_check(char *pstr, char *tstr, bit_extz_t *ez)
} }
} }
} }
if(err != ez->err) { if(err != ez->err) {
fprintf(stderr, "ERROR-err\n"); fprintf(stderr, "ERROR-err\n");
return 0; return 0;
} }
if(pi != ez->pe + 1) {
fprintf(stderr, "ERROR-pi\n");
return 0;
}
if(ti != ez->te + 1) {
fprintf(stderr, "ERROR-ti\n");
return 0;
}
return 1; return 1;
} }
@@ -3724,6 +3748,10 @@ inline void ed_band_cal_extension_64_1_w_trace(char *pstr, int32_t pn, char *tst
return; return;
} }
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);
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);
inline void ed_band_cal_semi_64_w_absent_diag(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, int32_t abs_diag, bit_extz_t *ez) inline void ed_band_cal_semi_64_w_absent_diag(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, int32_t abs_diag, bit_extz_t *ez)
{ {
init_base_ed(*ez, thre, pn, tn); ez->ps = ez->pe = -1; ez->ts = 0; ez->te = tn-1; init_base_ed(*ez, thre, pn, tn); ez->ps = ez->pe = -1; ez->ts = 0; ez->te = tn-1;
+11 -2
View File
@@ -5,7 +5,7 @@ CFLAGS= $(CXXFLAGS)
CPPFLAGS= CPPFLAGS=
INCLUDES= INCLUDES=
OBJS= CommandLines.o Process_Read.o Assembly.o Hash_Table.o \ 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 \ 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\ 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 tovlp.o inter.o kalloc.o gfa_ut.o gchain_map.o
EXE= hifiasm EXE= hifiasm
@@ -19,13 +19,22 @@ endif
.SUFFIXES:.cpp .c .o .SUFFIXES:.cpp .c .o
.PHONY:all clean depend .PHONY:all clean depend
all:$(EXE)
.cpp.o: .cpp.o:
$(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $< -o $@ $(CXX) -c $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $< -o $@
.c.o: .c.o:
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(INCLUDES) $< -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 $(EXE):$(OBJS) main.o
$(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS) $(CXX) $(CXXFLAGS) $^ -o $@ $(LIBS)
+1570 -182
View File
File diff suppressed because it is too large Load Diff
+7 -2
View File
@@ -35,6 +35,7 @@
// #define ALTER_LABLE 2 // #define ALTER_LABLE 2
// #define HAP_LABLE 4 // #define HAP_LABLE 4
#define ug_ext_len 75000 #define ug_ext_len 75000
#define UL_COV_THRES 2
#define Get_qn(RECORD) ((uint32_t)((RECORD).qns>>32)) #define Get_qn(RECORD) ((uint32_t)((RECORD).qns>>32))
#define Get_qs(RECORD) ((uint32_t)((RECORD).qns)) #define Get_qs(RECORD) ((uint32_t)((RECORD).qns))
@@ -262,6 +263,7 @@ 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; uint32_t *a; } asg32_v;
typedef struct { size_t n, m; ma_utg_t *a;} ma_utg_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 { asg64_v idx; kv_ul_ov_t srt;} mask_ul_ov_t;
typedef struct { uint64_t n, m; char *a; } asgchr_v;
typedef struct { typedef struct {
ma_utg_v u; ma_utg_v u;
@@ -631,7 +633,7 @@ static inline int count_out_without_del(const asg_t *g, uint32_t v)
void build_string_graph_without_clean( void build_string_graph_without_clean(
int min_dp, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 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, 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, float min_ovlp_drop_ratio, float max_ovlp_drop_ratio, char* output_file_name,
long long bubble_dist, int read_graph, int write); long long bubble_dist, int read_graph, int write);
@@ -926,7 +928,7 @@ ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, int m
void rescue_bubble_by_chain(asg_t *sg, ma_sub_t *coverage_cut, ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, 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, 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, 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); bub_label_t* b_mask_t, long long no_trio_recover, uint8_t *cmk);
typedef struct{ typedef struct{
double weight; double weight;
@@ -1241,6 +1243,9 @@ uint64_t infer_mmhap_copy(ma_ug_t *ug, asg_t *sg, ma_hit_t_alloc *src, uint8_t *
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); 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 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 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 {\ #define UC_Read_resize(v, s) do {\
if ((v).size<(s)) {REALLOC((v).seq,(s));(v).size=(s);}\ if ((v).size<(s)) {REALLOC((v).seq,(s));(v).size=(s);}\
+322 -12
View File
@@ -46,13 +46,20 @@ void init_All_reads(All_reads* r)
void destory_All_reads(All_reads* r) void destory_All_reads(All_reads* r)
{ {
uint64_t i = 0; uint64_t i = 0;
for (i = 0; i < r->total_reads; i++) { for (i = 0; i < r->tqn; i++) {
if (r->N_site[i]) free(r->N_site[i]); if (r->N_site[i]) free(r->N_site[i]);
if (r->read_sperate[i]) free(r->read_sperate[i]); if (r->read_sperate[i]) free(r->read_sperate[i]);
if (r->paf && r->paf[i].buffer) free(r->paf[i].buffer); if (r->paf && r->paf[i].buffer) free(r->paf[i].buffer);
if (r->reverse_paf && r->reverse_paf[i].buffer) free(r->reverse_paf[i].buffer); if (r->reverse_paf && r->reverse_paf[i].buffer) free(r->reverse_paf[i].buffer);
///if (r->pb_regions) kv_destroy(r->pb_regions[i].a); if(r->rsc && r->rsc[i]) free(r->rsc[i]);
} }
for (; i < r->total_reads; i++) {
if (r->N_site[i]) free(r->N_site[i]);
if (r->read_sperate[i]) free(r->read_sperate[i]);
if (r->paf && r->paf[i].buffer) free(r->paf[i].buffer);
if (r->reverse_paf && r->reverse_paf[i].buffer) free(r->reverse_paf[i].buffer);
}
free(r->paf); free(r->paf);
free(r->reverse_paf); free(r->reverse_paf);
free(r->N_site); free(r->N_site);
@@ -61,6 +68,7 @@ void destory_All_reads(All_reads* r)
free(r->name_index); free(r->name_index);
free(r->read_length); free(r->read_length);
free(r->trio_flag); free(r->trio_flag);
free(r->rsc);
///if (r->pb_regions) free(r->pb_regions); ///if (r->pb_regions) free(r->pb_regions);
} }
@@ -108,6 +116,20 @@ void write_All_reads(All_reads* r, char* read_file_name)
fwrite(&(asm_opt.hom_cov), sizeof(asm_opt.hom_cov), 1, fp); fwrite(&(asm_opt.hom_cov), sizeof(asm_opt.hom_cov), 1, fp);
fwrite(&(asm_opt.het_cov), sizeof(asm_opt.het_cov), 1, fp); fwrite(&(asm_opt.het_cov), sizeof(asm_opt.het_cov), 1, fp);
uint64_t mm = 2;///1;
if(asm_opt.is_sc) {
fwrite(&mm, sizeof(mm), 1, fp);
fwrite(&(r->tqn), sizeof(r->tqn), 1, fp);
for (i = 0; i < r->tqn; i++) {
fwrite(r->rsc[i], sizeof(uint8_t), ((r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0)), fp);
}
}
mm = 3;
fwrite(&mm, sizeof(mm), 1, fp);
fwrite(&(r->tr[0]), sizeof(r->tr[0]), 1, fp);
fwrite(&(r->tr[1]), sizeof(r->tr[1]), 1, fp);
free(index_name); free(index_name);
fflush(fp); fflush(fp);
fclose(fp); fclose(fp);
@@ -123,6 +145,7 @@ int load_All_reads(All_reads* r, char* read_file_name)
free(index_name); free(index_name);
return 0; return 0;
} }
// fprintf(stderr, "[M::%s]\tindex_name::%s\n", __func__, index_name);
int local_adapterLen; int local_adapterLen;
int f_flag; int f_flag;
f_flag = fread(&local_adapterLen, sizeof(local_adapterLen), 1, fp); f_flag = fread(&local_adapterLen, sizeof(local_adapterLen), 1, fp);
@@ -201,6 +224,34 @@ int load_All_reads(All_reads* r, char* read_file_name)
} }
///r->pb_regions = NULL; ///r->pb_regions = NULL;
uint64_t mm = 0;
if (!feof(fp)) {
if((fread(&mm, sizeof(mm), 1, fp)) && (mm == 1 || mm == 2)) {
if(mm == 1) {
mm = r->total_reads;
} else {
assert(mm == 2);
fread(&mm, sizeof(mm), 1, fp);
}
r->tqn = mm;
MALLOC(r->rsc, r->tqn);
for (i = 0; i < r->tqn; i++) {
MALLOC(r->rsc[i], (r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0));
f_flag += fread(r->rsc[i], sizeof(uint8_t), (r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0), fp);
}
mm = 0;
if(!feof(fp)) fread(&mm, sizeof(mm), 1, fp);
}
if(mm == 3) {
fread(&(r->tr[0]), sizeof(r->tr[0]), 1, fp);
fread(&(r->tr[1]), sizeof(r->tr[1]), 1, fp);
}
}
free(index_name); free(index_name);
fclose(fp); fclose(fp);
fprintf(stderr, "Reads has been loaded.\n"); fprintf(stderr, "Reads has been loaded.\n");
@@ -208,6 +259,60 @@ int load_All_reads(All_reads* r, char* read_file_name)
return 1; return 1;
} }
void write_cc_v(cc_v* r, char* read_file_name)
{
fprintf(stderr, "Writing raw reads to disk... \n");
char* index_name = (char*)malloc(strlen(read_file_name)+32);
sprintf(index_name, "%s.bin", read_file_name);
FILE* fp = fopen(index_name, "w"); free(index_name);
///typedef struct {size_t n, m; asg16_v *a; uint8_t *f; uint16_t *er; uint64_t bid;} cc_v;
asg16_v *z;
uint64_t k, rn = r->n; uint32_t zn; fwrite(&rn, sizeof(rn), 1, fp);
for (k = 0; k < r->n; k++) {
z = &(r->a[k]);
zn = z->n;
fwrite(&zn, sizeof(zn), 1, fp);
fwrite(z->a, sizeof((*(z->a))), zn, fp);
}
fflush(fp); fclose(fp);
fprintf(stderr, "Raw reads has been written.\n");
}
uint8_t load_cc_v(cc_v* r, char* read_file_name)
{
fprintf(stderr, "Loading raw reads... \n");
char* index_name = (char*)malloc(strlen(read_file_name)+32);
sprintf(index_name, "%s.bin", read_file_name);
FILE* fp = fopen(index_name, "r"); free(index_name);
if (!fp) {
fprintf(stderr, "No raw read bin.\n");
return 0;
}
///typedef struct {size_t n, m; asg16_v *a; uint8_t *f; uint16_t *er; uint64_t bid;} cc_v;
asg16_v *z; int f_flag = 0;
uint64_t k, rn; uint32_t zn; f_flag += fread(&rn, sizeof(rn), 1, fp);
r->n = r->m = rn;
if(rn == 0) {
free(r->a); r->a = NULL;
} else {
MALLOC(r->a, r->n);
for (k = 0; k < r->n; k++) {
z = &(r->a[k]);
f_flag += fread(&zn, sizeof(zn), 1, fp);
z->n = z->m = zn; MALLOC(z->a, z->n);
f_flag += fread(z->a, sizeof((*(z->a))), zn, fp);
}
}
fflush(fp); fclose(fp);
fprintf(stderr, "Raw reads has been loaded.\n");
return 1;
}
void read_ma(ma_hit_t* x, FILE* fp) void read_ma(ma_hit_t* x, FILE* fp)
{ {
int f_flag; int f_flag;
@@ -251,8 +356,8 @@ int append_All_reads(All_reads* r, char *idx, uint32_t id)
int local_adapterLen, f_flag; int local_adapterLen, f_flag;
f_flag = fread(&local_adapterLen, sizeof(local_adapterLen), 1, fp); f_flag = fread(&local_adapterLen, sizeof(local_adapterLen), 1, fp);
if(local_adapterLen != asm_opt.adapterLen) { if(local_adapterLen != asm_opt.adapterLen) {
fprintf(stderr, "the adapterLen of index is: %d, but the adapterLen set by user is: %d\n", fprintf(stderr, "[M::%s] the adapterLen of index is: %d, but the adapterLen set by user is: %d\n",
local_adapterLen, asm_opt.adapterLen); __func__, local_adapterLen, asm_opt.adapterLen);
exit(1); exit(1);
} }
uint64_t index_size0, name_index_size0, total_reads0, total_reads_bases0, total_name_length0; uint64_t index_size0, name_index_size0, total_reads0, total_reads_bases0, total_name_length0;
@@ -406,16 +511,24 @@ void ha_insert_read_len(All_reads *r, int read_len, int name_len)
r->name_index[r->total_reads] = r->name_index[r->total_reads - 1] + name_len; r->name_index[r->total_reads] = r->name_index[r->total_reads - 1] + name_len;
} }
void malloc_All_reads(All_reads* r) void malloc_All_reads(All_reads *r)
{ {
r->read_size = (uint64_t*)malloc(sizeof(uint64_t)*r->total_reads); r->read_size = (uint64_t*)malloc(sizeof(uint64_t)*r->total_reads);
memcpy(r->read_size, r->read_length, sizeof(uint64_t)*r->total_reads); memcpy(r->read_size, r->read_length, sizeof(uint64_t)*r->total_reads);
r->read_sperate = (uint8_t**)malloc(sizeof(uint8_t*)*r->total_reads); r->read_sperate = (uint8_t**)malloc(sizeof(uint8_t*)*r->total_reads);
long long i = 0; if(asm_opt.is_sc && r->tqn) MALLOC(r->rsc, r->tqn);
for (i = 0; i < (long long)r->total_reads; i++) assert(r->tqn <= r->total_reads);
{
r->read_sperate[i] = (uint8_t*)malloc(sizeof(uint8_t)*(r->read_length[i]/4+1)); uint64_t i = 0;
if(r->rsc) {
for (i = 0; i < r->tqn; i++) {
MALLOC(r->read_sperate[i], (r->read_length[i]/4+1));
MALLOC(r->rsc[i], (r->read_length[i]/sc_bn) + ((r->read_length[i]%sc_bn)?1:0));
}
}
for (; i < r->total_reads; i++) {
MALLOC(r->read_sperate[i], (r->read_length[i]/4+1));
} }
r->cigars = (Compressed_Cigar_record*)malloc(sizeof(Compressed_Cigar_record)*r->total_reads); r->cigars = (Compressed_Cigar_record*)malloc(sizeof(Compressed_Cigar_record)*r->total_reads);
@@ -424,8 +537,7 @@ void malloc_All_reads(All_reads* r)
r->reverse_paf = (ma_hit_t_alloc*)malloc(sizeof(ma_hit_t_alloc)*r->total_reads); r->reverse_paf = (ma_hit_t_alloc*)malloc(sizeof(ma_hit_t_alloc)*r->total_reads);
///r->pb_regions = (kvec_t_u64_warp*)malloc(r->total_reads*sizeof(kvec_t_u64_warp)); ///r->pb_regions = (kvec_t_u64_warp*)malloc(r->total_reads*sizeof(kvec_t_u64_warp));
for (i = 0; i < (long long)r->total_reads; i++) for (i = 0; i < r->total_reads; i++) {
{
r->second_round_cigar[i].size = r->cigars[i].size = 0; r->second_round_cigar[i].size = r->cigars[i].size = 0;
r->second_round_cigar[i].length = r->cigars[i].length = 0; r->second_round_cigar[i].length = r->cigars[i].length = 0;
r->second_round_cigar[i].record = r->cigars[i].record = NULL; r->second_round_cigar[i].record = r->cigars[i].record = NULL;
@@ -823,6 +935,130 @@ void ha_compress_base(uint8_t* dest, char* src, uint64_t src_l, uint64_t** N_sit
} }
} }
void convert_qual(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitu, uint64_t rev, uint64_t sc_off)
{
uint64_t i = 0; uint8_t c = 0, sc;
// fprintf(stderr, "\n[M::%s]\n", __func__);
for (i = 0; i < src_l; i++) {
for (c = 0, sc = ((uint8_t)src[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
if(c >= bitu) c = bitu - 1;
dest[(rev?(src_l-i-1):(i))] = c;
// fprintf(stderr, "%u->%u\n", sc, c);
}
}
void ha_compress_qual_bit(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitn)
{
uint64_t i = 0, k, bit_r = 8/bitn, dest_i = 0;
uint8_t tmp = 0, c = 0;
for (i = 0; i + bit_r <= src_l;) {
for (k = tmp = 0; k < bit_r; k++) {
c = ((uint8_t)src[i]);
tmp <<= bitn; tmp |= c; i++;
}
dest[dest_i++] = tmp;
}
if(i < src_l) {
for (k = tmp = 0; i < src_l; k++) {
c = ((uint8_t)src[i]);
tmp <<= bitn; tmp |= c; i++;
}
dest[dest_i++] = (tmp<<(8-(bitn*k)));
}
}
void ha_compress_qual(uint8_t* dest, char* src, uint64_t src_l, uint64_t bitn, uint64_t sc_off)
{
uint64_t i = 0, k, bit_r = 8/bitn, dest_i = 0, bitu = (1<<bitn);
uint8_t tmp = 0, c = 0, sc;
for (i = 0; i + bit_r <= src_l;) {
for (k = tmp = 0; k < bit_r; k++) {
for (c = 0, sc = ((uint8_t)src[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
if(c >= bitu) c = bitu - 1;
tmp <<= bitn; tmp |= c; i++;
}
dest[dest_i++] = tmp;
}
if(i < src_l) {
for (k = tmp = 0; i < src_l; k++) {
for (c = 0, sc = ((uint8_t)src[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
if(c >= bitu) c = bitu - 1;
tmp <<= bitn; tmp |= c; i++;
}
dest[dest_i++] = (tmp<<(8-(bitn*k)));
}
}
///[s, e)
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)
{
int64_t rl = Get_READ_LENGTH(R_INF, id), l;
if(s < 0) {s = 0;} if(e < 0) {e = rl;}
if(s >= e || e > rl) return -1;
uint8_t *da = NULL, *src = Get_QUAL(R_INF, id), mm = (((uint8_t)1)<<bitn)-1, mlf = 8 - bitn, mrf;
int64_t bitr = 8/bitn, dk, sk, swk;
l = e - s;
if(dv) {
kv_resize(uint8_t, *dv, ((uint64_t)l)); da = dv->a; dv->n = l;
} else {
da = ds;
}
if(!rev) {
dk = 0; sk = s;
mrf = ((s%bitr)*bitn);
// if(s == 21519 && e == 22332) {
// fprintf(stderr, "+[M::%s] id::%lu, in::[%ld, %ld), rev::%u, bitn::%ld, bitr::%ld, mrf::%u\n", __func__, id, s, e, rev, bitn, bitr, mrf);
// }
if(mrf) {
for (swk = sk/bitr; mrf < 8 && sk < e; mrf += bitn, sk++) da[dk++] = ((src[swk]<<mrf)>>mlf)&mm;
}
for (swk = sk/bitr; (sk + bitr) <= e; sk += bitr, swk++) {
for (mrf = 0; mrf < 8; mrf += bitn) da[dk++] = ((src[swk]<<mrf)>>mlf)&mm;
}
if(sk < e) {
for (mrf = 0; sk < e; mrf += bitn, sk++) da[dk++] = ((src[swk]<<mrf)>>mlf)&mm;
}
// if(dk != l) {
// fprintf(stderr, "+[M::%s] id::%lu, in::[%ld, %ld), rev::%u, bitn::%ld, bitr::%ld\n", __func__, id, s, e, rev, bitn, bitr);
// }
assert(dk == l);
} else {
sk = s; s = e; e = sk;
s = rl - s; e = rl - e;
dk = l; sk = s;
mrf = ((s%bitr)*bitn);
if(mrf) {
for (swk = sk/bitr; mrf < 8 && sk < e; mrf += bitn, sk++) da[--dk] = ((src[swk]<<mrf)>>mlf)&mm;
}
for (swk = sk/bitr; (sk + bitr) <= e; sk += bitr, swk++) {
for (mrf = 0; mrf < 8; mrf += bitn) da[--dk] = ((src[swk]<<mrf)>>mlf)&mm;
}
if(sk < e) {
for (mrf = 0; sk < e; mrf += bitn, sk++) da[--dk] = ((src[swk]<<mrf)>>mlf)&mm;
}
assert(dk == 0);
}
return l;
}
void reverse_complement(char* pattern, uint64_t length) void reverse_complement(char* pattern, uint64_t length)
{ {
uint64_t i = 0; uint64_t i = 0;
@@ -845,6 +1081,24 @@ void reverse_complement(char* pattern, uint64_t length)
} }
} }
void print_fastq(FILE *fp, char *id, char *bs, char *qual, uint64_t bitu, uint64_t sc_off)
{
uint64_t i = 0, ql = strlen(qual); uint8_t c = 0, sc;
if(fp) fprintf(fp, "@%s\n%s\n+\n", id, bs);
else fprintf(stdout, "@%s\n%s\n+\n", id, bs);
for (i = 0; i < ql; i++) {
for (c = 0, sc = ((uint8_t)qual[i]) - sc_off; (c < bitu) && (sc_tb[c] < sc); c++);
if(c >= bitu) c = bitu - 1;
if(fp) fprintf(fp, "%u", c);
else fprintf(stdout, "%u", c);
}
if(fp) fprintf(fp, "\n");
else fprintf(stdout, "\n");
}
void init_Debug_reads(Debug_reads* x, const char* file) void init_Debug_reads(Debug_reads* x, const char* file)
{ {
@@ -1330,7 +1584,7 @@ void append_ul_t(all_ul_t *x, uint64_t *rid, char* id, int64_t id_l, char* str,
p->rlen = str_l; p->rlen = str_l;
// fprintf(stderr, "str_l->%ld, str->%u\n", str_l, str?1:0); // fprintf(stderr, "str_l->%ld, str->%u\n", str_l, str?1:0);
if(o == NULL || on == 0) on = 0; en = 0; if(o == NULL || on == 0) {on = 0;} en = 0;
for (i = on-1, st = et = str_l; i >= 0; i--) { for (i = on-1, st = et = str_l; i >= 0; i--) {
z = &(o[i]); z = &(o[i]);
if(z->el) { if(z->el) {
@@ -1606,6 +1860,62 @@ void retrieve_u_seq(UC_Read* i_r, char* i_s, ma_utg_t *u, uint8_t strand, int64_
} }
} }
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)
{
if(u->m == 0 || u->n == 0) return;
if(l < 0) l = u->len;
char *r = NULL, *a = NULL;
int64_t e = s + l, ssp, sep, rs, re, des_i;
uint64_t k, rId, ori, r_l;
if(i_r) {
i_r->length = l; i_r->RID = 0;
if(i_r->length > i_r->size) {
i_r->size = i_r->length;
if(!km) REALLOC(i_r->seq, i_r->size);
else KREALLOC(km, i_r->seq, i_r->size);
// i_r->seq = (char*)realloc(i_r->seq,sizeof(char)*(i_r->size));
}
r = i_r->seq;
}
if(i_s) r = i_s;
if(u->s) {
memcpy(r, u->s + s, l * sizeof((*(u->s))));
} else {
if(strand == 1) {
sep = u->len - s;
ssp = u->len - e;
s = ssp; e = sep;
}
for (k = l = des_i = 0; k < u->n; k++) {
rId = u->a[k]>>33;
ori = u->a[k]>>32&1;
r_l = (uint32_t)u->a[k];
if(r_l == 0) continue;
ssp = l; sep = l + r_l;
l += r_l;
if(sep <= s) continue;
if(ssp >= e) break;
rs = MAX(ssp, s); re = MIN(sep, e);
a = r + des_i; des_i += re - rs;
recover_UC_Read_sub_region(a, rs-ssp, re-rs, ori, &R_INF, rId);
}
}
if(strand == 1) {
char t;
re = (e - s);
l = re>>1;
for (k = 0; k < (uint64_t)l; k++) {
des_i = re - k - 1;
t = r[des_i];
r[des_i] = RC_CHAR(r[k]);
r[k] = RC_CHAR(t);
}
if(re&1) r[l] = RC_CHAR(r[l]);
}
}
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) 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 *a = ul->cc->interval.a + ul->cc->idx[id], cc = 0, ff = 0; uint64_t *a = ul->cc->interval.a + ul->cc->idx[id], cc = 0, ff = 0;
+29
View File
@@ -8,6 +8,7 @@
#include <zlib.h> #include <zlib.h>
#include "Overlaps.h" #include "Overlaps.h"
#include "CommandLines.h" #include "CommandLines.h"
#include "Levenshtein_distance.h"
///#include "Hash_Table.h" ///#include "Hash_Table.h"
#define READ_INIT_NUMBER 1000 #define READ_INIT_NUMBER 1000
@@ -22,6 +23,7 @@
#define Get_NAME_LENGTH(R_INF, ID) ((R_INF).name_index[(ID)+1] - (R_INF).name_index[(ID)]) #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 + (R_INF.index[ID]>>2) + ID
#define Get_READ(R_INF, ID) (R_INF).read_sperate[(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 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)) && \ #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) memcmp((NAME), Get_NAME((R_INF), (ID)), Get_NAME_LENGTH((R_INF),(ID))) == 0)
@@ -38,6 +40,8 @@ extern char rc_Table[6];
void init_aux_table(); void init_aux_table();
typedef struct { size_t n, m; uint8_t *a; } asg8_v;
typedef struct typedef struct
{ {
uint64_t x_id; uint64_t x_id;
@@ -119,6 +123,7 @@ typedef struct
uint64_t* read_length; uint64_t* read_length;
uint64_t* read_size; uint64_t* read_size;
uint8_t* trio_flag; uint8_t* trio_flag;
uint8_t** rsc;
///seq start pos in uint8_t* read ///seq start pos in uint8_t* read
///do not need it ///do not need it
@@ -129,8 +134,10 @@ typedef struct
uint64_t* name_index; uint64_t* name_index;
uint64_t name_index_size; uint64_t name_index_size;
uint64_t total_reads; uint64_t total_reads;
uint64_t tqn;
uint64_t total_reads_bases; uint64_t total_reads_bases;
uint64_t total_name_length; uint64_t total_name_length;
uint64_t tr[2];
Compressed_Cigar_record* cigars; Compressed_Cigar_record* cigars;
Compressed_Cigar_record* second_round_cigar; Compressed_Cigar_record* second_round_cigar;
@@ -138,11 +145,16 @@ typedef struct
ma_hit_t_alloc* paf; ma_hit_t_alloc* paf;
ma_hit_t_alloc* reverse_paf; ma_hit_t_alloc* reverse_paf;
uint8_t is_syn;
///kvec_t_u64_warp* pb_regions; ///kvec_t_u64_warp* pb_regions;
} All_reads; } All_reads;
extern All_reads R_INF; 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 typedef struct
{ {
char* seq; char* seq;
@@ -223,6 +235,7 @@ void init_All_reads(All_reads* r);
void malloc_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_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_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 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(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_RC(UC_Read* r, All_reads* R_INF, uint64_t ID);
@@ -231,6 +244,8 @@ void destory_UC_Read(UC_Read* r);
void reverse_complement(char* pattern, uint64_t length); void reverse_complement(char* pattern, uint64_t length);
void write_All_reads(All_reads* r, char* read_file_name); void write_All_reads(All_reads* r, char* read_file_name);
int load_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); int append_All_reads(All_reads* r, char *idx, uint32_t id);
void destory_All_reads(All_reads* r); void destory_All_reads(All_reads* r);
int destory_read_bin(All_reads* r); int destory_read_bin(All_reads* r);
@@ -253,5 +268,19 @@ int64_t load_compress_base_disk(FILE *fp, uint64_t *ul_rid, char *dest, uint32_t
scaf_res_t *init_scaf_res_t(uint32_t n); scaf_res_t *init_scaf_res_t(uint32_t n);
void destroy_scaf_res_t(scaf_res_t *p); void destroy_scaf_res_t(scaf_res_t *p);
void read_ma(ma_hit_t* x, FILE* fp); 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 #endif
+14
View File
@@ -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 # Assemble heterozygous genomes with built-in duplication purging
hifiasm -o HG002.asm -t32 HG002-file1.fq.gz HG002-file2.fq.gz 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 # 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 hifiasm -o HG002.asm --h1 read1.fq.gz --h2 read2.fq.gz HG002-HiFi.fq.gz
@@ -45,6 +48,7 @@ See [tutorial][tutorial] for more details.
- [Why Hifiasm?](#why) - [Why Hifiasm?](#why)
- [Usage](#use) - [Usage](#use)
- [Assembling HiFi reads without additional data types](#hifionly) - [Assembling HiFi reads without additional data types](#hifionly)
- [Assembling ONT reads](#ontonly)
- [Hi-C integration](#hic) - [Hi-C integration](#hic)
- [Trio binning](#trio) - [Trio binning](#trio)
- [Ultra-long ONT integration](#ul) - [Ultra-long ONT integration](#ul)
@@ -116,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 than human, applying `-f38` or even `-f39` is preferred to save memory on k-mer
counting. 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 ### <a name="hic"></a>Hi-C integration
Hifiasm can generate a pair of haplotype-resolved assemblies with paired-end Hifiasm can generate a pair of haplotype-resolved assemblies with paired-end
+93
View File
@@ -388,6 +388,31 @@ inline void phrase_hstatus(char *s, char **rname, uint32_t *hid)
*hid = atoi(id); *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) uint32_t *ha_polybin_list(const hifiasm_opt_t *opt)
{ {
int64_t i; int64_t i;
@@ -447,6 +472,74 @@ uint32_t *ha_polybin_list(const hifiasm_opt_t *opt)
return ss; 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) void ha_triobin(const hifiasm_opt_t *opt)
{ {
memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t)); memset(R_INF.trio_flag, AMBIGU, R_INF.total_reads * sizeof(uint8_t));
+671 -30
View File
@@ -984,8 +984,8 @@ uint32_t *low_occ)
} }
void minimizers_qgen0(ha_abuf_t *ab, char* rs, int64_t rl, uint64_t mz_w, uint64_t mz_k, Candidates_list *cl, kvec_t_u8_warp* k_flag, uint64_t minimizers_qgen0(ha_abuf_t *ab, char* rs, int64_t rl, uint64_t mz_w, uint64_t mz_k, Candidates_list *cl, kvec_t_u8_warp* k_flag,
void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_mt_t *sp, uint32_t *high_occ, uint32_t *low_occ) void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_mt_t *sp, uint32_t *high_occ, uint32_t *low_occ, uint64_t ti_cut, uint8_t flt_chh)
{ {
// fprintf(stderr, "+[M::%s]\n", __func__); // fprintf(stderr, "+[M::%s]\n", __func__);
uint64_t i, k, l, max_cnt = UINT32_MAX, min_cnt = 0; int n, j; ha_mz1_t *z; seed1_t *s; uint64_t i, k, l, max_cnt = UINT32_MAX, min_cnt = 0; int n, j; ha_mz1_t *z; seed1_t *s;
@@ -1009,7 +1009,6 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
} }
for (i = 0, ab->n_a = 0; i < ab->mz.n; ++i) { for (i = 0, ab->n_a = 0; i < ab->mz.n; ++i) {
ab->seed[i].a = ha_pt_get(ha_idx, ab->mz.a[i].x, &n); ab->seed[i].a = ha_pt_get(ha_idx, ab->mz.a[i].x, &n);
ab->seed[i].n = n; ab->seed[i].n = n;
ab->n_a += n; ab->n_a += n;
@@ -1025,6 +1024,7 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
z = &ab->mz.a[i]; s = &ab->seed[i]; z = &ab->mz.a[i]; s = &ab->seed[i];
for (j = 0; j < s->n; ++j) { for (j = 0; j < s->n; ++j) {
const ha_idxpos_t *y = &s->a[j]; const ha_idxpos_t *y = &s->a[j];
if((flt_chh) && (y->rid < ti_cut)) continue;///ONT
anchor1_t *an = &ab->a[k++]; anchor1_t *an = &ab->a[k++];
uint8_t rev = z->rev == y->rev? 0 : 1; uint8_t rev = z->rev == y->rev? 0 : 1;
an->other_off = rev?((uint32_t)-1)-1-(y->pos+1-y->span):y->pos; an->other_off = rev?((uint32_t)-1)-1-(y->pos+1-y->span):y->pos;
@@ -1035,6 +1035,7 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
an->srt = (uint64_t)y->rid<<33 | (uint64_t)rev<<32 | an->self_off; an->srt = (uint64_t)y->rid<<33 | (uint64_t)rev<<32 | an->self_off;
} }
} }
ab->n_a = k;
// copy over to _cl_ // copy over to _cl_
if (ab->m_a >= (uint64_t)cl->size) { if (ab->m_a >= (uint64_t)cl->size) {
@@ -1042,7 +1043,7 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
REALLOC(cl->list, cl->size); REALLOC(cl->list, cl->size);
} }
k_mer_hit *p; uint64_t tid = (uint64_t)-1, tl = (uint64_t)-1; k_mer_hit *p; uint64_t tid = (uint64_t)-1, tl = (uint64_t)-1, tcut_n = 0;
radix_sort_ha_an1(ab->a, ab->a + ab->n_a); radix_sort_ha_an1(ab->a, ab->a + ab->n_a);
for (k = 1, l = 0; k <= ab->n_a; ++k) { for (k = 1, l = 0; k <= ab->n_a; ++k) {
if (k == ab->n_a || ab->a[k].srt != ab->a[l].srt) { if (k == ab->n_a || ab->a[k].srt != ab->a[l].srt) {
@@ -1052,6 +1053,7 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
tl = Get_READ_LENGTH((*rdb), tid); tl = Get_READ_LENGTH((*rdb), tid);
// tl = rdb?Get_READ_LENGTH((*rdb), tid):udb->ug->u.a[tid].len; // tl = rdb?Get_READ_LENGTH((*rdb), tid):udb->ug->u.a[tid].len;
} }
if(tid < ti_cut) tcut_n = k;
for (i = l; i < k; i++) { for (i = l; i < k; i++) {
p = &cl->list[i]; p = &cl->list[i];
p->readID = ab->a[i].srt>>33; p->readID = ab->a[i].srt>>33;
@@ -1078,6 +1080,7 @@ void *ha_flt_tab, ha_pt_t *ha_idx, All_reads* rdb, kvec_t_u64_warp* dbg_ct, st_m
} }
} }
cl->length = ab->n_a; cl->length = ab->n_a;
return tcut_n;
} }
void minimizers_qgen0_amz(ha_abuf_t *ab, char* rs, int64_t rl, uint64_t mz_w, uint64_t mz_k, Candidates_list *cl, kvec_t_u8_warp* k_flag, void minimizers_qgen0_amz(ha_abuf_t *ab, char* rs, int64_t rl, uint64_t mz_w, uint64_t mz_k, Candidates_list *cl, kvec_t_u8_warp* k_flag,
@@ -1414,10 +1417,10 @@ uint32_t *low_occ, ha_mzl_t *in, uint64_t in_n, ha_mzl_t *idx, int64_t idx_n, ui
z = &in[i]; p = &(idx[z->x]); n = 0; z = &in[i]; p = &(idx[z->x]); n = 0;
assert(z->pos == p->pos && z->rid == p->rid && z->span == p->span && z->rev == p->rev); assert(z->pos == p->pos && z->rid == p->rid && z->span == p->span && z->rev == p->rev);
for (zi = z->x+1; zi < idx_n && idx[zi].x == p->x && n < mzl_cutoff; zi++) { for (zi = z->x+1; zi < idx_n && idx[zi].x == p->x && n < mzl_cutoff; zi++) {
if(idx[zi].rid == rid) continue; n++; if(idx[zi].rid == rid) {continue;} n++;
} }
for (zi = ((int64_t)z->x)-1; zi >= 0 && idx[zi].x == p->x && n < mzl_cutoff; zi--) { for (zi = ((int64_t)z->x)-1; zi >= 0 && idx[zi].x == p->x && n < mzl_cutoff; zi--) {
if(idx[zi].rid == rid) continue; n++; if(idx[zi].rid == rid) {continue;} n++;
} }
if((!n) || (n >= mzl_cutoff)) continue; if((!n) || (n >= mzl_cutoff)) continue;
ab->n_a += n; ab->n_a += n;
@@ -1435,11 +1438,11 @@ uint32_t *low_occ, ha_mzl_t *in, uint64_t in_n, ha_mzl_t *idx, int64_t idx_n, ui
///z is one of the minimizer ///z is one of the minimizer
z = &in[i]; p = &(idx[z->x]); n = 0; ns = 0; ne = -1; z = &in[i]; p = &(idx[z->x]); n = 0; ns = 0; ne = -1;
for (zi = z->x+1; zi < idx_n && idx[zi].x == p->x && n < mzl_cutoff; zi++) { for (zi = z->x+1; zi < idx_n && idx[zi].x == p->x && n < mzl_cutoff; zi++) {
if(idx[zi].rid == rid) continue; n++; if(idx[zi].rid == rid) {continue;} n++;
} }
ne = zi; ne = zi;
for (zi = ((int64_t)z->x)-1; zi >= 0 && idx[zi].x == p->x && n < mzl_cutoff; zi--) { for (zi = ((int64_t)z->x)-1; zi >= 0 && idx[zi].x == p->x && n < mzl_cutoff; zi--) {
if(idx[zi].rid == rid) continue; n++; if(idx[zi].rid == rid) {continue;} n++;
} }
ns = zi + 1; ns = zi + 1;
if((!n) || (n >= mzl_cutoff)) continue; if((!n) || (n >= mzl_cutoff)) continue;
@@ -1917,20 +1920,354 @@ void lchain_qgen_mcopy(Candidates_list* cl, overlap_region_alloc* ol, uint32_t r
for (i = 0; i < ol->length; ++i) ol->list[i].align_length = 0; for (i = 0; i < ol->length; ++i) ol->list[i].align_length = 0;
} }
void lchain_qgen_mcopy_fast(Candidates_list* cl, overlap_region_alloc* ol, uint32_t rid, uint64_t rl, All_reads* rdb, static inline uint64_t mz_pos_bsearch(const ha_mz1_t *a, uint64_t lo, uint64_t hi, uint64_t key) {
uint64_t mid;
if((lo >= hi) || (a[lo].pos > key)) {lo = 0;}
else if(a[lo].pos == key) {return lo;}
while (lo < hi) {
mid = lo + ((hi - lo) >> 1);
if (a[mid].pos < key) {
lo = mid + 1;
} else if(a[mid].pos > key) {
hi = mid;
} else {
lo = mid;
break;
}
}
if (lo < hi && a[lo].pos == key) {
return lo;
}
return ((uint64_t)-1);
}
uint8_t cmp_chain_aln(overlap_region *a, /**uint32_t ak0,**/ overlap_region *b, k_mer_hit *ca)
{
uint64_t ak, bk, al[2], bl[2]/**, af[2], bf[2]**/;
al[0] = a->non_homopolymer_errors; al[1] = a->overlapLen;
bl[0] = b->non_homopolymer_errors; bl[1] = b->overlapLen;
for (ak = al[0], bk = bl[0]; (ak < al[1]) && (bk < bl[1]) && (ca[ak].self_offset == ca[bk].self_offset); ak++, bk++);
// if(ka == 128 && kb == 129) {
// fprintf(stderr, "[M::%s::] al::[%lu,%lu), bl::[%lu,%lu), ak::%lu, bk::%lu\n", __func__, al[0], al[1], bl[0], bl[1], ak, bk);
// }
if((ak < al[1]) || (bk < bl[1])) return 0;
/**
af[0] = af[1] = bf[0] = bf[1] = ((uint64_t)-1);
for (ak = ak0, bk = bl[0]; (bk < bl[1]) && (ca[bk].self_offset < ca[ak].self_offset); bk++);
// if(!((bk < bl[1]) && (ca[ak].self_offset == ca[bk].self_offset))) {
// fprintf(stderr, "[M::%s::]\ta::%.*s->b::%.*s\n", __func__,
// (int32_t)Get_NAME_LENGTH(R_INF, a->y_id), Get_NAME(R_INF, a->y_id), (int32_t)Get_NAME_LENGTH(R_INF, b->y_id), Get_NAME(R_INF, b->y_id));
// }
assert((bk < bl[1]) && (ca[ak].self_offset == ca[bk].self_offset));
af[0] = ak; af[1] = ++ak;
bf[0] = bk; bf[1] = ++bk;
for (; (ak < al[1]) && (bk < bl[1]) && (ca[ak].self_offset == ca[bk].self_offset); ak++, bk++);
af[1] = ak; bf[1] = bk;
if(af[0] > al[0] && bf[0] > bl[0]) return 0;
if(af[1] < al[1] && bf[1] < bl[1]) return 0;
**/
return 1;
}
void debug_chain_aln_de(overlap_region_alloc *ol, Candidates_list *cl)
{
uint64_t k, z, zn; overlap_region *pk, *pz;
for (k = 0; k < ol->length; k++) {
pk = &(ol->list[k]);
for (z = zn = 0; z < ol->length; z++) {
if(z == k) continue;
pz = &(ol->list[z]);
if(cmp_chain_aln(pk, pz, cl->list)) {
if((pk->x_id != pz->x_id) || (pk->x_id == ((uint32_t)-1)) || (pz->x_id == ((uint32_t)-1))) {
fprintf(stderr, "[M::%s::type0] k::%lu, z::%lu\n", __func__, k, z);
exit(1);
}
zn++;
}
}
if((pk->x_id == ((uint32_t)-1)) && (zn > 0)) {
fprintf(stderr, "[M::%s::type1] k::%lu, zn::%lu\n", __func__, k, zn + 1);
exit(1);
}
}
}
void chain_aln_de(ha_abuf_t *ab, overlap_region_alloc *ol, Candidates_list *cl, asg32_v *ik)
{
uint64_t k, l, p, pi, c, z, zn, zk; uint32_t pn/**, ikn0 = ik->n**/;
// fprintf(stderr, "-0-[M::%s::] ik->n::%lu, ol->length::%lu\n", __func__, (uint64_t)ik->n, ol->length);
for (k = 0; k < ol->length; k++) {
// fprintf(stderr, "\n---[k::%lu::M::%s::%.*s(qid::%u)] q[%d, %d), t[%d, %d), sc::%d, occ::%u\n", k, __func__,
// (int32_t)Get_NAME_LENGTH(R_INF, ol->list[k].y_id), Get_NAME(R_INF, ol->list[k].y_id), ol->list[k].y_id,
// ol->list[k].x_pos_s, ol->list[k].x_pos_e+1, ol->list[k].y_pos_s, ol->list[k].y_pos_e+1, ol->list[k].shared_seed, ol->list[k].align_length);
if(ol->list[k].x_id != ((uint32_t)-1)) continue;
/**
for (l = ol->list[k].non_homopolymer_errors, zn = 0; l < ol->list[k].overlapLen; l++) {
p = cl->list[l].readID;
// pa = ik->a + (ab->mz.a[p].x>>32);
pi = (ab->mz.a[p].x>>32);
pn = ((uint32_t)(ab->mz.a[p].x));
assert(pn > 0);
fprintf(stderr, "[M::%s::] qpos::%u, tpos::%u, cnt::%u, pn::%u\n", __func__, cl->list[l].self_offset, cl->list[l].offset, cl->list[l].cnt>>8, pn);
for (z = 0; z < pn; z++) {
c = ik->a[pi + z];
// if(k == 128 && c == 129) fprintf(stderr, "+0+c::%lu\n", c);
if(c == k) continue;
// if(k == 128 && c == 129) fprintf(stderr, "+1+c::%lu\n", c);
if(ol->list[c].x_id != ((uint32_t)-1)) continue;
// if(k == 128 && c == 129) fprintf(stderr, "+2+c::%lu\n", c);
if(ol->list[c].strong) continue;
// if(k == 128 && c == 129) fprintf(stderr, "+3+c::%lu\n", c);
ol->list[c].strong = 1;
kv_push(uint32_t, *ik, c);
if(!cmp_chain_aln(k, &(ol->list[k]), l, c, &(ol->list[c]), cl->list)) continue;
// if(k == 128 && c == 129) fprintf(stderr, "+4+c::%lu\n", c);
ol->list[c].x_id = k;
zn++;
}
}
if(zn) ol->list[k].x_id = k;
for (l = ikn0; l < ik->n; l++) {
ol->list[ik->a[l]].strong = 0;
}
ik->n = ikn0;
**/
for (l = zk = ol->list[k].non_homopolymer_errors, zn = ((uint32_t)-1); l < ol->list[k].overlapLen; l++) {
p = cl->list[l].readID;
pn = ((uint32_t)(ab->mz.a[p].x));
assert(pn > 0);
if(pn < zn) {
zk = l; zn = pn;
}
// fprintf(stderr, "[M::%s::] qpos::%u, tpos::%u, cnt::%u, pn::%u\n", __func__, cl->list[l].self_offset, cl->list[l].offset, cl->list[l].cnt>>8, pn);
}
l = zk; p = cl->list[l].readID;
pi = (ab->mz.a[p].x>>32); pn = ((uint32_t)(ab->mz.a[p].x));
assert(pn > 0);
kv_push(uint32_t, *ik, k);
for (z = 0; z < pn; z++) {
c = ik->a[pi + z];
if(c <= k) continue;
if(ol->list[c].x_id != ((uint32_t)-1)) continue;
if(!cmp_chain_aln(&(ol->list[k]), &(ol->list[c]), cl->list)) continue;
ol->list[c].x_id = k;
zn++;
kv_push(uint32_t, *ik, c);
}
// if(zn) ol->list[k].x_id = k;
ol->list[k].x_id = k;
// fprintf(stderr, "[M::%s::] zn::%lu\n", __func__, zn);
}
/**
fprintf(stderr, "-1-[M::%s::] ik->n::%lu, ol->length::%lu\n", __func__, (uint64_t)ik->n, ol->length);
for (k = 0; k < ol->length; k++) {
if((ol->list[k].x_id != ((uint32_t)-1)) && (ol->list[k].x_id != k)) continue;
if(k == ol->list[k].x_id) {
fprintf(stderr, "[M::%s::] cs::%lu->", __func__, k);
for (l = zn = 0; l < ol->length; l++) {
if(ol->list[k].x_id == ol->list[l].x_id) {
fprintf(stderr, "%lu,", l);
zn++;
}
}
fprintf(stderr, "(znn::%lu)\n", zn);
} else {
fprintf(stderr, "[M::%s::] cs::%lu->(znn::1)\n", __func__, k);
}
for (l = ol->list[k].non_homopolymer_errors, zn = 0; l < ol->list[k].overlapLen; l++) {
fprintf(stderr, "[M::%s::] qpos::%u, tpos::%u, cnt::%u\n", __func__, cl->list[l].self_offset, cl->list[l].offset, cl->list[l].cnt>>8);
}
}
debug_chain_aln_de(ol, cl);
// for (k = ik->n - ol->length; k < ik->n; k++) {
// ik->a[k]
// }
**/
}
void gen_chain_clus(ha_abuf_t *ab, overlap_region_alloc *ol, Candidates_list *cl, asg32_v *ik)
{
if(ol->length <= 0) return;
ks_introsort_or_ss(ol->length, ol->list);
uint64_t k, l, c, p_b, p_r, cln = cl->length; uint32_t *pa = NULL, pn, xid0 = ol->list[0].x_id;
for (k = 1, l = 0; k < ol->length; k++) {///sort for merging
if ((k == ol->length) || (ol->list[l].shared_seed != ol->list[k].shared_seed)) {
if (k - l > 1) {
ks_introsort_or_xs(k - l, ol->list + l);
}
l = k;
}
}
for (k = 0; k < ab->mz.n; k++) ab->mz.a[k].x = 0;
for (k = 0; k < ol->length; k++) {
l = ol->list[k].non_homopolymer_errors;
p_r = cl->list[l].readID;
for (; (l < cln) && (cl->list[l].readID == p_r); l++) {;}
ol->list[k].overlapLen = l;
}
for (k = ik->n = 0, p_b = ab->mz.n; k < ol->length; k++) {
for (l = ol->list[k].non_homopolymer_errors; l < ol->list[k].overlapLen; l++) {
p_b = mz_pos_bsearch(ab->mz.a, p_b + 1, ab->mz.n, cl->list[l].self_offset);
assert(p_b != ((uint64_t)-1));
// idx->a[p]++;
ab->mz.a[p_b].x++; ik->n++;
cl->list[l].readID = p_b;///minimizer id
}
// fprintf(stderr, "[M_beg::%s::]\tk::%lu\ty_id::%u\tc_n::%u\tc_beg::%u\n", __func__, k, ol->list[k].y_id, ol->list[k].overlapLen - ol->list[k].non_homopolymer_errors, ol->list[k].non_homopolymer_errors);
}
/**
for (k = ik->n = 0, p_b = ab->mz.n; k < ol->length; k++) {
l = ol->list[k].non_homopolymer_errors;
p_r = cl->list[l].readID;
for (; (l < cln) && (cl->list[l].readID == p_r); l++) {
p_b = mz_pos_bsearch(ab->mz.a, p_b + 1, ab->mz.n, cl->list[l].self_offset);
assert(p_b != ((uint64_t)-1));
// idx->a[p]++;
ab->mz.a[p_b].x++; ik->n++;
cl->list[l].readID = p_b;///minimizer id
}
ol->list[k].overlapLen = l;
fprintf(stderr, "[M_beg::%s::]\tk::%lu\ty_id::%u\tc_n::%u\tc_beg::%u\n", __func__, k, ol->list[k].y_id, ol->list[k].overlapLen - ol->list[k].non_homopolymer_errors, ol->list[k].non_homopolymer_errors);
}
**/
kv_resize(uint32_t, *ik, ik->n);
memset(ik->a, -1, sizeof((*(ik->a)))*ik->n);
for (k = l = 0; k < ab->mz.n; k++) {
ab->mz.a[k].x |= (l<<32);
l += (uint32_t)(ab->mz.a[k].x);
if((uint32_t)(ab->mz.a[k].x)) {
ik->a[(ab->mz.a[k].x>>32) + ((uint32_t)(ab->mz.a[k].x)) - 1] = 0;
}
}
assert(l == ik->n);
for (k = 0; k < ol->length; k++) {
for (l = ol->list[k].non_homopolymer_errors; l < ol->list[k].overlapLen; l++) {
p_b = cl->list[l].readID;
pa = ik->a + (ab->mz.a[p_b].x>>32);
pn = ((uint32_t)(ab->mz.a[p_b].x));
assert(pn > 0);
c = pa[pn - 1];
assert(c < pn);
pa[c] = k; ///pa[c] = l;
if(c + 1 < pn) {pa[pn - 1]++;}
// cl->list[l].readID = k;
}
// ol->list[k].overlapLen = 0;
ol->list[k].x_id = ((uint32_t)-1);///mark for clustering
}
chain_aln_de(ab, ol, cl, ik);
for (k = ik->n - ol->length, l = 0; k < ik->n; k++) {
ik->a[l++] = ik->a[k];
}
ik->n = ol->length;
ik->n = ol->length<<1; kv_resize(uint32_t, *ik, ik->n);
memset(ik->a + ol->length, -1, (sizeof((*(ik->a)))*ol->length));
// ik->n = ol->length;
for (k = 1, l = 0; k <= ol->length; k++) {
if((k == ol->length) || (ol->list[ik->a[l]].x_id != ol->list[ik->a[k]].x_id)) {
for (c = l; c < k; c++) {
ik->a[ik->a[c]+ol->length] = l;
}
l = k;
}
}
// for (k = 0, ik->n = ol->length; k < ol->length; k++) {
// ik->a[ik->n++] = ((ol->list[k].x_id == ((uint32_t)-1))?k:ol->list[k].x_id);
// }
///reset
for (k = 0; k < ol->length; k++) {
// fprintf(stderr, "[M_end::%s::]\tk::%lu\ty_id::%u\tc_n::%u\tc_beg::%u\n", __func__, k, ol->list[k].y_id, ol->list[k].overlapLen - ol->list[k].non_homopolymer_errors, ol->list[k].non_homopolymer_errors);
for (l = ol->list[k].non_homopolymer_errors; l < ol->list[k].overlapLen; l++) {
cl->list[l].readID = k;
}
ol->list[k].overlapLen = 0;
ol->list[k].x_id = xid0;
}
}
void lchain_qgen_mcopy_fast(ha_abuf_t *ab, Candidates_list* cl, overlap_region_alloc* ol, uint32_t rid, uint64_t rl, All_reads* rdb,
uint32_t apend_be, uint64_t max_n_chain, int64_t max_skip, int64_t max_iter, uint32_t apend_be, uint64_t max_n_chain, 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 quick_check, int64_t max_dis, double chn_pen_gap, double chn_pen_skip, double bw_rate_h, uint64_t cl_hn, double bw_rate_l, uint64_t cl_ln, int64_t quick_check,
uint32_t gen_off, int64_t mcopy_num, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut, st_mt_t *sp) uint32_t gen_off, int64_t mcopy_num, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut, st_mt_t *sp, uint64_t ocv_w, uint8_t is_raw_chain)
{ {
// fprintf(stderr, "+[M::%s] chain_cutoff::%u\n", __func__, chain_cutoff); // fprintf(stderr, "+[M::%s] chain_cutoff::%u\n", __func__, chain_cutoff);
uint64_t i, k, l, m, cn = cl->length, yid, ol0, lch; overlap_region *r, t; ///srt = 0 uint64_t i, k, l, m, cn = cl->length, yid, ol0, lch, *cc = NULL, cwn = 0, cws, cwe, os, oe, rs, re, cw0, cw1/**, dbgn = 0**/; overlap_region *r, t; ///srt = 0
clear_overlap_region_alloc(ol); clear_overlap_region_alloc(ol);
// for (l = 0, k = 1, m = 0, lch = 0; k <= cn; k++) {
// if((k == cn) || (cl->list[k].readID != cl->list[l].readID)) {
// if(cl->list[l].readID != rid) {
// yid = cl->list[l].readID; ol0 = ol->length;
// m += lchain_qdp_mcopy_fast(cl, l, k-l, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate,
// rid, rl, Get_READ_LENGTH((*rdb), yid), quick_check, apend_be, gen_off, mcopy_num, mcopy_rate, mcopy_khit_cut, 1);
// if((chain_cutoff >= 2) && (!lch)) {
// for (i = ol0; (i<ol->length) && (!lch); i++) {
// if(ol->list[i].align_length < chain_cutoff) lch = 1;
// }
// }
// }
// l = k;
// }
// }
// cl->length = m;
///cl->list[0, cl_hn) & cl->list[cl_hn, cl_hn + cl_ln)
cn = cl_hn;
for (l = 0, k = 1, m = 0, lch = 0; k <= cn; k++) { for (l = 0, k = 1, m = 0, lch = 0; k <= cn; k++) {
if((k == cn) || (cl->list[k].readID != cl->list[l].readID)) { if((k == cn) || (cl->list[k].readID != cl->list[l].readID)) {
if(cl->list[l].readID != rid) { if(cl->list[l].readID != rid) {
yid = cl->list[l].readID; ol0 = ol->length; yid = cl->list[l].readID; ol0 = ol->length;
m += lchain_qdp_mcopy_fast(cl, l, k-l, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate, m += lchain_qdp_mcopy_fast(cl, l, k-l, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate_h,
rid, rl, Get_READ_LENGTH((*rdb), yid), quick_check, apend_be, gen_off, mcopy_num, mcopy_rate, mcopy_khit_cut, 1); rid, rl, Get_READ_LENGTH((*rdb), yid), quick_check, apend_be, gen_off, mcopy_num, mcopy_rate, mcopy_khit_cut, 1);
if((chain_cutoff >= 2) && (!lch)) { if((chain_cutoff >= 2) && (!lch)) {
for (i = ol0; (i<ol->length) && (!lch); i++) { for (i = ol0; (i<ol->length) && (!lch); i++) {
@@ -1941,13 +2278,47 @@ void lchain_qgen_mcopy_fast(Candidates_list* cl, overlap_region_alloc* ol, uint3
l = k; l = k;
} }
} }
cn = cl_hn + cl_ln;
for (; k <= cn; k++) {
if((k == cn) || (cl->list[k].readID != cl->list[l].readID)) {
if(cl->list[l].readID != rid) {
yid = cl->list[l].readID; ol0 = ol->length;
m += lchain_qdp_mcopy_fast(cl, l, k-l, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_rate_l,
rid, rl, Get_READ_LENGTH((*rdb), yid), quick_check, apend_be, gen_off, mcopy_num, mcopy_rate, mcopy_khit_cut, 1);
if((chain_cutoff >= 2) && (!lch)) {
for (i = ol0; (i<ol->length) && (!lch); i++) {
if(ol->list[i].align_length < chain_cutoff) lch = 1;
}
}
}
l = k;
}
}
cl->length = m; cl->length = m;
// for (k = 0; k < ol->length; k++) { // fprintf(stderr, "\n[M::%s::] rn::%lu\tmax_n_chain::%lu\n", __func__, ol->length, max_n_chain);
// fprintf(stderr, "---[M::%s::utg%.6dl] q[%d, %d), t[%d, %d), khit_off::%u\n", __func__,
// (int32_t)ol->list[k].y_id+1, ol->list[k].x_pos_s, ol->list[k].x_pos_e+1, /**
// ol->list[k].y_pos_s, ol->list[k].y_pos_e+1, ol->list[k].non_homopolymer_errors); for (k = 0; k < ol->length; k++) {
// } if(ha_ov_type(&(ol->list[k]), rl) == 1) {
fprintf(stderr, "---[M::%s::%.*s(qid::%u)] q[%d, %d), t[%d, %d), sc::%d, occ::%u, type::%d\n", __func__,
(int32_t)Get_NAME_LENGTH(R_INF, ol->list[k].y_id), Get_NAME(R_INF, ol->list[k].y_id), ol->list[k].y_id,
ol->list[k].x_pos_s, ol->list[k].x_pos_e+1, ol->list[k].y_pos_s, ol->list[k].y_pos_e+1, ol->list[k].shared_seed, ol->list[k].align_length, ha_ov_type(&(ol->list[k]), rl));
int64_t km;
for (km = ol->list[k].non_homopolymer_errors; (km < cl->length) && (cl->list[km].readID == cl->list[ol->list[k].non_homopolymer_errors].readID); km++) {
fprintf(stderr, "[M::%s::] qpos::%u, tpos::%u, cnt::%u\n", __func__, cl->list[km].self_offset, cl->list[km].offset, cl->list[km].cnt>>8);
}
fprintf(stderr, "[M::%s::]\tk::%lu\tsi::%u\tei::%ld\n", __func__, k, ol->list[k].non_homopolymer_errors, km);
}
}
**/
// gen_chain_clus(ab, ol, cl, v32);
if(is_raw_chain) return;
k = ol->length; k = ol->length;
if (ol->length > max_n_chain) { if (ol->length > max_n_chain) {
@@ -1960,14 +2331,43 @@ void lchain_qgen_mcopy_fast(Candidates_list* cl, overlap_region_alloc* ol, uint3
++n[w]; ++n[w];
if (((uint64_t)n[w]) == max_n_chain) s[w] = r->shared_seed; if (((uint64_t)n[w]) == max_n_chain) s[w] = r->shared_seed;
} }
/**fprintf(stderr, "top[M::%s::] s[0]::%d, s[1]::%d, s[2]::%d, s[3]::%d\n", __func__, s[0], s[1], s[2], s[3]);**/
if (s[0] > 0 || s[1] > 0 || s[2] > 0 || s[3] > 0) { if (s[0] > 0 || s[1] > 0 || s[2] > 0 || s[3] > 0) {
// n[0] = n[1] = n[2] = n[3] = 0; if((((uint64_t)n[3]) >= max_n_chain) && (rl >= ocv_w)) {
cwn = (rl/ocv_w) + ((rl % ocv_w)?(1):(0));
kv_resize(uint64_t, (*sp), (cwn));
cc = sp->a;
for (i = cws = cwe = 0; i < cwn; i++) {
cwe = cws + ocv_w; if(cwe > rl) cwe = rl;
assert(cwe > cws);
cc[i] = (cwe - cws)*(max_n_chain>>1);
// fprintf(stderr, "[M::%s::] cw::[%lu, %lu), cc::%lu\n", __func__, cws, cwe, cc[i]);
if(cc[i] > UINT32_MAX) {cc[i] = UINT32_MAX;} cc[i] <<= 32;
cws += ocv_w;
}
}
for (i = 0, k = 0, lch = 0; i < ol->length; ++i) { for (i = 0, k = 0, lch = 0; i < ol->length; ++i) {
r = &(ol->list[i]); r = &(ol->list[i]);
w = ha_ov_type(r, rl); w = ha_ov_type(r, rl);
// ++n[w]; // ++n[w];
// if (((int)n[w] <= max_n_chain) || (r->shared_seed >= s[w] && s[w] >= (asm_opt.k_mer_length<<1))) { // if (((int)n[w] <= max_n_chain) || (r->shared_seed >= s[w] && s[w] >= (asm_opt.k_mer_length<<1))) {
if (r->shared_seed >= s[w]) { if (r->shared_seed >= s[w]) {
if(cwn) {
m = (ol->list[i].x_pos_s/ocv_w);
rs = ol->list[i].x_pos_s; re = ol->list[i].x_pos_e + 1;
for (cws = m*ocv_w; m < cwn; m++) {
cwe = cws + ocv_w; if(cwe > rl) cwe = rl;
os = ((rs >= cws)? rs : cws);
oe = ((re <= cwe)? re : cwe);
if(oe <= os) break;
if(((uint32_t)cc[m]) + (oe - os) < UINT32_MAX) {
cc[m] += (oe - os);
} else {
cc[m] >>= 32; cc[m] <<= 32; cc[m] |= UINT32_MAX;
}
cws += ocv_w;
}
}
if (k != i) { if (k != i) {
t = ol->list[k]; t = ol->list[k];
ol->list[k] = ol->list[i]; ol->list[k] = ol->list[i];
@@ -1975,6 +2375,52 @@ void lchain_qgen_mcopy_fast(Candidates_list* cl, overlap_region_alloc* ol, uint3
} }
if(ol->list[k].align_length < chain_cutoff) lch = 1; if(ol->list[k].align_length < chain_cutoff) lch = 1;
++k; ++k;
} else if(w == 3 && cwn > 0) {
m = (ol->list[i].x_pos_s/ocv_w); cw0 = cw1 = 0;
rs = ol->list[i].x_pos_s; re = ol->list[i].x_pos_e + 1;
for (cws = m*ocv_w; m < cwn; m++) {
cwe = cws + ocv_w; if(cwe > rl) cwe = rl;
os = ((rs >= cws)? rs : cws);
oe = ((re <= cwe)? re : cwe);
if(oe <= os) break;
// fprintf(stderr, "+++[M::%s::%.*s(qid::%u)] o[%lu, %lu), cur::%lu, max::%lu\n", __func__,
// (int32_t)Get_NAME_LENGTH(R_INF, ol->list[i].y_id), Get_NAME(R_INF, ol->list[i].y_id), ol->list[i].y_id,
// os, oe, ((uint64_t)((uint32_t)cc[m])), (cc[m]>>32));
if((oe - os) + ((uint64_t)((uint32_t)cc[m])) >= (cc[m]>>32)) {
cw1 += (oe - os);
} else {
cw0 += (oe - os);
}
cws += ocv_w;
}
if(cw0 >= ((cw0 + cw1)*0.7)) {
m = (ol->list[i].x_pos_s/ocv_w);
rs = ol->list[i].x_pos_s; re = ol->list[i].x_pos_e + 1;
for (cws = m*ocv_w; m < cwn; m++) {
cwe = cws + ocv_w; if(cwe > rl) cwe = rl;
os = ((rs >= cws)? rs : cws);
oe = ((re <= cwe)? re : cwe);
if(oe <= os) break;
if(((uint32_t)cc[m]) + (oe - os) < UINT32_MAX) {
cc[m] += (oe - os);
} else {
cc[m] >>= 32; cc[m] <<= 32; cc[m] |= UINT32_MAX;
}
cws += ocv_w;
}
if (k != i) {
t = ol->list[k];
ol->list[k] = ol->list[i];
ol->list[i] = t;
}
if(ol->list[k].align_length < chain_cutoff) lch = 1;
++k;
// dbgn++;
// fprintf(stderr, "+++[M::%s::%.*s(qid::%u)] q[%d, %d), t[%d, %d), sc::%d, type::%d, cw0::%lu, cw1::%lu\n", __func__,
// (int32_t)Get_NAME_LENGTH(R_INF, ol->list[k].y_id), Get_NAME(R_INF, ol->list[k].y_id), ol->list[k].y_id,
// ol->list[k].x_pos_s, ol->list[k].x_pos_e+1, ol->list[k].y_pos_s, ol->list[k].y_pos_e+1, ol->list[k].shared_seed, ha_ov_type(&(ol->list[k]), rl), cw0, cw1);
}
} }
} }
ol->length = k; ol->length = k;
@@ -2016,11 +2462,16 @@ void lchain_qgen_mcopy_fast(Candidates_list* cl, overlap_region_alloc* ol, uint3
} }
l++; l++;
} }
// fprintf(stderr, "+[M::%s] rid::%u, ol->length0::%lu, ol->length1::%lu\n", __func__, rid, ol->length, l);
ol->length = l; ol->length = l;
} }
for (i = 0; i < ol->length; ++i) ol->list[i].align_length = 0; for (i = 0; i < ol->length; ++i) ol->list[i].align_length = 0;
// fprintf(stderr, "+[M::%s] rid::%u, ol->length0::%lu, dbgn::%lu\n", __func__, rid, ol->length, dbgn);
}
void srt_olst(overlap_region_alloc* ol)
{
ks_introsort_or_xs(ol->length, ol->list);
} }
void lchain_qgen_mcopy_fast_re1(Candidates_list* cl, uint32_t cl_beg, overlap_region_alloc* ol, uint32_t rid, uint64_t rl, uint64_t tl, void lchain_qgen_mcopy_fast_re1(Candidates_list* cl, uint32_t cl_beg, overlap_region_alloc* ol, uint32_t rid, uint64_t rl, uint64_t tl,
@@ -2223,23 +2674,63 @@ void ul_map_lchain(ha_abufl_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t
lchain_qgen_mcopy(cl, overlap_list, rid, rl, NULL, uref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp); lchain_qgen_mcopy(cl, overlap_list, rid, rl, NULL, uref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp);
} }
void p_ec_lchain(ha_abufl_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, ul_idx_t *uref, overlap_region_alloc *ol, Candidates_list *cl, double bw_thres,
int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t mcopy_num, double mcopy_rate, uint32_t mcopy_khit_cut)
{
extern void *ha_flt_tab;
extern ha_pt_t *ha_idx;
int64_t max_skip, max_iter, max_dis, quick_check; double chn_pen_gap, chn_pen_skip;
set_lchain_dp_op(is_accurate, mz_k, &max_skip, &max_iter, &max_dis, &chn_pen_gap, &chn_pen_skip, &quick_check);
minimizers_qgen(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, NULL, uref, dbg_ct, sp, high_occ, low_occ);
uint64_t k, l, m, cn = cl->length, yid;
clear_overlap_region_alloc(ol);
for (l = 0, k = 1, m = 0; k <= cn; k++) {
if((k == cn) || (cl->list[k].readID != cl->list[l].readID)) {
if(cl->list[l].readID != rid) {
yid = cl->list[l].readID;
m += lchain_qdp_mcopy_fast(cl, l, k-l, m, &(cl->chainDP), ol, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres,
rid, rl, uref->ug->u.a[yid].len, quick_check, apend_be, gen_off, mcopy_num, mcopy_rate, mcopy_khit_cut, 1);
}
l = k;
}
}
cl->length = m;
}
void h_ec_lchain(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, All_reads *rref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres, void h_ec_lchain(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, All_reads *rref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres,
int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t mcopy_num, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut) int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t mcopy_num, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut, uint64_t ocv_w, uint8_t is_raw_chain)
{ {
extern void *ha_flt_tab; extern void *ha_flt_tab;
extern ha_pt_t *ha_idx; extern ha_pt_t *ha_idx;
int64_t max_skip, max_iter, max_dis, quick_check; double chn_pen_gap, chn_pen_skip; int64_t max_skip, max_iter, max_dis, quick_check; double chn_pen_gap, chn_pen_skip;
set_lchain_dp_op(is_accurate, mz_k, &max_skip, &max_iter, &max_dis, &chn_pen_gap, &chn_pen_skip, &quick_check); set_lchain_dp_op(is_accurate, mz_k, &max_skip, &max_iter, &max_dis, &chn_pen_gap, &chn_pen_skip, &quick_check);
// minimizers_gen(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, dbg_ct, sp, high_occ, low_occ); // minimizers_gen(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, dbg_ct, sp, high_occ, low_occ);
minimizers_qgen0(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, rref, dbg_ct, sp, high_occ, low_occ); minimizers_qgen0(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, rref, dbg_ct, sp, high_occ, low_occ, ((uint64_t)-1), 0);
// lchain_gen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off); // lchain_gen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
// lchain_qgen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off); // lchain_qgen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
///no need to sort here, overlap_list has been sorted at lchain_gen ///no need to sort here, overlap_list has been sorted at lchain_gen
lchain_qgen_mcopy_fast(cl, overlap_list, rid, rl, rref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off, mcopy_num, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp); lchain_qgen_mcopy_fast(ab, cl, overlap_list, rid, rl, rref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, cl->length, bw_thres, 0, quick_check, gen_off, mcopy_num, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp, ocv_w, is_raw_chain);
}
void h_ec_lchain_hybrid(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, All_reads *rref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres_h, double bw_thres_l,
int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t mcopy_num, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut, uint64_t ocv_w, uint64_t ti_cut, uint8_t flt_chh, uint8_t is_raw_chain)
{
extern void *ha_flt_tab;
extern ha_pt_t *ha_idx;
int64_t max_skip, max_iter, max_dis, quick_check; double chn_pen_gap, chn_pen_skip; uint64_t tcut_n = 0;
set_lchain_dp_op(is_accurate, mz_k, &max_skip, &max_iter, &max_dis, &chn_pen_gap, &chn_pen_skip, &quick_check);
// minimizers_gen(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, dbg_ct, sp, high_occ, low_occ);
tcut_n = minimizers_qgen0(ab, rs, rl, mz_w, mz_k, cl, k_flag, ha_flt_tab, ha_idx, rref, dbg_ct, sp, high_occ, low_occ, ti_cut, flt_chh);
// lchain_gen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
// lchain_qgen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
///no need to sort here, overlap_list has been sorted at lchain_gen
lchain_qgen_mcopy_fast(ab, cl, overlap_list, rid, rl, rref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres_h, tcut_n, bw_thres_l, cl->length - tcut_n, quick_check, gen_off, mcopy_num, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp, ocv_w, is_raw_chain);
} }
void h_ec_lchain_amz(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, All_reads *rref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres, void h_ec_lchain_amz(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_t mz_w, uint64_t mz_k, All_reads *rref, overlap_region_alloc *overlap_list, Candidates_list *cl, double bw_thres,
int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t enable_mcopy, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut) int max_n_chain, int apend_be, kvec_t_u8_warp* k_flag, 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, int64_t enable_mcopy, double mcopy_rate, uint32_t chain_cutoff, uint32_t mcopy_khit_cut, uint64_t ocv_w)
{ {
extern void *ha_flt_tab; extern void *ha_flt_tab;
extern ha_pt_t *ha_idx; extern ha_pt_t *ha_idx;
@@ -2250,7 +2741,7 @@ void h_ec_lchain_amz(ha_abuf_t *ab, uint32_t rid, char* rs, uint64_t rl, uint64_
// lchain_gen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off); // lchain_gen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
// lchain_qgen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off); // lchain_qgen(cl, overlap_list, rid, rl, NULL, uref, apend_be, f_cigar, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off);
///no need to sort here, overlap_list has been sorted at lchain_gen ///no need to sort here, overlap_list has been sorted at lchain_gen
lchain_qgen_mcopy_fast(cl, overlap_list, rid, rl, rref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, quick_check, gen_off, enable_mcopy, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp); lchain_qgen_mcopy_fast(ab, cl, overlap_list, rid, rl, rref, apend_be, max_n_chain, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres, cl->length, bw_thres, 0, quick_check, gen_off, enable_mcopy, mcopy_rate, chain_cutoff, mcopy_khit_cut, sp, ocv_w, 0);
} }
uint64_t recalu_minimizer0(char *s, uint64_t len, uint64_t is_hpc, int64_t mz_k, uint64_t mz_h, tiny_queue_t *tq, uint64_t *rpos, uint64_t *rspan) uint64_t recalu_minimizer0(char *s, uint64_t len, uint64_t is_hpc, int64_t mz_k, uint64_t mz_h, tiny_queue_t *tq, uint64_t *rpos, uint64_t *rspan)
@@ -2974,10 +3465,10 @@ uint64_t recalu_minimizer_non_retrieve(uint64_t rid, anchor1_t *z, asg16_v *sc,
} }
c = tstr[s1]; c = tstr[s1];
for (k = s1 - 1; k >= 0 && tstr[k] == c; k--); s1 = k + 1; for (k = s1 - 1; k >= 0 && tstr[k] == c; k--){;} s1 = k + 1;
c = tstr[e1-1]; c = tstr[e1-1];
for (k = e1; k < tl && tstr[k] == c; k++); e1 = k; for (k = e1; k < tl && tstr[k] == c; k++){;} e1 = k;
if(!trev) { if(!trev) {
s0 = s1; e0 = e1; s0 = s1; e0 = e1;
@@ -2999,15 +3490,15 @@ uint64_t recalu_minimizer_non_retrieve(uint64_t rid, anchor1_t *z, asg16_v *sc,
void hpc_ext_check(All_reads *rref, uint32_t id, int64_t s0, int64_t e0, int64_t l, uint64_t rev, char *buf) void hpc_ext_check(All_reads *rref, uint32_t id, int64_t s0, int64_t e0, int64_t l, uint64_t rev, char *buf)
{ {
if(s0 < 0) s0 = 0; if(e0 > l) e0 = l; if(s0 < 0) {s0 = 0;} if(e0 > l) {e0 = l;}
int64_t s = s0 - 256, e = e0 + 256, n, k, os0, oe0, os1, oe1; char c; if(s < 0) s = 0; if(e > l) e = l; int64_t s = s0 - 256, e = e0 + 256, n, k, os0, oe0, os1, oe1; char c; if(s < 0) s = 0; if(e > l) e = l;
recover_UC_Read_sub_region(buf, s, e - s, rev, rref, id); recover_UC_Read_sub_region(buf, s, e - s, rev, rref, id);
os0 = s0 - s; oe0 = e0 - s; n = e - s; os1 = os0; oe1 = oe0; os0 = s0 - s; oe0 = e0 - s; n = e - s; os1 = os0; oe1 = oe0;
c = buf[os0]; c = buf[os0];
for (k = os0 - 1; k >= 0 && buf[k] == c; k--); os1 = k + 1; for (k = os0 - 1; k >= 0 && buf[k] == c; k--){;} os1 = k + 1;
c = buf[oe0-1]; c = buf[oe0-1];
for (k = oe0; k < n && buf[k] == c; k++); oe1 = k; for (k = oe0; k < n && buf[k] == c; k++){;} oe1 = k;
if(os1 != os0 || oe1 != oe0) { if(os1 != os0 || oe1 != oe0) {
fprintf(stderr, "[M::%s]\to0::[%ld,%ld)\to1::[%ld,%ld)\n", __func__, os0 + s0, oe0 + s0, os1 + s0, oe1 + s0); fprintf(stderr, "[M::%s]\to0::[%ld,%ld)\to1::[%ld,%ld)\n", __func__, os0 + s0, oe0 + s0, os1 + s0, oe1 + s0);
@@ -3523,6 +4014,156 @@ void get_pi_ec_chain(ha_abuf_t *ab, uint64_t rid, uint64_t rl, uint32_t tid, cha
} }
uint64_t gen_srt_chain(ha_abuf_t *ab, ha_mz1_t *rfa, uint64_t *rfi, uint64_t rfn, ha_mz1_t *qra, uint64_t *qri, uint64_t qrn, uint32_t *high_occ, uint32_t *low_occ, Candidates_list *cl, uint32_t qrid)
{
uint64_t i, k, l, max_cnt = UINT32_MAX, min_cnt = 0, ri, qi, sn, x, rz, qz, n_a0, l0, k0, i0; anchor1_t *an; k_mer_hit *p;
if(high_occ) {
max_cnt = (*high_occ);
if(max_cnt < 2) max_cnt = 2;
}
if(low_occ) {
min_cnt = (*low_occ);
if(min_cnt < 2) min_cnt = 2;
}
radix_sort_anc64(rfi, rfi + rfn);
radix_sort_anc64(qri, qri + qrn);
i = ab->n_a = 0; n_a0 = l0 = i0 = 0; k0 = 1;
for (k = 1, l = 0; k <= rfn; ++k) {
if (k == rfn || (rfi[k]>>32) != (rfi[l]>>32)) {
x = rfi[l]>>32;
for (; i < qrn && (qri[i]>>32) < x; i++);
if(ab->n_a < ab->m_a) {
n_a0 = ab->n_a; l0 = l; i0 = i; k0 = k;
}
if(i < qrn && (qri[i]>>32) == x) {
// sn = 0;
// if(ab->n_a < ab->m_a) sn = ab->seed[l].n;///ha_pt_cnt(ha_idx, ra[l].x);
for (qi = i; qi < qrn && (qri[qi]>>32) == x; qi++) {
qz = (uint32_t)qri[qi];
for (ri = l; ri < k; ri++) {
rz = (uint32_t)rfi[ri];
if(qra[qz].rev != rfa[rz].rev) continue;
if(ab->n_a < ab->m_a) {
an = &(ab->a[ab->n_a++]);
an->other_off = qra[qz].pos;
an->self_off = rfa[rz].pos;
///an->cnt: cnt<<8|span
an->cnt = ab->seed[rz].n; if(an->cnt > ((uint32_t)(0xffffffu))) an->cnt = 0xffffffu;
an->cnt <<= 8; an->cnt |= ((rfa[rz].span <= ((uint32_t)(0xffu)))?rfa[rz].span:((uint32_t)(0xffu)));
an->srt = (((uint64_t)(an->self_off))<<32)|((uint64_t)(an->other_off));
} else {
ab->n_a++;
}
}
}
i = qi;
}
l = k;
}
}
if (ab->n_a > ab->m_a) {
ab->m_a = ab->n_a; REALLOC(ab->a, ab->m_a);
k = k0; i = i0; l = l0; ab->n_a = n_a0;
for (; k <= rfn; ++k) {
if (k == rfn || (rfi[k]>>32) != (rfi[l]>>32)) {
x = rfi[l]>>32;
for (; i < qrn && (qri[i]>>32) < x; i++);
if(ab->n_a < ab->m_a) {
n_a0 = ab->n_a; l0 = l; i0 = i; k0 = k;
}
if(i < qrn && (qri[i]>>32) == x) {
// sn = 0;
// if(ab->n_a < ab->m_a) sn = ab->seed[l].n;///ha_pt_cnt(ha_idx, ra[l].x);
for (qi = i; qi < qrn && (qri[qi]>>32) == x; qi++) {
qz = (uint32_t)qri[qi];
for (ri = l; ri < k; ri++) {
rz = (uint32_t)rfi[ri];
if(qra[qz].rev != rfa[rz].rev) continue;
if(ab->n_a < ab->m_a) {
an = &(ab->a[ab->n_a++]);
an->other_off = qra[qz].pos;
an->self_off = rfa[rz].pos;
///an->cnt: cnt<<8|span
an->cnt = ab->seed[rz].n; if(an->cnt > ((uint32_t)(0xffffffu))) an->cnt = 0xffffffu;
an->cnt <<= 8; an->cnt |= ((rfa[rz].span <= ((uint32_t)(0xffu)))?rfa[rz].span:((uint32_t)(0xffu)));
an->srt = (((uint64_t)(an->self_off))<<32)|((uint64_t)(an->other_off));
} else {
ab->n_a++;
}
}
}
i = qi;
}
l = k;
}
}
}
// copy over to _cl_
sn = ab->n_a + cl->length;
if (sn > (uint64_t)cl->size) {
cl->size = sn;
REALLOC(cl->list, cl->size);
}
radix_sort_ha_an1(ab->a, ab->a + ab->n_a);
for (i = 0; i < ab->n_a; i++) {
p = &cl->list[cl->length++];
p->readID = qrid;
p->strand = 0;
p->offset = ab->a[i].other_off;
p->self_offset = ab->a[i].self_off;
if(((ab->a[i].cnt>>8) < max_cnt) && ((ab->a[i].cnt>>8) > min_cnt)){
p->cnt = 1;
} else if((ab->a[i].cnt>>8) <= min_cnt) {
p->cnt = 2;
} else{
p->cnt = 1 + (((ab->a[i].cnt>>8) + (max_cnt<<1) - 1)/(max_cnt<<1));
p->cnt = pow(p->cnt, 1.1);
}
if(p->cnt > ((uint32_t)(0xffffffu))) p->cnt = 0xffffffu;
p->cnt <<= 8; p->cnt |= (((uint32_t)(0xffu))&(ab->a[i].cnt));
}
// cl->length = ab->n_a;
return ab->n_a;
}
void gen_self_global_chain(ha_abuf_t *ab, Candidates_list *cl, uint32_t rid, uint64_t rl, uint32_t tid, char *ts, uint64_t tl, uint64_t mz_w, uint64_t mz_k, kvec_t_u8_warp* k_flag, kvec_t_u64_warp* dbg_ct, st_mt_t *sp, uint32_t *high_occ, uint32_t *low_occ, asg64_v *ix,
uint8_t is_accurate, double bw_thres, int apend_be, uint32_t gen_off, int64_t enable_mcopy, double mcopy_rate, uint32_t mcopy_khit_cut, overlap_region_alloc *ores)
{
extern void *ha_flt_tab;
uint64_t k, rn = ab->mz.n, m = cl->length;
mz1_ha_sketch(ts, tl, mz_w, mz_k, 0, !(asm_opt.flag & HA_F_NO_HPC), &ab->mz, ha_flt_tab, asm_opt.mz_sample_dist, k_flag, dbg_ct, NULL, -1, asm_opt.dp_min_len, -1, sp, asm_opt.mz_rewin, 0, NULL);
kv_resize(uint64_t, *ix, ab->mz.n);
for (k = 0; k < rn; k++) {
ix->a[k] = ab->mz.a[k].x;
ix->a[k] <<= 32; ix->a[k] |= k;
}
for (; k < ab->mz.n; k++) {
ix->a[k] = ab->mz.a[k].x;
ix->a[k] <<= 32; ix->a[k] |= (k-rn);
}
ix->n = ab->mz.n;
if(gen_srt_chain(ab, ab->mz.a, ix->a, rn, ab->mz.a + rn, ix->a + rn, ab->mz.n - rn, high_occ, low_occ, cl, tid)) {
int64_t max_skip, max_iter, max_dis, quick_check; double chn_pen_gap, chn_pen_skip;
set_lchain_dp_op(is_accurate, mz_k, &max_skip, &max_iter, &max_dis, &chn_pen_gap, &chn_pen_skip, &quick_check);
m += lchain_qdp_mcopy_fast(cl, m, cl->length - m, m, &(cl->chainDP), ores, max_skip, max_iter, max_dis, chn_pen_gap, chn_pen_skip, bw_thres,
rid, rl, tl, quick_check, apend_be, gen_off, enable_mcopy, mcopy_rate, mcopy_khit_cut, 1);
cl->length = m;
}
ab->mz.n = rn;
}
int64_t ug_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, double bw_thres_sec, int64_t ug_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, double bw_thres_sec,
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, 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 mcopy_khit_cut, uint32_t is_hpc, ha_mzl_t *res, uint64_t res_n, ha_mzl_t *idx, uint64_t idx_n, uint64_t mzl_cutoff, uint64_t chain_cutoff, kv_u_trans_t *kov) uint32_t gen_off, double mcopy_rate, uint32_t mcopy_khit_cut, uint32_t is_hpc, ha_mzl_t *res, uint64_t res_n, ha_mzl_t *idx, uint64_t idx_n, uint64_t mzl_cutoff, uint64_t chain_cutoff, kv_u_trans_t *kov)
+5666 -297
View File
File diff suppressed because it is too large Load Diff
+8 -47
View File
@@ -7,57 +7,18 @@
#include "Process_Read.h" #include "Process_Read.h"
#include "kdq.h" #include "kdq.h"
KDQ_INIT(uint32_t)
typedef struct {
uint32_t v:31, f:1;
uint32_t sc;
} cns_arc;
typedef struct {size_t n, m, nou; cns_arc *a; } cns_arc_v;
typedef struct {
// uint16_t c:2, t:2, f:1, sc:3;
uint32_t c:2, f:1, sc:29;
cns_arc_v arc;
}cns_t;
typedef struct {
size_t n, m;
cns_t *a;
uint32_t si, ei, off, bn, bb0, bb1, cns_g_wl;
kdq_t(uint32_t) *q;
}cns_gfa;
typedef struct {
// chaining and overlapping related buffers
UC_Read self_read, ovlp_read;
Candidates_list clist;
overlap_region_alloc olist;
ha_abuf_t *ab;
// int64_t num_read_base, num_correct_base, num_recorrect_base;
uint64_t cnt[6], rr;
haplotype_evdience_alloc hap;
bit_extz_t exz;
kv_ul_ov_t pidx;
asg64_v v64;
asg32_v v32;
asg16_v v16;
kvec_t_u8_warp k_flag;
st_mt_t sp;
cns_gfa cns;
} ec_ovec_buf_t0;
typedef struct {
ec_ovec_buf_t0 *a;
uint32_t n, rev;
} ec_ovec_buf_t;
ec_ovec_buf_t* gen_ec_ovec_buf_t(uint32_t n);
void destroy_ec_ovec_buf_t(ec_ovec_buf_t *p);
void prt_chain(overlap_region_alloc *o); 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 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 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 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 #endif
+539 -58
View File
@@ -411,6 +411,153 @@ void init_integer_ml_t(integer_ml_t *x, ul_resolve_t *u, uint64_t n_thread)
int32_t if_sup_chimeric(ma_hit_t_alloc* src, uint64_t rLen, asg64_v *b, int if_exact); int32_t if_sup_chimeric(ma_hit_t_alloc* src, uint64_t rLen, asg64_v *b, int if_exact);
typedef struct {
const char *nn;
uint64_t nid;
} dbg_prt_t;
static void qry_nn_id(void *data, long i, int tid) // callback for kt_for()
{
dbg_prt_t *sl = (dbg_prt_t *)data; uint64_t ri = sl[i].nid, rl = 0; const char *nn = sl[i].nn;
rl = strlen(nn);
if((ri < R_INF.total_reads) && (Get_NAME_LENGTH((R_INF), ri) == rl) && (memcmp(nn, Get_NAME((R_INF), ri), Get_NAME_LENGTH((R_INF), ri)) == 0)) return;
for (ri = 0; ri < R_INF.total_reads; ri++) {
if((Get_NAME_LENGTH((R_INF), ri) == rl) && (memcmp(nn, Get_NAME((R_INF), ri), Get_NAME_LENGTH((R_INF), ri)) == 0)) {
sl[i].nid = ri;
return;
}
}
sl[i].nid = (uint64_t)-1;
}
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)
{
if((!paf) && (!ruIndex) && (!cov) && (!g)) return;
uint64_t k, z, n, ni, rid, uri, n_thre = asm_opt.thread_num; dbg_prt_t *ri = NULL; const char **ids = NULL; const uint64_t *iids = NULL;
if (cmd == NULL) cmd = "";
fprintf(stderr, "\n[M::%s::%s]\t********************************\n", __func__, cmd);
const char *ids1[] = {
///"m84039_230928_213653_s3/181277190/ccs",///tip 0, contained read issue
///"7e61bf83-7f09-49df-88b9-2a864587b19f", ///tip1 -> 916fced8-524e-4a65-b04d-5b5ea6937e6e(qn::199123)
///phasing error -> ONT specific bias && HPC intoduce fake SNPs
///"43691917-c944-4102-8a01-d63a9c635dc3",///tip3 -> 29ee66bc-ef49-42ae-b7b4-15c37d46beac(qn::3373007) overcorrected in the first round
//when only 2 reads supported (the read itself has high sequencing error rate so hard to be aligned)
//we may also consider increase the error rate threshold
///"21b83ce9-9b94-445d-93b0-b9e83aaa4326",///tip3
"6f240062-2451-4212-a22d-abecc73ae0d9",///tip4->63a321ea-1103-4ca5-97e1-531e55f6bc84(qn::3646295)
///phasing error -> ONT specific bias && HPC intoduce fake SNPs && the DP was to nice for the following SNPs, which we need to fix as high-sequencing depth we have more such cases
// +[M::gen_rphase_dp0_single_path_hybrid_0_multi] rn::2 hf_only::0
// +[M::gen_rphase_dp0_single_path_hybrid_0_multi] site::175009 sc::2 n0::57 n1::3 rn::2 krn::2 b0l::16 b0h::41 b1l::0 b1h::3
// +[M::gen_rphase_dp0_single_path_hybrid_0_multi] site::82558 sc::-1 n0::80 n1::4 rn::2 krn::2 b0l::4 b0h::76 b1l::2 b1h::2
"a72d3f7f-d74f-48ab-a3f7-5ecc74ad08ff",///tip5, contained read issue
};
if(ids0) {
ids = ids0; n = n0;
} else {
ids = ids1; n = sizeof(ids1) / sizeof(ids1[0]);
}
const uint64_t iids1[] = {
///5038496,///tip 0, contained read issue
///3799659,///tip 1, contained read issue
///3313150,///tip 2, contained read issue
///4192664,///tip3, contained read issue
508213,///tip4
3203512,///tip5
};
if(iids0) {
iids = iids0; ni = ni0;
} else {
iids = iids1; ni = sizeof(iids1) / sizeof(iids1[0]);
}
CALLOC(ri, n);
for (k = uri = 0; k < n; k++) {
rid = ((k<ni)?(iids[k]):((uint64_t)-1));
if(rid < R_INF.total_reads) {
if ((Get_NAME_LENGTH((R_INF), rid) != strlen(ids[k])) || (memcmp(ids[k], Get_NAME((R_INF), rid), Get_NAME_LENGTH((R_INF), rid)))) {
rid = (uint64_t)-1;
}
}
if(rid >= R_INF.total_reads) uri++;
ri[k].nid = rid; ri[k].nn = ids[k];
}
if(uri) {
if(n_thre > n) n_thre = n;
kt_for(n_thre, qry_nn_id, ri, n);
}
ma_hit_t *h = NULL; uint64_t nv, v, w; asg_arc_t *av; uint32_t cid, is_u;
for (k = 0; k < n; k++) {
if(ri[k].nid != ((uint64_t)-1)) {
fprintf(stderr, "\n[M::%s::%s]\trid::%lu\t%.*s\trlen::%lu\n", __func__, cmd, ri[k].nid, (int)Get_NAME_LENGTH(R_INF, ri[k].nid), Get_NAME(R_INF, ri[k].nid), Get_READ_LENGTH(R_INF, ri[k].nid));
if(paf) {
fprintf(stderr, "[M::%s::%s]\tpaf::(abnm->%u\tfcor->%u)\n", __func__, cmd, paf[ri[k].nid].is_abnormal, paf[ri[k].nid].is_fully_corrected);
for (z = 0; z < paf[ri[k].nid].length; z++) {
h = &(paf[ri[k].nid].buffer[z]);
fprintf(stderr, "[%s::paf]\t%.*s(qn::%u)\t%u\t%u\t%u\t%c\t%.*s(tn::%u)\t%u\t%u\t%u\tml::%u\tbl::%u\tel::%u\tdel::%u\tnl_idl::%u", cmd, (int)Get_NAME_LENGTH(R_INF, Get_qn(*h)), Get_NAME((R_INF), Get_qn(*h)), Get_qn(*h), (uint32_t)Get_READ_LENGTH(R_INF, Get_qn(*h)), Get_qs(*h), Get_qe(*h), "+-"[h->rev],
(int)Get_NAME_LENGTH(R_INF, Get_tn(*h)), Get_NAME((R_INF), Get_tn(*h)), Get_tn(*h), (uint32_t)Get_READ_LENGTH(R_INF, Get_tn(*h)), Get_ts(*h), Get_te(*h), h->ml, h->bl,
h->el, h->del, h->no_l_indel);
if(ruIndex) {
get_R_to_U(ruIndex, Get_tn(*h), &cid, &is_u);
if((is_u != (uint32_t)-1) && (is_u == 0)) {
fprintf(stderr, "\tis_contain::1\tis_cr::1(crid->::%u::%.*s)", cid, (int)Get_NAME_LENGTH(R_INF, cid), Get_NAME(R_INF, cid));
}
}
fprintf(stderr, "\n");
}
}
if(g) {
fprintf(stderr, "[M::%s::%s]\tsg::(del->%u\tc->%u)\n", __func__, cmd, g->seq[ri[k].nid].del, g->seq[ri[k].nid].c);
v = ri[k].nid<<1;
nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
for (z = 0; z < nv; ++z) {
w = av[z].v;
fprintf(stderr, "[M::%s::sg]\t%.*s(%c)\t%.*s(%c)\tol::%u\tel::%u\tdel::%u\tstrong::%u\tnl_idl::%u\n", __func__,
(int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1],
(int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[z].ol, av[z].el, av[z].del, av[z].strong, av[z].no_l_indel);
}
v = (ri[k].nid<<1) + 1;
nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
for (z = 0; z < nv; ++z) {
w = av[z].v;
fprintf(stderr, "[M::%s::sg]\t%.*s(%c)\t%.*s(%c)\tol::%u\tel::%u\tdel::%u\tstrong::%u\tnl_idl::%u\n", __func__,
(int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1],
(int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[z].ol, av[z].el, av[z].del, av[z].strong, av[z].no_l_indel);
}
}
if(cov) {
fprintf(stderr, "[M::%s::%s]\tcov::(del->%u\tc->%u)\n", __func__, cmd, cov[ri[k].nid].del, cov[ri[k].nid].c);
}
if(ruIndex) {
fprintf(stderr, "[M::%s::%s]\t", __func__, cmd);
get_R_to_U(ruIndex, ri[k].nid, &cid, &is_u);
if((is_u != (uint32_t)-1) && (is_u == 0)) {
fprintf(stderr, "is_contain::1\tis_cr::1(rid->::%u::%.*s)\tis_cu::0\n", cid, (int)Get_NAME_LENGTH(R_INF, cid), Get_NAME(R_INF, cid));
} else if(is_u != (uint32_t)-1) {
fprintf(stderr, "is_contain::1\tis_cr::0\tis_cu::1(uid->::%u)\n", cid);
} else {
fprintf(stderr, "is_contain::0\tis_cr::0\tis_cu::0\n");
}
}
} else {
fprintf(stderr, "\n[M::%s::%s]\trid::-1\t%.*s\n", __func__, cmd, (int)strlen(ri[k].nn), ri[k].nn);
}
}
free(ri);
}
void print_edge(asg_arc_t *t, const char *cmd) void print_edge(asg_arc_t *t, const char *cmd)
{ {
uint32_t v = t->ul>>32, w = t->v; uint32_t v = t->ul>>32, w = t->v;
@@ -966,7 +1113,7 @@ void asg_arc_cut_inexact(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, int32_t max
{ {
asg64_v tx = {0,0,0}, *b = NULL; asg64_v tx = {0,0,0}, *b = NULL;
uint32_t v, w, i, k, n_vtx = g->n_seq<<1; uint32_t v, w, i, k, n_vtx = g->n_seq<<1;
asg_arc_t *av, *aw, *ve, *vmax, *we; uint32_t nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *vmax, *we = NULL; uint32_t nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
uint32_t trioF = (uint32_t)-1, ntrioF = (uint32_t)-1; uint32_t trioF = (uint32_t)-1, ntrioF = (uint32_t)-1;
if(in) b = in; if(in) b = in;
else b = &tx; else b = &tx;
@@ -1280,7 +1427,7 @@ uint32_t is_topo, uint32_t min_diff, uint32_t min_ou, ma_hit_t_alloc *rev, R_to_
{ {
asg64_v tx = {0,0,0}, *b = NULL; asg64_v tx = {0,0,0}, *b = NULL;
uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou; uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
asg_arc_t *av, *aw, *ve, *we, *vl_max, *wl_max; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL, *vl_max = NULL, *wl_max = NULL;
if(in) b = in; if(in) b = in;
else b = &tx; else b = &tx;
@@ -1407,13 +1554,281 @@ uint32_t is_topo, uint32_t min_diff, uint32_t min_ou, ma_hit_t_alloc *rev, R_to_
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
} }
uint32_t is_dedup_weak_arc(asg_arc_t *av, uint32_t an, uint32_t ak, ma_hit_t_alloc *rev)
{
uint32_t k, w, m; ma_hit_t_alloc *z = NULL;
for (k = 0; k < an; k++) {
if((k == ak) || (av[k].del) || (!av[k].strong)) continue;
if(av[k].ol > av[ak].ol) {
z = &(rev[av[k].v>>1]); w = (av[ak].v^(av[k].v&1));
for (m = 0; m < z->length; m++) {
if((z->buffer[m].tn<<1|(z->buffer[m].rev)) == w) break;
}
if(m < z->length) return 1;
}
}
return 0;
}
void asg_arc_cut_weak(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, uint32_t test_bub, ma_hit_t_alloc *rev, R_to_U* rI, uint32_t *max_drop_len)
{
asg64_v tx = {0,0,0}, *b = NULL;
uint32_t i, k, v, w, wz, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou, olw[2], m;
asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL, *vl_max = NULL, *wl_max = NULL; ma_hit_t_alloc *z = NULL;
if(in) b = in;
else b = &tx;
b->n = 0;
for (v = 0; v < n_vtx; ++v) {
// if((v>>1)==17078) fprintf(stderr, "[M::%s::] v:%u, del:%u, seq_vis:%u\n", __func__, v, g->seq[v>>1].del, g->seq_vis[v]);
if (g->seq[v>>1].del) continue;
if((test_bub == 0) || (g->seq_vis[v] == 0)) {
av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
if (nv < 2) continue;
for (i = kv = 0; i < nv; ++i) {
if(av[i].del) continue;
kv++;
}
if(kv < 2) continue;
for (i = olw[1] = 0, olw[0] = (uint32_t)-1; i < nv; ++i) {
if(av[i].del) continue;
if(av[i].strong) {
if(av[i].ol > olw[av[i].strong]) olw[av[i].strong] = av[i].ol;
} else {
if(av[i].ol < olw[av[i].strong]) olw[av[i].strong] = av[i].ol;
}
}
if(olw[1] <= olw[0]) continue;
for (i = 0; i < nv; ++i) {
if(av[i].del || av[i].strong) continue;
if(av[i].ol >= olw[1]) continue;
if(max_drop_len && av[i].ol >= (*max_drop_len)) continue;
if(is_dedup_weak_arc(av, nv, i, rev)) {
kv_push(uint64_t, *b, (((uint64_t)av[i].ol)<<32) | ((uint64_t)(av-g->arc+i)));
}
}
}
}
if(rev && rI) memset(g->seq_vis, 0, g->n_seq*2*sizeof(uint8_t));
radix_sort_srt64(b->a, b->a + b->n);
for (k = 0; k < b->n; k++) {
if(g->arc[(uint32_t)b->a[k]].del) continue;
v = g->arc[(uint32_t)b->a[k]].ul>>32; w = g->arc[(uint32_t)b->a[k]].v^1;
if(g->seq[v>>1].del || g->seq[w>>1].del) continue;
nv = asg_arc_n(g, v); nw = asg_arc_n(g, w);
av = asg_arc_a(g, v); aw = asg_arc_a(g, w);
if(nv<=1 && nw <= 1) continue;
if(is_trio) {
if(get_arcs(g, v, NULL, 0)<=1 && get_arcs(g, w, NULL, 0)<=1) continue;///speedup
trioF = get_tip_trio_infor(g, v^1);
ntrioF = (trioF==FATHER? MOTHER : (trioF==MOTHER? FATHER : (uint32_t)-1));
}
ve = &(g->arc[(uint32_t)b->a[k]]);
for (i = 0; i < nw; ++i) {
if (aw[i].v == (v^1)) {
we = &(aw[i]);
break;
}
}
///mm_ol and mm_ou are used to make edge with long indel more easy to be cutted
mm_ol = MIN(ve->ol, we->ol); mm_ou = MIN(ve->ou, we->ou);
for (i = kv = ol_max = ou_max = 0, vl_max = NULL; i < nv; ++i) {
if(av[i].del) continue;
kv++;
if((av[i].v == ve->v) || (!av[i].strong) || (av[i].ol <= ve->ol)) continue;
if(is_trio && get_tip_trio_infor(g, av[i].v) == ntrioF) continue;
z = &(rev[av[i].v>>1]); wz = (ve->v^(av[i].v&1));
for (m = 0; m < z->length; m++) {
if((z->buffer[m].tn<<1|(z->buffer[m].rev)) == wz) break;
}
if(m >= z->length) continue;
if(ol_max < av[i].ol) ol_max = av[i].ol, vl_max = &(av[i]);
if(ou_max < av[i].ou) ou_max = av[i].ou;
}
if (kv < 1) continue;
if (kv >= 2) {
if (mm_ol > ol_max*len_rat) continue;
if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
if ((mm_ol + min_diff) > ol_max) continue;
}
for (i = kw = ol_max = ou_max = 0, wl_max = NULL; i < nw; ++i) {
if(aw[i].del) continue;
kw++;
if((aw[i].v == we->v) || (!aw[i].strong) || (aw[i].ol <= we->ol)) continue;
if(is_trio && get_tip_trio_infor(g, aw[i].v) == ntrioF) continue;
z = &(rev[aw[i].v>>1]); wz = (we->v^(aw[i].v&1));
for (m = 0; m < z->length; m++) {
if((z->buffer[m].tn<<1|(z->buffer[m].rev)) == wz) break;
}
if(m >= z->length) continue;
if(ol_max < aw[i].ol) ol_max = aw[i].ol, wl_max = &(aw[i]);
if(ou_max < aw[i].ou) ou_max = aw[i].ou;
}
if (kw < 1) continue;
if (kw >= 2) {
if (mm_ol > ol_max*len_rat) continue;
if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
if ((mm_ol + min_diff) > ol_max) continue;
}
if (kv <= 1 && kw <= 1) continue;
to_del = 0;
if(is_topo) {
if (kv > 1 && kw > 1) {
to_del = 1;
} else if (kw == 1) {
if (asg_topocut_aux(g, w^1, max_ext) < max_ext) to_del = 1;
} else if (kv == 1) {
if (asg_topocut_aux(g, v^1, max_ext) < max_ext) to_del = 1;
}
}
if(rev && rI) {
if((to_del == 0) && vl_max && (ve->v!=vl_max->v) && (trans_path_check(ve->v, vl_max->v, g, rev, rI, max_ext, b)==0)) {
to_del = 1;
}
if((to_del == 0) && wl_max && (we->v!=wl_max->v) && (trans_path_check(we->v, wl_max->v, g, rev, rI, max_ext, b)==0)) {
to_del = 1;
}
if(vl_max && wl_max) assert(ve->v!=vl_max->v||we->v!=wl_max->v);
}
if (to_del) {
ve->del = we->del = 1, ++cnt;
}
}
// stats_sysm(g);
if(!in) free(tx.a);
if (cnt > 0) asg_cleanup(g);
}
void asg_arc_cut_chimeric_cmk(asg_t *g, asg64_v *in, int32_t max_ext, float len_rat, float ou_rat, uint32_t is_ou, uint32_t is_topo, uint32_t min_ou, uint32_t test_bub, uint8_t *cmk, uint32_t cmk_cut)
{
asg64_v tx = {0,0,0}, *b = NULL; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL;
uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
if(in) b = in;
else b = &tx;
b->n = 0;
for (v = 0; v < n_vtx; ++v) {
// if((v>>1)==17078) fprintf(stderr, "[M::%s::] v:%u, del:%u, seq_vis:%u\n", __func__, v, g->seq[v>>1].del, g->seq_vis[v]);
if (g->seq[v>>1].del) continue;
if (cmk[v>>1] > cmk_cut) continue;
if((test_bub == 0) || (g->seq_vis[v] == 0)) {
av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
if (nv < 2) continue;
for (i = kv = 0; i < nv; ++i) {
if(av[i].del) continue;
kv++;
}
if(kv < 2) continue;
for (i = 0; i < nv; ++i) {
if(av[i].del) continue;
kv_push(uint64_t, *b, (((uint64_t)av[i].ol)<<32) | ((uint64_t)(av-g->arc+i)));
}
}
}
radix_sort_srt64(b->a, b->a + b->n);
for (k = 0; k < b->n; k++) {
if(g->arc[(uint32_t)b->a[k]].del) continue;
v = g->arc[(uint32_t)b->a[k]].ul>>32; w = g->arc[(uint32_t)b->a[k]].v^1;
if(g->seq[v>>1].del || g->seq[w>>1].del) continue;
nv = asg_arc_n(g, v); nw = asg_arc_n(g, w);
av = asg_arc_a(g, v); aw = asg_arc_a(g, w);
if(nv<=1 && nw <= 1) continue;
ve = &(g->arc[(uint32_t)b->a[k]]);
for (i = 0; i < nw; ++i) {
if (aw[i].v == (v^1)) {
we = &(aw[i]);
break;
}
}
///mm_ol and mm_ou are used to make edge with long indel more easy to be cutted
mm_ol = MIN(ve->ol, we->ol); mm_ou = MIN(ve->ou, we->ou);
for (i = kv = ol_max = ou_max = 0; i < nv; ++i) {
if(av[i].del) continue;
kv++;
if(ol_max < av[i].ol) ol_max = av[i].ol;
if(ou_max < av[i].ou) ou_max = av[i].ou;
}
if (kv < 1) continue;
if (kv >= 2) {
if (mm_ol > ol_max*len_rat) continue;
if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
}
for (i = kw = ol_max = ou_max = 0; i < nw; ++i) {
if(aw[i].del) continue;
kw++;
if(ol_max < aw[i].ol) ol_max = aw[i].ol;
if(ou_max < aw[i].ou) ou_max = aw[i].ou;
}
if (kw < 1) continue;
if (kw >= 2) {
if (mm_ol > ol_max*len_rat) continue;
if (is_ou && mm_ou > ou_max*ou_rat && mm_ou > min_ou) continue;
}
if (kv <= 1 && kw <= 1) continue;
to_del = 0;
if(is_topo) {
if (kv > 1 && kw > 1) {
to_del = 1;
} else if (kw == 1) {
if (asg_topocut_aux(g, w^1, max_ext) < max_ext) to_del = 1;
} else if (kv == 1) {
if (asg_topocut_aux(g, v^1, max_ext + 1) < max_ext + 1) to_del = 1;
}
}
if (to_del) {
asg_seq_del(g, v>>1); ++cnt;
}
}
// stats_sysm(g);
if(!in) free(tx.a);
if (cnt > 0) asg_cleanup(g);
// fprintf(stderr, "[M::%s::] cnt:%u\n", __func__, cnt);
}
void asg_arc_cut_length_adv(asg_t *g, asg64_v *in, int32_t max_ext, float len_rat, float ou_rat, uint32_t is_ou, uint32_t is_trio, void asg_arc_cut_length_adv(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, ma_hit_t_alloc *rev, R_to_U* rI, uint32_t *max_drop_len) uint32_t is_topo, uint32_t min_diff, ma_hit_t_alloc *rev, R_to_U* rI, uint32_t *max_drop_len)
{ {
asg64_v tx = {0,0,0}, *b = NULL; asg64_v tx = {0,0,0}, *b = NULL;
uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou; uint32_t i, k, v, w, n_vtx = g->n_seq<<1, nv, nw, kv, kw, trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, ol_max, ou_max, to_del, cnt = 0, mm_ol, mm_ou;
asg_arc_t *av, *aw, *ve, *we, *vl_max, *wl_max; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL, *vl_max = NULL, *wl_max = NULL;
if(in) b = in; if(in) b = in;
else b = &tx; else b = &tx;
@@ -1979,7 +2394,7 @@ void asg_arc_cut_contain(flex_asg_t *fg, asg64_v *in, asg64_v *in0, R_to_U* rI,
// } // }
} }
// stats_sysm(g); // stats_sysm(g);
if(!in) free(tx.a); if(!in0) free(tx0.a); if(!in) {free(tx.a);} if(!in0) {free(tx0.a);}
if(cnt > 0) flex_asg_t_cleanup(fg); if(cnt > 0) flex_asg_t_cleanup(fg);
// fprintf(stderr, "-[M::%s]\n", __func__); // fprintf(stderr, "-[M::%s]\n", __func__);
} }
@@ -2668,9 +3083,9 @@ void prt_specfic_sge(asg_t *g, uint32_t src, uint32_t dst, const char* cmd)
for (k = 0; k < nv; ++k) { for (k = 0; k < nv; ++k) {
if ((av[k].v>>1) == dst) { if ((av[k].v>>1) == dst) {
w = av[k].v; w = av[k].v;
fprintf(stderr, "[M::%s::]\t%.*s(%c)\t%.*s(%c)\tou::%u\n", __func__, fprintf(stderr, "[M::%s::]\t%.*s(%c)\t%.*s(%c)\tou::%u\tdel::%u\n", __func__,
(int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1], (int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1],
(int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[k].ou); (int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[k].ou, av[k].del);
} }
} }
@@ -2679,9 +3094,9 @@ void prt_specfic_sge(asg_t *g, uint32_t src, uint32_t dst, const char* cmd)
for (k = 0; k < nv; ++k) { for (k = 0; k < nv; ++k) {
if ((av[k].v>>1) == dst) { if ((av[k].v>>1) == dst) {
w = av[k].v; w = av[k].v;
fprintf(stderr, "[M::%s::]\t%.*s(%c)\t%.*s(%c)\tou::%u\n", __func__, fprintf(stderr, "[M::%s::]\t%.*s(%c)\t%.*s(%c)\tou::%u\tdel::%u\n", __func__,
(int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1], (int)Get_NAME_LENGTH(R_INF, (v>>1)), Get_NAME(R_INF, (v>>1)), "+-"[v&1],
(int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[k].ou); (int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), "+-"[w&1], av[k].ou, av[k].del);
} }
} }
} }
@@ -2742,22 +3157,22 @@ void print_raw_u2rgfa_seq(all_ul_t *aln, R_to_U* rI, uint32_t is_detail)
} }
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) 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)
{ {
rescue_contained_reads_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, NULL, NULL, b_mask_t); rescue_contained_reads_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, NULL, NULL, b_mask_t);
rescue_missing_overlaps_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 1, 0, NULL, b_mask_t); rescue_missing_overlaps_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 1, 0, NULL, b_mask_t);
rescue_missing_overlaps_backward(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, b_mask_t); rescue_missing_overlaps_backward(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, b_mask_t);
if(cmk) rescue_chimeric_reads_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, NULL, NULL, b_mask_t, cmk);
// rescue_wrong_overlaps_to_unitigs(NULL, sg, sources, reverse_sources, coverage_cut, ruIndex, // rescue_wrong_overlaps_to_unitigs(NULL, sg, sources, reverse_sources, coverage_cut, ruIndex,
// max_hang_length, mini_overlap_length, bubble_dist, NULL); // max_hang_length, mini_overlap_length, bubble_dist, NULL);
// rescue_no_coverage_aggressive(sg, sources, reverse_sources, &coverage_cut, ruIndex, max_hang_length, // rescue_no_coverage_aggressive(sg, sources, reverse_sources, &coverage_cut, ruIndex, max_hang_length,
// mini_overlap_length, bubble_dist, 10); // mini_overlap_length, bubble_dist, 10);
set_hom_global_coverage(&asm_opt, sg, uopt->coverage_cut, src, rev, rI, uopt->max_hang, uopt->min_ovlp); set_hom_global_coverage(&asm_opt, sg, uopt->coverage_cut, src, rev, rI, uopt->max_hang, uopt->min_ovlp);
rescue_bubble_by_chain(sg, uopt->coverage_cut, src, rev, (asm_opt.max_short_tip*2), 0.15, 3, rI, 0.05, 0.9, uopt->max_hang, rescue_bubble_by_chain(sg, uopt->coverage_cut, src, rev, (asm_opt.max_short_tip*2), 0.15, 3, rI, 0.05, 0.9, uopt->max_hang, uopt->min_ovlp, 10, uopt->gap_fuzz, b_mask_t, no_trio_recover, cmk);
uopt->min_ovlp, 10, uopt->gap_fuzz, b_mask_t, no_trio_recover);
} }
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, 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, char *o_file) 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)
{ {
#define HARD_OU_DROP 0.75 #define HARD_OU_DROP 0.75
#define HARD_OL_DROP 0.6 #define HARD_OL_DROP 0.6
@@ -2768,6 +3183,7 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
double drop = min_ovlp_drop_ratio; double drop = min_ovlp_drop_ratio;
int64_t i; asg64_v bu = {0,0,0}, ba = {0,0,0}; uint32_t l_drop = 2000; flex_asg_t *fg = NULL; uint32_t min_diff = 0, step_diff = 2000; int64_t i; asg64_v bu = {0,0,0}, ba = {0,0,0}; uint32_t l_drop = 2000; flex_asg_t *fg = NULL; uint32_t min_diff = 0, step_diff = 2000;
if(is_ou) fg = init_flex_asg_t(sg, uopt->sources, uopt->min_ovlp, uopt->max_hang, asm_opt.max_hang_rate, gap_fuzz); if(is_ou) fg = init_flex_asg_t(sg, uopt->sources, uopt->min_ovlp, uopt->max_hang, asm_opt.max_hang_rate, gap_fuzz);
// prt_specfic_sge(sg, 22708, 22646, "--sa--");
// if(is_ou) update_sg_uo(sg, src);///do not do it here // if(is_ou) update_sg_uo(sg, src);///do not do it here
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
// exit(1); // exit(1);
@@ -2784,39 +3200,64 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
// fprintf(stderr, "%.*s\tid::%u\tis_c::%u\n", // fprintf(stderr, "%.*s\tid::%u\tis_c::%u\n",
// (int)Get_NAME_LENGTH(R_INF, 10819), Get_NAME(R_INF, 10819), 10819, is_contain_r((*rI), 10819)); // (int)Get_NAME_LENGTH(R_INF, 10819), Get_NAME(R_INF, 10819), 10819, is_contain_r((*rI), 10819));
// debug_info_of_specfic_node("m64011_190830_220126/47516220/ccs", sg, rI, "beg-0"); // debug_info_of_specfic_node("m64011_190830_220126/47516220/ccs", sg, rI, "beg-0");
// debug_info_of_specfic_node("m64012_190920_173625/163644465/ccs", sg, rI, "beg-0"); // debug_info_of_specfic_node("c7ecbd6b-e09d-4042-93ac-2400839feaf6", sg, rI, "beg-0");
if(asm_opt.is_ont) asg_arc_cut_weak(sg, &bu, max_tip, 0.975, 0, is_ou, 0, 1, 16, UL_COV_THRES-1, 0, rev, NULL, NULL);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_a", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);///p_telo asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);///p_telo
// fprintf(stderr, "[M::%s] count_edges_v_w(sg, 49778, 49847)->%ld\n", __func__, count_edges_v_w(sg, 49778, 49847)); // fprintf(stderr, "[M::%s] count_edges_v_w(sg, 49778, 49847)->%ld\n", __func__, count_edges_v_w(sg, 49778, 49847));
// if(is_ou) dedup_contain_g(uopt, sg); // if(is_ou) dedup_contain_g(uopt, sg);
// debug_info_of_specfic_node("c7ecbd6b-e09d-4042-93ac-2400839feaf6", sg, rI, "beg-1");
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_b", NULL, rI, NULL, sg);
for (i = 0; i < clean_round; i++, drop += step) { for (i = 0; i < clean_round; i++, drop += step) {
if(drop > max_ovlp_drop_ratio) drop = max_ovlp_drop_ratio; if(drop > max_ovlp_drop_ratio) drop = max_ovlp_drop_ratio;
if(is_ou) { if(is_ou) {
if(drop <= 0.500001) min_diff = step_diff>>1; if(drop <= 0.500001) min_diff = step_diff>>1;
else min_diff = step_diff; else min_diff = step_diff;
} }
// fprintf(stderr, "(0):i->%ld, drop->%f\n", i, drop); // fprintf(stderr, "\n(0):i->%ld, drop->%f\n", i, drop);
// prt_specfic_sge(sg, 10531, 10519, "--0--");
if(asm_opt.is_ont) {
asg_arc_cut_weak(sg, &bu, max_tip, 0.975, 0, is_ou, 0, 1, 16, UL_COV_THRES-1, 0, rev, NULL, NULL);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_0", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_1", NULL, rI, NULL, sg);
}
// prt_specfic_sge(sg, 22708, 22646, "--0--");
// print_vw_edge(sg, 34156, 34090, "0"); // print_vw_edge(sg, 34156, 34090, "0");
// stats_chimeric(sg, src, &bu); // stats_chimeric(sg, src, &bu);
if(!is_ou) asg_iterative_semi_circ(sg, src, &bu, max_tip, 1, uopt->te);///p_telo if(!is_ou) asg_iterative_semi_circ(sg, src, &bu, max_tip, 1, uopt->te);///p_telo
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_3", NULL, rI, NULL, sg);
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1);
asg_arc_cut_chimeric(sg, src, &bu, is_ou?ou_thres:(uint32_t)-1, uopt->te);///p_telo asg_arc_cut_chimeric(sg, src, &bu, is_ou?ou_thres:(uint32_t)-1, uopt->te);///p_telo
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_4", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// prt_specfic_sge(sg, 10531, 10519, "--1--"); // hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_5", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--1--");
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
asg_arc_cut_inexact(sg, src, &bu, max_tip, is_ou, is_trio, min_diff, ou_drop_rate/**, NULL**//**&dbg**/); asg_arc_cut_inexact(sg, src, &bu, max_tip, is_ou, is_trio, min_diff, ou_drop_rate/**, NULL**//**&dbg**/);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_6", NULL, rI, NULL, sg);
// debug_edges(&dbg, d, 2); // debug_edges(&dbg, d, 2);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// prt_specfic_sge(sg, 10531, 10519, "--2--"); // hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_7", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--2--");
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1);
asg_arc_cut_length(sg, &bu, max_tip, drop, ou_drop_rate, is_ou, is_trio, 1, min_diff, 1, NULL, NULL, NULL); asg_arc_cut_length(sg, &bu, max_tip, drop, ou_drop_rate, is_ou, is_trio, 1, min_diff, 1, NULL, NULL, NULL);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_8", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_9", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 10531, 10519, "--3--"); // if(i == 0) {
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty3.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
// // exit(1);
// }
// prt_specfic_sge(sg, 22708, 22646, "--3--");
// if(is_ou) asg_arc_cut_contain(fg, &bu, &ba, rI, ((i+1)<clean_round)?ou_drop_rate:-1); // if(is_ou) asg_arc_cut_contain(fg, &bu, &ba, rI, ((i+1)<clean_round)?ou_drop_rate:-1);
if(is_ou) { if(is_ou) {
asg_arc_cut_contain(fg, &bu, &ba, rI, ou_drop_rate, 0); asg_arc_cut_contain(fg, &bu, &ba, rI, ou_drop_rate, 0);
@@ -2825,17 +3266,24 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1);
asg_arc_cut_bub_links(sg, &bu, HARD_OL_DROP, HARD_OL_SEC_DROP, HARD_OU_DROP, is_ou, asm_opt.large_pop_bubble_size, rev, rI, max_tip); asg_arc_cut_bub_links(sg, &bu, HARD_OL_DROP, HARD_OL_SEC_DROP, HARD_OU_DROP, is_ou, asm_opt.large_pop_bubble_size, rev, rI, max_tip);
// prt_specfic_sge(sg, 10531, 10519, "--4--"); // hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_10", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--4--");
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 1);
asg_arc_cut_complex_bub_links(sg, &bu, HARD_OL_DROP, HARD_OU_DROP, is_ou, b_mask_t); asg_arc_cut_complex_bub_links(sg, &bu, HARD_OL_DROP, HARD_OU_DROP, is_ou, b_mask_t);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_11", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// prt_specfic_sge(sg, 10531, 10519, "--5--"); // hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_c_12", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--5--");
/**
if(cmk && asm_opt.chemical_cov > FORCE_CUT) {
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
asg_arc_cut_chimeric_cmk(sg, &bu, max_tip, 1.1, 1.1, is_ou, 1, 1, 1, cmk, asm_opt.chemical_cov);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
}
**/
// if(i == 3) {
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty3.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
// // exit(1);
// }
if(is_ou) { if(is_ou) {
if(ul_refine_alignment(uopt, sg)) update_sg_uo(sg, src); if(ul_refine_alignment(uopt, sg)) update_sg_uo(sg, src);
@@ -2843,9 +3291,18 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
} }
} }
// prt_specfic_sge(sg, 22708, 22646, "--sb--");
if(asm_opt.is_ont) {
asg_arc_cut_weak(sg, &bu, max_tip, 0.975, 0, is_ou, 0, 1, 16, UL_COV_THRES-1, 0, rev, NULL, NULL);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_0", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_1", NULL, rI, NULL, sg);
}
if(is_ou) min_diff = step_diff; if(is_ou) min_diff = step_diff;
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty4.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty4.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
// debug_info_of_specfic_node("m64012_190921_234837/111673711/ccs", sg, rI, "end"); // debug_info_of_specfic_node("7b70a587-f56c-48ac-adf8-b98a67365063_2", sg, rI, "end");
// debug_info_of_specfic_node("m64011_190830_220126/95028102/ccs", sg, rI, "end"); // debug_info_of_specfic_node("m64011_190830_220126/95028102/ccs", sg, rI, "end");
if(is_ou) { if(is_ou) {
asg_arc_cut_contain(fg, &bu, &ba, rI, ou_drop_rate, 0); asg_arc_cut_contain(fg, &bu, &ba, rI, ou_drop_rate, 0);
@@ -2854,26 +3311,38 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
if(clean_contain_g(uopt, sg, 1)) update_sg_uo(sg, src); if(clean_contain_g(uopt, sg, 1)) update_sg_uo(sg, src);
} }
if(!is_ou) asg_iterative_semi_circ(sg, src, &bu, max_tip, 1, uopt->te); if(!is_ou) asg_iterative_semi_circ(sg, src, &bu, max_tip, 1, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_2", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--sb-0---");
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty5.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty5.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
asg_cut_large_indel(sg, &bu, max_tip, HARD_OU_DROP, is_ou, min_diff);///shoule we ignore ou here? asg_cut_large_indel(sg, &bu, max_tip, HARD_OU_DROP, is_ou, min_diff);///shoule we ignore ou here?
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_3", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_4", NULL, rI, NULL, sg);
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty6.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // prt_specfic_sge(sg, 22708, 22646, "--sb-1---");
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "hybrid.dirty6.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
if(!is_ou) { if(!is_ou) {
///asg_arc_del_triangular_directly might be unnecessary ///asg_arc_del_triangular_directly might be unnecessary
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
asg_arc_cut_length(sg, &bu, max_tip, HARD_ORTHOLOGY_DROP/**min_ovlp_drop_ratio**/, ou_drop_rate, is_ou, 0/**is_trio**/, is_ou?1:0, min_diff, 1, rev, rI, NULL); asg_arc_cut_length(sg, &bu, max_tip, HARD_ORTHOLOGY_DROP/**min_ovlp_drop_ratio**/, ou_drop_rate, is_ou, 0/**is_trio**/, is_ou?1:0, min_diff, 1, rev, rI, NULL);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_5", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_6", NULL, rI, NULL, sg);
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty7.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty7.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
asg_arc_cut_length(sg, &bu, max_tip, min_ovlp_drop_ratio, ou_drop_rate, is_ou, 0/**is_trio**/, is_ou?1:0, min_diff, 1, rev, rI, &l_drop); asg_arc_cut_length(sg, &bu, max_tip, min_ovlp_drop_ratio, ou_drop_rate, is_ou, 0/**is_trio**/, is_ou?1:0, min_diff, 1, rev, rI, &l_drop);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_7", NULL, rI, NULL, sg);
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_8", NULL, rI, NULL, sg);
} else { } else {
min_diff = step_diff; l_drop = 6000; min_diff = step_diff; l_drop = 6000;
asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0); asg_arc_identify_simple_bubbles_multi(sg, b_mask_t, 0);
@@ -2881,9 +3350,14 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te); asg_arc_cut_tips(sg, max_tip, &bu, is_ou, is_ou?rI:NULL, uopt->te);
} }
// prt_specfic_sge(sg, 22708, 22646, "--sb-2---");
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty8.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.dirty8.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
if(!is_ou) asg_cut_semi_circ(sg, LIM_LEN, 1); if(!is_ou) asg_cut_semi_circ(sg, LIM_LEN, 1);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_9", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--sb-3---");
/** /**
rescue_contained_reads_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, NULL, NULL, b_mask_t); rescue_contained_reads_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 10, 1, 0, NULL, NULL, b_mask_t);
rescue_missing_overlaps_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 1, 0, NULL, b_mask_t); rescue_missing_overlaps_aggressive(NULL, sg, src, uopt->coverage_cut, rI, uopt->max_hang, uopt->min_ovlp, 1, 0, NULL, b_mask_t);
@@ -2895,11 +3369,17 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
set_hom_global_coverage(&asm_opt, sg, uopt->coverage_cut, src, rev, rI, uopt->max_hang, uopt->min_ovlp); set_hom_global_coverage(&asm_opt, sg, uopt->coverage_cut, src, rev, rI, uopt->max_hang, uopt->min_ovlp);
rescue_bubble_by_chain(sg, uopt->coverage_cut, src, rev, (asm_opt.max_short_tip*2), 0.15, 3, rI, 0.05, 0.9, uopt->max_hang, uopt->min_ovlp, 10, uopt->gap_fuzz, b_mask_t); rescue_bubble_by_chain(sg, uopt->coverage_cut, src, rev, (asm_opt.max_short_tip*2), 0.15, 3, rI, 0.05, 0.9, uopt->max_hang, uopt->min_ovlp, 10, uopt->gap_fuzz, b_mask_t);
**/ **/
post_rescue(uopt, sg, src, rev, rI, b_mask_t, is_ou); post_rescue(uopt, sg, src, rev, rI, b_mask_t, is_ou, cmk);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_10", NULL, rI, NULL, sg);
// prt_specfic_sge(sg, 22708, 22646, "--sb-4---");
ug_ext_gfa(uopt, sg, ug_ext_len); ug_ext_gfa(uopt, sg, ug_ext_len);
// hc_dbg_prt_ma_hit_t(NULL, 0, NULL, 0, "clen_d_11", NULL, rI, NULL, sg);
// if(is_ou) dedup_contain_g(uopt, sg); // if(is_ou) dedup_contain_g(uopt, sg);
// prt_specfic_sge(sg, 22708, 22646, "--sb-5---");
// exit(1) // exit(1)
output_unitig_graph(sg, uopt->coverage_cut, o_file, src, rI, uopt->max_hang, uopt->min_ovlp); output_unitig_graph(sg, uopt->coverage_cut, o_file, src, rI, uopt->max_hang, uopt->min_ovlp);
@@ -2915,6 +3395,7 @@ double ou_drop_rate, int64_t max_tip, int64_t gap_fuzz, bub_label_t *b_mask_t, i
if(is_ou) { if(is_ou) {
des_flex_asg_t(fg); free(fg); des_flex_asg_t(fg); free(fg);
} }
// prt_specfic_sge(sg, 22708, 22646, "--sb-6---");
// print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0); // print_debug_gfa(sg, NULL, uopt->coverage_cut, "UL.debug", uopt->sources, uopt->ruIndex, uopt->max_hang, uopt->min_ovlp, 1, 0, 0);
// exit(1); // exit(1);
// print_node(sg, 17078); //print_node(sg, 8311); print_node(sg, 8294); // print_node(sg, 17078); //print_node(sg, 8311); print_node(sg, 8294);
@@ -5777,7 +6258,7 @@ void poa_chain_0(poa_g_t *g, ma_ug_t *ug, uc_block_t *raw, ul_str_t *str, int64_
i = integer_g_chain(g, ug, buf->b.a, buf->b.n, buf, &rr); assert(i); i = integer_g_chain(g, ug, buf->b.a, buf->b.n, buf, &rr); assert(i);
if(!i) return; buf->b.n = rr.e; assert(buf->b.n); if(!i) {return;} buf->b.n = rr.e; assert(buf->b.n);
append_aligned_integer_seq_by_aln_pair(ug, raw, g, g->seq.n, pat, pat_n, is_rev, buf->b.a, buf->b.n, str_id, (is_rev?(str->cn - e):(s))); append_aligned_integer_seq_by_aln_pair(ug, raw, g, g->seq.n, pat, pat_n, is_rev, buf->b.a, buf->b.n, str_id, (is_rev?(str->cn - e):(s)));
(*is_circle) = update_poa_dp(g, debug_qid, ug); (*is_circle) = update_poa_dp(g, debug_qid, ug);
} }
@@ -8453,7 +8934,7 @@ uint32_t ulg_arc_cut_tips(ul_resolve_t *uidx, ma_ug_t *ug, uint32_t max_ext, uin
} }
// stats_sysm(g); // stats_sysm(g);
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
@@ -8529,7 +9010,7 @@ float len_rat, uint32_t is_trio, uint32_t topo_level, uint32_t hom_check, uint32
{ {
asg64_v tx = {0,0,0}, tb = {0,0,0}, *b = NULL, *ub = NULL; asg_t *g = ug->g; asg64_v tx = {0,0,0}, tb = {0,0,0}, *b = NULL, *ub = NULL; asg_t *g = ug->g;
uint32_t v, w, i, k, kv, kw, nv, nw, cnt = 0, n_vtx = g->n_seq<<1, n_het, n_hom, ff, ol_max, mm_ol, to_del; uint32_t v, w, i, k, kv, kw, nv, nw, cnt = 0, n_vtx = g->n_seq<<1, n_het, n_hom, ff, ol_max, mm_ol, to_del;
asg_arc_t *av, *aw, *ve, *we, *vl_max, *wl_max; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL, *vl_max = NULL, *wl_max = NULL;
b = (in?(in):(&tx)); ub = (ib?(ib):(&tb)); b = (in?(in):(&tx)); ub = (ib?(ib):(&tb));
for (v = b->n = 0; v < n_vtx; ++v) { for (v = b->n = 0; v < n_vtx; ++v) {
@@ -8635,7 +9116,7 @@ float len_rat, uint32_t is_trio, uint32_t topo_level, uint32_t hom_check, uint32
} }
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
@@ -8706,7 +9187,7 @@ uint32_t is_trio, uint32_t topo_level, asg64_v *in, asg64_v *ib)
} }
} }
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
@@ -8718,7 +9199,7 @@ uint32_t *ul_cnt, uint32_t *bridge_w, uint32_t *bridge_am, asg64_v *b)
{ {
uint32_t v = s, w = (uint32_t)-1, kv, kw, uv = (uint32_t)-1, uw = (uint32_t)-1, bv, bw, l; uint32_t v = s, w = (uint32_t)-1, kv, kw, uv = (uint32_t)-1, uw = (uint32_t)-1, bv, bw, l;
ul_bg_t *bg = &(uidx->uovl.bg); ul_bg_t *bg = &(uidx->uovl.bg);
if(occ) (*occ) = 0; if(ul_cnt) (*ul_cnt) = 0; if(bridge_w) (*bridge_w) = 0; if(bridge_am) (*bridge_am) = 0; if(occ) {(*occ) = 0;} if(ul_cnt) {(*ul_cnt) = 0;} if(bridge_w) {(*bridge_w) = 0;} if(bridge_am) {(*bridge_am) = 0;}
while (1) { while (1) {
if(occ) (*occ)++; if(occ) (*occ)++;
@@ -8893,7 +9374,7 @@ float len_rat, uint32_t is_trio, uint32_t topo_level, uint32_t *max_drop_len, as
} }
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
} }
@@ -9165,7 +9646,7 @@ float len_rat, uint32_t is_trio, uint32_t topo_level, uint32_t *max_drop_len, as
if (nv < 2) continue; if (nv < 2) continue;
for (i = kv = 0, ul_max = -1; i < nv; ++i) { for (i = kv = 0, ul_max = -1; i < nv; ++i) {
if(av[i].del) continue; kv++; if(av[i].del) {continue;} kv++;
get_ul_path_info(uidx, ug, av[i].v, NULL, NULL, &ul_cnt, NULL, NULL, NULL); get_ul_path_info(uidx, ug, av[i].v, NULL, NULL, &ul_cnt, NULL, NULL, NULL);
if(ul_cnt > ul_max) ul_max = ul_cnt; if(ul_cnt > ul_max) ul_max = ul_cnt;
} }
@@ -9258,7 +9739,7 @@ float len_rat, uint32_t is_trio, uint32_t topo_level, uint32_t *max_drop_len, as
} }
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
} }
@@ -9486,7 +9967,7 @@ asg64_v *in, asg64_v *ib)
if (nv < 2) continue; if (nv < 2) continue;
for (i = kv = 0; i < nv && kv < 2; ++i) { for (i = kv = 0; i < nv && kv < 2; ++i) {
if(av[i].del) continue; kv++; if(av[i].del) {continue;} kv++;
} }
if(kv < 2) continue; if(kv < 2) continue;
@@ -9589,7 +10070,7 @@ asg64_v *in, asg64_v *ib)
} }
} }
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
return cnt; return cnt;
} }
@@ -9846,7 +10327,7 @@ uint64_t ulg_pop_bubble(ul_resolve_t *uidx, ma_ug_t *ug, uint64_t* i_max_dist, u
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a); free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
if(n_pop) asg_cleanup(g); if(n_pop) asg_cleanup(g);
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
// fprintf(stderr, "[M::%s::] Done...\n", __func__); // fprintf(stderr, "[M::%s::] Done...\n", __func__);
return n_pop; return n_pop;
} }
@@ -10060,7 +10541,7 @@ uint32_t skip_hom, uint32_t *max_drop_len, asg64_v *in, asg64_v *ib)
av = asg_arc_a(g, v); nv = asg_arc_n(g, v); av = asg_arc_a(g, v); nv = asg_arc_n(g, v);
if (nv < 2) continue; if (nv < 2) continue;
for (i = kv = 0; i < nv && kv <= 2; ++i) { for (i = kv = 0; i < nv && kv <= 2; ++i) {
if(av[i].del) continue; kv++; if(av[i].del) {continue;} kv++;
} }
if(kv != 2) continue; if(kv != 2) continue;
for (i = 0; i < nv; ++i) { for (i = 0; i < nv; ++i) {
@@ -10209,7 +10690,7 @@ uint32_t skip_hom, uint32_t *max_drop_len, asg64_v *in, asg64_v *ib)
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
if (cnt > 0) asg_cleanup(g); if (cnt > 0) asg_cleanup(g);
// fprintf(stderr, "[M::%s::] cnt::%u\n", __func__, cnt); // fprintf(stderr, "[M::%s::] cnt::%u\n", __func__, cnt);
return cnt; return cnt;
@@ -10683,7 +11164,7 @@ uint32_t is_topo, uint32_t *max_drop_len)
// } // }
asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL; asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL;
uint32_t i, k, v, w, n_vtx = g->n<<1, nv, nw, kv, kw, /**trioF = (uint32_t)-1, ntrioF = (uint32_t)-1,**/ ol_max, ou_max, to_del, cnt = 0, mm_ol; uint32_t i, k, v, w, n_vtx = g->n<<1, nv, nw, kv, kw, /**trioF = (uint32_t)-1, ntrioF = (uint32_t)-1,**/ ol_max, ou_max, to_del, cnt = 0, mm_ol;
usg_arc_t *av, *aw, *ve, *we; uint64_t x, kocc[2], ou; uint8_t *f; CALLOC(f, g->n); usg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL; uint64_t x, kocc[2], ou; uint8_t *f; CALLOC(f, g->n);
b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz)); b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz));
for (v = 0, b->n = ub->n = 0; v < n_vtx; ++v) { for (v = 0, b->n = ub->n = 0; v < n_vtx; ++v) {
@@ -10807,7 +11288,7 @@ uint32_t is_topo, uint32_t *max_drop_len)
// } // }
} }
if(in_0) free(tx.a); if(in_1) free(tz.a); if(in_0) {free(tx.a);} if(in_1) {free(tz.a);}
if (cnt > 0) usg_cleanup(g); if (cnt > 0) usg_cleanup(g);
free(f); free(f);
// fprintf(stderr, "-[M::%s::] max_ext::%d, len_rat::%f\n", __func__, max_ext, len_rat); // fprintf(stderr, "-[M::%s::] max_ext::%d, len_rat::%f\n", __func__, max_ext, len_rat);
@@ -10818,7 +11299,7 @@ uint32_t is_topo, uint32_t *max_drop_len, uint8_t *ff)
{ {
asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL; asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL;
uint32_t i, k, v, w, n_vtx = g->n<<1, nv, nw, kv, kw, /**trioF = (uint32_t)-1, ntrioF = (uint32_t)-1,**/ ol_max, ou_max, to_del, cnt = 0, mm_ol; uint32_t i, k, v, w, n_vtx = g->n<<1, nv, nw, kv, kw, /**trioF = (uint32_t)-1, ntrioF = (uint32_t)-1,**/ ol_max, ou_max, to_del, cnt = 0, mm_ol;
usg_arc_t *av, *aw, *ve, *we; uint64_t x, kocc[2]; uint8_t *f; CALLOC(f, g->n); usg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL; uint64_t x, kocc[2]; uint8_t *f; CALLOC(f, g->n);
b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz)); b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz));
for (v = 0, b->n = ub->n = 0; v < n_vtx; ++v) { for (v = 0, b->n = ub->n = 0; v < n_vtx; ++v) {
@@ -10937,7 +11418,7 @@ uint32_t is_topo, uint32_t *max_drop_len, uint8_t *ff)
// } // }
} }
if(in_0) free(tx.a); if(in_1) free(tz.a); if(in_0) {free(tx.a);} if(in_1) {free(tz.a);}
if (cnt > 0) usg_cleanup(g); if (cnt > 0) usg_cleanup(g);
free(f); free(f);
// fprintf(stderr, "-[M::%s::] max_ext::%d, len_rat::%f\n", __func__, max_ext, len_rat); // fprintf(stderr, "-[M::%s::] max_ext::%d, len_rat::%f\n", __func__, max_ext, len_rat);
@@ -10972,9 +11453,9 @@ uint64_t* nodeLen, uint64_t* baseLen, uint64_t *occ, asg64_v* b)
if(nodeLen) (*nodeLen) += g->a[v>>1].occ; if(nodeLen) (*nodeLen) += g->a[v>>1].occ;
if(b) kv_push(uint64_t, *b, v); if(b) kv_push(uint64_t, *b, v);
if(occ) (*occ)++; if(occ) {(*occ)++;}
///means reach the end of a unitig ///means reach the end of a unitig
if(kv!=1 && baseLen) (*baseLen) += g->a[v>>1].len; if((kv!=1) && (baseLen)) {(*baseLen) += g->a[v>>1].len;}
if(kv==0) { if(kv==0) {
return_flag = END_TIPS; break; return_flag = END_TIPS; break;
} }
@@ -11501,7 +11982,7 @@ void u2g_hybrid_extend(usg_t *ng, uint64_t* i_max_dist, asg64_v *in, asg64_v *ib
free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a); free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
if(n_pop) usg_cleanup(ng); if(n_pop) usg_cleanup(ng);
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
} }
@@ -13460,7 +13941,7 @@ void u2g_hybrid_detan(ul_resolve_t *uidx, usg_t *ng, uint32_t max_ext, asg64_v *
// fprintf(stderr, "-[M::%s::] ng->n::%u\n", __func__, (uint32_t)ng->n); // fprintf(stderr, "-[M::%s::] ng->n::%u\n", __func__, (uint32_t)ng->n);
} }
// prt_usg_t(uidx, ng, "ng_dbg"); // prt_usg_t(uidx, ng, "ng_dbg");
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
} }
void u2g_hybrid_aln(ul_resolve_t *uidx, usg_t *ng, asg64_v *ob, asg64_v *ub) void u2g_hybrid_aln(ul_resolve_t *uidx, usg_t *ng, asg64_v *ob, asg64_v *ub)
@@ -15096,7 +15577,7 @@ void u2g_hybrid_detan_iter(ul_resolve_t *uidx, usg_t *ng, uint32_t max_ext, uint
// } // }
// prt_usg_t(uidx, ng, "ng1"); // prt_usg_t(uidx, ng, "ng1");
if(!in) free(tx.a); if(!ib) free(tb.a); if(!in) {free(tx.a);} if(!ib) {free(tb.a);}
free(ng_occ); free(i_idx); free(ff); kv_destroy(b64); kv_destroy(ub64); free(ng_occ); free(i_idx); free(ff); kv_destroy(b64); kv_destroy(ub64);
} }
@@ -15538,7 +16019,7 @@ uint32_t is_topo, int32_t max_ext, float len_rat, uint8_t *f, asg64_v *in_0, asg
{ {
uint32_t i, k, v, w, nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, tip_v, mm_ol; uint32_t i, k, v, w, nv, nw, kv, kw, ol_max, ou_max, to_del, cnt = 0, tip_v, mm_ol;
asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL; int32_t n_tip, r_tip; asg64_v tx = {0,0,0}, tz = {0,0,0}, *b = NULL, *ub = NULL; int32_t n_tip, r_tip;
uint64_t kocc[2]; usg_arc_t *av, *aw, *ve, *we; uint64_t kocc[2]; usg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL;
b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz)); b = ((in_0)?(in_0):(&tx)); ub = ((in_1)?(in_1):(&tz));
for (k = b->n = ub->n = 0; k < a_n; ++k) { for (k = b->n = ub->n = 0; k < a_n; ++k) {
@@ -15605,10 +16086,10 @@ uint32_t is_topo, int32_t max_ext, float len_rat, uint8_t *f, asg64_v *in_0, asg
to_del = 1; to_del = 1;
} else if (kw == 1) { } else if (kw == 1) {
n_tip = usg_naive_topocut_aux(g, w^1, max_ext, f, b, ub); n_tip = usg_naive_topocut_aux(g, w^1, max_ext, f, b, ub);
if (n_tip < max_ext) to_del = 1; tip_v = w^1; if (n_tip < max_ext) {to_del = 1;} tip_v = w^1;
} else if (kv == 1) { } else if (kv == 1) {
n_tip = usg_naive_topocut_aux(g, v^1, max_ext, f, b, ub); n_tip = usg_naive_topocut_aux(g, v^1, max_ext, f, b, ub);
if (n_tip < max_ext) to_del = 1; tip_v = v^1; if (n_tip < max_ext) {to_del = 1;} tip_v = v^1;
} }
} }
@@ -15622,7 +16103,7 @@ uint32_t is_topo, int32_t max_ext, float len_rat, uint8_t *f, asg64_v *in_0, asg
} }
} }
if(in_0) free(tx.a); if(in_1) free(tz.a); if(in_0) {free(tx.a);} if(in_1) {free(tz.a);}
return cnt; return cnt;
} }
@@ -16431,7 +16912,7 @@ void renew_u2g_bg(ul_resolve_t *uidx)
for (v = 0, n_vtx = bg->bg->n_seq<<1; v < n_vtx; v++) { for (v = 0, n_vtx = bg->bg->n_seq<<1; v < n_vtx; v++) {
if(bg->bg->seq[v>>1].del) continue; if(bg->bg->seq[v>>1].del) continue;
av = asg_arc_a(bg->bg, v); nv = asg_arc_n(bg->bg, v); av = asg_arc_a(bg->bg, v); nv = asg_arc_n(bg->bg, v);
if(!nv) continue; w = av[0].v; if(!nv) {continue;} w = av[0].v;
v_occ[0] = v_occ[1] = w_occ[0] = w_occ[1] = (uint32_t)-1; v_occ[0] = v_occ[1] = w_occ[0] = w_occ[1] = (uint32_t)-1;
av = asg_arc_a(bg->bg, v); nv = asg_arc_n(bg->bg, v); av = asg_arc_a(bg->bg, v); nv = asg_arc_n(bg->bg, v);
@@ -17401,7 +17882,7 @@ ul_renew_t *ropt, const char *bin_file, uint64_t free_uld, uint64_t is_bridg, ui
(*(ropt->src)) = R_INF.paf; (*(ropt->r_src)) = R_INF.reverse_paf; (*(ropt->src)) = R_INF.paf; (*(ropt->r_src)) = R_INF.reverse_paf;
(*(ropt->n_read)) = R_INF.total_reads; (*(ropt->readLen)) = R_INF.read_length; (*(ropt->n_read)) = R_INF.total_reads; (*(ropt->readLen)) = R_INF.read_length;
renew_R_to_U(ng, (*(ropt->src)), (*(ropt->r_src)), (*(ropt->n_read)), (*(ropt->cov)), ropt->ruIndex, ropt->max_hang, ropt->mini_ovlp); renew_R_to_U(ng, (*(ropt->src)), (*(ropt->r_src)), (*(ropt->n_read)), (*(ropt->cov)), ropt->ruIndex, ropt->max_hang, ropt->mini_ovlp);
post_rescue(uopt, (*(ropt->sg)), (*(ropt->src)), (*(ropt->r_src)), ropt->ruIndex, ropt->b_mask_t, 0); post_rescue(uopt, (*(ropt->sg)), (*(ropt->src)), (*(ropt->r_src)), ropt->ruIndex, ropt->b_mask_t, 0, NULL);
// print_raw_uls_aln(uidx, asm_opt.output_file_name); // print_raw_uls_aln(uidx, asm_opt.output_file_name);
// exit(0); // exit(0);
} }
@@ -17557,7 +18038,7 @@ int usg_topocut_aux_del(ma_ug_t *ug, uint32_t v, int max_ext, asg64_v *b)
int32_t n_ext; int32_t n_ext;
for (n_ext = 0; n_ext < max_ext && v != (uint32_t)-1; ) { for (n_ext = 0; n_ext < max_ext && v != (uint32_t)-1; ) {
if (usg_topocut_aux_unambi1(ug->g, v^1) == (uint32_t)-1) break; if (usg_topocut_aux_unambi1(ug->g, v^1) == (uint32_t)-1) break;
if(b) kv_push(uint64_t, *b, v); n_ext += ug->u.a[v>>1].n; if(b) {kv_push(uint64_t, *b, v);} n_ext += ug->u.a[v>>1].n;
v = usg_topocut_aux_unambi1(ug->g, v); v = usg_topocut_aux_unambi1(ug->g, v);
} }
return n_ext; return n_ext;
@@ -17606,7 +18087,7 @@ uint32_t min_node)
// fprintf(stderr, "[M::%s]\tStart\n", __func__); // fprintf(stderr, "[M::%s]\tStart\n", __func__);
ma_ug_t *ug = sl->ug; asg_t *g = sl->ug->g; uint32_t ol_max, ou_max, lnid; ma_ug_t *ug = sl->ug; asg_t *g = sl->ug->g; uint32_t ol_max, ou_max, lnid;
uint32_t v, w, n_vtx = (g->n_seq<<1), nv, nw, i, k, z, kv, kw, bb, to_del, bn, tip; uint32_t v, w, n_vtx = (g->n_seq<<1), nv, nw, i, k, z, kv, kw, bb, to_del, bn, tip;
asg64_v tx = {0,0,0}, *b = NULL; asg_arc_t *av, *aw, *ve, *we; ma_utg_t *u; asg64_v tx = {0,0,0}, *b = NULL; asg_arc_t *av = NULL, *aw = NULL, *ve = NULL, *we = NULL; ma_utg_t *u;
uint32_t trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, mm_ol, mm_ou, cnt = 0, del_v, del_w; uint32_t trioF = (uint32_t)-1, ntrioF = (uint32_t)-1, mm_ol, mm_ou, cnt = 0, del_v, del_w;
if(in) b = in; if(in) b = in;
+3 -2
View File
@@ -16,7 +16,7 @@ typedef struct {
} sset_aux; } 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, 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, char *o_file); 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); 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_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_chimeric(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, uint32_t ou_thres, telo_end_t *te);
@@ -33,7 +33,7 @@ void recover_contain_g(asg_t *g, ma_hit_t_alloc *src, R_to_U* ruIndex, int64_t m
void normalize_gou(asg_t *g); void normalize_gou(asg_t *g);
void prt_specfic_sge(asg_t *g, uint32_t src, uint32_t dst, const char* cmd); 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); 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); 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); // 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); 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 filter_sg_by_ug(asg_t *rg, ma_ug_t *ug, ug_opt_t *uopt);
@@ -41,5 +41,6 @@ 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); 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); 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); 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 #endif
+1 -1
View File
@@ -6569,7 +6569,7 @@ min_cut_t* m, hc_links* link, G_partition* x)
if(res->full_bub == 0) if(res->full_bub == 0)
{ {
res->a.n = 0; res->a.n = 0;
uint32_t v, u = 0, uv, k_n, pre_n = x->n; uint32_t v, u = 0, uv = UINT32_MAX, k_n, pre_n = x->n;
hc_linkeage* t = NULL; hc_linkeage* t = NULL;
x->n--; x->n--;
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
+2 -2
View File
@@ -32,7 +32,7 @@ KRADIX_SORT_INIT(osg, osg_arc_t, osg_arc_key, member_size(osg_arc_t, u))
#define BREAK_CUTOFF 0.1 #define BREAK_CUTOFF 0.1
#define BREAK_BOUNDARY 0.015 #define BREAK_BOUNDARY 0.015
void reduce_hamming_error_adv(ma_ug_t *iug, asg_t *sg, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut, void reduce_hamming_error_adv(ma_ug_t *iug, asg_t *sg, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut,
int max_hang, int min_ovlp, long long gap_fuzz, R_to_U *ru, bubble_type* bub); int max_hang, int min_ovlp, long long gap_fuzz, R_to_U *ru, bubble_type* bub, uint32_t max_ext);
typedef struct { typedef struct {
uint64_t ruid; uint64_t ruid;
@@ -3936,7 +3936,7 @@ asg_t *i_rg, ma_ug_t* i_ug, bubble_type* bub, kv_u_trans_t *ref, ug_opt_t *opt,
// output_hic_rtg(i_ug, h->r_g, opt, asm_opt.output_file_name); // output_hic_rtg(i_ug, h->r_g, opt, asm_opt.output_file_name);
// reduce_hamming_error(h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz); // reduce_hamming_error(h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz);
reduce_hamming_error_adv(NULL, h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz, opt->ruIndex, NULL); reduce_hamming_error_adv(NULL, h->r_g, opt->sources, opt->coverage_cut, opt->max_hang, opt->min_ovlp, opt->gap_fuzz, opt->ruIndex, NULL, (asm_opt.max_short_tip*2));
/** /**
scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, FATHER); scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, FATHER);
scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, MOTHER); scaffold_hap(h, t_idx, opt, round, asm_opt.output_file_name, MOTHER);
+234 -26
View File
@@ -9,6 +9,7 @@
#include "ksort.h" #include "ksort.h"
#include "htab.h" #include "htab.h"
#include "Process_Read.h" #include "Process_Read.h"
#include "ecovlp.h"
#define YAK_COUNTER_BITS 12 #define YAK_COUNTER_BITS 12
#define YAK_N_COUNTS (1<<YAK_COUNTER_BITS) #define YAK_N_COUNTS (1<<YAK_COUNTER_BITS)
@@ -385,7 +386,7 @@ ha_pt_t *ha_pt_gen(ha_ct_t *ct, int n_thread, int is_l)
ha_ct_destroy_bf(ct); ha_ct_destroy_bf(ct);
CALLOC(pt, 1); CALLOC(pt, 1);
pt->k = ct->k, pt->pre = ct->pre, pt->tot = ct->tot; pt->k = ct->k, pt->pre = ct->pre, pt->tot = ct->tot;
CALLOC(pt->h, 1<<pt->pre); CALLOC(pt->h, (((uint64_t)1)<<pt->pre));
for (i = 0; i < 1<<pt->pre; ++i) { for (i = 0; i < 1<<pt->pre; ++i) {
pt->h[i].h = yak_pt_init(); pt->h[i].h = yak_pt_init();
yak_pt_resize(pt->h[i].h, kh_size(ct->h[i].h)); yak_pt_resize(pt->h[i].h, kh_size(ct->h[i].h));
@@ -422,7 +423,7 @@ ha_pt_t *ha_pt_gen_count(ha_ct_t *ct, int n_thread)
ha_ct_destroy_bf(ct); ha_ct_destroy_bf(ct);
CALLOC(pt, 1); CALLOC(pt, 1);
pt->k = ct->k, pt->pre = ct->pre, pt->tot = ct->tot; pt->k = ct->k, pt->pre = ct->pre, pt->tot = ct->tot;
CALLOC(pt->h, 1<<pt->pre); CALLOC(pt->h, (((uint64_t)1)<<pt->pre));
for (i = 0; i < 1<<pt->pre; ++i) { for (i = 0; i < 1<<pt->pre; ++i) {
pt->h[i].h = yak_pt_init(); pt->h[i].h = yak_pt_init();
yak_pt_resize(pt->h[i].h, kh_size(ct->h[i].h)); yak_pt_resize(pt->h[i].h, kh_size(ct->h[i].h));
@@ -546,6 +547,21 @@ const int ha_pt_cnt(const ha_pt_t *h, uint64_t hash)
return kh_key(g->h, k) & YAK_MAX_COUNT; return kh_key(g->h, k) & YAK_MAX_COUNT;
} }
inline uint64_t flt_quals(char *sc_a, uint64_t sc_l, uint64_t sc_off, int64_t sc_cut)
{
int64_t sc_min = sc_l * sc_cut, sc_tot; uint64_t k;
for (k = sc_tot = 0; (k < sc_l) && (sc_tot < sc_min); k++) {
sc_tot += (((uint8_t)sc_a[k]) - sc_off);
}
// if(sc_tot < sc_min) {
// fprintf(stderr, "[M::%s] sc_tot::%ld, sc_min::%ld, sc_l::%lu\n", __func__, sc_tot, sc_min, sc_l);
// }
if(sc_tot < sc_min) return 0;
return 1;
}
/********************************** /**********************************
* Buffer for counting all k-mers * * Buffer for counting all k-mers *
**********************************/ **********************************/
@@ -563,7 +579,7 @@ KSEQ_INIT(gzFile, gzread)
typedef struct { // global data structure for kt_pipeline() typedef struct { // global data structure for kt_pipeline()
const yak_copt_t *opt; const yak_copt_t *opt;
const void *flt_tab; const void *flt_tab;
int flag, create_new, is_store, uq; int flag, create_new, is_store, uq, ifq;
uint64_t n_mz, n_seq; ///number of total reads uint64_t n_mz, n_seq; ///number of total reads
kseq_t *ks; kseq_t *ks;
UC_Read ucr; UC_Read ucr;
@@ -692,6 +708,7 @@ static inline void sf##_pt_insert_buf(sf##_ch_buf_t *buf, int p, const HType *y)
static void *sf##_worker_count(void *data, int step, void *in) /** callback for kt_pipeline()**/\ static void *sf##_worker_count(void *data, int step, void *in) /** callback for kt_pipeline()**/\
{\ {\
pl_data_t *p = (pl_data_t*)data;\ pl_data_t *p = (pl_data_t*)data;\
/**uint8_t src_a[1000000], des_a[1000000];**/\
if (step == 0) { /** step 1: read a block of sequences**/\ if (step == 0) { /** step 1: read a block of sequences**/\
int ret;\ int ret;\
sf##_st_data_t *s;\ sf##_st_data_t *s;\
@@ -744,7 +761,8 @@ static void *sf##_worker_count(void *data, int step, void *in) /** callback for
} else {\ } else {\
while ((ret = kseq_read(p->ks)) >= 0) {\ while ((ret = kseq_read(p->ks)) >= 0) {\
int l = (int)(p->ks->seq.l) - (int)(p->opt->adaLen) - (int)(p->opt->adaLen);\ int l = (int)(p->ks->seq.l) - (int)(p->opt->adaLen) - (int)(p->opt->adaLen);\
if(l <= 0) continue;\ if((l <= 0) || (l < asm_opt.rl_cut)) continue;\
if((p->ifq) && (asm_opt.sc_cut > 0) && (!flt_quals(p->ks->qual.s+p->opt->adaLen, l, 33, asm_opt.sc_cut))) continue;\
if (p->n_seq >= 1<<28) {\ if (p->n_seq >= 1<<28) {\
fprintf(stderr, "ERROR: this implementation supports no more than %d reads\n", 1<<28);\ fprintf(stderr, "ERROR: this implementation supports no more than %d reads\n", 1<<28);\
exit(1);\ exit(1);\
@@ -762,6 +780,16 @@ static void *sf##_worker_count(void *data, int step, void *in) /** callback for
++n_N;\ ++n_N;\
ha_compress_base(Get_READ(*p->rs_out, p->n_seq), p->ks->seq.s+p->opt->adaLen, l, &p->rs_out->N_site[p->n_seq], n_N);\ ha_compress_base(Get_READ(*p->rs_out, p->n_seq), p->ks->seq.s+p->opt->adaLen, l, &p->rs_out->N_site[p->n_seq], n_N);\
memcpy(&p->rs_out->name[p->rs_out->name_index[p->n_seq]], p->ks->name.s, p->ks->name.l);\ memcpy(&p->rs_out->name[p->rs_out->name_index[p->n_seq]], p->ks->name.s, p->ks->name.l);\
if(p->ifq) {\
ha_compress_qual(Get_QUAL(*p->rs_out, p->n_seq), p->ks->qual.s+p->opt->adaLen, l, sc_bn, 33);\
/**print_fastq(NULL, p->ks->name.s, p->ks->seq.s, p->ks->qual.s, (1<<sc_bn), 33);**/\
/**if(l <= 1000000) {\
convert_qual(src_a, p->ks->qual.s+p->opt->adaLen, l, (1<<sc_bn), 0, 33);\
retrive_bqual(NULL, des_a, p->n_seq, -1, -1, 0, sc_bn);\
if(memcmp(src_a, des_a, l)!=0) fprintf(stderr, "ERROR: incorrect qual values\n");\
else fprintf(stderr, "Correct: correct qual values\n");\
}**/\
}\
}\ }\
}\ }\
if (s->n_seq == s->m_seq) {\ if (s->n_seq == s->m_seq) {\
@@ -809,7 +837,7 @@ static void *sf##_worker_count(void *data, int step, void *in) /** callback for
uint32_t j;\ uint32_t j;\
/**s->n_seq is how many reads at this buffer**/\ /**s->n_seq is how many reads at this buffer**/\
/**s->mz && s->mz_buf are lists of minimzer vectors**/\ /**s->mz && s->mz_buf are lists of minimzer vectors**/\
CALLOC(s->mz, s->n_seq), CALLOC(s->mz_buf, p->opt->n_thread), CALLOC(s->mt, p->opt->n_thread);\ CALLOC(s->mz, s->n_seq); CALLOC(s->mz_buf, p->opt->n_thread); CALLOC(s->mt, p->opt->n_thread);\
/**calculate minimzers for each read, each read corresponds to one thread**/\ /**calculate minimzers for each read, each read corresponds to one thread**/\
kt_for(p->opt->n_thread, sf##_worker_for_mz, s, s->n_seq);\ kt_for(p->opt->n_thread, sf##_worker_for_mz, s, s->n_seq);\
for (i = 0; i < p->opt->n_thread; ++i) free(s->mt[i].a), free(s->mz_buf[i].a);\ for (i = 0; i < p->opt->n_thread; ++i) free(s->mt[i].a), free(s->mz_buf[i].a);\
@@ -900,7 +928,7 @@ void debug_adapter(const hifiasm_opt_t *asm_opt, All_reads *rs)
exit(1); exit(1);
} }
static ha_ct_t *yak_count(const yak_copt_t *opt, const char *fn, int flag, ha_pt_t *p0, ha_ct_t *c0, const void *flt_tab, All_reads *rs, ma_utg_v *us, int64_t *n_seq) static ha_ct_t *yak_count(const yak_copt_t *opt, const char *fn, int flag, ha_pt_t *p0, ha_ct_t *c0, const void *flt_tab, All_reads *rs, ma_utg_v *us, int64_t *n_seq, uint8_t ifq)
{ {
///for 0-th counting, flag = HAF_COUNT_ALL|HAF_RS_WRITE_LEN|HAF_CREATE_NEW ///for 0-th counting, flag = HAF_COUNT_ALL|HAF_RS_WRITE_LEN|HAF_CREATE_NEW
int read_rs = (rs && (flag & HAF_RS_READ)); int read_rs = (rs && (flag & HAF_RS_READ));
@@ -908,7 +936,7 @@ static ha_ct_t *yak_count(const yak_copt_t *opt, const char *fn, int flag, ha_pt
pl_data_t pl; pl_data_t pl;
gzFile fp = 0; gzFile fp = 0;
memset(&pl, 0, sizeof(pl_data_t)); memset(&pl, 0, sizeof(pl_data_t));
pl.n_seq = *n_seq; pl.n_seq = *n_seq; pl.ifq = ifq;
if(ug_rs) { if(ug_rs) {
pl.us_in = us; pl.us_in = us;
} else if (read_rs) { } else if (read_rs) {
@@ -980,11 +1008,38 @@ ha_ct_t *ha_count(const hifiasm_opt_t *asm_o, int flag, int HPC, int k, int w, h
opt.adaLen = (keep_adapter? asm_o->adapterLen : 0); opt.adaLen = (keep_adapter? asm_o->adapterLen : 0);
opt.min_rcnt = (low_freq?*low_freq:-1); opt.min_rcnt = (low_freq?*low_freq:-1);
opt.uq = (unique_only?1:0); opt.uq = (unique_only?1:0);
///asm_opt->num_reads is the number of fastq files
for (i = n_bs = 0; i < (us?1:asm_o->num_reads); ++i){ n_bs = 0;
h = yak_count(&opt, asm_o->read_file_names[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq); ///pending for integration
/**
if(rs && asm_o->ar && asm_o->ul_mod) {
for (i = 0; i < asm_o->ar->n; ++i){
h = yak_count(&opt, asm_o->ar->a[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq);
if(h) n_bs += h->bs; if(h) n_bs += h->bs;
} }
}**/
///asm_opt->num_reads is the number of fastq files
for (i = 0; i < (us?1:asm_o->num_reads); ++i){
h = yak_count(&opt, asm_o->read_file_names[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq, asm_opt.is_sc);
if(h) n_bs += h->bs;
}
if((rs) && (flag & HAF_RS_WRITE_LEN) && (asm_opt.is_sc)) {
rs->tqn = rs->total_reads; rs->tr[0] = rs->total_reads_bases;
}
if((asm_o->hf) && (!us)) {
for (i = 0; i < asm_o->hf->n; ++i) {
h = yak_count(&opt, asm_o->hf->a[i], flag|HAF_CREATE_NEW, p0, h, flt_tab, rs, us, &n_seq, 0);
if(h) n_bs += h->bs;
}
}
if((rs) && (flag & HAF_RS_WRITE_LEN) && (asm_opt.is_sc)) {
rs->tr[1] = rs->total_reads_bases - rs->tr[0];
}
// fprintf(stderr, "[M::%s]\t# tqn::%lu, Ont base::%lu, # HiFi bases::%lu\n", __func__, R_INF.tqn, R_INF.tr[0], R_INF.tr[1]);
if(h) h->bs = n_bs; if(h) h->bs = n_bs;
if (h && opt.bf_shift > 0) if (h && opt.bf_shift > 0)
ha_ct_destroy_bf(h); ha_ct_destroy_bf(h);
@@ -1066,13 +1121,26 @@ void debug_ct_index(void* q_ct_idx, void* r_ct_idx)
/************************* /*************************
* High-level interfaces * * High-level interfaces *
*************************/ *************************/
void *ha_ft_ul_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int k, int w, int cutoff)
int64_t ha_ct_ug_cutoff(ha_ct_t *h, int64_t num_thre, double cut_rate)
{ {
yak_ft_t *flt_tab; int64_t cnt[YAK_N_COUNTS], k, tot_n = 0, tot_cutn = 0;
ha_ct_t *h; ha_ct_hist(h, cnt, num_thre);
for (k = tot_n = 0; k < YAK_N_COUNTS; k++) tot_n += cnt[k];
tot_cutn = tot_n - (tot_n*cut_rate);
for (k = tot_n = 0; k < YAK_N_COUNTS && tot_n < tot_cutn; k++) tot_n += cnt[k];
return k;
}
void *ha_ft_ul_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int k, int w, int cutoff, int max_cutoff)
{
yak_ft_t *flt_tab; ha_ct_t *h;
///HAF_COUNT_EXACT ---> no bf; HAF_COUNT_ALL ---> no minimizer ///HAF_COUNT_EXACT ---> no bf; HAF_COUNT_ALL ---> no minimizer
h = ha_count(asm_opt, HAF_COUNT_ALL|HAF_UG_READ, !(asm_opt->flag&HA_F_NO_HPC), k, w, NULL, NULL, NULL, us, 0, NULL, 0); h = ha_count(asm_opt, HAF_COUNT_ALL|HAF_UG_READ, !(asm_opt->flag&HA_F_NO_HPC), k, w, NULL, NULL, NULL, us, 0, NULL, 0);
if(cutoff < 0) cutoff = ha_ct_ug_cutoff(h, asm_opt->thread_num, 0.0002);
if(cutoff > max_cutoff) cutoff = max_cutoff;
// cutoff = (int)(asm_opt->hom_cov * asm_opt->high_factor); // cutoff = (int)(asm_opt->hom_cov * asm_opt->high_factor);
if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1; if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1;
// fprintf(stderr, "[M::%s::] cutoff->%d\n\n", __func__, cutoff); // fprintf(stderr, "[M::%s::] cutoff->%d\n\n", __func__, cutoff);
@@ -1084,12 +1152,20 @@ void *ha_ft_ul_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int k, int w, int
return (void*)flt_tab; return (void*)flt_tab;
} }
void *ha_ft_ug_gen(const 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_ug_gen(hifiasm_opt_t *asm_opt, ma_utg_v *us, int is_HPC, int k, int w, int min_freq, int max_freq)
{ {
yak_ft_t *flt_tab; yak_ft_t *flt_tab;
ha_ct_t *h; ha_ct_t *h; ///int32_t b0;
// if(min_freq < 0 || max_freq < 0) {
// b0 = asm_opt->bf_shift; asm_opt->bf_shift = 0;
// }
///HAF_COUNT_EXACT ---> no bf; HAF_COUNT_ALL ---> no minimizer ///HAF_COUNT_EXACT ---> no bf; HAF_COUNT_ALL ---> no minimizer
h = ha_count(asm_opt, HAF_COUNT_ALL|HAF_UG_READ|HAF_COUNT_EXACT, is_HPC, k, w, NULL, NULL, NULL, us, 0, NULL, 0); h = ha_count(asm_opt, HAF_COUNT_ALL|HAF_UG_READ|HAF_COUNT_EXACT, is_HPC, k, w, NULL, NULL, NULL, us, 0, NULL, 0);
// if(min_freq < 0 || max_freq < 0) {
// asm_opt->bf_shift = b0;
// }
ha_ct_shrink(h, min_freq, max_freq>YAK_MAX_COUNT-1?YAK_MAX_COUNT-1:max_freq, asm_opt->thread_num); ha_ct_shrink(h, min_freq, max_freq>YAK_MAX_COUNT-1?YAK_MAX_COUNT-1:max_freq, asm_opt->thread_num);
flt_tab = gen_hh(h, YAK_MAX_COUNT); flt_tab = gen_hh(h, YAK_MAX_COUNT);
ha_ct_destroy(h); ha_ct_destroy(h);
@@ -1104,7 +1180,7 @@ void *ha_ft_gen(const hifiasm_opt_t *asm_opt, All_reads *rs, int *hom_cov, int i
if(is_hp_mode) ex_flag = HAF_RS_READ|HAF_SKIP_READ; if(is_hp_mode) ex_flag = HAF_RS_READ|HAF_SKIP_READ;
ha_ct_t *h; ha_ct_t *h;
h = ha_count(asm_opt, HAF_COUNT_ALL|ex_flag|((read_from_store)?(HAF_RS_READ):(HAF_RS_WRITE_LEN)), !(asm_opt->flag&HA_F_NO_HPC), asm_opt->k_mer_length, asm_opt->mz_win, NULL, NULL, rs, NULL, 1, NULL, 0); h = ha_count(asm_opt, HAF_COUNT_ALL|ex_flag|((read_from_store)?(HAF_RS_READ):(HAF_RS_WRITE_LEN)), !(asm_opt->flag&HA_F_NO_HPC), asm_opt->k_mer_length, asm_opt->mz_win, NULL, NULL, rs, NULL, 1, NULL, 0);
if((asm_opt->flag & HA_F_VERBOSE_GFA)) if((asm_opt->flag & HA_F_VERBOSE_GFA) || (asm_opt->restart))
{ {
write_ct_index((void*)h, asm_opt->output_file_name); write_ct_index((void*)h, asm_opt->output_file_name);
// load_ct_index(&ha_ct_table, asm_opt->output_file_name); // load_ct_index(&ha_ct_table, asm_opt->output_file_name);
@@ -1117,10 +1193,20 @@ void *ha_ft_gen(const hifiasm_opt_t *asm_opt, All_reads *rs, int *hom_cov, int i
{ {
ha_ct_hist(h, cnt, asm_opt->thread_num); ha_ct_hist(h, cnt, asm_opt->thread_num);
peak_hom = ha_analyze_count(YAK_N_COUNTS, asm_opt->min_hist_kmer_cnt, asm_opt->hg_size>0?(h->bs/asm_opt->hg_size):(-1), cnt, &peak_het); peak_hom = ha_analyze_count(YAK_N_COUNTS, asm_opt->min_hist_kmer_cnt, asm_opt->hg_size>0?(h->bs/asm_opt->hg_size):(-1), cnt, &peak_het);
///r850
fprintf(stderr, "[M::%s::auto] inferred peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
if((asm_opt->het_cov_ss > 0) || (asm_opt->hmo_cov_ss > 0)) {
fprintf(stderr, "[M::%s::user] override requested peak_hom: %ld; peak_het: %ld\n", __func__, asm_opt->hmo_cov_ss, asm_opt->het_cov_ss);
if(asm_opt->hmo_cov_ss > 0) peak_hom = asm_opt->hmo_cov_ss;
if(asm_opt->het_cov_ss > 0) peak_het = asm_opt->het_cov_ss;
}
if (hom_cov) *hom_cov = peak_hom; if (hom_cov) *hom_cov = peak_hom;
if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het); if (peak_hom > 0) fprintf(stderr, "[M::%s::final] using peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
///in default, asm_opt->high_factor = 5.0 ///in default, asm_opt->high_factor = 5.0
///r833
cutoff = (int)(peak_hom * asm_opt->high_factor); cutoff = (int)(peak_hom * asm_opt->high_factor);
if(cutoff < asm_opt->hf_cutoff) cutoff = asm_opt->hf_cutoff;
if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1; if (cutoff > YAK_MAX_COUNT - 1) cutoff = YAK_MAX_COUNT - 1;
} }
ha_ct_shrink(h, cutoff, YAK_MAX_COUNT, asm_opt->thread_num); ha_ct_shrink(h, cutoff, YAK_MAX_COUNT, asm_opt->thread_num);
@@ -1215,9 +1301,16 @@ ha_pt_t *ha_pt_gen(const hifiasm_opt_t *asm_opt, const void *flt_tab, int read_f
ha_ct_hist(ct, cnt, asm_opt->thread_num); ha_ct_hist(ct, cnt, asm_opt->thread_num);
fprintf(stderr, "[M::%s] count[%d] = %ld (for sanity check)\n", __func__, YAK_MAX_COUNT, (long)cnt[YAK_MAX_COUNT]); fprintf(stderr, "[M::%s] count[%d] = %ld (for sanity check)\n", __func__, YAK_MAX_COUNT, (long)cnt[YAK_MAX_COUNT]);
peak_hom = ha_analyze_count(YAK_N_COUNTS, asm_opt->min_hist_kmer_cnt, asm_opt->hg_size>0?(ct->bs/asm_opt->hg_size):(-1), cnt, &peak_het); peak_hom = ha_analyze_count(YAK_N_COUNTS, asm_opt->min_hist_kmer_cnt, asm_opt->hg_size>0?(ct->bs/asm_opt->hg_size):(-1), cnt, &peak_het);
///r850
fprintf(stderr, "[M::%s::auto] inferred peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
if((asm_opt->het_cov_ss > 0) || (asm_opt->hmo_cov_ss > 0)) {
fprintf(stderr, "[M::%s::user] override requested peak_hom: %ld; peak_het: %ld\n", __func__, asm_opt->hmo_cov_ss, asm_opt->het_cov_ss);
if(asm_opt->hmo_cov_ss > 0) peak_hom = asm_opt->hmo_cov_ss;
if(asm_opt->het_cov_ss > 0) peak_het = asm_opt->het_cov_ss;
}
if (hom_cov) *hom_cov = peak_hom; if (hom_cov) *hom_cov = peak_hom;
if (het_cov) *het_cov = peak_het; if (het_cov) *het_cov = peak_het;
if (peak_hom > 0) fprintf(stderr, "[M::%s] peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het); if (peak_hom > 0) fprintf(stderr, "[M::%s::final] using peak_hom: %d; peak_het: %d\n", __func__, peak_hom, peak_het);
///here ha_ct_shrink is mostly used to remove k-mer appearing only 1 time ///here ha_ct_shrink is mostly used to remove k-mer appearing only 1 time
if (flt_tab == 0) { if (flt_tab == 0) {
int cutoff = (int)(peak_hom * asm_opt->high_factor); int cutoff = (int)(peak_hom * asm_opt->high_factor);
@@ -1327,10 +1420,11 @@ int load_ct_index(void **i_ct_idx, char* file_name)
return 1; return 1;
} }
int write_pt_index(void *flt_tab, ha_pt_t *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)
{ {
char* gfa_name = (char*)malloc(strlen(file_name)+64); char* gfa_name = (char*)malloc(strlen(file_name)+64);
sprintf(gfa_name, "%s.pt_flt", file_name); if(r) sprintf(gfa_name, "%s.pt_flt", file_name);
else sprintf(gfa_name, "%s.pt_flt.bin", file_name);
FILE* fp = fopen(gfa_name, "w"); FILE* fp = fopen(gfa_name, "w");
if (!fp) { if (!fp) {
free(gfa_name); free(gfa_name);
@@ -1369,7 +1463,7 @@ int write_pt_index(void *flt_tab, ha_pt_t *ha_idx, All_reads* r, hifiasm_opt_t*
fwrite(&opt->het_cov, sizeof(opt->het_cov), 1, fp); fwrite(&opt->het_cov, sizeof(opt->het_cov), 1, fp);
fwrite(&opt->max_n_chain, sizeof(opt->max_n_chain), 1, fp); fwrite(&opt->max_n_chain, sizeof(opt->max_n_chain), 1, fp);
if(r) {
write_All_reads(r, gfa_name); write_All_reads(r, gfa_name);
sprintf(gfa_name, "%s.pt_flt.paf.bin", file_name); sprintf(gfa_name, "%s.pt_flt.paf.bin", file_name);
@@ -1386,16 +1480,32 @@ int write_pt_index(void *flt_tab, ha_pt_t *ha_idx, All_reads* r, hifiasm_opt_t*
fwrite(r->paf[k].buffer, sizeof((*(r->paf[k].buffer))), r->paf[k].length, fp); fwrite(r->paf[k].buffer, sizeof((*(r->paf[k].buffer))), r->paf[k].length, fp);
} }
int8_t rff = opt->post_syn;
if(force_rpaf_load) rff = 1;
fwrite(&rff, sizeof(rff), 1, fp);
if(rff) {
for (k = 0; k < r->total_reads; k++) {
fwrite(&(r->reverse_paf[k].is_fully_corrected), sizeof(r->reverse_paf[k].is_fully_corrected), 1, fp);
fwrite(&(r->reverse_paf[k].is_abnormal), sizeof(r->reverse_paf[k].is_abnormal), 1, fp);
fwrite(&(r->reverse_paf[k].length), sizeof(r->reverse_paf[k].length), 1, fp);
fwrite(r->reverse_paf[k].buffer, sizeof((*(r->reverse_paf[k].buffer))), r->reverse_paf[k].length, fp);
}
}
}
fprintf(stderr, "[M::%s] Index has been written.\n", __func__); fprintf(stderr, "[M::%s] Index has been written.\n", __func__);
free(gfa_name); free(gfa_name);
fclose(fp); fclose(fp);
return 1; return 1;
} }
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 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)
{ {
char* gfa_name = (char*)malloc(strlen(file_name)+64); char* gfa_name = (char*)malloc(strlen(file_name)+64);
sprintf(gfa_name, "%s.pt_flt", file_name); if(r) sprintf(gfa_name, "%s.pt_flt", file_name);
else sprintf(gfa_name, "%s.pt_flt.bin", file_name);
// fprintf(stderr, "[M::%s]\tgfa_name::%s\n", __func__, gfa_name);
FILE* fp = fopen(gfa_name, "r"); FILE* fp = fopen(gfa_name, "r");
if (!fp) { if (!fp) {
free(gfa_name); free(gfa_name);
@@ -1475,9 +1585,8 @@ int load_pt_index(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads *r, hifiasm_op
// fclose(fp); // fclose(fp);
if(r) {
if(!load_All_reads(r, gfa_name)) if(!load_All_reads(r, gfa_name)) {
{
free(gfa_name); free(gfa_name);
return 0; return 0;
} }
@@ -1508,6 +1617,28 @@ int load_pt_index(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads *r, hifiasm_op
r->paf[k].buffer = (ma_hit_t*)malloc(sizeof(ma_hit_t)*r->paf[k].length); r->paf[k].buffer = (ma_hit_t*)malloc(sizeof(ma_hit_t)*r->paf[k].length);
fread(r->paf[k].buffer, sizeof((*(r->paf[k].buffer))), r->paf[k].length, fp); fread(r->paf[k].buffer, sizeof((*(r->paf[k].buffer))), r->paf[k].length, fp);
} }
int8_t rff = 0;
f_flag += fread(&rff, sizeof(rff), 1, fp);
if(!force_rpaf_load) {
opt->post_syn = rff;
fprintf(stderr, "[M::%s] overwritten post_syn to::%u\n", __func__, (uint32_t)opt->post_syn);
}
if(rff) {
for (k = 0; k < r->total_reads; k++) {
f_flag += fread(&(r->reverse_paf[k].is_fully_corrected), sizeof(r->reverse_paf[k].is_fully_corrected), 1, fp);
f_flag += fread(&(r->reverse_paf[k].is_abnormal), sizeof(r->reverse_paf[k].is_abnormal), 1, fp);
f_flag += fread(&(r->reverse_paf[k].length), sizeof(r->reverse_paf[k].length), 1, fp);
r->reverse_paf[k].size = r->reverse_paf[k].length;
r->reverse_paf[k].buffer = NULL;
if(r->reverse_paf[k].length == 0) continue;
r->reverse_paf[k].buffer = (ma_hit_t*)malloc(sizeof(ma_hit_t)*r->reverse_paf[k].length);
fread(r->reverse_paf[k].buffer, sizeof((*(r->reverse_paf[k].buffer))), r->reverse_paf[k].length, fp);
}
}
}
fclose(fp); fclose(fp);
fprintf(stderr, "[M::%s] Index has been loaded.\n", __func__); fprintf(stderr, "[M::%s] Index has been loaded.\n", __func__);
@@ -1516,6 +1647,83 @@ int load_pt_index(void **r_flt_tab, ha_pt_t **r_ha_idx, All_reads *r, hifiasm_op
return 1; return 1;
} }
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)
{
char* gfa_name = (char*)malloc(strlen(file_name)+64);
sprintf(gfa_name, "%s.ad", file_name);
if(is_w) {
write_pt_index(*flt_tab, *ha_idx, NULL, opt, gfa_name, 0);
} else {
load_pt_index(flt_tab, ha_idx, NULL, opt, gfa_name, 0);
}
free(gfa_name);
}
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)
{
char* gfa_name = (char*)malloc(strlen(file_name)+64);
FILE *fp = NULL; int f_flag = 0; uint64_t rr0 = (uint64_t)-1, tot_rr0 = (uint64_t)-1;
if(is_load) {
sprintf(gfa_name, "%s.r%lu.ht.bin", file_name, rr);
fp = fopen(gfa_name, "r");
if (!fp) {
free(gfa_name);
return 0;
}
f_flag += fread(&rr0, sizeof(rr0), 1, fp);
f_flag += fread(&tot_rr0, sizeof(tot_rr0), 1, fp);
fclose(fp);
if(rr0 != rr || tot_rr0 != tot_rr) {
free(gfa_name);
return 0;
}
sprintf(gfa_name, "%s.r%lu", file_name, rr);
if(!load_pt_index(r_flt_tab, r_ha_idx, r, opt, gfa_name, force_rpaf_load)) {
destory_All_reads(r);
ha_pt_destroy(*r_ha_idx); (*r_ha_idx) = NULL;
ha_ft_destroy(*r_flt_tab); (*r_flt_tab) = NULL;
free(gfa_name);
return 0;
}
sprintf(gfa_name, "%s.r%lu.rec", file_name, rr);
if(!load_cc_v(rcc, gfa_name)) {
destory_All_reads(r);
ha_pt_destroy(*r_ha_idx); (*r_ha_idx) = NULL;
ha_ft_destroy(*r_flt_tab); (*r_flt_tab) = NULL;
destroy_cc_v(rcc);
free(gfa_name);
return 0;
}
fprintf(stderr, "[M::%s] restarting from round %lu\n", __func__, rr0);
} else {
sprintf(gfa_name, "%s.r%lu.rec", file_name, rr);
write_cc_v(rcc, gfa_name);
sprintf(gfa_name, "%s.r%lu", file_name, rr);
write_pt_index(*r_flt_tab, *r_ha_idx, r, opt, gfa_name, force_rpaf_load);
sprintf(gfa_name, "%s.r%lu.ht.bin", file_name, rr);
fp = fopen(gfa_name, "w");
if (!fp) {
free(gfa_name);
return 0;
}
fwrite(&rr, sizeof(rr), 1, fp);
fwrite(&tot_rr, sizeof(tot_rr), 1, fp);
fclose(fp);
}
free(gfa_name);
return 1;
}
int uidx_write(void *flt_tab, ha_pt_t *ha_idx, char* file_name, ma_ug_t *ug) int uidx_write(void *flt_tab, ha_pt_t *ha_idx, char* file_name, ma_ug_t *ug)
+8 -5
View File
@@ -72,8 +72,8 @@ extern void *ha_flt_tab_hp;
extern ha_pt_t *ha_idx_hp; extern ha_pt_t *ha_idx_hp;
extern void *ha_ct_table; extern void *ha_ct_table;
void *ha_ft_ul_gen(const hifiasm_opt_t *asm_opt, ma_utg_v *us, int k, int w, int cutoff); 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(const 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_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); 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); int32_t ha_ft_cnt(const void *hh, uint64_t y);
void ha_ft_destroy(void *h); void ha_ft_destroy(void *h);
@@ -86,13 +86,15 @@ 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 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); 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 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); 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_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 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 write_ct_index(void *ct_idx, char* file_name);
int load_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); 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_abuf_t *ha_abuf_init_buf(void *km);
ha_abufl_t *ha_abufl_init_buf(void *km); ha_abufl_t *ha_abufl_init_buf(void *km);
@@ -117,6 +119,7 @@ double yak_cpu_usage(void);
void ha_triobin(const hifiasm_opt_t *opt); void ha_triobin(const hifiasm_opt_t *opt);
uint32_t test_yak_binning(char* fn, char *cmd); uint32_t test_yak_binning(char* fn, char *cmd);
uint32_t *ha_polybin_list(const hifiasm_opt_t *opt); 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 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 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); 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);
@@ -166,7 +169,7 @@ 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]); 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 MALLOC(ptr, len) ((ptr) = (__typeof__(ptr))malloc((len) * sizeof(*(ptr))))
#define REALLOC(ptr, len) ((ptr) = (__typeof__(ptr))realloc((ptr), (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)))) #define MEMCPY(dest, src, len) (memcpy((dest), (src), (len) * sizeof(*(src))))
+23 -23
View File
@@ -514,7 +514,7 @@ double diff_ec_ul, double diff_ec_ul_low, double diff_ec_ul_hpc, int ec_ul_round
void uidx_l_build(ma_ug_t *ug, mg_idxopt_t *opt, int cutoff) void uidx_l_build(ma_ug_t *ug, mg_idxopt_t *opt, int cutoff)
{ {
ha_flt_tab = ha_ft_ul_gen(&asm_opt, &(ug->u), opt->k, opt->w, cutoff); ha_flt_tab = ha_ft_ul_gen(&asm_opt, &(ug->u), opt->k, opt->w, cutoff, -1);
ha_idx = ha_pt_ul_gen(&asm_opt, ha_flt_tab, &(ug->u), opt->k, opt->w, cutoff); ha_idx = ha_pt_ul_gen(&asm_opt, ha_flt_tab, &(ug->u), opt->k, opt->w, cutoff);
fprintf(stderr, "[M::%s] Index has been built.\n", __func__); fprintf(stderr, "[M::%s] Index has been built.\n", __func__);
} }
@@ -1381,8 +1381,8 @@ const int64_t qlen, const int64_t rlen, int32_t *r_qs, int32_t *r_qe, int32_t *r
re = rlen - 1; qe += rtail; re = rlen - 1; qe += rtail;
} }
if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe + 1; if(r_qs) {(*r_qs) = qs;} if(r_qe) {(*r_qe) = qe + 1;}
if(r_rs) (*r_rs) = rs; if(r_re) (*r_re) = re + 1; if(r_rs) {(*r_rs) = rs;} if(r_re) {(*r_re) = re + 1;}
if(rev) { if(rev) {
if(r_rs) (*r_rs) = rlen - re - 1; if(r_rs) (*r_rs) = rlen - re - 1;
if(r_re) (*r_re) = rlen - rs; if(r_re) (*r_re) = rlen - rs;
@@ -1413,8 +1413,8 @@ int32_t *r_qs, int32_t *r_qe, int32_t *r_rs, int32_t *r_re)
re = rlen - 1; qe += rtail; re = rlen - 1; qe += rtail;
} }
if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe + 1; if(r_qs) {(*r_qs) = qs;} if(r_qe) {(*r_qe) = qe + 1;}
if(r_rs) (*r_rs) = rs; if(r_re) (*r_re) = re + 1; if(r_rs) {(*r_rs) = rs;} if(r_re) {(*r_re) = re + 1;}
if(ri->v&1) { if(ri->v&1) {
if(r_rs) (*r_rs) = rlen - re - 1; if(r_rs) (*r_rs) = rlen - re - 1;
if(r_re) (*r_re) = rlen - rs; if(r_re) (*r_re) = rlen - rs;
@@ -4500,7 +4500,7 @@ int64_t g_adjacent_dis(const asg_t *g, uint32_t v, uint32_t w)
void get_r_offset(ma_ug_t *ug, mg_lchain_t *x, int64_t *rs, int64_t *re, int64_t *qs, int64_t *qe) void get_r_offset(ma_ug_t *ug, mg_lchain_t *x, int64_t *rs, int64_t *re, int64_t *qs, int64_t *qe)
{ {
if(qs) *qs = x->qs; if(qe) *qe = x->qe; if(qs) {*qs = x->qs;} if(qe) {*qe = x->qe;}
if(!(x->score&1)) { if(!(x->score&1)) {
if(rs) *rs = x->rs + x->off; if(rs) *rs = x->rs + x->off;
if(re) *re = x->re + x->off; if(re) *re = x->re + x->off;
@@ -4512,7 +4512,7 @@ void get_r_offset(ma_ug_t *ug, mg_lchain_t *x, int64_t *rs, int64_t *re, int64_t
void get_u_offset(ma_ug_t *ug, mg_lchain_t *x, int64_t *rs, int64_t *re, int64_t *qs, int64_t *qe) void get_u_offset(ma_ug_t *ug, mg_lchain_t *x, int64_t *rs, int64_t *re, int64_t *qs, int64_t *qe)
{ {
if(qs) *qs = x->qs; if(qe) *qe = x->qe; if(qs) {*qs = x->qs;} if(qe) {*qe = x->qe;}
if(!(x->v&1)) { if(!(x->v&1)) {
if(rs) *rs = x->rs + x->off; if(rs) *rs = x->rs + x->off;
if(re) *re = x->re + x->off; if(re) *re = x->re + x->off;
@@ -6730,13 +6730,13 @@ int64_t comput_sc_partial_cigar(int64_t sc, int64_t ol, double err_sc_r, overlap
// pk = (*wi); pe = (*werr); // pk = (*wi); pe = (*werr);
if(k < 0) { if(k < 0) {
k = 0; err = 0; k = 0; err = 0;
if(wi) (*wi) = k; if(werr) (*werr) = err; if(wi) {(*wi) = k;} if(werr) {(*werr) = err;}
// assert(e <= z->w_list.a[0].x_start); // assert(e <= z->w_list.a[0].x_start);
} else { } else {
if(z->w_list.a[k].y_end != -1) { if(z->w_list.a[k].y_end != -1) {
err -= z->w_list.a[k].error; err -= z->w_list.a[k].error;
} }
if(wi) (*wi) = k; if(werr) (*werr) = err; if(wi) {(*wi) = k;} if(werr) {(*werr) = err;}
// if(!(err >= 0 && k >= 0 && k < wn && z->w_list.a[k].x_start < e && z->w_list.a[k].x_end + 1 >= e)){ // if(!(err >= 0 && k >= 0 && k < wn && z->w_list.a[k].x_start < e && z->w_list.a[k].x_end + 1 >= e)){
// fprintf(stderr, "[M::%s] ol::%ld, e::%ld, z::[%u, %u], k::%ld, wn::%ld, w::[%d, %d], err::%ld\n", __func__, // fprintf(stderr, "[M::%s] ol::%ld, e::%ld, z::[%u, %u], k::%ld, wn::%ld, w::[%d, %d], err::%ld\n", __func__,
@@ -8817,7 +8817,7 @@ double e_rate, kv_rtrace_t *trace, uint32_t rechain_w, ul_ov_t *res, ul_ov_t *rr
for (i = k = 0; i < nv; i++) { for (i = k = 0; i < nv; i++) {
if(res[i].qn == (uint32_t)-1) continue; if(res[i].qn == (uint32_t)-1) continue;
res[k] = res[i]; res[k] = res[i];
if(res[k].sec&mm) res[k].sec -= mm; k++; if(res[k].sec&mm) {res[k].sec -= mm;} k++;
// res[k] = res[i]; // res[k] = res[i];
// id[k] = res[k].sec; // id[k] = res[k].sec;
// if(id[k]&mm) id[k] -= mm; // if(id[k]&mm) id[k] -= mm;
@@ -10099,7 +10099,7 @@ uint32_t test_het_aln(ma_ug_t *ug, uint64_t rid, u_trans_t *a, uint64_t a_n, st_
uint32_t is_mmhom_node(uint64_t *ca, ma_utg_t *u, asg_t *sg, uint64_t cov_bd, double cut_rate) uint32_t is_mmhom_node(uint64_t *ca, ma_utg_t *u, asg_t *sg, uint64_t cov_bd, double cut_rate)
{ {
if(cut_rate < 0) cut_rate = 0; if(cut_rate > 1.0) cut_rate = 1.0; if(cut_rate < 0) {cut_rate = 0;} if(cut_rate > 1.0) {cut_rate = 1.0;}
uint64_t k, a, na, a_cut = u->n*cut_rate, na_cut = u->n*(1.0-cut_rate); uint64_t k, a, na, a_cut = u->n*cut_rate, na_cut = u->n*(1.0-cut_rate);
for (k = a = na = 0; k < u->n; k++) { for (k = a = na = 0; k < u->n; k++) {
if(ca[k] > (cov_bd*((uint64_t)sg->seq[u->a[k]>>33].len))) { if(ca[k] > (cov_bd*((uint64_t)sg->seq[u->a[k]>>33].len))) {
@@ -13637,8 +13637,8 @@ void gen_end_coord(ul_ov_t *z, int64_t qlen, int64_t tlen, int64_t *r_qs, int64_
te = tlen; qe += ttail; te = tlen; qe += ttail;
} }
if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe; if(r_qs) {(*r_qs) = qs;} if(r_qe) {(*r_qe) = qe;}
if(r_ts) (*r_ts) = ts; if(r_te) (*r_te) = te; if(r_ts) {(*r_ts) = ts;} if(r_te) {(*r_te) = te;}
if(z->rev) { if(z->rev) {
if(r_ts) (*r_ts) = tlen - te; if(r_ts) (*r_ts) = tlen - te;
if(r_te) (*r_te) = tlen - ts; if(r_te) (*r_te) = tlen - ts;
@@ -13822,8 +13822,8 @@ void extend_end_coord(mg_lchain_t *li, ul_ov_t *ui, const int64_t qlen, const in
re = rlen; qe += rtail; re = rlen; qe += rtail;
} }
if(r_qs) (*r_qs) = qs; if(r_qe) (*r_qe) = qe; if(r_qs) {(*r_qs) = qs;} if(r_qe) {(*r_qe) = qe;}
if(r_rs) (*r_rs) = rs; if(r_re) (*r_re) = re; if(r_rs) {(*r_rs) = rs;} if(r_re) {(*r_re) = re;}
if(rev) { if(rev) {
if(r_rs) (*r_rs) = rlen - re; if(r_rs) (*r_rs) = rlen - re;
if(r_re) (*r_re) = rlen - rs; if(r_re) (*r_re) = rlen - rs;
@@ -14327,7 +14327,7 @@ uint64_t detect_mul_way, float len_dif)
int64_t hc_chain_backtrack(int64_t n, const int64_t *f, const uint64_t *p, uint64_t *srt, uint64_t *u, uint64_t *v, int64_t hc_chain_backtrack(int64_t n, const int64_t *f, const uint64_t *p, uint64_t *srt, uint64_t *u, uint64_t *v,
int64_t *n_u_, int64_t *n_v_) int64_t *n_u_, int64_t *n_v_)
{ {
if(n_u_) *n_u_ = 0; if(n_v_) *n_v_ = 0; if(n_u_) {*n_u_ = 0;} if(n_v_) {*n_v_ = 0;}
int64_t i, k, n_v, n_srt, n_v0, n_u, sc; int64_t i, k, n_v, n_srt, n_v0, n_u, sc;
if (n == 0) return 0; if (n == 0) return 0;
// v[] keeps the peak score up to i; f[] is the score ending at i, not always the peak // v[] keeps the peak score up to i; f[] is the score ending at i, not always the peak
@@ -14351,7 +14351,7 @@ int64_t *n_u_, int64_t *n_v_)
u[n_u++] = (((uint64_t)sc)<<32) | ((uint64_t)(n_v-n_v0)); u[n_u++] = (((uint64_t)sc)<<32) | ((uint64_t)(n_v-n_v0));
} }
if(n_u_) *n_u_ = n_u; if(n_v_) *n_v_ = n_v; if(n_u_) {*n_u_ = n_u;} if(n_v_) {*n_v_ = n_v;}
return n_u; return n_u;
} }
@@ -15532,7 +15532,7 @@ void update_rovlp_chain_qse(ma_ug_t *ug, int64_t sidx, int64_t eidx, mg_lchain_t
for (i = sidx+1; i < eidx; i++) { for (i = sidx+1; i < eidx; i++) {
get_r_offset(ug, &(a[i]), &rs, &re, NULL, NULL); get_r_offset(ug, &(a[i]), &rs, &re, NULL, NULL);
a[i].qe = cal_qext_coor(left_r[1], re, left_q[1], left_q[1] + re - left_r[1], re); a[i].qe = cal_qext_coor(left_r[1], re, left_q[1], left_q[1] + re - left_r[1], re);
if(a[i].qe < 0) a[i].qe = 0; if(a[i].qe > qlen) a[i].qe = qlen; if(a[i].qe < 0) {a[i].qe = 0;} if(a[i].qe > qlen) {a[i].qe = qlen;}
a[i].qs = cal_qext_coor(left_r[0], (a[i].qe<=left_q[1])?re:left_r[1], a[i].qs = cal_qext_coor(left_r[0], (a[i].qe<=left_q[1])?re:left_r[1],
left_q[0], (a[i].qe<=left_q[1])?a[i].qe:left_q[1], rs); left_q[0], (a[i].qe<=left_q[1])?a[i].qe:left_q[1], rs);
assert(a[i].qs >= 0 && a[i].qs <= qlen); assert(a[i].qs >= 0 && a[i].qs <= qlen);
@@ -15553,7 +15553,7 @@ void update_rovlp_chain_qse(ma_ug_t *ug, int64_t sidx, int64_t eidx, mg_lchain_t
a[i].qe = cal_qext_coor(right_r[0], right_r[1], right_q[0], right_q[1], re); a[i].qe = cal_qext_coor(right_r[0], right_r[1], right_q[0], right_q[1], re);
assert(a[i].qe >= 0 && a[i].qe <= qlen); assert(a[i].qe >= 0 && a[i].qe <= qlen);
a[i].qs = cal_qext_coor(rs, right_r[0], right_q[0]-(right_r[0]-rs), right_q[0], rs); a[i].qs = cal_qext_coor(rs, right_r[0], right_q[0]-(right_r[0]-rs), right_q[0], rs);
if(a[i].qs < 0) a[i].qs = 0; if(a[i].qs > qlen) a[i].qs = qlen; if(a[i].qs < 0) {a[i].qs = 0;} if(a[i].qs > qlen) {a[i].qs = qlen;}
if(a[i].qs > a[i].qe) { if(a[i].qs > a[i].qe) {
tt = a[i].qs; a[i].qs = a[i].qe; a[i].qe = tt; tt = a[i].qs; a[i].qs = a[i].qe; a[i].qe = tt;
} }
@@ -16345,8 +16345,8 @@ void ctg_rg2ug_gen(ma_utg_t *r_cl, kv_ul_ov_t *u_cl, const ul_idx_t *uref, uint6
for (i = l; i < k; i++) {///could be merged for (i = l; i < k; i++) {///could be merged
m = get_unique_rctg_aln(uref, r_cl->a[i]>>32, i, ls, r_cl->len, &kp, NULL, ((uint32_t)-1)); m = get_unique_rctg_aln(uref, r_cl->a[i]>>32, i, ls, r_cl->len, &kp, NULL, ((uint32_t)-1));
assert(m == 1); assert(kp.tn == lp.tn); assert(kp.qn == lp.qn + i - l); assert(kp.sec == lp.sec + i - l); assert(m == 1); assert(kp.tn == lp.tn); assert(kp.qn == lp.qn + i - l); assert(kp.sec == lp.sec + i - l);
if(kp.qs < lp.qs) lp.qs = kp.qs; if(kp.qe > lp.qe) lp.qe = kp.qe; if(kp.qs < lp.qs) {lp.qs = kp.qs;} if(kp.qe > lp.qe) {lp.qe = kp.qe;}
if(kp.ts < lp.ts) lp.ts = kp.ts; if(kp.te > lp.te) lp.te = kp.te; if(kp.ts < lp.ts) {lp.ts = kp.ts;} if(kp.te > lp.te) {lp.te = kp.te;}
ls += (uint32_t)(r_cl->a[i]); ls += (uint32_t)(r_cl->a[i]);
// if(id == 123) { // if(id == 123) {
@@ -18590,7 +18590,7 @@ void collect_pp_ovlps(ul_ov_t *a, uint64_t a_n, kv_ul_ov_t *res, const ug_opt_t
if(((*mqe) == ((uint64_t)-1)) || ((*mqe) < a[i].qe)) (*mqe) = a[i].qe; if(((*mqe) == ((uint64_t)-1)) || ((*mqe) < a[i].qe)) (*mqe) = a[i].qe;
} }
if(st) (*mqs) = st->qs; if(et) (*mqe) = et->qe; if(st) {(*mqs) = st->qs;} if(et) {(*mqe) = et->qe;}
} }
uint64_t gen_cns_chain_linear_hard(ul_ov_t *a, int64_t a_n, const asg_t *rg, int64_t qlen, int64_t bw, double diff_thre, Chain_Data* dp, uint64_t gen_cns_chain_linear_hard(ul_ov_t *a, int64_t a_n, const asg_t *rg, int64_t qlen, int64_t bw, double diff_thre, Chain_Data* dp,
@@ -21768,7 +21768,7 @@ void asg_arc_push_contain_trans(asg_t *g, ma_hit_t_alloc* ov, int64_t min_ovlp,
nv = asg_arc_n(g, v); av = asg_arc_a(g, v); avi = g->idx[v]>>32; nv = asg_arc_n(g, v); av = asg_arc_a(g, v); avi = g->idx[v]>>32;
while(nv) { while(nv) {
for (i = nc = cc = 0; i < nv; ++i) { for (i = nc = cc = 0; i < nv; ++i) {
if(av[i].del) continue; w = av[i].v; if(av[i].del) {continue;} w = av[i].v;
if(!(is_contain_r((*ri), (w>>1)))) continue;///new arcs must be bridged by contained reads if(!(is_contain_r((*ri), (w>>1)))) continue;///new arcs must be bridged by contained reads
assert(!(g->seq[w>>1].del)); assert(!(g->seq[w>>1].del));
nw = asg_arc_n(g, w); aw = asg_arc_a(g, w); awi = g->idx[w]>>32; nw = asg_arc_n(g, w); aw = asg_arc_a(g, w); awi = g->idx[w]>>32;
+37 -2
View File
@@ -8,6 +8,7 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
// setvbuf(stderr, NULL, _IONBF, 0);
int i, ret; int i, ret;
yak_reset_realtime(); yak_reset_realtime();
init_opt(&asm_opt); init_opt(&asm_opt);
@@ -61,8 +62,42 @@ int main(int argc, char *argv[])
// ed_band_cal_global((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3), // ed_band_cal_global((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3),
// ed_band_cal_global_128bit((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3)); // ed_band_cal_global_128bit((char*)"ACTTTTTT", 8, (char*)"AATTTT", 6, 3));
// exit(1); // 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(); if(asm_opt.sec_in) ret = ha_assemble_pair();
else if(asm_opt.dbg_ovec_cal) ret = ha_assemble_ovec(); else if(asm_opt.dbg_ovec_cal) ret = ha_ec_dbg();
else ret = ha_assemble(); else ret = ha_assemble();
destory_opt(&asm_opt); destory_opt(&asm_opt);
@@ -70,6 +105,6 @@ int main(int argc, char *argv[])
fprintf(stderr, "[M::%s] CMD:", __func__); fprintf(stderr, "[M::%s] CMD:", __func__);
for (i = 0; i < argc; ++i) for (i = 0; i < argc; ++i)
fprintf(stderr, " %s", argv[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; return ret;
} }
+15 -6
View File
@@ -806,8 +806,19 @@ uint32_t mc_edges_symm(mc_match_t *ma)
static void normalize_mb_edge(mb_edge_t *a, mb_edge_t *b) static void normalize_mb_edge(mb_edge_t *a, mb_edge_t *b)
{ {
if(a->w >= b->w) uint8_t f = 0;
{ if(a->w[0] > b->w[0]) {
f = 1;
} else if(a->w[0] == b->w[0] && a->w[1] > b->w[1]) {
f = 1;
} else if(a->w[0] == b->w[0] && a->w[1] == b->w[1] && a->w[2] > b->w[2]) {
f = 1;
} else if(a->w[0] == b->w[0] && a->w[1] == b->w[1] && a->w[2] == b->w[2] && a->w[3] > b->w[3]) {
f = 1;
}
// if(a->w >= b->w) {
if(f) {
b->x = (uint32_t)a->x; b->x = (uint32_t)a->x;
b->x <<= 32; b->x <<= 32;
b->x |= (a->x>>32); b->x |= (a->x>>32);
@@ -815,9 +826,7 @@ static void normalize_mb_edge(mb_edge_t *a, mb_edge_t *b)
b->w[3] = a->w[3]; b->w[3] = a->w[3];
b->w[1] = a->w[2]; b->w[1] = a->w[2];
b->w[2] = a->w[1]; b->w[2] = a->w[1];
} } else {
else
{
a->x = (uint32_t)b->x; a->x = (uint32_t)b->x;
a->x <<= 32; a->x <<= 32;
a->x |= (b->x>>32); a->x |= (b->x>>32);
@@ -3346,7 +3355,7 @@ mc_clus_t *init_mc_clus_t(const mc_opt_t *opt, mc_g_t *mg, bubble_type* bub, uin
mc_clus_t *p; CALLOC(p, 1); mc_clus_t *p; CALLOC(p, 1);
p->bub = bub; p->opt = opt; p->mg = mg; p->n = bub->ug->g->n_seq; p->bub = bub; p->opt = opt; p->mg = mg; p->n = bub->ug->g->n_seq;
CALLOC(p->lock, p->n); CALLOC(p->lock, p->n);
if(n_thread > 64) n_thread = 64; p->n_thread = n_thread; if(n_thread > 64) {n_thread = 64;} p->n_thread = n_thread;
CALLOC(p->aux, p->n_thread); CALLOC(p->aux, p->n_thread);
uint32_t k, ss = (p->n>>3)+(!!(p->n&7)); uint32_t k, ss = (p->n>>3)+(!!(p->n&7));
for (k = 0; k < p->n_thread; k++) { for (k = 0; k < p->n_thread; k++) {