From e0baf1ad54c5c3762cc9e330b1f38b251ba5ced0 Mon Sep 17 00:00:00 2001 From: Heng Li Date: Thu, 5 Oct 2017 16:15:14 -0400 Subject: [PATCH] r479: a bit code cleanup --- Makefile | 6 +++--- align.c | 8 +++++--- format.c | 2 +- main.c | 2 +- map.c | 17 +++++++++-------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 602ff33..972ecd6 100644 --- a/Makefile +++ b/Makefile @@ -68,7 +68,7 @@ chain.o: minimap.h mmpriv.h bseq.h kalloc.h example.o: minimap.h kseq.h format.o: kalloc.h mmpriv.h minimap.h bseq.h getopt.o: getopt.h -hit.o: mmpriv.h minimap.h bseq.h kalloc.h +hit.o: mmpriv.h minimap.h bseq.h kalloc.h khash.h index.o: kthread.h bseq.h minimap.h mmpriv.h kvec.h kalloc.h khash.h kalloc.o: kalloc.h ksw2_extd2_sse.o: ksw2.h kalloc.h @@ -76,8 +76,8 @@ ksw2_exts2_sse.o: ksw2.h kalloc.h ksw2_extz2_sse.o: ksw2.h kalloc.h ksw2_ll_sse.o: ksw2.h kalloc.h main.o: bseq.h minimap.h mmpriv.h getopt.h -map.o: kthread.h kvec.h kalloc.h sdust.h mmpriv.h minimap.h bseq.h +map.o: kthread.h kvec.h kalloc.h sdust.h mmpriv.h minimap.h bseq.h khash.h misc.o: minimap.h ksort.h -pe.o: mmpriv.h minimap.h bseq.h +pe.o: mmpriv.h minimap.h bseq.h kvec.h kalloc.h ksort.h sdust.o: kalloc.h kdq.h kvec.h sdust.h sketch.o: kvec.h kalloc.h minimap.h diff --git a/align.c b/align.c index 7034b3a..dc4b7fd 100644 --- a/align.c +++ b/align.c @@ -487,9 +487,11 @@ mm_reg1_t *mm_align_skeleton(void *km, const mm_mapopt_t *opt, const mm_idx_t *m regs[i].p->trans_strand = opt->flag&MM_F_SPLICE_FOR? 1 : 2; } if (r2.cnt > 0) regs = mm_insert_reg(&r2, i, &n_regs, regs); - if (i > 0 && mm_align1_inv(km, opt, mi, qlen, qseq0, ®s[i-1], ®s[i], &r2, &ez)) { - regs = mm_insert_reg(&r2, i, &n_regs, regs); - ++i; // skip the inserted INV alignment + if (!(opt->flag&MM_F_SPLICE) && !(opt->flag&MM_F_SR) && i > 0) { // don't try inversion alignment for -xsplice or -xsr + if (mm_align1_inv(km, opt, mi, qlen, qseq0, ®s[i-1], ®s[i], &r2, &ez)) { + regs = mm_insert_reg(&r2, i, &n_regs, regs); + ++i; // skip the inserted INV alignment + } } } *n_regs_ = n_regs; diff --git a/format.c b/format.c index 913bfcb..ef12397 100644 --- a/format.c +++ b/format.c @@ -254,7 +254,7 @@ void mm_write_sam2(kstring_t *s, const mm_idx_t *mi, const mm_bseq1_t *t, int se { int flag, n_regs = n_regss[seg_idx]; int this_rid = -1, this_pos = -1, this_rev = 0; - const mm_reg1_t *regs = regss[seg_idx], *r_prev, *r_next; + const mm_reg1_t *regs = regss[seg_idx], *r_prev = NULL, *r_next; const mm_reg1_t *r = n_regs > 0 && reg_idx < n_regs && reg_idx >= 0? ®s[reg_idx] : NULL; // find the primary of the previous and the next segments, if they are mapped diff --git a/main.c b/main.c index 8db8a24..9a9da20 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ #include "mmpriv.h" #include "getopt.h" -#define MM_VERSION "2.2-r478-dirty" +#define MM_VERSION "2.2-r479-dirty" #ifdef __linux__ #include diff --git a/map.c b/map.c index b349142..55f426b 100644 --- a/map.c +++ b/map.c @@ -260,7 +260,7 @@ static mm_reg1_t *align_regs(const mm_mapopt_t *opt, const mm_idx_t *mi, void *k void mm_map_frag(const mm_idx_t *mi, int n_segs, const int *qlens, const char **seqs, int *n_regs, mm_reg1_t **regs, mm_tbuf_t *b, const mm_mapopt_t *opt, const char *qname) { - int i, j, max_gap_ref, rep_len, qlen_sum, n_regs0, rechain = 0; + int i, j, max_gap_ref, rep_len, qlen_sum, n_regs0; uint32_t hash; int64_t n_a; uint64_t *u; @@ -291,7 +291,8 @@ void mm_map_frag(const mm_idx_t *mi, int n_segs, const int *qlens, const char ** a = mm_chain_dp(max_gap_ref, opt->max_gap, opt->bw, opt->max_chain_skip, opt->min_cnt, opt->min_chain_score, !!(opt->flag&MM_F_SPLICE), n_segs, n_a, a, &n_regs0, &u, b->km); if ((opt->flag & MM_F_SR) && rep_len > 0) { - if (n_regs0 > 0) { + int rechain = 0; + if (n_regs0 > 0) { // test if the best chain has all the segments int n_chained_segs = 1, max = 0, max_i = -1, max_off = -1, off = 0; for (i = 0; i < n_regs0; ++i) { // find the best chain if (max < u[i]>>32) max = u[i]>>32, max_i = i, max_off = off; @@ -322,22 +323,22 @@ void mm_map_frag(const mm_idx_t *mi, int n_segs, const int *qlens, const char ** chain_post(opt, mi, b->km, qlen_sum, n_segs, qlens, &n_regs0, regs0, a); - if (n_segs == 1) { + if (n_segs == 1) { // uni-segment regs0 = align_regs(opt, mi, b->km, qlens[0], seqs[0], &n_regs0, regs0, a); mm_set_mapq(n_regs0, regs0, opt->min_chain_score, opt->a, rep_len); n_regs[0] = n_regs0, regs[0] = regs0; - } else { + } else { // multi-segment mm_seg_t *seg; - seg = mm_seg_gen(b->km, hash, n_segs, qlens, n_regs0, regs0, n_regs, regs, a); + seg = mm_seg_gen(b->km, hash, n_segs, qlens, n_regs0, regs0, n_regs, regs, a); // split fragment chain to separate segment chains free(regs0); for (i = 0; i < n_segs; ++i) { - mm_set_parent(b->km, opt->mask_level, n_regs[i], regs[i], opt->a * 2 + opt->b); + mm_set_parent(b->km, opt->mask_level, n_regs[i], regs[i], opt->a * 2 + opt->b); // update mm_reg1_t::parent regs[i] = align_regs(opt, mi, b->km, qlens[i], seqs[i], &n_regs[i], regs[i], seg[i].a); mm_set_mapq(n_regs[i], regs[i], opt->min_chain_score, opt->a, rep_len); } mm_seg_free(b->km, n_segs, seg); if (n_segs == 2 && opt->pe_ori >= 0 && (opt->flag&MM_F_CIGAR)) - mm_pair(b->km, max_gap_ref, opt->pe_bonus, opt->a * 2 + opt->b, opt->a, qlens, n_regs, regs); + mm_pair(b->km, max_gap_ref, opt->pe_bonus, opt->a * 2 + opt->b, opt->a, qlens, n_regs, regs); // pairing } kfree(b->km, a); @@ -424,7 +425,7 @@ static void *worker_pipeline(void *shared, int step, void *in) for (i = 0; i < p->n_threads; ++i) s->buf[i] = mm_tbuf_init(); s->n_reg = (int*)calloc(3 * s->n_seq, sizeof(int)); - s->seg_off = s->n_reg + s->n_seq; + s->seg_off = s->n_reg + s->n_seq; // seg_off and n_seg are allocated together with n_reg s->n_seg = s->seg_off + s->n_seq; s->reg = (mm_reg1_t**)calloc(s->n_seq, sizeof(mm_reg1_t*)); for (i = 1, j = 0; i <= s->n_seq; ++i)