]> git.donarmstrong.com Git - samtools.git/blobdiff - bam_plcmd.c
allow to read the prior from the error output. EM iteration is working.
[samtools.git] / bam_plcmd.c
index 8affabfd078f0a18452e65c29d60a39b0071e0ba..0cf081d046a0614303957723a94061069545cc86 100644 (file)
@@ -454,11 +454,12 @@ int bam_pileup(int argc, char *argv[])
 #define MPLP_VAR   0x2
 #define MPLP_AFALL 0x8
 #define MPLP_GLF   0x10
+#define MPLP_NO_COMP 0x20
 
 #define MPLP_AFS_BLOCK 0x10000
 
 typedef struct {
-       int max_mq, min_mq, prior_type, flag;
+       int max_mq, min_mq, prior_type, flag, min_baseQ;
        double theta;
        char *reg, *fn_pos;
        faidx_t *fai;
@@ -498,6 +499,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
        bcf_callret1_t *bcr = 0;
        bcf_call_t bc;
        bcf_t *bp = 0;
+       bcf_hdr_t *bh = 0;
 
        memset(&bc, 0, sizeof(bcf_call_t));
        data = calloc(n, sizeof(void*));
@@ -537,15 +539,16 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
        // write the VCF header
        if (conf->flag & MPLP_GLF) {
                kstring_t s;
+               bh = calloc(1, sizeof(bcf_hdr_t));
                s.l = s.m = 0; s.s = 0;
-               bp = bcf_open("-", "w");
+               bp = bcf_open("-", (conf->flag&MPLP_NO_COMP)? "wu" : "w");
                for (i = 0; i < h->n_targets; ++i) {
                        kputs(h->target_name[i], &s);
                        kputc('\0', &s);
                }
-               bp->h.l_nm = s.l;
-               bp->h.name = malloc(s.l);
-               memcpy(bp->h.name, s.s, s.l);
+               bh->l_nm = s.l;
+               bh->name = malloc(s.l);
+               memcpy(bh->name, s.s, s.l);
                s.l = 0;
                for (i = 0; i < n; ++i) {
                        const char *p;
@@ -554,13 +557,13 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                        else kputs(fn[i], &s);
                        kputc('\0', &s);
                }
-               bp->h.l_smpl = s.l;
-               bp->h.sname = malloc(s.l);
-               memcpy(bp->h.sname, s.s, s.l);
-               bp->h.l_txt = 0;
+               bh->l_smpl = s.l;
+               bh->sname = malloc(s.l);
+               memcpy(bh->sname, s.s, s.l);
+               bh->l_txt = 0;
                free(s.s);
-               bcf_hdr_sync(&bp->h);
-               bcf_hdr_write(bp);
+               bcf_hdr_sync(bh);
+               bcf_hdr_write(bp, bh);
        } else if (conf->flag & MPLP_VCF) {
                kstring_t s;
                s.l = s.m = 0; s.s = 0;
@@ -583,7 +586,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
        }
        // mpileup
        if (conf->flag & MPLP_GLF) {
-               bca = bcf_call_init(-1.);
+               bca = bcf_call_init(-1., conf->min_baseQ);
                bcr = calloc(n, sizeof(bcf_callret1_t));
        } else if (conf->flag & MPLP_VCF) {
                ma = mc_init(n);
@@ -612,7 +615,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                                bcf_call_glfgen(n_plp[i], plp[i], ref16, bca, bcr + i);
                        bcf_call_combine(n, bcr, ref16, &bc);
                        bcf_call2bcf(tid, pos, &bc, b);
-                       bcf_write(bp, b);
+                       bcf_write(bp, bh, b);
                        //fprintf(stderr, "%d,%d,%d\n", b->tid, b->pos, b->l_str);
                        bcf_destroy(b);
                } else if (conf->flag & MPLP_VCF) {
@@ -695,7 +698,7 @@ static int mpileup(mplp_conf_t *conf, int n, char **fn)
                        if (kh_exist(hash, k)) free(kh_val(hash, k));
                kh_destroy(64, hash);
        }
-       bcf_call_destroy(bca); free(bc.PL); free(bcr);
+       bcf_hdr_destroy(bh); bcf_call_destroy(bca); free(bc.PL); free(bcr);
        mc_destroy(ma);
        bam_mplp_destroy(iter);
        bam_header_destroy(h);
@@ -716,7 +719,8 @@ int bam_mpileup(int argc, char *argv[])
        mplp.max_mq = 60;
        mplp.prior_type = MC_PTYPE_FULL;
        mplp.theta = 1e-3;
-       while ((c = getopt(argc, argv, "gvVcFSP:f:r:l:VM:q:t:")) >= 0) {
+       mplp.min_baseQ = 13;
+       while ((c = getopt(argc, argv, "gvVcFSP:f:r:l:VM:q:t:Q:u")) >= 0) {
                switch (c) {
                case 't': mplp.theta = atof(optarg); break;
                case 'P':
@@ -739,8 +743,10 @@ int bam_mpileup(int argc, char *argv[])
                case 'c': mplp.flag |= MPLP_VCF; break;
                case 'F': mplp.flag |= MPLP_AFALL; break;
                case 'v': mplp.flag |= MPLP_VAR; break;
+               case 'u': mplp.flag |= MPLP_NO_COMP; 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;
                }
        }
        if (mplp.flag&MPLP_GLF) mplp.flag &= ~MPLP_VCF;
@@ -754,6 +760,7 @@ 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, "         -t FLOAT    scaled mutation rate [%lg]\n", mplp.theta);
                fprintf(stderr, "         -P STR      prior: full, flat, cond2 [full]\n");
+               fprintf(stderr, "         -Q INT      min base quality [%d]\n", mplp.min_baseQ);
                fprintf(stderr, "         -c          generate VCF output (consensus calling)\n");
                fprintf(stderr, "         -g          generate GLF output\n");
                fprintf(stderr, "         -v          show variant sites only\n");