X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=bcftools%2Fbcf.c;h=24728dbe1515e7cc1171a8cc08f842bafa167d5e;hb=70c740facc966321754c6bfcc6d61ea056480638;hp=e3daaeb5786916085d2725e703d01e1d18a6e2dd;hpb=ec294adf095b60c90e57e31f3af1335138c5a22a;p=samtools.git diff --git a/bcftools/bcf.c b/bcftools/bcf.c index e3daaeb..24728db 100644 --- a/bcftools/bcf.c +++ b/bcftools/bcf.c @@ -269,7 +269,7 @@ void bcf_fmt_core(const bcf_hdr_t *h, bcf1_t *b, kstring_t *s) if ( ploidy==1 ) { if ( y>>7&1 ) - kputsn(".", 3, s); + kputc('.', s); else kputc('0' + (y>>3&7), s); } @@ -323,6 +323,50 @@ int bcf_append_info(bcf1_t *b, const char *info, int l) return 0; } +int remove_tag(char *str, const char *tag, char delim) +{ + char *tmp = str, *p; + int len_diff = 0, ori_len = strlen(str); + while ( *tmp && (p = strstr(tmp,tag)) ) + { + if ( p>str ) + { + if ( *(p-1)!=delim ) { tmp=p+1; continue; } // shared substring + p--; + } + char *q=p+1; + while ( *q && *q!=delim ) q++; + if ( p==str && *q ) q++; // the tag is first, don't move the delim char + len_diff += q-p; + if ( ! *q ) { *p = 0; break; } // the tag was last, no delim follows + else + memmove(p,q,ori_len-(int)(p-str)-(int)(q-p)); // *q==delim + } + if ( len_diff==ori_len ) + str[0]='.', str[1]=0, len_diff--; + + return len_diff; +} + + +void rm_info(kstring_t *s, const char *key) +{ + char *p = s->s; + int n = 0; + while ( n<4 ) + { + if ( !*p ) n++; + p++; + } + char *q = p+1; + while ( *q && q-s->sl ) q++; + + int nrm = remove_tag(p, key, ';'); + if ( nrm ) + memmove(q-nrm, q, s->s+s->l-q+1); + s->l -= nrm; +} + int bcf_cpy(bcf1_t *r, const bcf1_t *b) { char *t1 = r->str;