From: Heng Li Date: Tue, 7 Jul 2009 08:49:27 +0000 (+0000) Subject: * samtools-0.1.4-23 (r372) X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=21cb882e9cbf5a43f1de4143e0661a038ab83748;p=samtools.git * samtools-0.1.4-23 (r372) * keep header text if "view -t" is used (by Gerton) --- diff --git a/bamtk.c b/bamtk.c index a30c9f5..56cca0a 100644 --- a/bamtk.c +++ b/bamtk.c @@ -4,7 +4,7 @@ #include "bam.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.1.4-22 (r369)" +#define PACKAGE_VERSION "0.1.4-23 (r372)" #endif int bam_taf2baf(int argc, char *argv[]); diff --git a/sam.c b/sam.c index 5b02abb..d53aa0e 100644 --- a/sam.c +++ b/sam.c @@ -22,6 +22,17 @@ 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 + 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 +51,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");