Index: src/hg/hgTracks/bamTrack.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgTracks/bamTrack.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -b -B -U 4 -r1.19 -r1.20
--- src/hg/hgTracks/bamTrack.c	10 Dec 2009 15:02:12 -0000	1.19
+++ src/hg/hgTracks/bamTrack.c	14 Dec 2009 23:19:57 -0000	1.20
@@ -19,9 +19,8 @@
 struct bamTrackData
     {
     struct track *tg;
     struct hash *pairHash;
-    struct hash *nameHash;
     int minAliQual;
     char *colorMode;
     char *grayMode;
     char *userTag;
@@ -251,10 +250,8 @@
  * or add it to tg->items. */
 {
 const bam1_core_t *core = &bam->core;
 struct bamTrackData *btd = (struct bamTrackData *)data;
-if (btd->nameHash != NULL && hashLookup(btd->nameHash, bam1_qname(bam)) == NULL)
-    return 0;
 if (! passesFilters(bam, btd))
     return 0;
 struct linkedFeatures *lf = bamToLf(bam, data);
 struct track *tg = btd->tg;
@@ -342,9 +339,9 @@
 int minAliQual = atoi(cartOrTdbClosest(tg->tdb, BAM_MIN_ALI_QUAL, BAM_MIN_ALI_QUAL_DEFAULT));
 char *colorMode = cartOrTdbClosest(tg->tdb, BAM_COLOR_MODE, BAM_COLOR_MODE_DEFAULT);
 char *grayMode = cartOrTdbClosest(tg->tdb, BAM_GRAY_MODE, BAM_GRAY_MODE_DEFAULT);
 char *userTag = cartOrTdbClosest(tg->tdb, BAM_COLOR_TAG, BAM_COLOR_TAG_DEFAULT);
-struct bamTrackData btd = {tg, pairHash, NULL, minAliQual, colorMode, grayMode, userTag};
+struct bamTrackData btd = {tg, pairHash, minAliQual, colorMode, grayMode, userTag};
 char *fileName;
 if (tg->customPt)
     {
     fileName = trackDbSettingClosestToHome(tg->tdb, "bigDataUrl");
@@ -352,30 +349,26 @@
 	errAbort("bamLoadItemsCore: can't find bigDataUrl for custom track %s", tg->mapName);
     }
 else
     fileName = bamFileNameFromTable(database, tg->mapName, chromName);
-bamFetch(fileName, position, (isPaired ? addBamPaired : addBam), &btd);
-if (isPaired)
+if (!isPaired)
+    bamFetch(fileName, position, addBam, &btd);
+else
     {
+    char posForBam[512];
+    safecpy(posForBam, sizeof(posForBam), position);
     char *setting = trackDbSettingClosestToHomeOrDefault(tg->tdb, "pairSearchRange", "20000");
     int pairSearchRange = atoi(setting);
-    if (pairSearchRange > 0 && hashNumEntries(pairHash) > 0)
-	{
-	// Search in a wider region, only for item names that are left over in pairHash
-	// (i.e. improperly paired reads whose mates aren't in the window)
-	struct hash *newPairHash = hashNew(12);
-	btd.nameHash = pairHash;
-	btd.pairHash = newPairHash;
-	char posForBam[512];
+    if (pairSearchRange > 0)
 	safef(posForBam, sizeof(posForBam), "%s:%d-%d", chromName,
 	      max(0, winStart-pairSearchRange), winEnd+pairSearchRange);
 	bamFetch(fileName, posForBam, addBamPaired, &btd);
-	}
     struct hashEl *hel;
     struct hashCookie cookie = hashFirst(btd.pairHash);
     while ((hel = hashNext(&cookie)) != NULL)
 	{
 	struct linkedFeatures *lf = hel->val;
+	if (lf->start < winEnd && lf->end > winStart)
 	slAddHead(&(tg->items), lfsFromLf(lf));
 	}
     }
 if (tg->visibility != tvDense)

