src/hg/hgTracks/bedTrack.c 1.13

1.13 2009/05/29 17:28:25 mikep
make colorByStrand work for ordinary beds (item is a bed) and for sequences where basecoloring is done (item is a linkedFeature)
Index: src/hg/hgTracks/bedTrack.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/bedTrack.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -b -B -U 4 -r1.12 -r1.13
--- src/hg/hgTracks/bedTrack.c	29 May 2009 14:53:35 -0000	1.12
+++ src/hg/hgTracks/bedTrack.c	29 May 2009 17:28:25 -0000	1.13
@@ -545,9 +545,11 @@
 boolean withHgsid = (trackDbSetting(tdb, "hgsid") != NULL);
 boolean thickDrawItem = (trackDbSetting(tdb, "thickDrawItem") != NULL);
 
 if (tg->itemColor != NULL)
+    {
     color = tg->itemColor(tg, bed, hvg);
+    }
 else if (tg->colorShades)
     {
     adjustBedScoreGrayLevel(tdb, bed, scoreMin, scoreMax);
     color = tg->colorShades[grayInRange(bed->score, scoreMin, scoreMax)];
@@ -758,25 +760,24 @@
 tg->items = simpleBedListToLinkedFeatures(tg->items, tg->bedSize, TRUE, TRUE);
 }
 
 
-Color lfItemColorByStrand(struct track *tg, void *item, struct hvGfx *hvg)
+static Color itemColorByStrand(struct track *tg, int orientation, struct hvGfx *hvg)
 /* Look up the RGB color from the trackDb setting 'colorByStrand' based on
- * the linkedFeature item orientation, and convert this to a color index
+ * the orientation (1='+', 0=unknown, -1='-'), and convert this to a color index
  * using hvGfx */
 {
-struct linkedFeatures *lf = item;
 char *words[3];
 unsigned char r, g, b;
 
 char *colors = cloneString(trackDbSetting(tg->tdb, "colorByStrand"));
 if (!colors)
     errAbort("colorByStrand setting missing (in %s)", tg->mapName);
 if (chopByWhite(colors, words, sizeof(words)) != 2)
     errAbort("invalid colorByStrand setting %s (expecting pair of RGB values r,g,b r,g,b)", colors);
-if (lf->orientation == 1)
+if (orientation == 1)
     parseColor(words[0], &r, &g, &b);
-else if (lf->orientation == -1) 
+else if (orientation == -1) 
     parseColor(words[1], &r, &g, &b);
 else // return the main color
     {
     r = tg->color.r; g = tg->color.g; b = tg->color.b;
@@ -784,8 +785,25 @@
 freez(&colors);
 return hvGfxFindColorIx(hvg, r, g, b);
 }
 
+Color lfItemColorByStrand(struct track *tg, void *item, struct hvGfx *hvg)
+/* Look up the RGB color from the trackDb setting 'colorByStrand' based on
+ * the linkedFeature item orientation, and convert this to a color index
+ * using hvGfx */
+{
+struct linkedFeatures *lf = item;
+return itemColorByStrand(tg, lf->orientation, hvg);
+}
+
+Color bedItemColorByStrand(struct track *tg, void *item, struct hvGfx *hvg)
+/* Look up the RGB color from the trackDb setting 'colorByStrand' based on
+ * the bed item strand, and convert this to a color index
+ * using hvGfx */
+{
+struct bed *b = item;
+return itemColorByStrand(tg, (b->strand[0] == '+' ? 1 : (b->strand[0] == '-' ? -1 : 0)), hvg);
+}
 
 void complexBedMethods(struct track *track, struct trackDb *tdb, boolean isBigBed,
                                 int wordCount, char *words[])
 /* Fill in methods for more complex bed tracks. */
@@ -812,16 +830,22 @@
 	if (isNotEmpty(setting) && sameString(setting, "seq1Seq2"))
 	    track->loadItems = loadPairedTagAlignAsLinkedFeaturesPerBase;
 	else
 	    track->loadItems = loadSimpleBedAsLinkedFeaturesPerBase;
+	if (trackDbSetting(tdb, "colorByStrand"))
+	    {
+	    track->itemColor = lfItemColorByStrand;
+	    }
 	}
     else
 	{
 	bedMethods(track);
 	track->loadItems = loadSimpleBed;
-	}
     if (trackDbSetting(tdb, "colorByStrand"))
-	track->itemColor = lfItemColorByStrand;
+	    {
+	    track->itemColor = bedItemColorByStrand;
+	    }
+	}
     }
 else if (useItemRgb && fieldCount == 9)
     {
     linkedFeaturesMethods(track);