Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leak of print_utg #455

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ static void worker_ovec_related_reads(void *data, long i, int tid)

if(k < R_INF_FLAG.query_num)
{
R_INF_FLAG.read_id[k] = i;
int fully_cov, abnormal, q_idx = k;

ha_get_candidates_interface(b->ab, i, &b->self_read, &b->olist, &b->olist_hp, &b->clist,
Expand Down Expand Up @@ -766,6 +767,7 @@ static void worker_ovec_related_reads(void *data, long i, int tid)
Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
}

/**
fprintf(R_INF_FLAG.fp, "***************************unmatched ovlp***************************\n");
for (k = 0; k < b->olist.length; k++)
{
Expand All @@ -777,6 +779,7 @@ static void worker_ovec_related_reads(void *data, long i, int tid)
b->olist.list[k].y_pos_strand, b->olist.list[k].strong, b->olist.list[k].without_large_indel,
Get_READ_LENGTH(R_INF, b->olist.list[k].y_id));
}
**/

R_INF.trio_flag[i] = AMBIGU;

Expand Down Expand Up @@ -950,6 +953,19 @@ void print_het_cnt_log(uint32_t *het_cnt)
fclose(output_file);
}

void prt_dbg_rs(FILE *fp, Debug_reads* x, uint64_t round)
{
uint64_t k, id; UC_Read g_read; init_UC_Read(&g_read);
for (k = 0; k < R_INF_FLAG.query_num; k++) {
id = x->read_id[k];
if(id == ((uint64_t)-1)) continue;
recover_UC_Read(&g_read, &R_INF, id);
fprintf(fp, ">%.*s_r%lu\n", (int)Get_NAME_LENGTH((R_INF), id), Get_NAME((R_INF), id), round);
fprintf(fp, "%.*s\n", (int)g_read.length, g_read.seq);
}
destory_UC_Read(&g_read);
}


void ha_overlap_and_correct(int round)
{
Expand Down Expand Up @@ -999,8 +1015,7 @@ void ha_overlap_and_correct(int round)
ha_ovec_destroy(b[i]);
}
free(b);

if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r0, &R_INF_FLAG, 0); // for debugging only

// save corrected reads to R_INF
CALLOC(e, asm_opt.thread_num);
Expand All @@ -1017,6 +1032,9 @@ void ha_overlap_and_correct(int round)
free(e[i].second_round_read);
}
free(e);

if (asm_opt.required_read_name) prt_dbg_rs(R_INF_FLAG.fp_r1, &R_INF_FLAG, 1); // for debugging only
if (asm_opt.required_read_name) destory_Debug_reads(&R_INF_FLAG), exit(0); // for debugging only
///debug_print_pob_regions();
}

Expand Down
2 changes: 1 addition & 1 deletion CommandLines.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <pthread.h>
#include <stdint.h>

#define HA_VERSION "0.19.5-r587"
#define HA_VERSION "0.19.5-r589"

#define VERBOSE 0

Expand Down
30 changes: 17 additions & 13 deletions Overlaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ KRADIX_SORT_INIT(ha_mzl_t_srt1, ha_mzl_t, ha_mzl_t_key, member_size(ha_mzl_t, x)
#define PHASE_SEP_RATE 0.04
#define PHASE_MISS_LEN 1000000
#define PHASE_MISS_N 8
// #define PHASE_MISS_SLEN 500000
// #define PHASE_MISS_SN 24

KSORT_INIT_GENERIC(uint32_t)

Expand Down Expand Up @@ -13578,40 +13580,40 @@ void destory_hc_links(hc_links* link)
kv_destroy(link->enzymes);
}

void print_utg(ma_ug_t *ug, asg_t *sg, ma_sub_t* coverage_cut, char* output_file_name,
void print_utg(ma_ug_t **ug, 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, kvec_asg_arc_t_warp* new_rtg_edges)
{
if(asm_opt.b_low_cov > 0)
{
break_ug_contig(&ug, sg, &R_INF, coverage_cut, sources, ruIndex, new_rtg_edges, max_hang, min_ovlp,
break_ug_contig(ug, sg, &R_INF, coverage_cut, sources, ruIndex, new_rtg_edges, max_hang, min_ovlp,
&asm_opt.b_low_cov, NULL, asm_opt.m_rate);
}

if(asm_opt.b_high_cov > 0)
{
break_ug_contig(&ug, sg, &R_INF, coverage_cut, sources, ruIndex, new_rtg_edges, max_hang, min_ovlp,
break_ug_contig(ug, sg, &R_INF, coverage_cut, sources, ruIndex, new_rtg_edges, max_hang, min_ovlp,
NULL, &asm_opt.b_high_cov, asm_opt.m_rate);
}

ma_ug_seq(ug, sg, coverage_cut, sources, new_rtg_edges, max_hang, min_ovlp, 0, 1);
ma_ug_seq(*ug, sg, coverage_cut, sources, new_rtg_edges, max_hang, min_ovlp, 0, 1);


char* gfa_name = (char*)malloc(strlen(output_file_name)+35);
sprintf(gfa_name, "%s.p_ctg.gfa", output_file_name);
fprintf(stderr, "Writing %s to disk... \n", gfa_name);
FILE* output_file = fopen(gfa_name, "w");
ma_ug_print(ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
ma_ug_print(*ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
fclose(output_file);

sprintf(gfa_name, "%s.p_ctg.noseq.gfa", output_file_name);
output_file = fopen(gfa_name, "w");
ma_ug_print_simple(ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
ma_ug_print_simple(*ug, sg, coverage_cut, sources, ruIndex, "ptg", output_file);
fclose(output_file);
if(asm_opt.bed_inconsist_rate != 0)
{
sprintf(gfa_name, "%s.p_ctg.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,
ma_ug_print_bed(*ug, sg, &R_INF, coverage_cut, sources, new_rtg_edges,
max_hang, min_ovlp, asm_opt.bed_inconsist_rate, "ptg", output_file, NULL);
fclose(output_file);
}
Expand Down Expand Up @@ -15668,7 +15670,7 @@ long long gap_fuzz, bub_label_t* b_mask_t, ug_opt_t *opt)
adjust_utg_by_primary(&copy_ug, copy_sg, TRIO_THRES, sources, reverse_sources, coverage_cut,
tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, drop_ratio,
max_hang, min_ovlp, &new_rtg_edges, &cov, b_mask_t, 1, 0);
print_utg(copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
print_utg(&copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
min_ovlp, &new_rtg_edges);

if(asm_opt.is_alt)
Expand Down Expand Up @@ -15924,7 +15926,7 @@ float chimeric_rate, float drop_ratio, int max_hang, int min_ovlp, long long gap
adjust_utg_by_primary(&copy_ug, copy_sg, TRIO_THRES, sources, reverse_sources, coverage_cut,
tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate, drop_ratio,
max_hang, min_ovlp, &new_rtg_edges, &cov, b_mask_t, 1, 0);
print_utg(copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
print_utg(&copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
min_ovlp, &new_rtg_edges);

if(asm_opt.is_alt) {
Expand Down Expand Up @@ -16920,7 +16922,7 @@ int gap_fuzz, bub_label_t* b_mask_t, ug_opt_t *opt)
// ruIndex, max_hang, min_ovlp, &new_rtg_edges, b_mask_t, NULL);
// exit(1);
/*******************************for debug************************************/
print_utg(copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
print_utg(&copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
min_ovlp, &new_rtg_edges);
ma_ug_destroy(copy_ug);
asg_destroy(copy_sg);
Expand Down Expand Up @@ -17003,7 +17005,7 @@ long long gap_fuzz, ug_opt_t *opt)
// ruIndex, max_hang, min_ovlp, &new_rtg_edges, b_mask_t, NULL);
// exit(1);
/*******************************for debug************************************/
print_utg(copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
print_utg(&copy_ug, copy_sg, coverage_cut, output_file_name, sources, ruIndex, max_hang,
min_ovlp, &new_rtg_edges);
ma_ug_destroy(copy_ug);
asg_destroy(copy_sg);
Expand Down Expand Up @@ -20546,7 +20548,7 @@ int min_ovlp, int is_bench, long long gap_fuzz, ug_opt_t *opt, bub_label_t* b_ma
reverse_sources, tipsLen, tip_drop_ratio, stops_threshold, ruIndex, chimeric_rate,
drop_ratio, max_hang, min_ovlp, gap_fuzz, 1, b_mask_t, NULL, NULL, &r_edges);
filter_set_kug(R_INF.trio_flag, sg, rf, &r_edges, asm_opt.kpt_rate, &kug);
print_utg(kug, sg, coverage_cut, kug_n, sources, ruIndex, max_hang, min_ovlp, &r_edges);
print_utg(&kug, sg, coverage_cut, kug_n, sources, ruIndex, max_hang, min_ovlp, &r_edges);

free(kug_n), kv_destroy(r_edges.a); ma_ug_destroy(kug);
free(rf);
Expand Down Expand Up @@ -20804,7 +20806,9 @@ int min_ovlp, long long gap_fuzz, bub_label_t* b_mask_t, ma_ug_t **rhu0, ma_ug_t
s = dedup_exact_ug(hidx0, hidx1, coverage_cut, sources, ruIndex, ff, MOTHER); dedup_base += s;
destroy_dedup_idx_t(hidx0); destroy_dedup_idx_t(hidx1);

miss_base = append_miss_nid(sg, hu0, hu1, ff, PHASE_MISS_LEN, PHASE_MISS_N); free(ff);
s = append_miss_nid(sg, hu0, hu1, ff, PHASE_MISS_LEN, PHASE_MISS_N); miss_base += s;
// s = append_miss_nid(sg, hu0, hu1, ff, PHASE_MISS_SLEN, PHASE_MISS_SN); miss_base += s;
free(ff);

renew_utg((&hu0), sg, &arcs0); renew_utg((&hu1), sg, &arcs1);
fprintf(stderr, "[M::%s] dedup_base::%lu, miss_base::%lu\n", __func__, dedup_base, miss_base);
Expand Down
15 changes: 13 additions & 2 deletions Process_Read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ void init_Debug_reads(Debug_reads* x, const char* file)
}
x->read_name = (char**)malloc(sizeof(char*)*x->query_num);
x->candidate_count = (kvec_t_u64_warp*)malloc(sizeof(kvec_t_u64_warp)*x->query_num);
x->read_id = NULL; MALLOC(x->read_id, x->query_num);
memset(x->read_id, -1, sizeof((*(x->read_id)))*x->query_num);
fseek(x->fp, 0, SEEK_SET);

i = 0;
Expand All @@ -732,6 +734,15 @@ void init_Debug_reads(Debug_reads* x, const char* file)
sprintf(Name_Buffer, "%s.debug.stdout", file);
x->fp = fopen(Name_Buffer,"w");
fprintf(stderr, "Print debugging information to: %s\n", Name_Buffer);

sprintf(Name_Buffer, "%s.debug.r0.fa", file);
x->fp_r0 = fopen(Name_Buffer,"w");
fprintf(stderr, "Print raw reads to: %s\n", Name_Buffer);

sprintf(Name_Buffer, "%s.debug.r1.fa", file);
x->fp_r1 = fopen(Name_Buffer,"w");
fprintf(stderr, "Print corrected reads to: %s\n", Name_Buffer);

free(Name_Buffer);
}

Expand All @@ -744,8 +755,8 @@ void destory_Debug_reads(Debug_reads* x)
kv_destroy(x->candidate_count[i].a);
}

free(x->read_name);
fclose(x->fp);
free(x->read_name); free(x->read_id);
fclose(x->fp); fclose(x->fp_r0); fclose(x->fp_r1);
}


Expand Down
3 changes: 2 additions & 1 deletion Process_Read.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ typedef struct
typedef struct
{
char** read_name;
uint64_t *read_id;
uint64_t query_num;
kvec_t_u64_warp* candidate_count;
FILE* fp;
FILE *fp, *fp_r0, *fp_r1;
pthread_mutex_t OutputMutex;
} Debug_reads;

Expand Down