8bf058e19dd56b134b5def2464f1c648d2845273 braney Fri Oct 25 13:03:00 2024 -0700 add setColorWith trackDb variable to set wiggle color with bigBed diff --git src/hg/hgTracks/wigTrack.c src/hg/hgTracks/wigTrack.c index 8ba210a..0c41c8c 100644 --- src/hg/hgTracks/wigTrack.c +++ src/hg/hgTracks/wigTrack.c @@ -58,42 +58,48 @@ return trackDbSettingOn(tg->tdb, "logo") || ((trackDbSetting(tg->tdb, "logoMaf") != NULL) && wigCart->doSequenceLogo); } static void wigFillInColorLfArray(struct track *wigTrack, Color *colArray, int colSize, struct track *colorTrack) /* Fill in a color array with the linkedFeatures based colorTrack's color where it would normally have an exon. */ { struct linkedFeatures *lf = NULL, *lfList = colorTrack->items; struct simpleFeature *sf = NULL; double scale = scaleForPixels(colSize); int x1 = 0, x2 = 0; int i = 0; for(lf = lfList; lf != NULL; lf = lf->next) { + unsigned color; + if (colorTrack->isColorBigBed) + color = bedColorToGfxColor(lf->filterColor); + else + color = colorTrack->ixAltColor; + for (sf = lf->components; sf != NULL; sf = sf->next) { x1 = round((double)((int)sf->start-winStart)*scale); x2 = round((double)((int)sf->end-winStart)*scale); if(x1 < 0) x1 = 0; if(x2 > colSize) x2 = colSize; if(x1 == x2) x2++; for(i = x1; i < x2; i++) - colArray[i] = colorTrack->ixAltColor; + colArray[i] = color; } } } static void wigFillInColorBedArray(struct track *wigTrack, Color *colArray, int colSize, struct track *colorTrack, struct hvGfx *hvg) /* Fill in a color array with the simple bed based colorTrack's color where it would normally have an block. */ { struct bed *bed = NULL, *bedList = colorTrack->items; double scale = scaleForPixels(colSize); int x1 = 0, x2 = 0; int i = 0; for (bed = bedList; bed != NULL; bed = bed->next) { @@ -757,106 +763,109 @@ *graphUpperLimit = overallUpperLimit; *graphLowerLimit = overallLowerLimit; } } else { *graphUpperLimit = maxY; *graphLowerLimit = minY; } double graphRange = *graphUpperLimit - *graphLowerLimit; *epsilon = graphRange / lineHeight; return(graphRange); } -static struct trackDb *makeFakeColorTrackTdb(char *bb) +static struct track *makeFakeColorTrack(char *bb) +/* make a fake track to color a wig. */ { struct trackDb *tdb; AllocVar(tdb); -//tdb->loadItems = loadBed9; -//tdb->isBigBed = isBigBed; tdb->grp = "other"; tdb->track = "fakeTrackForColorBy"; tdb->type = "bigBed 9"; tdb->settingsHash = newHash(5); hashAdd(tdb->settingsHash, "bigDataUrl", hubConnectSkipHubPrefix(bb)); -//tdb->drawItemAt = linkedFeaturesDrawAt; -return tdb; +struct track *cTrack = trackFromTrackDb(tdb); +cTrack->isColorBigBed = TRUE; + +return cTrack; } struct track *colorTrackIsBigBed(char *colorTrack) { // cTrack = trackFromTrackDb(tdb); struct track *cTrack = NULL; -if (endsWith(colorTrack, ".bb")) - { - cTrack = trackFromTrackDb(makeFakeColorTrackTdb(colorTrack)); - printf("colorTrack is bb %s\n", colorTrack); - } +if (endsWith(colorTrack, ".bb") || endsWith(colorTrack, ".bigBed")) + cTrack = makeFakeColorTrack(colorTrack); return cTrack; } static Color * makeColorArray(struct preDrawElement *preDraw, int width, int preDrawZero, struct wigCartOptions *wigCart, struct track *tg, struct hvGfx *hvg) /* allocate and fill in a coloring array based on another track */ { char *colorTrack = wigCart->colorTrack; +char *colorBigBed = wigCart->colorBigBed; int x1; Color *colorArray = NULL; /* Array of pixels to be drawn. */ /* Set up the color by array. Determine color of each pixel * based initially on the sign of the data point. If a colorTrack * is specified also fill in the color array with that. */ AllocArray(colorArray, width); for(x1 = 0; x1 < width; ++x1) { int preDrawIndex = x1 + preDrawZero; if (preDraw[preDrawIndex].count) { double dataValue; /* the data value in data space */ dataValue = preDraw[preDrawIndex].smooth; /* negative data is the alternate color */ if (dataValue < 0.0) colorArray[x1] = tg->ixAltColor; else colorArray[x1] = tg->ixColor; } } -/* Fill in colors from alternate track if necessary. */ -if (colorTrack != NULL) +/* Fill in colors from alternate track or bigBed if necessary. */ +struct track *cTrack = NULL; + +if (colorBigBed != NULL) + { + cTrack = makeFakeColorTrack(colorBigBed); + } +else if (colorTrack != NULL) { struct track *cTrack = hashFindVal(trackHash, colorTrack); if (cTrack == NULL) // rightClick update of wigColorBy track may not have colorTrack in hash { // so create it on the fly - if ((cTrack = colorTrackIsBigBed(colorTrack)) == NULL) - { struct trackDb *tdb = hTrackDbForTrack(database,colorTrack); if (tdb != NULL) cTrack = trackFromTrackDb(tdb); } } + if (cTrack != NULL) wigFillInColorArray(tg, hvg, colorArray, width, cTrack); - } return colorArray; } void vLineViaHvg(void *image, int x, int y, int height, Color color) /* A vertical line drawer that works via hvGfx system. */ { hvGfxBox(image, x, y, 1, height, color); } Color somewhatLighterColor32(Color color) /* Get a somewhat lighter shade of a color - 1/3 of the way towards white. * Specialized here to bypass image parameter requirement.*/ { struct rgbColor rgbColor = mgColorIxToRgb(NULL, color); @@ -2254,30 +2263,31 @@ wigCart->yLineMark = yLineMark; wigCart->yLineOnOff = wigFetchYLineMarkWithCart(cart,tdb,tdb->track, (char **) NULL); wigCart->alwaysZero = (enum wiggleAlwaysZeroEnum)wigFetchAlwaysZeroWithCart(cart,tdb,tdb->track, (char **) NULL); wigCart->transformFunc = (enum wiggleTransformFuncEnum)wigFetchTransformFuncWithCart(cart,tdb,tdb->track, (char **) NULL); wigCart->doNegative = wigFetchDoNegativeWithCart(cart,tdb,tdb->track, (char **) NULL); if (zoomedToCodonLevel) wigCart->doSequenceLogo = wigFetchDoSequenceLogoWithCart(cart,tdb,tdb->track, (char **) NULL); wigCart->maxHeight = maxHeight; wigCart->defaultHeight = defaultHeight; wigCart->minHeight = minHeight; wigFetchMinMaxYWithCart(cart,tdb,tdb->track, &wigCart->minY, &wigCart->maxY, NULL, NULL, wordCount, words); wigCart->colorTrack = trackDbSetting(tdb, "wigColorBy"); +wigCart->colorBigBed = trackDbSetting(tdb, "setColorWith"); char *containerType = trackDbSetting(tdb, "container"); if (containerType != NULL && sameString(containerType, "multiWig")) wigCart->isMultiWig = TRUE; wigCart->aggregateFunction = wigFetchAggregateFunctionWithCart(cart,tdb,tdb->track, (char **) NULL); // can't do mean with whiskers in stacked mode if ((wigCart->aggregateFunction == wiggleAggregateStacked) && ( wigCart->windowingFunction == wiggleWindowingWhiskers)) wigCart->windowingFunction = wiggleWindowingMax; return wigCart; } /* Make track group for wig multiple alignment.