src/hg/hgTracks/simpleTracks.c 1.73

1.73 2009/03/19 22:21:06 angie
Refactoring for performance issue raised by David: moved all baseColor work that was done at load-time to draw-time, and removed the freeing-by-default of original genePred and psl structs converted to lf. Now, when there are so many items in the window that limitVisibility kicks it down to dense mode, we don't waste time on baseColor stuff that won't be used. Also some refactoring for tidiness in cds.c: got rid of a couple unused function args.
Index: src/hg/hgTracks/simpleTracks.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/simpleTracks.c,v
retrieving revision 1.72
retrieving revision 1.73
diff -b -B -U 4 -r1.72 -r1.73
--- src/hg/hgTracks/simpleTracks.c	17 Mar 2009 19:49:12 -0000	1.72
+++ src/hg/hgTracks/simpleTracks.c	19 Mar 2009 22:21:06 -0000	1.73
@@ -2423,8 +2423,29 @@
 lfColors(tg, lf, hvg, &color, &bColor);
 if (vis == tvDense && trackDbSetting(tg->tdb, EXP_COLOR_DENSE))
     color = saveColor;
 
+if (psl && (drawOpt == baseColorDrawItemCodons || drawOpt == baseColorDrawDiffCodons ||
+	    drawOpt == baseColorDrawGenomicCodons))
+    {
+    boolean isXeno = ((tg->subType == lfSubXeno) || (tg->subType == lfSubChain) ||
+		      startsWith("mrnaBla", tg->mapName));
+    int sizeMul = pslIsProtein(psl) ? 3 : 1;
+    lf->codons = baseColorCodonsFromPsl(lf, psl, sizeMul, isXeno, maxShade, drawOpt, tg);
+    }
+else if (drawOpt > baseColorDrawOff)
+    {
+    struct genePred *gp = NULL;
+    if (startsWith("genePred", tg->tdb->type))
+	gp = (struct genePred *)(lf->original);
+    if (gp && gp->cdsStart != gp->cdsEnd)
+	lf->codons = baseColorCodonsFromGenePred(lf, gp,
+						 (gp->optFields >= genePredExonFramesFld),
+						 (drawOpt != baseColorDrawDiffCodons));
+    }
+if (psl && drawOpt == baseColorDrawCds && !zoomedToCdsColorLevel)
+    baseColorSetCdsBounds(lf, psl, tg);
+
 tallStart = lf->tallStart;
 tallEnd = lf->tallEnd;
 if ((tallStart == 0 && tallEnd == 0) && !sameWord(tg->mapName, "jaxQTL3"))
     {
@@ -3345,9 +3366,8 @@
 	{
 	struct psl *psl = pslLoad(row+rowOffset);
 	lf = lfFromPsl(psl, FALSE);
 	slAddHead(&lfList, lf);
-	pslFree(&psl);
 	}
     sqlFreeResult(&sr);
     }
 slReverse(&lfList);
@@ -3730,19 +3750,15 @@
 safef(varName, sizeof(varName), "%s.%s", table, HIDE_NONCODING_SUFFIX);
 boolean hideNoncoding = cartUsualBoolean(cart, varName, HIDE_NONCODING_DEFAULT);  // TODO: Use cartUsualBooleanClosestToHome if tableName == tg->tdb->tableName
 boolean doNmd = FALSE;
 char buff[256];
-enum baseColorDrawOpt drawOpt = baseColorDrawOff;
 safef(buff, sizeof(buff), "hgt.%s.nmdFilter",  tg->mapName);
 
 /* Should we remove items that appear to be targets for nonsense
  * mediated decay? */
 if(nmdTrackFilter)
     doNmd = cartUsualBoolean(cart, buff, FALSE);
 
-if (table != NULL)
-    drawOpt = baseColorGetDrawOpt(tg);
-
 if (tg->itemAttrTbl != NULL)
     itemAttrTblLoad(tg->itemAttrTbl, conn, chrom, start, end);
 
 char *noncodingClause = (hideNoncoding ? "cdsStart != cdsEnd" : NULL);
@@ -3760,13 +3776,8 @@
     if (extra && gp->name2)
         lf->extra = cloneString(gp->name2);
     lf->orientation = orientFromChar(gp->strand[0]);
 
-    if (drawOpt > baseColorDrawOff && gp->cdsStart != gp->cdsEnd)
-        lf->codons = baseColorCodonsFromGenePred(chrom, lf, gp, NULL,
-                (gp->optFields >= genePredExonFramesFld),
-		(drawOpt != baseColorDrawDiffCodons));
-
     lf->components = sfFromGenePred(gp, grayIx);
 
     if (tg->itemAttrTbl != NULL)
         lf->itemAttr = itemAttrTblGet(tg->itemAttrTbl, gp->name,
@@ -3783,11 +3794,11 @@
         {
         lf->tallStart = gp->cdsStart;
         lf->tallEnd = gp->cdsEnd;
         }
-
+    // Don't free gp; it might be used in the drawing phase by baseColor code.
+    lf->original = gp;
     slAddHead(&lfList, lf);
-    genePredFree(&gp);
     }
 slReverse(&lfList);
 genePredReaderFree(&gpr);
 return lfList;