f3fd89193f28ab85e5c51c52f20b7c8400c26350
larrym
  Tue Jan 10 15:38:06 2012 -0800
move chrom name normalizing code out of bamFile (we weren't handling stuff like 'IV' and '2L')
diff --git src/lib/bamFile.c src/lib/bamFile.c
index 01356e5..ce15864 100644
--- src/lib/bamFile.c
+++ src/lib/bamFile.c
@@ -486,67 +486,43 @@
     else if (type == 's') { dyStringPrintf(dy, "%d", *(int16_t*)s); s += 2; }
     else if (type == 'I') { dyStringPrintf(dy, "%u", *(uint32_t*)s); s += 4; }
     else if (type == 'i') { dyStringPrintf(dy, "%d", *(int32_t*)s); s += 4; }
     else if (type == 'f') { dyStringPrintf(dy, "%g", *(float*)s); s += 4; }
     else if (type == 'd') { dyStringPrintf(dy, "%lg", *(double*)s); s += 8; }
     else if (type == 'Z' || type == 'H')
 	{
 	dyStringAppend(dy, (char *)s);
 	s += strlen((char *)s) + 1;
 	}
     }
 }
 
 struct bamChromInfo *bamChromList(samfile_t *fh)
 {
-/* Return list of chromosomes from bam header. We normalize chromosome names to UCSC format. */
+/* Return list of chromosomes from bam header. We make no attempty to normalize chromosome names to UCSC format,
+   so list may contain things like "1" for "chr1", "I" for "chrI", "MT" for "chrM" etc. */
 int i;
 struct bamChromInfo *list = NULL;
 bam_header_t *bamHeader = fh->header;
 if(bamHeader == NULL)
     return NULL;
 for(i = 0; i < bamHeader->n_targets; i++)
     {
     struct bamChromInfo *info = NULL;
-    char chrom[512];
-    uint32_t size = bamHeader->target_len[i];
-    safecpy(chrom, sizeof(chrom), bamHeader->target_name[i]);
-
-    // normalize to UCSC chrom naming conventions
-    if(sameString(chrom, "MT"))
-        strcpy(chrom, "chrM");
-    else if(sameString(chrom, "X"))
-        strcpy(chrom, "chrX");
-    else if(sameString(chrom, "Y"))
-        strcpy(chrom, "chrY");
-    else
-        {
-        // convert "1" => "chr1"
-        boolean allDigits = TRUE;
-        int j;
-        for(j = 0; chrom[j] && allDigits; j++)
-            allDigits = isdigit(chrom[j]);
-        if(allDigits)
-            {
-            char *copy = cloneString(chrom);
-            safef(chrom, sizeof(chrom), "chr%s", copy);
-            freeMem(copy);
-            }
-        }
     AllocVar(info);
-    info->name = cloneString(chrom);
-    info->size = size;
+    info->name = cloneString(bamHeader->target_name[i]);
+    info->size = bamHeader->target_len[i];
     slAddHead(&list, info);
     }
 slReverse(&list);
 return list;
 }
 
 #else
 // If we're not compiling with samtools, make stub routines so compile won't fail:
 
 boolean bamFileExists(char *bamFileName)
 /* Return TRUE if we can successfully open the bam file and its index file. */
 {
 warn(COMPILE_WITH_SAMTOOLS, "bamFileExists");
 return FALSE;
 }