23332f326a436169da2eb06cc9fd726ee5fc5429
braney
  Sat Feb 12 14:42:09 2011 -0800
fix a bug where blocks were being dropped
diff --git src/hg/hgTracks/snakeTrack.c src/hg/hgTracks/snakeTrack.c
index 67e3c9d..8b308ab 100644
--- src/hg/hgTracks/snakeTrack.c
+++ src/hg/hgTracks/snakeTrack.c
@@ -46,93 +46,88 @@
     dyStringPrintf(query, 
 	"select chainId,tStart,tEnd,qStart from %sLink %s where ",
 	fullName, force);
 else
     dyStringPrintf(query, 
 	"select chainId, tStart,tEnd,qStart from %sLink where chainId=%d and ",
 	fullName, chainId);
 if (!isSplit)
     dyStringPrintf(query, "tName='%s' and ", chromName);
 hAddBinToQuery(start, end, query);
 dyStringPrintf(query, "tStart<%u and tEnd>%u", end, start);
 sr = sqlGetResult(conn, query->string);
 
 /* Loop through making up simple features and adding them
  * to the corresponding linkedFeature. */
-//printf("read chain\n");
 while ((row = sqlNextRow(sr)) != NULL)
     {
     lf = hashFindVal(hash, row[0]);
     if (lf != NULL)
 	{
 	struct chain *pChain = lf->extra;
 	lmAllocVar(lm, sf);
 	sf->start = sqlUnsigned(row[1]);
 	sf->end = sqlUnsigned(row[2]);
 	sf->qStart = sqlUnsigned(row[3]); 
 
 	sf->qEnd = sf->qStart + (sf->end - sf->start);
 	if ((pChain) && pChain->qStrand == '-')
 	    {
 	    int temp;
 
 	    temp = sf->qStart;
 	    sf->qStart = pChain->qSize - sf->qEnd;
 	    sf->qEnd = pChain->qSize - temp;
 	    }
-	//printf("%d \n",sf->qStart);
 	sf->grayIx = lf->orientation;
 	slAddHead(&lf->components, sf);
 	}
     }
 sqlFreeResult(&sr);
 dyStringFree(&query);
 }
 
 int snakeItemHeight(struct track *tg, void *item)
 {
-//printf("snakeItemHeight\n");
 //return 40;
 struct linkedFeatures  *lf = (struct linkedFeatures *)item;
 struct simpleFeature  *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)
     size = lineHeight;
 for (sf =  lf->components; sf ;  sf = sf->next)
     {
     int orient = sf->grayIx;
 
     s = sf->start; e = sf->end;
     /*
     if ((e < winStart) || (s > winEnd))
 	continue;
     if (s < winStart) s = winStart;
     */
-    //printf("bounds %d %d\n",winStart, winEnd);
     
     if (((oldOrient) && (oldOrient != orient))
 	||  ((oldOrient == 1) && (tEnd) && (s < tEnd))
 	||  ((oldOrient == -1) && (tStart) && (e > tStart)))
 	{
-	//printf("plus \n");
 	size += lineHeight;
 	}
     oldOrient = orient;
     tEnd = e;
     tStart = s;
     }
 return size;
 }
 
 static int linkedFeaturesCmpScore(const void *va, const void *vb)
 /* Help sort linkedFeatures by starting pos. */
 {
 const struct linkedFeatures *a = *((struct linkedFeatures **)va);
 const struct linkedFeatures *b = *((struct linkedFeatures **)vb);
 if (a->score > b->score)
@@ -200,36 +195,40 @@
 int midY;
 int  qs, qe;
 qStart = 0;
 tStart = xOff;
 tEnd = winEnd;
 prevSf = NULL;
 
 qe = lastQEnd = 0;
 for (sf =  lf->components; sf != NULL; lastQEnd = qe, prevSf = sf, sf = sf->next)
     {
     int orient = sf->grayIx;
     midY = y + heightPer/2;
 
     qs = sf->qStart;
     s = sf->start; e = sf->end;
+    /*
     if (qs < lastQEnd )
 	continue;
+	*/
 
     qe = sf->qEnd;
+    /*
     if ((e < winStart) || (s > winEnd))
 	continue;
+	*/
 
     if (s < winStart) s = winStart;
     
     if (((oldOrient) && (oldOrient != orient))
 	||  ((oldOrient == 1) && (tEnd) && (s < tEnd))
 	||  ((oldOrient == -1) && (tStart) && (e > tStart)))
 	{
 	if ((qStart) && (sf->qStart - qStart) < 500000)
 	    {
 	    if (oldOrient == 1)
 		{
 		if ((orient == -1) && (tEnd < sf->start))
 		    {
 		    int x1, x2, x3, w;
 
@@ -385,31 +384,30 @@
     diff = a->start - b->start;
     }
 
 return diff;
 }
 
 static int linkedFeaturesCmpChrom(const void *va, const void *vb)
 /* Help sort linkedFeatures by starting pos. */
 {
 const struct linkedFeatures *a = *((struct linkedFeatures **)va);
 const struct linkedFeatures *b = *((struct linkedFeatures **)vb);
 return strcmp(a->name, b->name);
 }
 
 int snakeHeight(struct track *tg, enum trackVisibility vis)
-/* set up size of sequence logo */
 {
 int height = 0;
 struct slList *item = tg->items, *nextItem;
 struct linkedFeatures *firstLf, *lf = (struct linkedFeatures *)tg->items;
 struct simpleFeature  *sf,  *nextSf;
 
 slSort(&tg->items, linkedFeaturesCmpChrom);
 
 item = tg->items;
 
 lf =  (struct linkedFeatures *)tg->items;
 if (item)
     {
     firstLf = lf;
     for (;item; item = nextItem)
@@ -447,31 +445,31 @@
 static void chainDraw(struct track *tg, int seqStart, int seqEnd,
         struct hvGfx *hvg, int xOff, int yOff, int width, 
         MgFont *font, Color color, enum trackVisibility vis)
 /* Draw chained features. This loads up the simple features from 
  * the chainLink table, calls linkedFeaturesDraw, and then
  * frees the simple features again. */
 {
 struct linkedFeatures *lf;
 struct simpleFeature *sf;
 struct lm *lm;
 struct hash *hash;	/* Hash of chain ids. */
 struct sqlConnection *conn;
 //double scale = ((double)(winEnd - winStart))/width;
 char fullName[64];
 int start, end, extra;
-struct simpleFeature *lastSf = NULL;
+//struct simpleFeature *lastSf = NULL;
 int maxOverLeft = 0, maxOverRight = 0;
 int overLeft, overRight;
 
 if (tg->items == NULL)		/*Exit Early if nothing to do */
     return;
 
 lm = lmInit(1024*4);
 hash = newHash(0);
 conn = hAllocConn(database);
 
 /* Make up a hash of all linked features keyed by
  * id, which is held in the extras field.  To
  * avoid burning memory on full chromosome views
  * we'll just make a single simple feature and
  * exclude from hash chains less than three pixels wide, 
@@ -524,30 +522,31 @@
 	{
 	/* if chains extend beyond edge of window we need to get 
 	 * elements that are off the screen
 	 * in both directions so we know whether to draw
 	 * one or two lines to the edge of the screen.
 	 */
 #define STARTSLOP	10000
 #define MULTIPLIER	10
 #define MAXLOOK		100000
 	extra = (STARTSLOP < maxOverLeft) ? STARTSLOP : maxOverLeft;
 	start = seqStart - extra;
 	extra = (STARTSLOP < maxOverRight) ? STARTSLOP : maxOverRight;
 	end = seqEnd + extra;
 	doQuery(conn, fullName, lm,  hash, start, end,  isSplit, -1);
 
+#ifdef NOTNOW
 	for (lf = tg->items; lf != NULL; lf = lf->next)
 	    {
 	    struct chain *pChain = lf->extra;
 	    int chainId = pChain->id;
 
 	    if (lf->components == NULL)
 		continue;
 	    slSort(&lf->components, linkedFeaturesCmpStart);
 	    extra = (STARTSLOP < maxOverRight)?STARTSLOP:maxOverRight;
 	    end = seqEnd + extra;
 	    lastSf = NULL;
 	    while (lf->end > end )
 		{
 		for(lastSf=sf=lf->components;sf;lastSf=sf,sf=sf->next)
 		    ;
@@ -594,30 +593,31 @@
 		slSort(&lf->components, linkedFeaturesCmpStart);
 		}
 	    if ((lf->components->start > seqStart) && (lf->start < lf->components->start))
 		{
 		lmAllocVar(lm, sf);
 		sf->start = 0;
 		sf->end = 1;
 		sf->grayIx = lf->grayIx;
 		sf->qStart = lf->components->qStart;
 		sf->qEnd = sf->qStart + (sf->end - sf->start);
 		sf->next = lf->components;
 		lf->components = sf;
 		slSort(&lf->components, linkedFeaturesCmpStart);
 		}
 	    }
+#endif
 	}
     }
 if (1)
 {
 snakeHeight(tg, vis);
 snakeDraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width,
 	font, color, vis);
 	}
     else
     {
 linkedFeaturesDraw(tg, seqStart, seqEnd, hvg, xOff, yOff, width,
 	font, color, vis);
 	}
 /* Cleanup time. */
 for (lf = tg->items; lf != NULL; lf = lf->next)