]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.2-24
authorHeng Li <lh3@live.co.uk>
Sun, 12 Apr 2009 19:57:05 +0000 (19:57 +0000)
committerHeng Li <lh3@live.co.uk>
Sun, 12 Apr 2009 19:57:05 +0000 (19:57 +0000)
 * in merge, gives a warning rather than error if the target sequence length is different
 * allow empty header

bam.c
bam_import.c
bam_sort.c
bamtk.c
kseq.h

diff --git a/bam.c b/bam.c
index ee145a1f20587236e8b4b99567f9d9f23eb3ba02..1b74c6d150a8d1003c3775785e7c93e108009b29 100644 (file)
--- a/bam.c
+++ b/bam.c
@@ -102,7 +102,6 @@ bam_header_t *bam_header_read(bamFile fp)
        bam_read(fp, header->text, header->l_text);
        bam_read(fp, &header->n_targets, 4);
        if (bam_is_be) bam_swap_endian_4p(&header->n_targets);
        bam_read(fp, header->text, header->l_text);
        bam_read(fp, &header->n_targets, 4);
        if (bam_is_be) bam_swap_endian_4p(&header->n_targets);
-       assert(header->n_targets > 0);
        // read reference sequence names and lengths
        header->target_name = (char**)calloc(header->n_targets, sizeof(char*));
        header->target_len = (uint32_t*)calloc(header->n_targets, 4);
        // read reference sequence names and lengths
        header->target_name = (char**)calloc(header->n_targets, sizeof(char*));
        header->target_len = (uint32_t*)calloc(header->n_targets, 4);
index 7157f2ae242aef58c621702b07448cefc83e34a8..746dc5bbbde0415911794b28d666a4a53ef86be8 100644 (file)
@@ -102,7 +102,7 @@ bam_header_t *sam_header_read2(const char *fn)
        assert(fp);
        ks = ks_init(fp);
        str = (kstring_t*)calloc(1, sizeof(kstring_t));
        assert(fp);
        ks = ks_init(fp);
        str = (kstring_t*)calloc(1, sizeof(kstring_t));
-       while (ks_getuntil(ks, 0, str, &dret) >= 0) {
+       while (ks_getuntil(ks, 0, str, &dret) > 0) {
                char *s = strdup(str->s);
                int len, i;
                i = kh_size(hash);
                char *s = strdup(str->s);
                int len, i;
                i = kh_size(hash);
index dbe7495a0f1a5e6646911ff8230c110e78d91b53..7c5fbb2faf4e7cc5268cbf924550461979bb4a84 100644 (file)
@@ -66,13 +66,17 @@ void bam_merge_core(int by_qname, const char *out, int n, char * const *fn)
                else { // validate multiple baf
                        if (hout->n_targets != hin->n_targets) {
                                fprintf(stderr, "[bam_merge_core] file '%s' has different number of target sequences. Abort!\n", fn[i]);
                else { // validate multiple baf
                        if (hout->n_targets != hin->n_targets) {
                                fprintf(stderr, "[bam_merge_core] file '%s' has different number of target sequences. Abort!\n", fn[i]);
-                               abort();
+                               exit(1);
                        }
                        for (j = 0; j < hout->n_targets; ++j) {
                        }
                        for (j = 0; j < hout->n_targets; ++j) {
-                               if (strcmp(hout->target_name[j], hin->target_name[j]) || hout->target_len[j] != hin->target_len[j]) {
-                                       fprintf(stderr, "[bam_merge_core] file '%s' has a different target sequence. Abort!\n", fn[i]);
-                                       abort();
+                               if (strcmp(hout->target_name[j], hin->target_name[j])) {
+                                       fprintf(stderr, "[bam_merge_core] different target sequence name: '%s' != '%s' in file '%s'. Abort!\n",
+                                                       hout->target_name[j], hin->target_name[j], fn[i]);
+                                       exit(1);
                                }
                                }
+                               if (hout->target_len[j] != hin->target_len[j])
+                                       fprintf(stderr, "[bam_merge_core] different target sequence length: %d != %d in file '%s'. Continue.\n",
+                                                       hout->target_len[j], hin->target_len[j], fn[i]);
                        }
                        bam_header_destroy(hin);
                }
                        }
                        bam_header_destroy(hin);
                }
diff --git a/bamtk.c b/bamtk.c
index 62dc2a6ebfce1d14554b6d54c8e7d078dc1ecf5b..1dac729ab27bbd18d670f813161de0558db3197c 100644 (file)
--- a/bamtk.c
+++ b/bamtk.c
@@ -3,7 +3,7 @@
 #include "bam.h"
 
 #ifndef PACKAGE_VERSION
 #include "bam.h"
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.2-23"
+#define PACKAGE_VERSION "0.1.2-24"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
diff --git a/kseq.h b/kseq.h
index e99a8abb2abf7c70ae83d4d3162d994fdbbdec30..bbe012552ff3b2ac047ddd10655e80827bbb4008 100644 (file)
--- a/kseq.h
+++ b/kseq.h
@@ -128,6 +128,10 @@ typedef struct __kstring_t {
                                break;                                                                                                  \
                        }                                                                                                                       \
                }                                                                                                                               \
                                break;                                                                                                  \
                        }                                                                                                                       \
                }                                                                                                                               \
+               if (str->l == 0) {                                                                                              \
+                       str->m = 1;                                                                                                     \
+                       str->s = (char*)calloc(1, 1);                                                           \
+               }                                                                                                                               \
                str->s[str->l] = '\0';                                                                                  \
                return str->l;                                                                                                  \
        }
                str->s[str->l] = '\0';                                                                                  \
                return str->l;                                                                                                  \
        }