From 41efd03d7aeedb21c221f12901c3e30ba22a277f Mon Sep 17 00:00:00 2001 From: Heng Li Date: Fri, 30 Jun 2017 23:48:00 -0400 Subject: [PATCH] r129: fixed memory leak caused by qualities --- bseq.c | 4 ++-- bseq.h | 2 +- index.c | 2 +- main.c | 2 +- map.c | 3 ++- minimap2.1 | 19 +++++++++++++++++-- 6 files changed, 24 insertions(+), 8 deletions(-) diff --git a/bseq.c b/bseq.c index 16ead16..f68b11d 100644 --- a/bseq.c +++ b/bseq.c @@ -32,7 +32,7 @@ void bseq_close(bseq_file_t *fp) free(fp); } -bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_) +bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int with_qual, int *n_) { int size = 0, m, n; bseq1_t *seqs; @@ -48,7 +48,7 @@ bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_) s = &seqs[n]; s->name = strdup(ks->name.s); s->seq = strdup(ks->seq.s); - s->qual = ks->qual.l? strdup(ks->qual.s) : 0; + s->qual = with_qual && ks->qual.l? strdup(ks->qual.s) : 0; s->l_seq = ks->seq.l; size += seqs[n++].l_seq; if (size >= chunk_size) break; diff --git a/bseq.h b/bseq.h index bb06766..df9d5bb 100644 --- a/bseq.h +++ b/bseq.h @@ -13,7 +13,7 @@ typedef struct { bseq_file_t *bseq_open(const char *fn); void bseq_close(bseq_file_t *fp); -bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_); +bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int with_qual, int *n_); int bseq_eof(bseq_file_t *fp); extern unsigned char seq_nt4_table[256]; diff --git a/index.c b/index.c index 426f7a9..6dc1f76 100644 --- a/index.c +++ b/index.c @@ -217,7 +217,7 @@ static void *worker_pipeline(void *shared, int step, void *in) step_t *s; if (p->sum_len > p->batch_size) return 0; s = (step_t*)calloc(1, sizeof(step_t)); - s->seq = bseq_read(p->fp, p->mini_batch_size, &s->n_seq); // read a mini-batch + s->seq = bseq_read(p->fp, p->mini_batch_size, 0, &s->n_seq); // read a mini-batch if (s->seq) { uint32_t old_m, m; uint64_t sum_len, old_max_len, max_len; diff --git a/main.c b/main.c index ea3d6d6..3c312f1 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,7 @@ #include "minimap.h" #include "mmpriv.h" -#define MM_VERSION "2.0-r126-pre" +#define MM_VERSION "2.0-r129-pre" void liftrlimit() { diff --git a/map.c b/map.c index 3e0d26b..53c85db 100644 --- a/map.c +++ b/map.c @@ -304,7 +304,7 @@ static void *worker_pipeline(void *shared, int step, void *in) if (step == 0) { // step 0: read sequences step_t *s; s = (step_t*)calloc(1, sizeof(step_t)); - s->seq = bseq_read(p->fp, p->mini_batch_size, &s->n_seq); + s->seq = bseq_read(p->fp, p->mini_batch_size, !!(p->opt->flag & MM_F_OUT_SAM), &s->n_seq); if (s->seq) { s->p = p; for (i = 0; i < s->n_seq; ++i) @@ -339,6 +339,7 @@ static void *worker_pipeline(void *shared, int step, void *in) } free(s->reg[i]); free(s->seq[i].seq); free(s->seq[i].name); + if (s->seq[i].qual) free(s->seq[i].qual); } free(s->reg); free(s->n_reg); free(s->seq); if (mm_verbose >= 3) diff --git a/minimap2.1 b/minimap2.1 index a4cb1e6..2aa83b1 100644 --- a/minimap2.1 +++ b/minimap2.1 @@ -5,7 +5,7 @@ minimap2 - mapping and alignment between collections of DNA sequences .SH SYNOPSIS -* Index the target sequences (optional): +* Indexing the target sequences (optional): .RS 4 minimap2 .RB [ -H ] @@ -13,12 +13,14 @@ minimap2 .IR kmer ] .RB [ -w .IR miniWinSize ] +.RB [ -I +.IR batchSize ] .B -d .I target.mmi .I target.fa .RE -* Align with CIGAR: +* Long-read alignment with CIGAR: .RS 4 minimap2 .B -b @@ -43,6 +45,19 @@ minimap2 .I output.paf .RE +* Long read overlap without CIGAR: +.RS 4 +minimap2 +.B -x +.R ava10k +.RB [ -t +.IR nThreads ] +.I target.fa +.I query.fa +> +.I output.paf +.RE + .SH DESCRIPTION .PP Minimap2 is a fast sequence mapping and alignment program that can find