098b0567c51ecc6e2098f17d8fbcf9dcf4f830ca
angie
  Tue Nov 13 12:25:19 2012 -0800
Problem: when we have a BAM or VCF track with per-chromosome files,and then view a chromosome for which there is no file (e.g. a random
or hap), hgTracks was hitting an early errAbort that is more appropriate
for a single-big-file track that is missing its filename. Fix: allow
bbiNameFromTableChrom to return NULL if there is a seqName column and
there simply isn't a file for that seqName.

diff --git src/hg/lib/hdb.c src/hg/lib/hdb.c
index d4067f3..6d2d1c6 100644
--- src/hg/lib/hdb.c
+++ src/hg/lib/hdb.c
@@ -5023,63 +5023,63 @@
 }
 
 boolean hIsBigBed(char *database, char *table, struct trackDb *parent, struct customTrack *(*ctLookupName)(char *table))
 /* Return TRUE if table corresponds to a bigBed file.
  * if table has no parent trackDb pass NULL for parent
  * If this is a custom track, pass in function ctLookupName(table) which looks up a
  * custom track by name, otherwise pass NULL
  */
 {
 return trackIsType(database, table, parent, "bigBed", ctLookupName);
 }
 
 static char *bbiNameFromTableChrom(struct sqlConnection *conn, char *table, char *seqName)
 /* Return file name from table.  If table has a seqName column, then grab the
  * row associated with chrom (which can be e.g. '1' not 'chr1' if that is the
- * case in the big remote file). */
+ * case in the big remote file), or return NULL if there's no file for that particular
+ * chrom (like a random or hap). */
 {
 boolean checkSeqName = (sqlFieldIndex(conn, table, "seqName") >= 0);
 if (checkSeqName && seqName == NULL)
-    errAbort("bamFileNameFromTable: table %s has seqName column, but NULL seqName passed in",
+    errAbort("bbiNameFromTableChrom: table %s has seqName column, but NULL seqName passed in",
 	     table);
 char query[512];
 if (checkSeqName)
     safef(query, sizeof(query), "select fileName from %s where seqName = '%s'",
 	  table, seqName);
 else
     safef(query, sizeof(query), "select fileName from %s", table);
 char *fileName = sqlQuickString(conn, query);
-if (fileName == NULL && checkSeqName)
+if (fileName == NULL)
+    {
+    if (checkSeqName)
     {
     if (startsWith("chr", seqName))
 	safef(query, sizeof(query), "select fileName from %s where seqName = '%s'",
 	      table, seqName+strlen("chr"));
     else
 	safef(query, sizeof(query), "select fileName from %s where seqName = 'chr%s'",
 	      table, seqName);
     fileName = sqlQuickString(conn, query);
     }
-if (fileName == NULL)
-    {
-    if (checkSeqName)
-	errAbort("Missing fileName for seqName '%s' in %s table", seqName, table);
     else
 	errAbort("Missing fileName in %s table", table);
     }
 return fileName;
 }
 
 char *bbiNameFromSettingOrTableChrom(struct trackDb *tdb, struct sqlConnection *conn, char *table,
 				     char *seqName)
-/* Return file name from bigDataUrl or little table (which might have a seqName column). */
+/* Return file name from bigDataUrl or little table that might have a seqName column.
+ * If table does have a seqName column, return NULL if there is no file for seqName. */
 {
 char *fileName = cloneString(trackDbSetting(tdb, "bigDataUrl"));
 if (fileName == NULL)
     fileName = bbiNameFromTableChrom(conn, table, seqName);
 return fileName;
 }
 
 char *bbiNameFromSettingOrTable(struct trackDb *tdb, struct sqlConnection *conn, char *table)
 /* Return file name from bigDataUrl or little table. */
 {
 return bbiNameFromSettingOrTableChrom(tdb, conn, table, NULL);
 }