src/hg/makeDb/hgTrackDb/hgTrackDb.c 1.52

1.52 2009/06/05 19:27:44 hiram
Fix error for -strict operation, and properly clean up subTracks that had parents disappear
Index: src/hg/makeDb/hgTrackDb/hgTrackDb.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/makeDb/hgTrackDb/hgTrackDb.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -b -B -U 4 -r1.51 -r1.52
--- src/hg/makeDb/hgTrackDb/hgTrackDb.c	4 Jun 2009 19:14:43 -0000	1.51
+++ src/hg/makeDb/hgTrackDb/hgTrackDb.c	5 Jun 2009 19:27:44 -0000	1.52
@@ -167,8 +167,11 @@
 /* No need to slReverse, it's sorted later. */
 *tdListPtr = strictList;
 }
 
+/* keep track of prunedTracks so their subTracks can also be pruned */
+static struct hash *prunedTracks = NULL;
+
 static void pruneRelease(struct trackDb **tdListPtr, char *database)
 /* prune out alternate track entries for another release */
 {
 struct trackDb *td;
@@ -187,8 +190,14 @@
              * confuses Q/A */
             hashRemove(td->settingsHash, "release");
             slSafeAddHead(&relList, td);
             }
+	else
+            {
+	    if (prunedTracks == NULL)
+		prunedTracks = newHash(8);
+	    hashAddInt(prunedTracks, td->tableName, 1);
+            }
         }
     else
         slSafeAddHead(&relList, td);
     }
@@ -391,8 +400,10 @@
 
 	}
     }
 
+struct hash *removeSubTracks = newHash(8);
+
 /* now verify subtracks */
 for (td = tdList; td != NULL; td = tdNext)
     {
 
@@ -408,13 +419,24 @@
 	    trackName = words[0];
 
 
 	    struct subGroupData *sgd = hashFindVal(compositeHash, trackName);
+	    if ( sgd )
+		{
 	    td->parent = sgd->compositeTdb;
 	    tdbMarkAsCompositeChild(td);
-	    if (!sgd)
+		}
+	    else
+		{
+		if (hashFindVal(prunedTracks, trackName))
+		    {	/* parent was pruned, get rid of subTrack too */
+		    hashAdd(removeSubTracks, td->tableName, td);
+		    }
+		else
 		{
-		verbose(1,"parent %s missing for subtrack %s\n", trackName, td->tableName);
+		    verbose(1,"parent %s missing for subtrack %s\n",
+			trackName, td->tableName);
+		    }
 		continue;
 		}
 	    char *subGroups = trackDbSetting(td, "subGroups");
 	    if (subGroups && (sgd->numSubGroups == 0))
@@ -462,8 +484,14 @@
 
 	    }
 	}
     }
+/* clean up subTracks that had parents disappear */
+struct hashCookie cookie = hashFirst(removeSubTracks);
+struct hashEl *hel;
+while ((hel = hashNext(&cookie)) != NULL)
+    slRemoveEl(&tdList, (struct trackDb*)hel->val);
+
 }
 
 static void prioritizeContainerItems(struct trackDb *tdbList)
 /* set priorities in containers if they have no priorities already set