]> git.donarmstrong.com Git - samtools.git/blobdiff - misc/bamcheck.c
init_regions: check for non-matching sequence names
[samtools.git] / misc / bamcheck.c
index f61fac18c73ddfb2074e2b7e246dd4ce606a75fb..c7db8abfb8c153fcc5a95c947a6013e258e6e95a 100644 (file)
@@ -15,7 +15,7 @@
 
 */
 
-#define BAMCHECK_VERSION "2012-04-23"
+#define BAMCHECK_VERSION "2012-04-24"
 
 #define _ISOC99_SOURCE
 #include <stdio.h>
@@ -1018,7 +1018,7 @@ void output_stats(stats_t *stats)
     }
 }
 
-size_t getline(char **line, size_t *n, FILE *fp)
+size_t mygetline(char **line, size_t *n, FILE *fp)
 {
     if (line == NULL || n == NULL || fp == NULL)
     {
@@ -1068,7 +1068,7 @@ void init_regions(stats_t *stats, char *file)
     ssize_t nread;
     int warned = 0;
     int prev_tid=-1, prev_pos=-1;
-    while ((nread = getline(&line, &len, fp)) != -1) 
+    while ((nread = mygetline(&line, &len, fp)) != -1) 
     {
         if ( line[0] == '#' ) continue;
 
@@ -1082,7 +1082,7 @@ void init_regions(stats_t *stats, char *file)
         if ( iter == kh_end(header_hash) )
         {
             if ( !warned )
-                fprintf(stderr,"Warning: Some sequences not present in the BAM (%s)\n", line);
+                fprintf(stderr,"Warning: Some sequences not present in the BAM, e.g. \"%s\". This message is printed only once.\n", line);
             warned = 1;
             continue;
         }
@@ -1116,6 +1116,7 @@ void init_regions(stats_t *stats, char *file)
         stats->regions[tid].npos++;
     }
     if (line) free(line);
+    if ( !stats->regions ) error("Unable to map the -t sequences to the BAM sequences.\n");
     fclose(fp);
 }