mirror of
https://github.com/chhylp123/hifiasm.git
synced 2026-10-11 06:00:55 +08:00
r226: more careful about ma_hit_t_alloc memory
This commit is contained in:
+15
-9
@@ -250,7 +250,12 @@ inline void push_cigar(Compressed_Cigar_record* records, long long ID, Cigar_rec
|
|||||||
void push_overlaps(ma_hit_t_alloc* paf, overlap_region_alloc* overlap_list, int flag, All_reads* R_INF, int if_reverse)
|
void push_overlaps(ma_hit_t_alloc* paf, overlap_region_alloc* overlap_list, int flag, All_reads* R_INF, int if_reverse)
|
||||||
{
|
{
|
||||||
long long i = 0, xLen, yLen;
|
long long i = 0, xLen, yLen;
|
||||||
|
int32_t size = 0;
|
||||||
ma_hit_t tmp;
|
ma_hit_t tmp;
|
||||||
|
for (i = 0; i < (long long)overlap_list->length; ++i)
|
||||||
|
if (overlap_list->list[i].is_match == flag)
|
||||||
|
++size;
|
||||||
|
resize_ma_hit_t_alloc(paf, size);
|
||||||
clear_ma_hit_t_alloc(paf);
|
clear_ma_hit_t_alloc(paf);
|
||||||
for (i = 0; i < (long long)overlap_list->length; i++)
|
for (i = 0; i < (long long)overlap_list->length; i++)
|
||||||
{
|
{
|
||||||
@@ -278,7 +283,6 @@ void push_overlaps(ma_hit_t_alloc* paf, overlap_region_alloc* overlap_list, int
|
|||||||
tmp.te = overlap_list->list[i].y_pos_e;
|
tmp.te = overlap_list->list[i].y_pos_e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///for overlap_list, the x_strand of all overlaps are 0, so the tmp.rev is the same as the y_strand
|
///for overlap_list, the x_strand of all overlaps are 0, so the tmp.rev is the same as the y_strand
|
||||||
tmp.rev = overlap_list->list[i].y_pos_strand;
|
tmp.rev = overlap_list->list[i].y_pos_strand;
|
||||||
|
|
||||||
@@ -322,7 +326,7 @@ long long push_final_overlaps(ma_hit_t_alloc* paf, ma_hit_t_alloc* reverse_paf_l
|
|||||||
long long i = 0;
|
long long i = 0;
|
||||||
long long available_overlaps = 0;
|
long long available_overlaps = 0;
|
||||||
ma_hit_t tmp;
|
ma_hit_t tmp;
|
||||||
clear_ma_hit_t_alloc(paf);
|
clear_ma_hit_t_alloc(paf); // paf has been preallocated, so we don't need preallocation
|
||||||
for (i = 0; i < (long long)overlap_list->length; i++)
|
for (i = 0; i < (long long)overlap_list->length; i++)
|
||||||
{
|
{
|
||||||
if (overlap_list->list[i].is_match == flag)
|
if (overlap_list->list[i].is_match == flag)
|
||||||
@@ -374,7 +378,7 @@ long long push_final_overlaps(ma_hit_t_alloc* paf, ma_hit_t_alloc* reverse_paf_l
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int is_final;
|
int is_final, save_ov;
|
||||||
// chaining and overlapping related buffers
|
// chaining and overlapping related buffers
|
||||||
UC_Read self_read, ovlp_read;
|
UC_Read self_read, ovlp_read;
|
||||||
Candidates_list clist;
|
Candidates_list clist;
|
||||||
@@ -390,11 +394,11 @@ typedef struct {
|
|||||||
Round2_alignment round2;
|
Round2_alignment round2;
|
||||||
} ha_ovec_buf_t;
|
} ha_ovec_buf_t;
|
||||||
|
|
||||||
ha_ovec_buf_t *ha_ovec_init(int is_final)
|
ha_ovec_buf_t *ha_ovec_init(int is_final, int save_ov)
|
||||||
{
|
{
|
||||||
ha_ovec_buf_t *b;
|
ha_ovec_buf_t *b;
|
||||||
CALLOC(b, 1);
|
CALLOC(b, 1);
|
||||||
b->is_final = !!is_final;
|
b->is_final = !!is_final, b->save_ov = !!save_ov;
|
||||||
init_UC_Read(&b->self_read);
|
init_UC_Read(&b->self_read);
|
||||||
init_UC_Read(&b->ovlp_read);
|
init_UC_Read(&b->ovlp_read);
|
||||||
init_Candidates_list(&b->clist);
|
init_Candidates_list(&b->clist);
|
||||||
@@ -493,8 +497,10 @@ static void worker_ovec(void *data, long i, int tid)
|
|||||||
}
|
}
|
||||||
R_INF.paf[i].is_abnormal = abnormal;
|
R_INF.paf[i].is_abnormal = abnormal;
|
||||||
|
|
||||||
push_overlaps(&(R_INF.paf[i]), &b->olist, 1, &R_INF, asm_opt.roundID%2);
|
if (b->save_ov) {
|
||||||
push_overlaps(&(R_INF.reverse_paf[i]), &b->olist, 2, &R_INF, asm_opt.roundID%2);
|
push_overlaps(&(R_INF.paf[i]), &b->olist, 1, &R_INF, 1);
|
||||||
|
push_overlaps(&(R_INF.reverse_paf[i]), &b->olist, 2, &R_INF, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void worker_ovec_related_reads(void *data, long i, int tid)
|
static void worker_ovec_related_reads(void *data, long i, int tid)
|
||||||
@@ -632,7 +638,7 @@ void ha_overlap_and_correct(int round)
|
|||||||
// overlap and correct reads
|
// overlap and correct reads
|
||||||
CALLOC(b, asm_opt.thread_num);
|
CALLOC(b, asm_opt.thread_num);
|
||||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||||
b[i] = ha_ovec_init(0);
|
b[i] = ha_ovec_init(0, (round == asm_opt.number_of_round - 1));
|
||||||
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, round == 0? 0 : 1, &R_INF, &hom_cov); // build the index
|
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, round == 0? 0 : 1, &R_INF, &hom_cov); // build the index
|
||||||
if (round == 0 && ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
|
if (round == 0 && ha_flt_tab == 0) // then asm_opt.hom_cov hasn't been updated
|
||||||
ha_opt_update_cov(&asm_opt, hom_cov);
|
ha_opt_update_cov(&asm_opt, hom_cov);
|
||||||
@@ -1140,7 +1146,7 @@ void ha_overlap_final(void)
|
|||||||
ha_ovec_buf_t **b;
|
ha_ovec_buf_t **b;
|
||||||
CALLOC(b, asm_opt.thread_num);
|
CALLOC(b, asm_opt.thread_num);
|
||||||
for (i = 0; i < asm_opt.thread_num; ++i)
|
for (i = 0; i < asm_opt.thread_num; ++i)
|
||||||
b[i] = ha_ovec_init(1);
|
b[i] = ha_ovec_init(1, 1);
|
||||||
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, 1, &R_INF, &hom_cov); // build the index
|
ha_idx = ha_pt_gen(&asm_opt, ha_flt_tab, 1, &R_INF, &hom_cov); // build the index
|
||||||
kt_for(asm_opt.thread_num, worker_ov_final, b, R_INF.total_reads);
|
kt_for(asm_opt.thread_num, worker_ov_final, b, R_INF.total_reads);
|
||||||
ha_pt_destroy(ha_idx);
|
ha_pt_destroy(ha_idx);
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#define HA_VERSION "0.3.0-dirty-r224"
|
#define HA_VERSION "0.3.0-dirty-r226"
|
||||||
|
|
||||||
#define VERBOSE 0
|
#define VERBOSE 0
|
||||||
|
|
||||||
|
|||||||
+9
-22
@@ -358,12 +358,12 @@ void clear_ma_hit_t_alloc(ma_hit_t_alloc* x)
|
|||||||
x->length = 0;
|
x->length = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize_ma_hit_t_alloc(ma_hit_t_alloc* x, uint64_t size)
|
void resize_ma_hit_t_alloc(ma_hit_t_alloc* x, uint32_t size)
|
||||||
{
|
|
||||||
if(size > x->size)
|
|
||||||
{
|
{
|
||||||
|
if (size > x->size) {
|
||||||
x->size = size;
|
x->size = size;
|
||||||
x->buffer = (ma_hit_t*)realloc(x->buffer, x->size*sizeof(ma_hit_t));
|
kroundup32(x->size);
|
||||||
|
REALLOC(x->buffer, x->size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,30 +372,17 @@ void destory_ma_hit_t_alloc(ma_hit_t_alloc* x)
|
|||||||
free(x->buffer);
|
free(x->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void destory_all_ma_hit_t_alloc(ma_hit_t_alloc* x, uint64_t n_read)
|
|
||||||
{
|
|
||||||
uint64_t i = 0;
|
|
||||||
for (i = 0; i < n_read; i++)
|
|
||||||
{
|
|
||||||
free(x[i].buffer);
|
|
||||||
}
|
|
||||||
free(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
void add_ma_hit_t_alloc(ma_hit_t_alloc* x, ma_hit_t* element)
|
void add_ma_hit_t_alloc(ma_hit_t_alloc* x, ma_hit_t* element)
|
||||||
{
|
{
|
||||||
if(x->length + 1 > x->size)
|
if (x->length + 1 > x->size) {
|
||||||
{
|
x->size = x->length + 1;
|
||||||
x->size = (x->length + 1) * 2;
|
kroundup32(x->size);
|
||||||
x->buffer = (ma_hit_t*)realloc(x->buffer, x->size*sizeof(ma_hit_t));
|
REALLOC(x->buffer, x->size);
|
||||||
}
|
}
|
||||||
|
x->buffer[x->length++] = *element;
|
||||||
x->buffer[x->length] = (*element);
|
|
||||||
x->length++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long long get_specific_overlap(ma_hit_t_alloc* x, uint32_t qn, uint32_t tn)
|
long long get_specific_overlap(ma_hit_t_alloc* x, uint32_t qn, uint32_t tn)
|
||||||
{
|
{
|
||||||
long long i;
|
long long i;
|
||||||
|
|||||||
+1
-2
@@ -68,8 +68,7 @@ typedef struct {
|
|||||||
|
|
||||||
void init_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
void init_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
||||||
void clear_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
void clear_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
||||||
void resize_ma_hit_t_alloc(ma_hit_t_alloc* x, uint64_t size);
|
void resize_ma_hit_t_alloc(ma_hit_t_alloc* x, uint32_t size);
|
||||||
void destory_all_ma_hit_t_alloc(ma_hit_t_alloc* x, uint64_t n_read);
|
|
||||||
void destory_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
void destory_ma_hit_t_alloc(ma_hit_t_alloc* x);
|
||||||
void add_ma_hit_t_alloc(ma_hit_t_alloc* x, ma_hit_t* element);
|
void add_ma_hit_t_alloc(ma_hit_t_alloc* x, ma_hit_t* element);
|
||||||
void ma_hit_sort_tn(ma_hit_t *a, long long n);
|
void ma_hit_sort_tn(ma_hit_t *a, long long n);
|
||||||
|
|||||||
+1
-1
@@ -1098,7 +1098,7 @@ void print_asg_arc_t_offset(asg_arc_t_offset* x, long long n, const char* info)
|
|||||||
x_off = (long long)(x[i].Off>>32);
|
x_off = (long long)(x[i].Off>>32);
|
||||||
y_off = (long long)((uint32_t)x[i].Off);
|
y_off = (long long)((uint32_t)x[i].Off);
|
||||||
fprintf(stderr, "i: %lld, x_off: %lld, y_off: %lld, weight: %lu, rev: %u, ol: %u\n",
|
fprintf(stderr, "i: %lld, x_off: %lld, y_off: %lld, weight: %lu, rev: %u, ol: %u\n",
|
||||||
i, x_off, y_off, x[i].weight, x[i].x.el, x[i].x.ol);
|
i, x_off, y_off, (unsigned long)x[i].weight, x[i].x.el, x[i].x.ol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user