src/hg/lib/hdb.c 1.404

1.404 2009/07/08 21:50:18 angie
Added some special cases to support tracks all_{mrna,est} in a database that could have split tables.
Index: src/hg/lib/hdb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/hdb.c,v
retrieving revision 1.403
retrieving revision 1.404
diff -b -B -U 4 -r1.403 -r1.404
--- src/hg/lib/hdb.c	20 May 2009 20:59:54 -0000	1.403
+++ src/hg/lib/hdb.c	8 Jul 2009 21:50:18 -0000	1.404
@@ -719,19 +719,29 @@
 	if (tHel == NULL)
 	    hashAdd(dbTblHash, trackName, tbl);
 	else if (! sameString(tbl->name, trackName))
 	    slAddHead(&(tHel->val), tbl);
+	if (sameString("all_mrna", tbl->name) || sameString("all_est", tbl->name))
+	    {
+	    struct slName *sln = slNameNew(tbl->name + strlen("all_"));
+	    hashAdd(dbTblHash, sln->name, tbl);
+	    }
 	}
     }
 else
     {
-    /* Just hash all table names: */
+    /* Just hash all table names (watch out for all_mrna and all_est): */
     struct slName *tbl = NULL, *nextTbl = NULL;
     for (tbl = allTables;  tbl != NULL;  tbl = nextTbl)
 	{
 	nextTbl = tbl->next;
 	tbl->next = NULL;
 	hashAdd(dbTblHash, tbl->name, tbl);
+	if (sameString("all_mrna", tbl->name) || sameString("all_est", tbl->name))
+	    {
+	    struct slName *sln = slNameNew(tbl->name + strlen("all_"));
+	    hashAdd(dbTblHash, sln->name, tbl);
+	    }
 	}
     }
 hFreeConn(&conn);
 }
@@ -824,19 +834,17 @@
  * table names in databases that support split tables, and just parses text.
  * When chromosome/table name conventions change, this will need an update! */
 {
 /* It might not be a split table; provide defaults: */
-safef(trackName, HDB_MAX_TABLE_STRING, "%s", table);
-safef(chrom, HDB_MAX_CHROM_STRING, "%s", hDefaultChrom(db));
+safecpy(trackName, HDB_MAX_TABLE_STRING, table);
+safecpy(chrom, HDB_MAX_CHROM_STRING, hDefaultChrom(db));
 if (startsWith("chr", table) || startsWith("Group", table))
     {
     char *ptr = strrchr(table, '_');
     if (ptr != NULL)
 	{
-	int chromLen = min(HDB_MAX_CHROM_STRING-1, (ptr - table));
-	strncpy(chrom, table, chromLen);
-	chrom[chromLen] = 0;
-	safef(trackName, HDB_MAX_TABLE_STRING, "%s", ptr+1);
+	safencpy(chrom, HDB_MAX_CHROM_STRING, table, (ptr-table));
+	safecpy(trackName, HDB_MAX_TABLE_STRING, ptr+1);
 	}
     }
 }
 
@@ -2869,10 +2877,19 @@
     if (!isSplit)
         {
 	safef(fullName, sizeof(fullName), "%s", rootName);
 	if (!hTableExists(db, fullName))
+	    {
+	    if (sameString(rootName, "mrna") || sameString(rootName, "est"))
+		{
+		safef(fullName, sizeof(fullName), "all_%s", rootName);
+		if (!hTableExists(db, fullName))
 	    return NULL;
 	}
+	    else
+		return NULL;
+	    }
+	}
     AllocVar(hti);
     hashAddSaveName(hash, rootName, hti, &hti->rootName);
     hti->isSplit = isSplit;
     hti->isPos = hFindBed12FieldsAndBinWithConn(conn, fullName,
@@ -3139,10 +3156,11 @@
 	}
     else
         {
 	table = rootTable;
-	dyStringPrintf(query, "%s where %s='%s' and ",
-	    table, hti->chromField, chrom);
+	char *prefix = (sameString(table, "mrna") || sameString(table, "est")) ? "all_" : "";
+	dyStringPrintf(query, "%s%s where %s='%s' and ",
+		       prefix, table, hti->chromField, chrom);
 	}
     }
 if (table != NULL)
     {