src/hg/lib/trackDbCustom.c 1.87

1.87 2010/05/11 01:43:30 kent
Refactoring to split the trackDb.tableName field into separate track and table fields. Similarly track.mapName field goes to the same track and table fields.
Index: src/hg/lib/trackDbCustom.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/lib/trackDbCustom.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -b -B -U 4 -r1.86 -r1.87
--- src/hg/lib/trackDbCustom.c	7 May 2010 05:03:55 -0000	1.86
+++ src/hg/lib/trackDbCustom.c	11 May 2010 01:43:30 -0000	1.87
@@ -72,9 +72,9 @@
                            struct lineFile *lf)
 /* parse the track line */
 {
 char *val2 = cloneString(value);
-bt->tableName = nextWord(&val2);
+bt->track = nextWord(&val2);
 
 // check for override option
 if (val2 != NULL)
     {
@@ -243,9 +243,9 @@
 void trackDbPolish(struct trackDb *bt)
 /* Fill in missing values with defaults. */
 {
 if (bt->shortLabel == NULL)
-    bt->shortLabel = cloneString(bt->tableName);
+    bt->shortLabel = cloneString(bt->track);
 if (bt->longLabel == NULL)
     bt->longLabel = cloneString(bt->shortLabel);
 if (bt->altColorR == 0 && bt->altColorG == 0 && bt->altColorB == 0)
     {
@@ -294,11 +294,8 @@
 struct lineFile *lf = lineFileOpen(raFile, TRUE);
 char *line, *word;
 struct trackDb *btList = NULL, *bt;
 boolean done = FALSE;
-#ifdef UNUSED
-struct hash *compositeHash = hashNew(8);
-#endif /* UNUSED */
 char *incFile;
 
 for (;;)
     {
@@ -349,83 +346,16 @@
 	line = trimSpaces(line);
 	trackDbUpdateOldTag(&word, &line);
 	trackDbAddInfo(bt, word, line, lf);
 	}
-#ifdef UNUSED
-    if (trackDbLocalSetting(bt, "compositeTrack") != NULL)
-        hashAdd(compositeHash, bt->tableName, bt);
-#endif /* UNUSED */
     }
 lineFileClose(&lf);
 
 slReverse(&btList);
 return btList;
 }
 
-#ifdef UNUSED
-void trackDbOverrideVisbility(struct hash *tdHash, char *visibilityRa,
-			      boolean hideFirst)
-/* Override visbility settings using a ra file.  If hideFirst, set all
- * visibilities to hide before applying visibilityRa. */
-{
-struct lineFile *lf;
-struct hash *raRecord;
-
-if (hideFirst)
-    {
-    /* Set visibility to hide on all entries */
-    struct hashEl *hel;
-    struct hashCookie cookie;
-    cookie = hashFirst(tdHash);
-    while ((hel = hashNext(&cookie)) != NULL)
-	((struct trackDb *)hel->val)->visibility = tvHide;
-    }
-
-/* Parse the ra file, adjusting visibility accordingly */
-lf = lineFileOpen(visibilityRa, TRUE);
-while ((raRecord = raNextRecord(lf)) != NULL)
-    {
-    char *trackName = hashFindVal(raRecord, "track");
-    char *visibility = hashFindVal(raRecord, "visibility");
-    if ((trackName != NULL) && (visibility != NULL))
-        {
-        struct trackDb *td = hashFindVal(tdHash, trackName);
-        if (td != NULL)
-            td->visibility = parseVisibility(visibility);
-        }
-    hashFree(&raRecord);
-    }
-lineFileClose(&lf);
-}
-#endif /* UNUSED */
 
-#ifdef OLD
-void trackDbOverridePriority(struct hash *tdHash, char *priorityRa)
-/* Override priority settings using a ra file. */
-{
-struct lineFile *lf;
-struct hash *raRecord;
-
-/* Parse the ra file, adjusting priority accordingly */
-lf = lineFileOpen(priorityRa, TRUE);
-while ((raRecord = raNextRecord(lf)) != NULL)
-    {
-    char *trackName = hashFindVal(raRecord, "track");
-    char *priority = hashFindVal(raRecord, "priority");
-    if ((trackName != NULL) && (priority != NULL))
-        {
-        struct trackDb *td = hashFindVal(tdHash, trackName);
-        if (td != NULL)
-            {
-            td->priority = atof(priority);
-            trackDbPolish(td);
-            }
-        }
-    hashFree(&raRecord);
-    }
-lineFileClose(&lf);
-}
-#endif /* OLD */
 
 struct hash *trackDbHashSettings(struct trackDb *tdb)
 /* Force trackDb to hash up it's settings.  Usually this is just
  * done on demand. Returns settings hash. */
@@ -487,9 +417,9 @@
 /* Return setting string or squawk and die. */
 {
 char *ret = trackDbSetting(tdb, name);
 if (ret == NULL)
-   errAbort("Missing required %s setting in %s track", name, tdb->tableName);
+   errAbort("Missing required %s setting in %s track", name, tdb->track);
 return ret;
 }
 
 char *trackDbSettingOrDefault(struct trackDb *tdb, char *name, char *defaultVal)
@@ -615,10 +545,10 @@
     if (stInfo->isSuper)
         {
         tdbMarkAsSuperTrack(tdb);
         tdb->isShow = stInfo->isShow;
-        if (!hashLookup(superHash, tdb->tableName))
-            hashAdd(superHash, tdb->tableName, tdb);
+        if (!hashLookup(superHash, tdb->track))
+            hashAdd(superHash, tdb->track, tdb);
         }
     freeMem(stInfo);
     }
 /* adjust settings on supertrack members after verifying they have
@@ -714,9 +644,9 @@
 if(cType == cfgNone && warnIfNecessary)
     {
     if(!startsWith("bed ", type) && !startsWith("bigBed", type)
     && subgroupFind(tdb,"view",NULL))
-        warn("Track type \"%s\" is not yet supported in multi-view composites for %s.",type,tdb->tableName);
+        warn("Track type \"%s\" is not yet supported in multi-view composites for %s.",type,tdb->track);
     }
 return cType;
 }
 
@@ -762,9 +692,9 @@
                      || sameWord(setting,"enabled")
                      || atoi(setting) != 0));
 }
 
-struct trackDb *subTdbFind(struct trackDb *parent,char *table)
+struct trackDb *subTdbFind(struct trackDb *parent,char *childName)
 /* Return child tdb if it exists in parent. */
 {
 if(parent == NULL)
     return NULL;
@@ -773,9 +703,9 @@
 struct slRef *tdbRef, *tdbRefList = trackDbListGetRefsToDescendants(parent->subtracks);
 for (tdbRef = tdbRefList; tdbRef != NULL; tdbRef = tdbRef->next)
     {
     struct trackDb *tdb = tdbRef->val;
-    if (sameString(tdb->tableName, table))
+    if (sameString(tdb->track, childName))
 	{
 	found = tdb;
         break;
 	}
@@ -783,25 +713,25 @@
 slFreeList(&tdbRefList);
 return found;
 }
 
-struct trackDb *tdbFindOrCreate(char *db,struct trackDb *parent,char *table)
-/* Find or creates the tdb for this table. May return NULL. */
+struct trackDb *tdbFindOrCreate(char *db,struct trackDb *parent,char *track)
+/* Find or creates the tdb for this track. May return NULL. */
 {
 struct trackDb *tdb = NULL;
 if (parent != NULL)
     {
-    if(sameString(parent->tableName, table))
+    if(sameString(parent->track, track))
         tdb = parent;
-    else if(consWiggleFind(db,parent,table) != NULL)
+    else if(consWiggleFind(db,parent,track) != NULL)
         tdb = parent;
     else
-        tdb = subTdbFind(parent,table);
+        tdb = subTdbFind(parent,track);
     }
 if(tdb == NULL && db != NULL)
     {
     struct sqlConnection *conn = hAllocConn(db);
-    tdb = hMaybeTrackInfo(conn, table);
+    tdb = hMaybeTrackInfo(conn, track);
     hFreeConn(&conn);
     }
 return tdb;
 }
@@ -867,9 +797,9 @@
  *     superTrack parentName
  * In the subTrack system the parents have the tag:
  *     compositeTrack on
  * and the children have the tag:
- *     subTrack parentName
+ *     parent parentName
  * In this routine the subtracks are removed from the list, and stuffed into
  * the subtracks lists of their parents.  The highest level parents stay on
  * the list.  There can be multiple levels of inheritance.
  *    For the supertracks the _parents_ are removed from the list.  The only
@@ -880,9 +810,9 @@
 struct trackDb *forest = NULL;
 struct hash *trackHash = hashNew(0);
 struct trackDb *tdb, *next;
 for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
-    hashAdd(trackHash, tdb->tableName, tdb);
+    hashAdd(trackHash, tdb->track, tdb);
 
 /* Do superTrack inheritance.  This involves setting up the parent pointers to superTracks,
  * but removing the superTracks themselves from the list. */
 struct trackDb *superlessList = NULL;
@@ -901,9 +831,9 @@
 	    char *parentName = tdb->parentName = cloneFirstWord(superTrack);
 	    struct trackDb *parent = hashFindVal(trackHash, parentName);
 	    if (parent == NULL)
 		errAbort("Parent track %s of supertrack %s doesn't exist",
-			parentName, tdb->tableName);
+			parentName, tdb->track);
 	    tdb->parent = parent;
 	    slAddHead(&superlessList, tdb);
 	    }
 	}
@@ -928,9 +858,9 @@
 	    tdb->parent = parent;
 	    }
 	else
 	    {
-	    errAbort("Parent track %s of child %s doesn't exist", parentName, tdb->tableName);
+	    errAbort("Parent track %s of child %s doesn't exist", parentName, tdb->track);
 	    }
 	freez(&parentName);
 	}
     else
@@ -942,8 +872,22 @@
 hashFree(&trackHash);
 return forest;
 }
 
+void trackDbAddTableField(struct trackDb *tdbList)
+/* Add table field by looking it up in settings.  */
+{
+struct trackDb *tdb;
+for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
+    {
+    char *table = trackDbLocalSetting(tdb, "table");
+    if (table != NULL)
+        tdb->table = cloneString(table);
+    else
+        tdb->table = cloneString(tdb->track);
+    }
+}
+
 void rGetRefsToDescendants(struct slRef **pList, struct trackDb *tdbList)
 /* Add all member of tdbList, and all of their children to pList recursively. */
 /* Convert a list to a forest - filling in parent and subtrack pointers.
  * The exact topology of the forest is a little complex due to the