X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bam_plcmd.c;h=75f5691c7815184b43d29e9c9072df5856ddff5e;hb=f221655a2515b417a545caece40b6985e927fb83;hp=f0e63ce62cd91cc6cada955eaa19c9b2493e1872;hpb=6ee6fd65332260af63fbfbf0a625ea3847371eda;p=samtools.git diff --git a/bam_plcmd.c b/bam_plcmd.c index f0e63ce..75f5691 100644 --- a/bam_plcmd.c +++ b/bam_plcmd.c @@ -183,10 +183,15 @@ static inline void pileup_seq(const bam_pileup1_t *p, int pos, int ref_len, cons putchar(p->b->core.qual > 93? 126 : p->b->core.qual + 33); } if (!p->is_del) { - int rb, c = bam_nt16_rev_table[bam1_seqi(bam1_seq(p->b), p->qpos)]; - rb = (ref && pos < ref_len)? ref[pos] : 'N'; - if (c == '=' || toupper(c) == toupper(rb)) c = bam1_strand(p->b)? ',' : '.'; - else c = bam1_strand(p->b)? tolower(c) : toupper(c); + int c = bam_nt16_rev_table[bam1_seqi(bam1_seq(p->b), p->qpos)]; + if (ref) { + int rb = pos < ref_len? ref[pos] : 'N'; + if (c == '=' || bam_nt16_table[c] == bam_nt16_table[rb]) c = bam1_strand(p->b)? ',' : '.'; + else c = bam1_strand(p->b)? tolower(c) : toupper(c); + } else { + if (c == '=') c = bam1_strand(p->b)? ',' : '.'; + else c = bam1_strand(p->b)? tolower(c) : toupper(c); + } putchar(c); } else putchar(p->is_refskip? (bam1_strand(p->b)? '<' : '>') : '*'); if (p->indel > 0) { @@ -286,16 +291,18 @@ static int pileup_func(uint32_t tid, uint32_t pos, int n, const bam_pileup1_t *p } // print pileup sequences printw(n, stdout); putchar('\t'); - rms_aux = 0; // we need to recalculate rms_mapq when -c is not flagged on the command line - for (i = 0; i < n; ++i) { - const bam_pileup1_t *p = pu + i; - int tmp = p->b->core.qual < d->c->cap_mapQ? p->b->core.qual : d->c->cap_mapQ; - rms_aux += tmp * tmp; - pileup_seq(p, pos, d->len, d->ref); - } + for (i = 0; i < n; ++i) + pileup_seq(pu + i, pos, d->len, d->ref); // finalize rms_mapq - rms_aux = (uint64_t)(sqrt((double)rms_aux / n) + .499); - if (rms_mapq < 0) rms_mapq = rms_aux; + if (d->format & BAM_PLF_CNS) { + for (i = rms_aux = 0; i < n; ++i) { + const bam_pileup1_t *p = pu + i; + int tmp = p->b->core.qual < d->c->cap_mapQ? p->b->core.qual : d->c->cap_mapQ; + rms_aux += tmp * tmp; + } + rms_aux = (uint64_t)(sqrt((double)rms_aux / n) + .499); + if (rms_mapq < 0) rms_mapq = rms_aux; + } putchar('\t'); // print quality for (i = 0; i < n; ++i) { @@ -466,6 +473,7 @@ int bam_pileup(int argc, char *argv[]) bam_plp_set_mask(iter, d->mask); while ((ret = samread(fp, b)) >= 0) { int skip = 0; + if ((int)b->core.tid < 0) break; // update d->ref if necessary if (d->fai && (int)b->core.tid != d->tid) { free(d->ref); @@ -520,6 +528,7 @@ int bam_pileup(int argc, char *argv[]) #define MPLP_NO_COMP 0x20 #define MPLP_NO_ORPHAN 0x40 #define MPLP_REALN 0x80 +#define MPLP_SAMINFO 0x100 typedef struct { int max_mq, min_mq, flag, min_baseQ, capQ_thres; @@ -706,7 +715,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn) for (i = 0; i < gplp.n; ++i) bcf_call_glfgen(gplp.n_plp[i], gplp.plp[i], ref16, bca, bcr + i); bcf_call_combine(gplp.n, bcr, ref16, &bc); - bcf_call2bcf(tid, pos, &bc, b); + bcf_call2bcf(tid, pos, &bc, b, (conf->flag&MPLP_SAMINFO)? bcr : 0); bcf_write(bp, bh, b); bcf_destroy(b); } else { @@ -761,7 +770,8 @@ int bam_mpileup(int argc, char *argv[]) mplp.max_mq = 60; mplp.min_baseQ = 13; mplp.capQ_thres = 0; - while ((c = getopt(argc, argv, "gf:r:l:M:q:Q:uaORC:")) >= 0) { + mplp.flag = MPLP_NO_ORPHAN | MPLP_REALN; + while ((c = getopt(argc, argv, "gf:r:l:M:q:Q:uaORC:BI")) >= 0) { switch (c) { case 'f': mplp.fai = fai_load(optarg); @@ -772,8 +782,10 @@ int bam_mpileup(int argc, char *argv[]) case 'g': mplp.flag |= MPLP_GLF; break; case 'u': mplp.flag |= MPLP_NO_COMP | MPLP_GLF; break; case 'a': mplp.flag |= MPLP_NO_ORPHAN | MPLP_REALN; break; + case 'B': mplp.flag &= ~MPLP_REALN & ~MPLP_NO_ORPHAN; break; case 'O': mplp.flag |= MPLP_NO_ORPHAN; break; case 'R': mplp.flag |= MPLP_REALN; break; + case 'I': mplp.flag |= MPLP_SAMINFO; 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; @@ -791,6 +803,8 @@ int bam_mpileup(int argc, char *argv[]) fprintf(stderr, " -q INT filter out alignment with MQ smaller than INT [%d]\n", mplp.min_mq); fprintf(stderr, " -g generate BCF output\n"); fprintf(stderr, " -u do not compress BCF output\n"); + fprintf(stderr, " -B disable BAQ computation\n"); + fprintf(stderr, " -I additional individual information (DP and ST)\n"); fprintf(stderr, "\n"); fprintf(stderr, "Notes: Assuming diploid individuals.\n\n"); return 1;