]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.4-23 (r372)
authorHeng Li <lh3@live.co.uk>
Tue, 7 Jul 2009 08:49:27 +0000 (08:49 +0000)
committerHeng Li <lh3@live.co.uk>
Tue, 7 Jul 2009 08:49:27 +0000 (08:49 +0000)
 * keep header text if "view -t" is used (by Gerton)

bamtk.c
sam.c

diff --git a/bamtk.c b/bamtk.c
index a30c9f5fe941a582ba7d39e5b558dc20b7055b2f..56cca0a5d3a552d70e35e8622db91ec9bc39aaf5 100644 (file)
--- 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 5b02abbc94daad6f5eb7b19f596fba6d9dc54109..d53aa0eacd47b24ebf74629e7d15c5d88a6cfcc6 100644 (file)
--- 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");