diff --git a/hit.c b/hit.c index 5623c4e..bc20b16 100644 --- a/hit.c +++ b/hit.c @@ -109,6 +109,28 @@ void mm_update_parent(void *km, float mask_level, int n, mm_reg1_t *r) // due to if (j == k) w[k++] = i; } kfree(km, w); + + for (i = 0; i < n; ++i) { + mm_reg1_t *ri = &r[i], *rp, tmp; + int t; + if (ri->p == 0 || ri->id == ri->parent || ri->parent < 0) continue; + rp = &r[ri->parent]; + if (rp->p && ri->p->dp_max > rp->p->dp_max) { + ri->subsc = rp->score; + tmp = *ri, *ri = *rp, *rp = tmp; + t = ri->id, ri->id = rp->id, rp->id = t; + t = ri->parent, ri->parent = rp->parent, rp->parent = t; + } + } + + for (i = 0; i < n; ++i) { + mm_reg1_t *ri = &r[i], *rp; + if (ri->id == ri->parent || ri->parent < 0) continue; + rp = &r[ri->parent]; + rp->subsc = rp->subsc > ri->score? rp->subsc : ri->score; + if (rp->p && ri->p) + rp->p->dp_max2 = rp->p->dp_max2 > ri->p->dp_max? rp->p->dp_max2 : ri->p->dp_max; + } } void mm_sync_regs(void *km, int n_regs, mm_reg1_t *regs) // keep mm_reg1_t::{id,parent} in sync; also reset id @@ -255,7 +277,9 @@ void mm_set_mapq(int n_regs, mm_reg1_t *regs) mm_reg1_t *r = ®s[i]; if (r->parent == r->id) { int mapq; - mapq = (int)(30.0 * (1. - (float)r->subsc / r->score) * logf(r->score)); + if (r->p && r->p->dp_max2 > 0 && r->p->dp_max > 0) + mapq = (int)(30.0 * (1. - (float)(r->p->dp_max2 * r->subsc) / (r->p->dp_max * r->score)) * logf(r->score)); + else mapq = (int)(30.0 * (1. - (float)r->subsc / r->score) * logf(r->score)); mapq = mapq > 0? mapq : 0; r->mapq = mapq < 60? mapq : 60; } else r->mapq = 0; diff --git a/main.c b/main.c index 24fce9e..749b5f7 100644 --- a/main.c +++ b/main.c @@ -10,7 +10,7 @@ #include "minimap.h" #include "mmpriv.h" -#define MM_VERSION "2.0-r143-pre" +#define MM_VERSION "2.0-r144-pre" void liftrlimit() { diff --git a/minimap.h b/minimap.h index af0cd00..496fe87 100644 --- a/minimap.h +++ b/minimap.h @@ -45,7 +45,7 @@ typedef struct { typedef struct { uint32_t capacity; - int32_t dp_score, dp_max; + int32_t dp_score, dp_max, dp_max2; uint32_t blen; uint32_t n_diff, n_ambi; uint32_t n_cigar;