From: Heng Li Date: Sun, 12 Apr 2009 19:57:05 +0000 (+0000) Subject: * samtools-0.1.2-24 X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=8cc87acf088966330e253d44e67791696d74f35b * samtools-0.1.2-24 * in merge, gives a warning rather than error if the target sequence length is different * allow empty header --- diff --git a/bam.c b/bam.c index ee145a1..1b74c6d 100644 --- 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); - 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); diff --git a/bam_import.c b/bam_import.c index 7157f2a..746dc5b 100644 --- a/bam_import.c +++ b/bam_import.c @@ -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)); - 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); diff --git a/bam_sort.c b/bam_sort.c index dbe7495..7c5fbb2 100644 --- a/bam_sort.c +++ b/bam_sort.c @@ -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]); - abort(); + exit(1); } 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); } diff --git a/bamtk.c b/bamtk.c index 62dc2a6..1dac729 100644 --- a/bamtk.c +++ b/bamtk.c @@ -3,7 +3,7 @@ #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[]); diff --git a/kseq.h b/kseq.h index e99a8ab..bbe0125 100644 --- a/kseq.h +++ b/kseq.h @@ -128,6 +128,10 @@ typedef struct __kstring_t { break; \ } \ } \ + if (str->l == 0) { \ + str->m = 1; \ + str->s = (char*)calloc(1, 1); \ + } \ str->s[str->l] = '\0'; \ return str->l; \ }