1c28f7b2a9766b4d0d964ebcd2fe11aeba4e0937
angie
  Fri May 6 16:42:40 2011 -0700
Feature #3711 (vcfTabix haplotype clustering): added pgSnp-like mouseovertext, but with genotype counts instead of allele counts.

diff --git src/hg/hgTracks/vcfTrack.c src/hg/hgTracks/vcfTrack.c
index 5b41470..de722ff 100644
--- src/hg/hgTracks/vcfTrack.c
+++ src/hg/hgTracks/vcfTrack.c
@@ -394,30 +394,69 @@
 }
 
 
 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)
 /* Draw a base-colored box for genotype[hapIx].  Return the new y offset. */
 {
 Color color = colorHapByRefAlt ? colorFromRefAlt(gt, hapIx, TRUE) :
 				 colorFromGt(gt, hapIx, ref, altAlleles, altCount, TRUE);
 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!
+{
+static struct dyString *dy = NULL;
+if (dy == NULL)
+    dy = dyStringNew(0);
+dyStringClear(dy);
+const struct vcfFile *vcff = rec->file;
+int gtRefRefCount = 0, gtRefAltCount = 0, gtAltAltCount = 0, gtOtherCount = 0;
+int i;
+for (i=0;  i < vcff->genotypeCount;  i++)
+    {
+    struct vcfGenotype *gt = &(rec->genotypes[i]);
+    if (gt->hapIxA == 0 && gt->hapIxB == 0)
+	gtRefRefCount++;
+    else if (gt->hapIxA == 1 && gt->hapIxB == 1)
+	gtAltAltCount++;
+    else if ((gt->hapIxA == 0 && gt->hapIxB == 1) || (gt->hapIxA == 1 && gt->hapIxB == 0))
+	gtRefAltCount++;
+    else
+	gtOtherCount++;
+    }
+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 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;
 unsigned short gtHapEnd = 0;
 unsigned short *gtHapOrder = clusterChroms(vcff, &gtHapEnd);
 struct dyString *tmp = dyStringNew(0);
 struct vcfRecord *rec;
 const int lineHeight = tg->lineHeight;
 const int itemHeight = tg->heightPer;
 const double scale = scaleForPixels(width);
 for (rec = vcff->records;  rec != NULL;  rec = rec->next)
@@ -430,33 +469,33 @@
     int x2 = round((double)(rec->chromEnd-winStart)*scale) + xOff;
     int w = x2-x1;
     if (w < 1)
 	w = 1;
     int y = yOff;
     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);
 	}
-    //#*** TODO: pgSnp-like mouseover text?
     mapBoxHgcOrHgGene(hvg, rec->chromStart, rec->chromEnd, x1, yOff, w, tg->height, tg->track,
-		      rec->name, rec->name, FALSE, TRUE, NULL);
+		      rec->name, gtSummaryString(rec, altAlleles, altCount),
+		      NULL, TRUE, NULL);
     }
 // left labels?
 }
 
 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;
 int ploidy = 2;
 tg->height = ploidy * vcff->genotypeCount * tg->lineHeight;
 return tg->height;
 }