ad2dc6d21a6f99ba5403b11cfb94ef586d46930d
angie
  Fri May 20 15:29:34 2011 -0700
Feature #3711 (VCF haplotype sorting): David didn't like the altered colorfor center variant, asked for thicker black outline instead.

diff --git src/hg/hgTracks/vcfTrack.c src/hg/hgTracks/vcfTrack.c
index f3c697f..036741b 100644
--- src/hg/hgTracks/vcfTrack.c
+++ src/hg/hgTracks/vcfTrack.c
@@ -298,51 +298,47 @@
     return shadesOfGray[5];
 // Copying pgSnp color scheme here, using first base of allele which is not ideal for multibase
 // but allows us to simplify it to 5 colors:
 else if (allele[0] == 'A')
     return MG_RED;
 else if (allele[0] == 'C')
     return MG_BLUE;
 else if (allele[0] == 'G')
     return darkGreenColor;
 else if (allele[0] == 'T')
     return MG_MAGENTA;
 else
     return shadesOfGray[5];
 }
 
-INLINE Color colorFromRefAlt(struct vcfGenotype *gt, int hapIx, boolean grayUnphasedHet,
-			     boolean isCenter)
+INLINE Color colorFromRefAlt(struct vcfGenotype *gt, int hapIx, boolean grayUnphasedHet)
 /* Color allele red for alternate allele, blue for reference allele -- 
  * except for special center variant, make it yellow/green for contrast. */
 {
 if (grayUnphasedHet && !gt->isPhased && gt->hapIxA != gt->hapIxB)
     return shadesOfGray[5];
 int alIx = hapIx ? gt->hapIxB : gt->hapIxA;
-if (isCenter)
-    return alIx ? MG_YELLOW : MG_GREEN;
 return alIx ? MG_RED : MG_BLUE;
 }
 
 
 INLINE int drawOneHap(struct vcfGenotype *gt, int hapIx,
 		      char *ref, char *altAlleles[], int altCount,
-		      struct hvGfx *hvg, int x1, int y, int w, int itemHeight, int lineHeight,
-		      boolean isCenter)
+		      struct hvGfx *hvg, int x1, int y, int w, int itemHeight, int lineHeight)
 /* Draw a base-colored box for genotype[hapIx].  Return the new y offset. */
 {
-Color color = colorHapByRefAlt ? colorFromRefAlt(gt, hapIx, TRUE, isCenter) :
+Color color = colorHapByRefAlt ? colorFromRefAlt(gt, hapIx, TRUE) :
 				 colorFromGt(gt, hapIx, ref, altAlleles, altCount, TRUE);
 if (w == 1)
     {
     x1--;
     w = 3;
     }
 hvGfxBox(hvg, x1, y, w, itemHeight+1, color);
 y += itemHeight+1;
 return y;
 }
 
 INLINE char *gtSummaryString(struct vcfRecord *rec, char **altAlleles, int altCount)
 // Make pgSnp-like mouseover text, but with genotype counts instead of allele counts.
 // NOTE 1: Returned string is statically allocated, don't free it!
 // NOTE 2: if revCmplDisp is set, this reverse-complements rec->ref and altAlleles!
@@ -369,98 +365,96 @@
 if (revCmplDisp)
     {
     reverseComplement(rec->ref, strlen(rec->ref));
     for (i=0;  i < altCount;  i++)
 	reverseComplement(altAlleles[i], strlen(altAlleles[i]));
     }
 
 dyStringPrintf(dy, "%s/%s:%d %s/%s:%d %s/%s:%d", rec->ref, rec->ref, gtRefRefCount,
 	       rec->ref, altAlleles[0], gtRefAltCount,
 	       altAlleles[0], altAlleles[0], gtAltAltCount);
 if (gtOtherCount > 0)
     dyStringPrintf(dy, " other:%d", gtOtherCount);
 return dy->string;
 }
 
-static void drawOneRec(struct vcfRecord *rec, boolean isCenter,
-		       unsigned short *gtHapOrder, int gtHapEnd,
+static void drawOneRec(struct vcfRecord *rec, unsigned short *gtHapOrder, int gtHapEnd,
 		       struct track *tg, struct hvGfx *hvg, int xOff, int yOff, int width)
 /* Draw a stack of genotype bars for this record */
 {
 static struct dyString *tmp = NULL;
 if (tmp == NULL)
     tmp = dyStringNew(0);
 char *altAlleles[256];
 int altCount;
 const int lineHeight = tg->lineHeight;
 const int itemHeight = tg->heightPer;
 const double scale = scaleForPixels(width);
 int x1 = round((double)(rec->chromStart-winStart)*scale) + xOff;
 int x2 = round((double)(rec->chromEnd-winStart)*scale) + xOff;
 int w = x2-x1;
 if (w < 1)
     w = 1;
 int y = yOff;
 dyStringClear(tmp);
 dyStringAppend(tmp, rec->alt);
 altCount = chopCommas(tmp->string, altAlleles);
 int gtHapOrderIx;
 for (gtHapOrderIx = 0;  gtHapOrderIx < gtHapEnd;  gtHapOrderIx++)
     {
     int gtHapIx = gtHapOrder[gtHapOrderIx];
     int hapIx = gtHapIx & 1;
     int gtIx = gtHapIx >>1;
     struct vcfGenotype *gt = &(rec->genotypes[gtIx]);
     y = drawOneHap(gt, hapIx, rec->ref, altAlleles, altCount,
-		   hvg, x1, y, w, itemHeight, lineHeight, isCenter);
+		   hvg, x1, y, w, itemHeight, lineHeight);
     }
 mapBoxHgcOrHgGene(hvg, rec->chromStart, rec->chromEnd, x1, yOff, w, tg->height, tg->track,
 		  rec->name, gtSummaryString(rec, altAlleles, altCount),
 		  NULL, TRUE, NULL);
 }
 
 static void vcfHapClusterDraw(struct track *tg, int seqStart, int seqEnd,
 			      struct hvGfx *hvg, int xOff, int yOff, int width,
 			      MgFont *font, Color color, enum trackVisibility vis)
 /* Split samples' chromosomes (haplotypes), cluster them by center-weighted
  * alpha similarity, and draw in the order determined by clustering. */
 {
 const struct vcfFile *vcff = tg->extraUiData;
 if (vcff->records == NULL)
     return;
 unsigned short gtHapEnd = 0;
 // Use the median variant in the window as the center; would be even nicer to allow
 // the user to choose a variant (or position) to use as center:
 int ix, centerIx = (slCount(vcff->records)-1) / 2;
 unsigned short *gtHapOrder = clusterChroms(vcff, centerIx, &gtHapEnd);
 struct vcfRecord *rec, *centerRec = NULL;
 for (rec = vcff->records, ix=0;  rec != NULL;  rec = rec->next, ix++)
     {
-    boolean isCenter = (ix == centerIx);
-    drawOneRec(rec, isCenter, gtHapOrder, gtHapEnd, tg, hvg, xOff, yOff, width);
-    if (isCenter)
+    drawOneRec(rec, gtHapOrder, gtHapEnd, tg, hvg, xOff, yOff, width);
+    if (ix == centerIx)
 	centerRec = rec;
     }
 // Draw the center rec on top, outlined with black lines, to make sure it is very visible:
-drawOneRec(centerRec, TRUE, gtHapOrder, gtHapEnd, tg, hvg, xOff, yOff, width);
+drawOneRec(centerRec, gtHapOrder, gtHapEnd, tg, hvg, xOff, yOff, width);
 const double scale = scaleForPixels(width);
 int x1 = round((double)(centerRec->chromStart-winStart)*scale) + xOff;
 int x2 = round((double)(centerRec->chromEnd-winStart)*scale) + xOff;
 int yBot = yOff + tg->height - 2;
-hvGfxLine(hvg, x1-2, yOff, x1-2, yBot, MG_BLACK);
+hvGfxBox(hvg, x1-4, yOff, 3, tg->height, color);
+hvGfxBox(hvg, x2+2, yOff, 3, tg->height, color);
 hvGfxLine(hvg, x1-2, yOff, x2+2, yOff, MG_BLACK);
-hvGfxLine(hvg, x2+2, yOff, x2+2, yBot, MG_BLACK);
 hvGfxLine(hvg, x1-2, yBot, x2+2, yBot, MG_BLACK);
 }
 
 static int vcfHapClusterTotalHeight(struct track *tg, enum trackVisibility vis)
 /* Return height of haplotype graph (2 * #samples * lineHeight);
  * 2 because we're assuming diploid genomes here, no XXY, tetraploid etc. */
 {
 // Should we make it single-height when on chrY?
 const struct vcfFile *vcff = tg->extraUiData;
 if (vcff->records == NULL)
     return 0;
 int ploidy = 2;
 tg->height = ploidy * vcff->genotypeCount * tg->lineHeight;
 return tg->height;
 }