#define MPLP_NO_COMP 0x20
#define MPLP_NO_ORPHAN 0x40
#define MPLP_REALN 0x80
-#define MPLP_NO_HALFTRIM 0x100
typedef struct {
- int max_mq, min_mq, flag, min_baseQ;
- double theta;
+ int max_mq, min_mq, flag, min_baseQ, capQ_thres;
char *reg, *fn_pos;
faidx_t *fai;
kh_64_t *hash;
typedef struct {
bamFile fp;
bam_iter_t iter;
- int min_mq, flag;
+ int min_mq, flag, ref_id, capQ_thres;
char *ref;
} mplp_aux_t;
static int mplp_func(void *data, bam1_t *b)
{
extern int bam_realn(bam1_t *b, const char *ref);
+ extern int bam_prob_realn(bam1_t *b, const char *ref);
+ extern int bam_cap_mapQ(bam1_t *b, char *ref, int thres);
mplp_aux_t *ma = (mplp_aux_t*)data;
- int ret, cond = 0;
+ int ret, skip = 0;
do {
- cond = 0;
+ int has_ref = (ma->ref && ma->ref_id == b->core.tid)? 1 : 0;
ret = ma->iter? bam_iter_read(ma->fp, ma->iter, b) : bam_read1(ma->fp, b);
if (ret < 0) break;
- if (b->core.qual < ma->min_mq) cond = 1;
- else if ((ma->flag&MPLP_NO_ORPHAN) && (b->core.flag&1) && !(b->core.flag&2)) cond = 1;
- if (ma->ref && !cond && (ma->flag&MPLP_REALN)) bam_realn(b, ma->ref);
- } while (cond);
+ skip = 0;
+ if (has_ref && (ma->flag&MPLP_REALN)) bam_prob_realn(b, ma->ref);
+ if (has_ref && ma->capQ_thres > 10) {
+ int q = bam_cap_mapQ(b, ma->ref, ma->capQ_thres);
+ if (q < 0) skip = 1;
+ else if (b->core.qual > q) b->core.qual = q;
+ } else if (b->core.flag&BAM_FUNMAP) skip = 1;
+ else if (b->core.qual < ma->min_mq) skip = 1;
+ else if ((ma->flag&MPLP_NO_ORPHAN) && (b->core.flag&1) && !(b->core.flag&2)) skip = 1;
+ } while (skip);
return ret;
}
data[i] = calloc(1, sizeof(mplp_aux_t));
data[i]->min_mq = conf->min_mq;
data[i]->flag = conf->flag;
- data[i]->fp = bam_open(fn[i], "r");
+ data[i]->capQ_thres = conf->capQ_thres;
+ data[i]->fp = strcmp(fn[i], "-") == 0? bam_dopen(fileno(stdin), "r") : bam_open(fn[i], "r");
h_tmp = bam_header_read(data[i]->fp);
bam_smpl_add(sm, fn[i], h_tmp->text);
if (conf->reg) {
if (k == kh_end(hash)) continue;
}
if (tid != ref_tid) {
- free(ref);
+ free(ref); ref = 0;
if (conf->fai) ref = fai_fetch(conf->fai, h->target_name[tid], &ref_len);
- for (i = 0; i < n; ++i) data[i]->ref = ref;
+ for (i = 0; i < n; ++i) data[i]->ref = ref, data[i]->ref_id = tid;
ref_tid = tid;
}
if (conf->flag & MPLP_GLF) {
mplp_conf_t mplp;
memset(&mplp, 0, sizeof(mplp_conf_t));
mplp.max_mq = 60;
- mplp.theta = 1e-3;
mplp.min_baseQ = 13;
- while ((c = getopt(argc, argv, "gf:r:l:M:q:t:Q:uaORH")) >= 0) {
+ mplp.capQ_thres = 0;
+ while ((c = getopt(argc, argv, "gf:r:l:M:q:Q:uaORC:")) >= 0) {
switch (c) {
- case 't': mplp.theta = atof(optarg); break;
case 'f':
mplp.fai = fai_load(optarg);
if (mplp.fai == 0) return 1;
case 'r': mplp.reg = strdup(optarg); break;
case 'l': mplp.fn_pos = strdup(optarg); break;
case 'g': mplp.flag |= MPLP_GLF; break;
- case 'u': mplp.flag |= MPLP_NO_COMP; break;
- case 'a': mplp.flag |= MPLP_NO_ORPHAN | MPLP_REALN | MPLP_NO_HALFTRIM; break;
+ case 'u': mplp.flag |= MPLP_NO_COMP | MPLP_GLF; break;
+ case 'a': mplp.flag |= MPLP_NO_ORPHAN | MPLP_REALN; break;
case 'O': mplp.flag |= MPLP_NO_ORPHAN; break;
- case 'H': mplp.flag |= MPLP_NO_HALFTRIM; break;
case 'R': mplp.flag |= MPLP_REALN; break;
+ case 'C': mplp.capQ_thres = atoi(optarg); break;
case 'M': mplp.max_mq = atoi(optarg); break;
case 'q': mplp.min_mq = atoi(optarg); break;
case 'Q': mplp.min_baseQ = atoi(optarg); break;
fprintf(stderr, " -M INT cap mapping quality at INT [%d]\n", mplp.max_mq);
fprintf(stderr, " -Q INT min base quality [%d]\n", mplp.min_baseQ);
fprintf(stderr, " -q INT filter out alignment with MQ smaller than INT [%d]\n", mplp.min_mq);
- fprintf(stderr, " -t FLOAT scaled mutation rate [%lg]\n", mplp.theta);
fprintf(stderr, " -g generate BCF output\n");
fprintf(stderr, " -u do not compress BCF output\n");
fprintf(stderr, "\n");