23bc1ba098279a4676b6767f8fa21b78563c09c6
braney
  Mon May 23 16:46:06 2011 -0700
still under development.....
diff --git src/hg/hgTracks/snakeTrack.c src/hg/hgTracks/snakeTrack.c
index 9560efe..a7f1e1f 100644
--- src/hg/hgTracks/snakeTrack.c
+++ src/hg/hgTracks/snakeTrack.c
@@ -227,35 +227,39 @@
     {
     clearLevels();
     calcSnake((struct snakeFeature *)lf->components, 0);
     lf->components = (struct simpleFeature *)newList;
     newList = NULL;
     slSort(&lf->components, snakeFeatureCmpQStart);
     struct snakeInfo *si;
     AllocVar(si);
     si->maxLevel = maxLevel;
     lf->codons = (struct simpleFeature *)si;
     }
 }
 
 int packSnakeItemHeight(struct track *tg, void *item)
 {
+if (item == NULL)
+    return 0;
 struct linkedFeatures  *lf = (struct linkedFeatures *)item;
+if (lf->components == NULL)
+    return 0;
 calcPackSnake(tg, item);
 struct snakeInfo *si = (struct snakeInfo *)lf->codons;
 int lineHeight = tg->lineHeight ;
-return (si->maxLevel + 1) * lineHeight;
+return (si->maxLevel + 1) * (2 * lineHeight);
 }
 
 int fullSnakeItemHeight(struct track *tg, void *item)
 {
 struct linkedFeatures  *lf = (struct linkedFeatures *)item;
 struct snakeFeature  *sf;
 int s, e;
 int lineHeight = tg->lineHeight ;
 int oldOrient = 0;
 int tStart, tEnd;
 int size = 0;
 //int count = 0;
 tStart = 0;
 tEnd = 0;
 if (lf->components)
@@ -342,85 +346,111 @@
 void snakeLeftLabels(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 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. */
 {
 struct linkedFeatures  *lf = (struct linkedFeatures *)item;
 calcPackSnake(tg, item);
 
-int x;
+int lastLevel;
+//int x;
 int offY = y;
 struct snakeFeature  *sf, *prevSf;
 int lineHeight = tg->lineHeight ;
 int tStart, tEnd, qStart;
 int  qs, qe;
 int s, e;
 int heightPer = tg->heightPer;
 int lastX = -1,lastY = y;
 int lastQEnd = 0;
 qe = lastQEnd = 0;
 for (sf =  (struct snakeFeature *)lf->components; sf != NULL; lastQEnd = qe, prevSf = sf, sf = sf->next)
     {
     qs = sf->qStart;
     qe = sf->qEnd;
-    y = offY + sf->level * lineHeight;
+    y = offY + (sf->level * 2) * lineHeight;
     s = sf->start; e = sf->end;
     tEnd = sf->end;
-    x = round((double)((int)tEnd-winStart)*scale) + xOff;
+    //x = round((double)((int)tEnd-winStart)*scale) + xOff;
     //color =	    lfChromColor(tg, item, hvg);
 color = (sf->orientation == -1) ? MG_RED : MG_BLUE;
 
     //if (lastX != -1)
 	//hvGfxLine(hvg, lastX, lastY + lineHeight/2, x, y + lineHeight/2, MG_BLACK);
     drawScaledBoxSample(hvg, s, e, scale, xOff, y, heightPer, 
 			color, lf->score );
     tEnd = e;
     tStart = s;
     qStart = sf->qStart;
     lastY = y;
-    lastX = x;
+    //lastX = x;
     }
 lastX = -1,lastY = y;
 lastQEnd = 0;
+lastLevel = 0;
 qe = lastQEnd = 0;
 for (sf =  (struct snakeFeature *)lf->components; sf != NULL; lastQEnd = qe, prevSf = sf, sf = sf->next)
     {
+    int y1, y2;
+    int sx, ex;
     qs = sf->qStart;
     qe = sf->qEnd;
-    y = offY + sf->level * lineHeight;
+    if (lastLevel == sf->level)
+	{
+	y1 = offY + (lastLevel * 2) * lineHeight + lineHeight/2;
+	y2 = offY + (sf->level * 2) * lineHeight + lineHeight/2;
+	}
+    else if (lastLevel > sf->level)
+	{
+	y1 = offY + (lastLevel * 2 ) * lineHeight;
+	y2 = offY + (sf->level * 2 + 1) * lineHeight;
+	}
+    else
+	{
+	y1 = offY + (lastLevel * 2 + 1) * lineHeight;
+	y2 = offY + (sf->level * 2 ) * lineHeight;
+	}
     s = sf->start; e = sf->end;
-    tEnd = sf->end;
-    x = round((double)((int)tEnd-winStart)*scale) + xOff;
+    //tStart = sf->start;
+    //tEnd = sf->end;
+
+    sx = round((double)((int)s-winStart)*scale) + xOff;
+    ex = round((double)((int)e-winStart)*scale) + xOff;
     //color =	    lfChromColor(tg, item, hvg);
 color = (sf->orientation == -1) ? MG_RED : MG_BLUE;
 
     if (lastX != -1)
-	hvGfxLine(hvg, lastX, lastY + lineHeight/2, x, y + lineHeight/2, MG_BLACK);
+	{
+	hvGfxLine(hvg, lastX, y1, sx, y2, MG_GRAY);
+	//hvGfxLine(hvg, lastX, lastY + lineHeight/2, x, y + lineHeight/2, MG_BLACK);
+	//hvGfxLine(hvg,  x, y + lineHeight/2, x, y + lineHeight + lineHeight/2, MG_BLACK);
+	}
     //drawScaledBoxSample(hvg, s, e, scale, xOff, y, heightPer, 
 			//color, lf->score );
     tEnd = e;
     tStart = s;
     qStart = sf->qStart;
-    lastY = y;
-    lastX = x;
+    //lastY = y;
+    lastX = ex;
+    lastLevel = sf->level;
     }
 }
 
 void fullSnakeDrawAt(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. */
 {
 struct linkedFeatures  *lf = (struct linkedFeatures *)item;
 struct snakeFeature  *sf, *prevSf;
 int s, e;
 int heightPer = tg->heightPer;
 int lineHeight = tg->lineHeight ;
 int oldOrient = 0;
 int tStart, tEnd, qStart;
@@ -626,52 +656,55 @@
 {
 const struct linkedFeatures *a = *((struct linkedFeatures **)va);
 const struct linkedFeatures *b = *((struct linkedFeatures **)vb);
 return strcmp(a->name, b->name);
 }
 
 void fixItems(struct linkedFeatures *lf)
 {
 struct linkedFeatures *firstLf, *next;
 struct snakeFeature  *sf,  *nextSf;
 
 firstLf = lf;
 for (;lf; lf = next)
     {
     next = lf->next;
-    if (!sameString(firstLf->name, lf->name))
+    if (!sameString(firstLf->name, lf->name) && (lf->components != NULL))
 	{
 	slSort(&firstLf->components, snakeFeatureCmpQStart);
 	firstLf = lf;
 	}
     for (sf =  (struct snakeFeature *)lf->components; sf != NULL; sf = nextSf)
 	{
 	sf->orientation = lf->orientation;
 	nextSf = sf->next;
 	if (firstLf != lf)
 	    {
 	    
 	    lf->components = NULL;
 	    slAddHead(&firstLf->components, sf);
 
 	    }
 	}
     }
 
+if (firstLf != NULL)
+    {
 slSort(&firstLf->components, snakeFeatureCmpQStart);
 firstLf->next = 0;
 }
+}
 
 int snakeHeight(struct track *tg, enum trackVisibility vis)
 {
 int height = 0;
 struct slList *item = tg->items;
 
 slSort(&tg->items, linkedFeaturesCmpChrom);
 
 item = tg->items;
 
 for (item=tg->items;item; item = item->next)
     {
     height += tg->itemHeight(tg, item);
     }
 return height;