X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=sam.c;h=45cb05cf3dd6f8a04acfd4dd92c8d250835855a2;hb=dc1501028f961adf4939576fa59d9b1b7fb50798;hp=4c16b02fb87de19426f50dc3e1573b3f58801a26;hpb=78de989ec56e7c17e1fa854cb8c1c4f9ae08856c;p=samtools.git diff --git a/sam.c b/sam.c index 4c16b02..45cb05c 100644 --- a/sam.c +++ b/sam.c @@ -22,6 +22,18 @@ bam_header_t *bam_header_dup(const bam_header_t *h0) if (h0->rg2lib) h->rg2lib = bam_strmap_dup(h0->rg2lib); return h; } +static void append_header_text(bam_header_t *header, char* text, int len) +{ + int x = header->l_text + 1; + int y = header->l_text + len + 1; // 1 byte null + if (text == 0) return; + kroundup32(x); + kroundup32(y); + if (x < y) header->text = (char*)realloc(header->text, y); + strncpy(header->text + header->l_text, text, len); // we cannot use strcpy() here. + header->l_text += len; + header->text[header->l_text] = 0; +} samfile_t *samopen(const char *fn, const char *mode, const void *aux) { @@ -40,8 +52,10 @@ samfile_t *samopen(const char *fn, const char *mode, const void *aux) fp->header = sam_header_read(fp->x.tamr); if (fp->header->n_targets == 0) { // no @SQ fields if (aux) { // check if aux is present - bam_header_destroy(fp->header); + bam_header_t *textheader = fp->header; fp->header = sam_header_read2((const char*)aux); + append_header_text(fp->header, textheader->text, textheader->l_text); + bam_header_destroy(textheader); } if (fp->header->n_targets == 0) fprintf(stderr, "[samopen] no @SQ lines in the header.\n"); @@ -120,7 +134,7 @@ int samwrite(samfile_t *fp, const bam1_t *b) } } -int sampileup(samfile_t *fp, int mask, int min_mapQ, bam_pileup_f func, void *func_data) +int sampileup(samfile_t *fp, int mask, bam_pileup_f func, void *func_data) { bam_plbuf_t *buf; int ret; @@ -129,8 +143,7 @@ int sampileup(samfile_t *fp, int mask, int min_mapQ, bam_pileup_f func, void *fu buf = bam_plbuf_init(func, func_data); bam_plbuf_set_mask(buf, mask); while ((ret = samread(fp, b)) >= 0) - if (b->core.qual >= min_mapQ) - bam_plbuf_push(b, buf); + bam_plbuf_push(b, buf); bam_plbuf_push(0, buf); bam_plbuf_destroy(buf); bam_destroy1(b);