]> git.donarmstrong.com Git - samtools.git/blobdiff - bam_stat.c
* no changes to samtools itself
[samtools.git] / bam_stat.c
index 142933666d687e261367664aaabcdbfcb4e3107f..81b7b6356ed2f32c255ddcf6129c38d84ca4ab15 100644 (file)
@@ -1,3 +1,4 @@
+#include <unistd.h>
 #include "bam.h"
 
 typedef struct {
@@ -33,13 +34,15 @@ bam_flagstat_t *bam_flagstat_core(bamFile fp)
        bam_flagstat_t *s;
        bam1_t *b;
        bam1_core_t *c;
+       int ret;
        s = (bam_flagstat_t*)calloc(1, sizeof(bam_flagstat_t));
        b = bam_init1();
        c = &b->core;
-       while (bam_read1(fp, b) >= 0) {
+       while ((ret = bam_read1(fp, b)) >= 0)
                flagstat_loop(s, c);
-       }
        bam_destroy1(b);
+       if (ret != -1)
+               fprintf(stderr, "[bam_flagstat_core] Truncated file? Continue anyway.\n");
        return s;
 }
 int bam_flagstat(int argc, char *argv[])
@@ -62,9 +65,9 @@ int bam_flagstat(int argc, char *argv[])
        printf("%lld paired in sequencing\n", s->n_pair_all);
        printf("%lld read1\n", s->n_read1);
        printf("%lld read2\n", s->n_read2);
-       printf("%lld properly paired (%.2f%%)\n", s->n_pair_good, (float)s->n_pair_good / s->n_reads * 100.0);
+       printf("%lld properly paired (%.2f%%)\n", s->n_pair_good, (float)s->n_pair_good / s->n_pair_all * 100.0);
        printf("%lld with itself and mate mapped\n", s->n_pair_map);
-       printf("%lld singletons (%.2f%%)\n", s->n_sgltn, (float)s->n_sgltn / s->n_reads * 100.0);
+       printf("%lld singletons (%.2f%%)\n", s->n_sgltn, (float)s->n_sgltn / s->n_pair_all * 100.0);
        printf("%lld with mate mapped to a different chr\n", s->n_diffchr);
        printf("%lld with mate mapped to a different chr (mapQ>=5)\n", s->n_diffhigh);
        free(s);