]> git.donarmstrong.com Git - samtools.git/commitdiff
* samtools-0.1.6-7 (r468)
authorHeng Li <lh3@live.co.uk>
Mon, 28 Sep 2009 09:18:29 +0000 (09:18 +0000)
committerHeng Li <lh3@live.co.uk>
Mon, 28 Sep 2009 09:18:29 +0000 (09:18 +0000)
 * make merge stable

bam_sort.c
bamtk.c
misc/samtools.pl

index 1817eb4e43f02e11b4310d7dc25355b6a3090dfc..19a93cb348c7123fc3392d348dbf674b36790306 100644 (file)
@@ -33,18 +33,20 @@ static inline int strnum_cmp(const char *a, const char *b)
 
 typedef struct {
        int i;
-       uint64_t pos;
+       uint64_t pos, idx;
        bam1_t *b;
 } heap1_t;
 
+#define __pos_cmp(a, b) ((a).pos > (b).pos || ((a).pos == (b).pos && ((a).i > (b).i || ((a).i == (b).i && (a).idx > (b).idx))))
+
 static inline int heap_lt(const heap1_t a, const heap1_t b)
 {
        if (g_is_by_qname) {
                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);
+               return (t > 0 || (t == 0 && __pos_cmp(a, b)));
+       } else return __pos_cmp(a, b);
 }
 
 KSORT_INIT(heap, heap1_t, heap_lt)
@@ -76,6 +78,7 @@ void bam_merge_core(int by_qname, const char *out, const char *headers, int n, c
        bam_header_t *hout = 0;
        bam_header_t *hheaders = NULL;
        int i, j;
+       uint64_t idx = 0;
 
        if (headers) {
                tamFile fpheaders = sam_open(headers);
@@ -137,8 +140,10 @@ void bam_merge_core(int by_qname, const char *out, const char *headers, int n, c
                h = heap + i;
                h->i = i;
                h->b = (bam1_t*)calloc(1, sizeof(bam1_t));
-               if (bam_read1(fp[i], h->b) >= 0)
+               if (bam_read1(fp[i], h->b) >= 0) {
                        h->pos = ((uint64_t)h->b->core.tid<<32) | (uint32_t)h->b->core.pos<<1 | bam1_strand(h->b);
+                       h->idx = idx++;
+               }
                else h->pos = HEAP_EMPTY;
        }
        fpout = strcmp(out, "-")? bam_open(out, "w") : bam_dopen(fileno(stdout), "w");
@@ -152,6 +157,7 @@ void bam_merge_core(int by_qname, const char *out, const char *headers, int n, c
                bam_write1_core(fpout, &b->core, b->data_len, b->data);
                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);
+                       heap->idx = idx++;
                } else if (j == -1) {
                        heap->pos = HEAP_EMPTY;
                        free(heap->b->data); free(heap->b);
diff --git a/bamtk.c b/bamtk.c
index a9efb2b314b6a69e2cc75e14bcd4d35c6e5a4b01..b824c1ecd29102cb7fd50d79d9d3b39312d72ee4 100644 (file)
--- a/bamtk.c
+++ b/bamtk.c
@@ -9,7 +9,7 @@
 #endif
 
 #ifndef PACKAGE_VERSION
-#define PACKAGE_VERSION "0.1.6-6 (r466)"
+#define PACKAGE_VERSION "0.1.6-7 (r468)"
 #endif
 
 int bam_taf2baf(int argc, char *argv[]);
index 86b285c5fa6c144a1d60ed61cb48a23bde7f134f..12dca31220b75b7aa5acae6fe3662e8d76573cd6 100755 (executable)
@@ -37,6 +37,16 @@ sub showALEN {
 # varFilter
 #
 
+#
+# Filtration code:
+#
+# d low depth
+# D high depth
+# W too many SNPs in a window (SNP only)
+# G close to a high-quality indel (SNP only)
+# Q low RMS mapping quality (SNP only)
+# g close to another indel with higher quality (indel only)
+
 sub varFilter {
   my %opts = (d=>3, D=>100, l=>30, Q=>25, q=>10, G=>25, s=>100, w=>10, W=>10, N=>2, p=>undef);
   getopts('pq:d:D:l:Q:w:W:N:G:', \%opts);