]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.5-28 (r444)
authorHeng Li <lh3@live.co.uk>
Tue, 11 Aug 2009 09:02:36 +0000 (09:02 +0000)
committerHeng Li <lh3@live.co.uk>
Tue, 11 Aug 2009 09:02:36 +0000 (09:02 +0000)
 * bug in "merge -n"

bam_sort.c
bamtk.c

index 402792aea44952a5962e340e9a0efbad75654494..c43e56f356a5578d0a2365ddba5708826fb96975 100644 (file)
@@ -40,7 +40,9 @@ typedef struct {
 static inline int heap_lt(const heap1_t a, const heap1_t b)
 {
        if (g_is_by_qname) {
-               int t = strnum_cmp(bam1_qname(a.b), bam1_qname(b.b));
+               int t;
+               if (a.b == 0 || b.b == 0) return a.b == 0? 1 : 0;
+               t = strnum_cmp(bam1_qname(a.b), bam1_qname(b.b));
                return (t > 0 || (t == 0 && a.pos > b.pos));
        } else return (a.pos > b.pos);
 }
@@ -106,18 +108,17 @@ void bam_merge_core(int by_qname, const char *out, int n, char * const *fn)
        while (heap->pos != HEAP_EMPTY) {
                bam1_t *b = heap->b;
                bam_write1_core(fpout, &b->core, b->data_len, b->data);
-               if ((j = bam_read1(fp[heap->i], b)) >= 0)
+               if ((j = bam_read1(fp[heap->i], b)) >= 0) {
                        heap->pos = ((uint64_t)b->core.tid<<32) | (uint32_t)b->core.pos<<1 | bam1_strand(b);
-               else if (j == -1) heap->pos = HEAP_EMPTY;
-               else fprintf(stderr, "[bam_merge_core] '%s' is truncated. Continue anyway.\n", fn[heap->i]);
+               } else if (j == -1) {
+                       heap->pos = HEAP_EMPTY;
+                       free(heap->b->data); free(heap->b);
+                       heap->b = 0;
+               } else fprintf(stderr, "[bam_merge_core] '%s' is truncated. Continue anyway.\n", fn[heap->i]);
                ks_heapadjust(heap, 0, n, heap);
        }
 
-       for (i = 0; i != n; ++i) {
-               bam_close(fp[i]);
-               free(heap[i].b->data);
-               free(heap[i].b);
-       }
+       for (i = 0; i != n; ++i) bam_close(fp[i]);
        bam_close(fpout);
        free(fp); free(heap);
 }
@@ -222,7 +223,7 @@ void bam_sort_core(int is_by_qname, const char *fn, const char *prefix, size_t m
                bam_merge_core(is_by_qname, fnout, n, fns);
                free(fnout);
                for (i = 0; i < n; ++i) {
-                       unlink(fns[i]);
+//                     unlink(fns[i]);
                        free(fns[i]);
                }
                free(fns);
diff --git a/bamtk.c b/bamtk.c
index 2df90323812775db7102785effc8c9192948178f..a7c67ab615024eddb843401730f1f393a132b19f 100644 (file)
--- a/bamtk.c
+++ b/bamtk.c
@@ -9,7 +9,7 @@
 #endif
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.5-27 (r443)"
+#define PACKAGE_VERSION "0.1.5-28 (r444)"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);