6a669653cb62b01c69de4da19c4baa27cf625e40 braney Sun Sep 1 09:37:57 2013 -0700 add snake configuration options, only link in HAL libraries in hgTracks,temporarily(?) remove support for snakes based on chains #10637 diff --git src/hg/hgTracks/snakeTrack.c src/hg/hgTracks/snakeTrack.c index 95e1902..29009da 100644 --- src/hg/hgTracks/snakeTrack.c +++ src/hg/hgTracks/snakeTrack.c @@ -9,30 +9,33 @@ #include "localmem.h" #include "linefile.h" #include "jksql.h" #include "hdb.h" #include "hgTracks.h" #include "chainBlock.h" #include "chainLink.h" #include "chainDb.h" #include "chainCart.h" #include "errCatch.h" #include "twoBit.h" #include "bigWarn.h" #include <pthread.h> #include "trackHub.h" #include "values.h" +#include "snakeUi.h" + +#ifdef USE_HAL #ifdef USE_HAL #include "halBlockViz.h" #endif struct snakeFeature { struct snakeFeature *next; int start, end; /* Start/end in browser coordinates. */ int qStart, qEnd; /* query start/end */ int level; /* level in packed snake */ int orientation; /* strand... -1 is '-', 1 is '+' */ boolean drawn; /* did we draw this feature? */ char *sequence; /* may have sequence, or NULL */ char *qName; /* chrom name on other species */ @@ -434,53 +437,55 @@ for (item = tg->items; item != NULL; item = item->next) { if(tg->itemColor != NULL) color = tg->itemColor(tg, item, hvg); tg->drawItemAt(tg, item, hvg, xOff, y, scale, font, color, vis); if (vis == tvFull) y += tg->itemHeight(tg, item); } } static void packSnakeDrawAt(struct track *tg, void *item, struct hvGfx *hvg, int xOff, int y, double scale, MgFont *font, Color color, enum trackVisibility vis) /* Draw a single simple bed item at position. */ { +unsigned showSnpWidth = cartOrTdbInt(cart, tg->tdb, + SNAKE_SHOW_SNP_WIDTH, SNAKE_DEFAULT_SHOW_SNP_WIDTH); struct linkedFeatures *lf = (struct linkedFeatures *)item; calcPackSnake(tg, item); if (lf->components == NULL) return; #ifdef USE_HAL boolean isHalSnake = lf->isHalSnake; #else boolean isHalSnake = FALSE; #endif struct snakeFeature *sf = (struct snakeFeature *)lf->components, *prevSf = NULL; int s = tg->itemStart(tg, item); int sClp = (s < winStart) ? winStart : s; int x1 = round((sClp - winStart)*scale) + xOff; int textX = x1; int yOff = y; -//boolean withLabels = (withLeftLabels && (vis == tvFull) && !tg->drawName); +boolean withLabels = (withLeftLabels && (vis == tvFull) && !tg->drawName); unsigned labelColor = MG_BLACK; -// draw the labels (this code needs a clean up ) -if (0)//withLabels) +// draw the labels +if (withLabels) { char *name = tg->itemName(tg, item); int nameWidth = mgFontStringWidth(font, name); int dotWidth = tl.nWidth/2; boolean snapLeft = FALSE; boolean drawNameInverted = FALSE; textX -= nameWidth + dotWidth; snapLeft = (textX < insideX); /* Special tweak for expRatio in pack mode: force all labels * left to prevent only a subset from being placed right: */ snapLeft |= (startsWith("expRatio", tg->tdb->type)); #ifdef IMAGEv2_NO_LEFTLABEL_ON_FULL if (theImgBox == NULL && snapLeft) #else///ifndef IMAGEv2_NO_LEFTLABEL_ON_FULL if (snapLeft) /* Snap label to the left. */ @@ -567,58 +572,65 @@ if (!positiveRangeIntersection(winStart, winEnd, s, e)) continue; osx = sx = round((double)((int)s-winStart)*scale) + xOff; ex = round((double)((int)e-winStart)*scale) + xOff; // color by strand static Color darkBlueColor = 0; static Color darkRedColor = 0; if (darkRedColor == 0) { //the light blue: rgb(149, 204, 252) //the light red: rgb(232, 156, 156) darkRedColor = hvGfxFindColorIx(hvg, 232,156,156); darkBlueColor = hvGfxFindColorIx(hvg, 149,204,252); } - color = (sf->orientation == -1) ? darkRedColor : darkBlueColor; - // for the moment, always color blue + char *colorBy = cartOrTdbString(cart, tg->tdb, + SNAKE_COLOR_BY, SNAKE_DEFAULT_COLOR_BY); + + extern Color getChromColor(char *name, struct hvGfx *hvg); + if (sameString(colorBy, SNAKE_COLOR_BY_STRAND_VALUE)) + color = (sf->orientation == -1) ? darkRedColor : darkBlueColor; + else if (sameString(colorBy, SNAKE_COLOR_BY_CHROM_VALUE)) + color = getChromColor(lf->name, hvg); + else color = darkBlueColor; int w = ex - sx; if (w == 0) w = 1; assert(w > 0); char buffer[1024]; safef(buffer, sizeof buffer, "%d %d",sf->qStart,sf->qEnd); if (sx < insideX) { int olap = insideX - sx; sx = insideX; w -= olap; } char qAddress[4096]; if (vis == tvFull) { safef(qAddress, sizeof qAddress, "qName=%s&qs=%d&qe=%d&qWidth=%d",tg->itemName(tg, item), qs, qe, winEnd - winStart); mapBoxHgcOrHgGene(hvg, s, e, sx+1, y, w-2, heightPer, tg->track, buffer, buffer, NULL, TRUE, qAddress); } hvGfxBox(hvg, sx, y, w, heightPer, color); // now draw the mismatches if we're at high enough resolution - if ((winBaseCount < 50000) && (vis == tvFull)) + if ((winBaseCount < showSnpWidth) && (vis == tvFull)) { char *twoBitString = trackDbSetting(tg->tdb, "twoBit"); static struct twoBitFile *tbf = NULL; static char *lastTwoBitString = NULL; static struct dnaSeq *seq = NULL; static char *lastQName = NULL; // sequence for chain snakes is in 2bit files which we cache if (!isHalSnake) { if (twoBitString == NULL) twoBitString = "/gbdb/hg19/hg19.2bit"; if ((lastTwoBitString == NULL) || differentString(lastTwoBitString, twoBitString)) @@ -724,31 +736,31 @@ sx = round((double)((int)s-winStart)*scale) + xOff; ex = round((double)((int)e-winStart)*scale) + xOff; color = (sf->orientation == -1) ? MG_RED : MG_BLUE; if (lastX != -1) { char buffer[1024]; #define MG_ORANGE 0xff0082E6 int color = MG_GRAY; if (lastQEnd != qs) color = MG_ORANGE; // draw the vertical orange bars if there is an insert in the other sequence - if ((winBaseCount < 50000) ) + if ((winBaseCount < showSnpWidth) ) { if ((sf->orientation == 1) && (qs != lastQEnd) && (lastE == s)) { hvGfxLine(hvg, sx, y2 - lineHeight/2 , sx, y2 + lineHeight/2, MG_ORANGE); safef(buffer, sizeof buffer, "%dbp", qs - lastQEnd); mapBoxHgcOrHgGene(hvg, s, e, sx, y2 - lineHeight/2, 1, lineHeight, tg->track, "foo", buffer, NULL, TRUE, NULL); } else if ((sf->orientation == -1) && (qs != lastQEnd) && (lastS == e)) { hvGfxLine(hvg, ex, y2 - lineHeight/2 , ex, y2 + lineHeight/2, MG_ORANGE); safef(buffer, sizeof buffer, "%dbp", qs - lastQEnd); mapBoxHgcOrHgGene(hvg, s, e, ex, y2 - lineHeight/2, 1, lineHeight, tg->track, "foo", buffer, NULL, TRUE, NULL); } @@ -935,37 +947,39 @@ #define MULTIPLIER 10 #define MAXLOOK 100000 extra = (STARTSLOP < maxOverLeft) ? STARTSLOP : maxOverLeft; start = seqStart - extra; extra = (STARTSLOP < maxOverRight) ? STARTSLOP : maxOverRight; end = seqEnd + extra; doQuery(conn, fullName, lm, hash, start, end, isSplit, -1); } } hFreeConn(&conn); } #ifdef USE_HAL void halSnakeLoadItems(struct track *tg) { +unsigned showSnpWidth = cartOrTdbInt(cart, tg->tdb, + SNAKE_SHOW_SNP_WIDTH, SNAKE_DEFAULT_SHOW_SNP_WIDTH); struct errCatch *errCatch = errCatchNew(); if (errCatchStart(errCatch)) { char *fileName = trackDbSetting(tg->tdb, "bigDataUrl"); char *otherSpecies = trackDbSetting(tg->tdb, "otherSpecies"); int handle = halOpenLOD(fileName); - int needSeq = (winBaseCount < 50000) ? 1 : 0; + int needSeq = (winBaseCount < showSnpWidth) ? 1 : 0; struct hal_block_results_t *head = halGetBlocksInTargetRange(handle, otherSpecies, trackHubSkipHubName(database), chromName, winStart, winEnd, needSeq, 1); // did we get any blocks from HAL if (head == NULL) { errCatchEnd(errCatch); return; } struct hal_block_t* cur = head->mappedBlocks; struct linkedFeatures *lf; struct hash *qChromHash = newHash(5); struct linkedFeatures *lfList = NULL; char buffer[4096]; #ifdef NOTNOW @@ -1158,75 +1172,87 @@ else slReverse(&list); tg->items = list; /* Clean up. */ sqlFreeResult(&sr); hFreeConn(&conn); /* now load the items */ loadLinks(tg, ourStart, ourEnd, tg->visibility); lf=tg->items; fixItems(lf); } /* chainLoadItems() */ +#ifdef NOTNOW static Color chainScoreColor(struct track *tg, void *item, struct hvGfx *hvg) { struct linkedFeatures *lf = (struct linkedFeatures *)item; return(tg->colorShades[lf->grayIx]); } static Color chainNoColor(struct track *tg, void *item, struct hvGfx *hvg) { return(tg->ixColor); } static void setNoColor(struct track *tg) { tg->itemColor = chainNoColor; tg->color.r = 0; tg->color.g = 0; tg->color.b = 0; tg->altColor.r = 127; tg->altColor.g = 127; tg->altColor.b = 127; tg->ixColor = MG_BLACK; tg->ixAltColor = MG_GRAY; } +#endif #ifdef USE_HAL +void halSnakeDrawLeftLabels(struct track *tg, int seqStart, int seqEnd, + struct hvGfx *hvg, int xOff, int yOff, int width, int height, + boolean withCenterLabels, MgFont *font, + Color color, enum trackVisibility vis) +{ +} + + void halSnakeMethods(struct track *tg, struct trackDb *tdb, int wordCount, char *words[]) { //errAbort("halSnakeMethds\n"); linkedFeaturesMethods(tg); tg->canPack = FALSE; tdb->canPack = FALSE; tg->loadItems = halSnakeLoadItems; tg->drawItems = snakeDraw; tg->mapItemName = lfMapNameFromExtra; tg->subType = lfSubChain; //tg->extraUiData = (void *) chainCart; tg->totalHeight = snakeHeight; +tg->drawLeftLabels = halSnakeDrawLeftLabels; tg->drawItemAt = snakeDrawAt; tg->itemHeight = snakeItemHeight; } #endif +#ifdef NOTNOW void snakeMethods(struct track *tg, struct trackDb *tdb, int wordCount, char *words[]) /* Fill in custom parts of alignment chains. */ { struct cartOptions *chainCart; AllocVar(chainCart); boolean normScoreAvailable = chainDbNormScoreAvailable(tdb); /* what does the cart say about coloring option */ chainCart->chainColor = chainFetchColorOption(cart, tdb, FALSE); chainCart->scoreFilter = cartUsualIntClosestToHome(cart, tdb, @@ -1268,15 +1294,17 @@ else chainCart->chainColor = chainColorChromColors; } tg->canPack = FALSE; tg->loadItems = snakeLoadItems; tg->drawItems = snakeDraw; tg->mapItemName = lfMapNameFromExtra; tg->subType = lfSubChain; tg->extraUiData = (void *) chainCart; tg->totalHeight = snakeHeight; tg->drawItemAt = snakeDrawAt; tg->itemHeight = snakeItemHeight; } +#endif +#endif