hic first

This commit is contained in:
chhylp123
2020-11-14 23:35:32 -05:00
parent 35e3423f93
commit ab073aa1fc
5 changed files with 2266 additions and 227 deletions
+71 -18
View File
@@ -11630,18 +11630,74 @@ ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp)
kv_destroy(new_rtg_edges.a);
}
void classify_untigs(ma_ug_t *ug, asg_t *sg, ma_sub_t* coverage_cut,
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex,
kvec_asg_arc_t_warp* new_rtg_edges, int max_hang, int min_ovlp)
{
uint64_t i, dip_thres;
uint8_t* primary_flag = (uint8_t*)calloc(sg->n_seq, sizeof(uint8_t));
int tmp_cov = asm_opt.hom_global_coverage;
asm_opt.hom_global_coverage = -1;
purge_dups(ug, sg, coverage_cut, sources, reverse_sources, ruIndex, new_rtg_edges,
asm_opt.purge_simi_rate, asm_opt.purge_overlap_len, max_hang, min_ovlp, 0, 0, 0, 1);
dip_thres = ((double)asm_opt.hom_global_coverage)/((double)HOM_PEAK_RATE)*0.6;
asm_opt.hom_global_coverage = tmp_cov;
for (i = 0; i < ug->g->n_seq; i++)
{
if(get_ug_coverage(&ug->u.a[i], sg, coverage_cut, sources, ruIndex, primary_flag)<dip_thres)
{
ug->g->seq[i].c = 1;
}
else
{
ug->g->seq[i].c = 0;
}
}
free(primary_flag);
///fprintf(stderr, "[M::%s] diploid coverage threshold: %lu\n", __func__, dip_thres);
}
void output_hic_graph(asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name,
ma_hit_t_alloc* sources, R_to_U* ruIndex, int max_hang, int min_ovlp)
{
ma_hit_t_alloc* sources, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex, int max_hang,
int min_ovlp)
{
kvec_asg_arc_t_warp new_rtg_edges;
kv_init(new_rtg_edges.a);
ma_ug_t *ug = NULL;
ug = ma_ug_gen(sg);
ma_ug_seq(ug, sg, &R_INF, coverage_cut, sources, &new_rtg_edges, max_hang, min_ovlp);
hic_analysis(ug);
/**
fprintf(stderr, "Writing raw unitig GFA to disk... \n");
char* gfa_name = (char*)malloc(strlen(output_file_name)+25);
sprintf(gfa_name, "%s.r_utg.gfa", output_file_name);
FILE* output_file = fopen(gfa_name, "w");
ma_ug_print(ug, &R_INF, sg, coverage_cut, sources, ruIndex, "utg", output_file);
fclose(output_file);
sprintf(gfa_name, "%s.r_utg.noseq.gfa", output_file_name);
output_file = fopen(gfa_name, "w");
ma_ug_print_simple(ug, &R_INF, sg, coverage_cut, sources, ruIndex, "utg", output_file);
fclose(output_file);
if(asm_opt.bed_inconsist_rate != 0)
{
sprintf(gfa_name, "%s.r_utg.lowQ.bed", output_file_name);
output_file = fopen(gfa_name, "w");
ma_ug_print_bed(ug, sg, &R_INF, coverage_cut, sources, &new_rtg_edges,
max_hang, min_ovlp, asm_opt.bed_inconsist_rate, "utg", output_file);
fclose(output_file);
}
free(gfa_name);
**/
classify_untigs(ug, sg, coverage_cut, sources, reverse_sources, ruIndex, &new_rtg_edges,
max_hang, min_ovlp);
hic_analysis(ug);
ma_ug_destroy(ug);
kv_destroy(new_rtg_edges.a);
}
@@ -27426,20 +27482,6 @@ ma_sub_t **coverage_cut_ptr, int debug_g)
asg_arc_del_simple_circle_untig(sources, coverage_cut, sg, 100, 0);
if (asm_opt.flag & HA_F_VERBOSE_GFA)
{
/*******************************for debug***************************************/
write_debug_graph(sg, sources, coverage_cut, output_file_name, n_read, reverse_sources, ruIndex);
debug_gfa:;
/*******************************for debug***************************************/
}
/**
debug_ma_hit_t(sources, coverage_cut, n_read, max_hang_length,
mini_overlap_length);
debug_ma_hit_t(reverse_sources, coverage_cut, n_read, max_hang_length,
mini_overlap_length);
**/
///note: don't apply asg_arc_del_too_short_overlaps() after this function!!!!
rescue_contained_reads_aggressive(NULL, sg, sources, coverage_cut, ruIndex, max_hang_length,
mini_overlap_length, bubble_dist, 10, 1, 0, NULL, NULL);
@@ -27452,6 +27494,14 @@ ma_sub_t **coverage_cut_ptr, int debug_g)
// rescue_no_coverage_aggressive(sg, sources, reverse_sources, &coverage_cut, ruIndex, max_hang_length,
// mini_overlap_length, bubble_dist, 10);
if (asm_opt.flag & HA_F_VERBOSE_GFA)
{
/*******************************for debug***************************************/
write_debug_graph(sg, sources, coverage_cut, output_file_name, n_read, reverse_sources, ruIndex);
debug_gfa:;
/*******************************for debug***************************************/
}
if (ha_opt_triobin(&asm_opt))
{
char *buf = (char*)calloc(strlen(output_file_name) + 25, 1);
@@ -27468,7 +27518,10 @@ ma_sub_t **coverage_cut_ptr, int debug_g)
}
else if(ha_opt_hic(&asm_opt))
{
output_hic_graph(sg, coverage_cut, output_file_name, sources, ruIndex, max_hang_length, mini_overlap_length);;
char *buf = (char*)calloc(strlen(output_file_name) + 25, 1);
sprintf(buf, "%s.hic", output_file_name);
output_hic_graph(sg, coverage_cut, buf, sources, reverse_sources, ruIndex, max_hang_length, mini_overlap_length);;
free(buf);
}
else
{
+8 -5
View File
@@ -67,7 +67,7 @@ static yak_ch_t *yak_ch_restore_core(yak_ch_t *ch0, const char *fn, int mode, ..
{
va_list ap;
FILE *fp;
uint32_t t[3];
uint32_t t[3], f_tmp = 0;
char magic[4];
int i, j, absent, min_cnt = 0, mid_cnt = 0, mode_err = 0;
uint64_t mask = (1ULL<<YAK_COUNTER_BITS) - 1, n_ins = 0, n_new = 0;
@@ -92,33 +92,36 @@ static yak_ch_t *yak_ch_restore_core(yak_ch_t *ch0, const char *fn, int mode, ..
fclose(fp);
return 0;
}
fread(t, 4, 3, fp);
f_tmp += fread(t, 4, 3, fp);
if (t[2] != YAK_COUNTER_BITS) {
fprintf(stderr, "ERROR: saved counter bits: %d; compile-time counter bits: %d\n", t[2], YAK_COUNTER_BITS);
fclose(fp);
return 0;
}
///t[0] = k; t[1] = pre, t[2] = YAK_COUNTER_BITS;
ch = ch0 == 0? yak_ch_init(t[0], t[1]) : ch0;
assert((int)t[0] == ch->k && (int)t[1] == ch->pre);
for (i = 0; i < 1<<ch->pre; ++i) {
yak_ht_t *h = ch->h[i].h;
fread(t, 4, 2, fp);
f_tmp += fread(t, 4, 2, fp);
///t[0] = kh_capacity(h), t[1] = kh_size(h);
if (ch0 == 0) yak_ht_resize(h, t[0]);
for (j = 0; j < (int)t[1]; ++j) {
uint64_t key;
fread(&key, 8, 1, fp);
f_tmp += fread(&key, 8, 1, fp);
if (mode == YAK_LOAD_ALL) {
++n_ins;
yak_ht_put(h, key, &absent);
if (absent) ++n_new;
} else if (mode == YAK_LOAD_TRIOBIN1 || mode == YAK_LOAD_TRIOBIN2) {
int cnt = key & mask, x, shift = mode == YAK_LOAD_TRIOBIN1? 0 : 2;
//1. filter singleton k-mer; 2. label non-repeat and repeat
if (cnt >= mid_cnt) x = 2<<shift;
else if (cnt >= min_cnt) x = 1<<shift;
else x = -1;
if (x >= 0) {
khint_t k;
///no need cnt at all
key = (key & ~mask) | x;
++n_ins;
k = yak_ht_put(h, key, &absent);
+2175 -194
View File
File diff suppressed because it is too large Load Diff
+6 -5
View File
@@ -1002,16 +1002,17 @@ int load_ct_index(void **i_ct_idx, char* file_name)
}
ha_ct_t** ct_idx = (ha_ct_t**)i_ct_idx;
double index_time = 0;
uint64_t flag = 0;
int i;
ha_ct_t *h = 0;
ha_ct1_t *g;
CALLOC(h, 1);
fread(&h->k, sizeof(h->k), 1, fp);
fread(&h->pre, sizeof(h->pre), 1, fp);
fread(&h->n_hash, sizeof(h->n_hash), 1, fp);
fread(&h->n_shift, sizeof(h->n_shift), 1, fp);
fread(&h->tot, sizeof(h->tot), 1, fp);
flag += fread(&h->k, sizeof(h->k), 1, fp);
flag += fread(&h->pre, sizeof(h->pre), 1, fp);
flag += fread(&h->n_hash, sizeof(h->n_hash), 1, fp);
flag += fread(&h->n_shift, sizeof(h->n_shift), 1, fp);
flag += fread(&h->tot, sizeof(h->tot), 1, fp);
CALLOC(h->h, 1<<h->pre);
+6 -5
View File
@@ -147,13 +147,14 @@ static kh_inline khint_t __kh_h2b(khint_t hash, khint_t bits) { return hash * 26
SCOPE khint_t prefix##_load(HType **h, FILE* fp) { \
(*h) = prefix##_init(); \
khint_t n_buckets; \
fread(&n_buckets, sizeof(n_buckets), 1, fp); \
fread(&(*h)->bits, sizeof((*h)->bits), 1, fp); \
fread(&(*h)->count, sizeof((*h)->count), 1, fp); \
uint64_t flag = 0;\
flag += fread(&n_buckets, sizeof(n_buckets), 1, fp); \
flag += fread(&(*h)->bits, sizeof((*h)->bits), 1, fp); \
flag += fread(&(*h)->count, sizeof((*h)->count), 1, fp); \
(*h)->used = (khint32_t*)kmalloc(__kh_fsize(n_buckets) * sizeof(khint32_t)); \
(*h)->keys = (khkey_t*)kmalloc(n_buckets * sizeof(khkey_t)); \
fread((*h)->used, sizeof(khint32_t), __kh_fsize(n_buckets), fp); \
fread((*h)->keys, sizeof(khkey_t), n_buckets, fp); \
flag += fread((*h)->used, sizeof(khint32_t), __kh_fsize(n_buckets), fp); \
flag += fread((*h)->keys, sizeof(khkey_t), n_buckets, fp); \
return 1; \
} \