src/hg/hgTracks/pslTrack.c 1.30
1.30 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/pslTrack.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/pslTrack.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -b -B -U 4 -r1.29 -r1.30
--- src/hg/hgTracks/pslTrack.c 3 Sep 2008 19:19:04 -0000 1.29
+++ src/hg/hgTracks/pslTrack.c 19 Mar 2009 22:21:06 -0000 1.30
@@ -8,9 +8,8 @@
#include "jksql.h"
#include "hdb.h"
#include "hgTracks.h"
#include "psl.h"
-#include "cds.h"
#ifndef GBROWSE
#include "../gsid/gsidTable/gsidTable.h"
#define SELECT_SUBJ "selectSubject"
@@ -248,56 +247,17 @@
}
return(sfList);
}
-
-
-
-/* If useful elsewhere someday, could libify: */
-static struct psl *pslClone(struct psl *pslIn)
-/* Return a newly allocated copy of pslIn's contents. */
-{
-struct psl *pslOut = cloneMem(pslIn, sizeof(*pslIn));
-pslOut->next = NULL;
-pslOut->tName = cloneString(pslIn->tName);
-pslOut->qName = cloneString(pslIn->qName);
-pslOut->blockSizes = cloneMem(pslIn->blockSizes, sizeof(pslIn->blockSizes[0]) *
- pslIn->blockCount);
-pslOut->qStarts = cloneMem(pslIn->qStarts, sizeof(pslIn->qStarts[0]) *
- pslIn->blockCount);
-pslOut->tStarts = cloneMem(pslIn->tStarts, sizeof(pslIn->tStarts[0]) *
- pslIn->blockCount);
-if (pslIn->qSequence != NULL)
- {
- int i;
- pslOut->qSequence = needMem(sizeof(pslIn->qSequence[0]) *
- pslIn->blockCount);
- pslOut->tSequence = needMem(sizeof(pslIn->qSequence[0]) *
- pslIn->blockCount);
- for (i = 0; i < pslIn->blockCount; i++)
- {
- pslOut->qSequence[i] = cloneString(pslIn->qSequence[i]);
- pslOut->tSequence[i] = cloneString(pslIn->tSequence[i]);
- }
- }
-return pslOut;
-}
-
-
struct linkedFeatures *lfFromPslx(struct psl *psl,
int sizeMul, boolean isXeno, boolean nameGetsPos, struct track *tg)
/* Create a linked feature item from pslx. Pass in sizeMul=1 for DNA,
- * sizeMul=3 for protein. */
+ * sizeMul=3 for protein.
+ * Don't free psl afterwards! */
{
-struct simpleFeature *sfList = NULL;
int grayIx = pslGrayIx(psl, isXeno, maxShade);
struct linkedFeatures *lf;
boolean rcTarget = (psl->strand[1] == '-');
-enum baseColorDrawOpt drawOpt = baseColorGetDrawOpt(tg);
-boolean indelShowDoubleInsert, indelShowQueryInsert, indelShowPolyA;
-
-indelEnabled(cart, (tg ? tg->tdb : NULL), basesPerPixel,
- &indelShowDoubleInsert, &indelShowQueryInsert, &indelShowPolyA);
AllocVar(lf);
lf->score = (psl->match - psl->misMatch - psl->repMatch);
lf->grayIx = grayIx;
@@ -315,41 +275,21 @@
lf->orientation = orientFromChar(psl->strand[0]);
if (rcTarget)
lf->orientation = -lf->orientation;
-sfList = sfFromPslX(psl, grayIx, sizeMul);
-slReverse(&sfList);
-lf->components = sfList;
-
-/*if we are coloring by codon and zoomed in close
- enough, then split simple feature by the psl record
- and the mRNA sequence. Otherwise do the default conversion
- from psl to simple feature.*/
-if (drawOpt == baseColorDrawItemCodons ||
- drawOpt == baseColorDrawDiffCodons ||
- drawOpt == baseColorDrawGenomicCodons)
- {
- baseColorCodonsFromPsl(chromName, lf, psl, sizeMul, isXeno, maxShade,
- drawOpt, tg);
- lf->grayIx = lfCalcGrayIx(lf);
- }
-else
- {
- linkedFeaturesBoundsAndGrays(lf);
- if (drawOpt == baseColorDrawCds)
- baseColorSetCdsBounds(lf, psl, tg);
- }
-/* If we are drawing anything special, stash psl for use in drawing phase: */
-if (drawOpt > baseColorDrawOff || indelShowQueryInsert || indelShowPolyA)
- lf->original = pslClone(psl);
-lf->start = psl->tStart; /* Correct for rounding errors... */
-lf->end = psl->tEnd;
+lf->components = sfFromPslX(psl, grayIx, sizeMul);
+lf->start = lf->tallStart = psl->tStart;
+lf->end = lf->tallEnd = psl->tEnd;
+
+/* Hang on to psl for use in drawing phase (this is why caller must not free psl!): */
+lf->original = psl;
return lf;
}
struct linkedFeatures *lfFromPsl(struct psl *psl, boolean isXeno)
-/* Create a linked feature item from psl. */
+/* Create a linked feature item from psl.
+ * Don't free psl afterwards! */
{
return lfFromPslx(psl, 1, isXeno, FALSE, NULL);
}
@@ -458,19 +398,8 @@
char *optionChrStr;
struct linkedFeatures *lfList = NULL, *lf;
char optionChr[128]; /* Option - chromosome filter */
char extraWhere[128];
-boolean checkSelected; /* flag indicating if checking for selection of an entry is needed */
-
-checkSelected = FALSE;
-
-#ifndef GBROWSE
-/* if this is a GSID track, check if we need to check for inclusion of the item */
-if (hIsGsidServer())
- {
- checkSelected = gsidCheckSelected(tg);
- }
-#endif /* GBROWSE */
safef( optionChr, sizeof(optionChr), "%s.chromFilter", tg->mapName);
optionChrStr = cartUsualString(cart, optionChr, "All");
if (startsWith("chr",optionChrStr))
@@ -490,19 +419,19 @@
while ((row = sqlNextRow(sr)) != NULL)
{
struct psl *psl = pslLoad(row+rowOffset);
lf = lfFromPslx(psl, sizeMul, isXeno, nameGetsPos, tg);
- if (checkSelected)
- {
#ifndef GBROWSE
- if (isSelected(lf->name)) slAddHead(&lfList, lf);
-#endif /* GBROWSE */
- }
- else
+ /* if this is a GSID track, check if we need to check for inclusion of the item */
+ if (hIsGsidServer() && gsidCheckSelected(tg))
{
+ if (isSelected(lf->name))
slAddHead(&lfList, lf);
}
- pslFree(&psl);
+ else
+#endif /* GBROWSE */
+ slAddHead(&lfList, lf);
+ // Don't free psl - may be used by baseColor code (and freeing is slow)
}
slReverse(&lfList);
if (tg->visibility != tvDense)
slSort(&lfList, linkedFeaturesCmpStart);