ecfd33824b0553d60a898c114fe1e6e3f8326ec1 braney Wed Apr 15 14:47:32 2020 -0700 tweak Jacob's rna structure code to be used on wuhCor1 diff --git src/hg/hgTracks/rnaFoldTrack.c src/hg/hgTracks/rnaFoldTrack.c index f6137ef..bdefcff 100644 --- src/hg/hgTracks/rnaFoldTrack.c +++ src/hg/hgTracks/rnaFoldTrack.c @@ -76,59 +76,68 @@ void spreadAndColorString(struct hvGfx *hvg, int x, int y, int width, int height, Color *colorIxs, int maxShade, MgFont *font, char *text, int count, double *scores, double minScore, double maxScore) /* Draw evenly spaced letters in string. The scores array contains a * score for each letter in the text string. The score will determine * which color in the colorIxs will be used for a given * letter. ColorIxs is an array of size maxShade+1. The count param is * the number of bases to print, not length of the input line * (text) */ { char c[2] = ""; int i; int x1, x2; Color clr; -for (i=0; i<count; i++, text++, scores++) +for (i=0; i<count; i++, text++) { x1 = i * width / count; x2 = (i+1) * width/count; + if (scores) clr = colorIxs[assignBin(*scores, minScore, maxScore, maxShade+1)]; + else + clr = colorIxs[maxShade]; c[0] = *text; hvGfxTextCentered(hvg, x1+x, y, x2-x1, height, clr, font, c); + if (scores) + scores++; } } void spreadAndGrayShadeString(struct hvGfx *hvg, int x, int y, int width, int height, MgFont *font, char *text, int count, double *scores, double minScore, double maxScore) /* Draw evenly spaced letters in string and gray shade letters according to scores. */ { spreadAndColorString(hvg, x, y, width, height, shadesOfGray+2, maxShade-2, font, text, count, scores, minScore, maxScore); } void spreadRnaFoldAnno(struct hvGfx *hvg, int x, int y, int width, int height, Color color, MgFont *font, struct rnaSecStr *item) /* Draw parenthesis structure which defines rna secondary structure. */ { char *fold = cloneString(item->secStr); -double *scores = CloneArray(item->conf, item->size); +double *scores = NULL; +if (item->conf != NULL) + scores = CloneArray(item->conf, item->size); if (*item->strand == '-') { reverseFold(fold); + if (scores) reverseDoubles(scores, item->size); } spreadAndGrayShadeString(hvg, x, y, width, height, font, fold, item->size, scores, 0.0, 1.0); freeMem(fold); +if (scores) freeMem(scores); } void drawCharBox(struct hvGfx *hvg, int x, int y, int width, int height, Color color, char *s, char c) /* s defines a string which spans width. Draw a box in intervals * corresponding to positions where s has letter c */ { double charWidth = ((double)width)/strlen(s); int i = 0, begin = 0, length = 0; for (;*s;s++,i++) { if (*s == c) {