src/hg/hgc/bamClick.c 1.12

1.12 2009/11/26 00:29:11 angie
Refinements to searching for mates out of window: don't do the extra bamFetch unless pairSearchRange > 0; increase default pairSearchRange default; clip start of window at 0; there's only one item name, so don't need to loop on pairHash name.
Index: src/hg/hgc/bamClick.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/hgc/bamClick.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -b -B -U 4 -r1.11 -r1.12
--- src/hg/hgc/bamClick.c	8 Oct 2009 06:38:26 -0000	1.11
+++ src/hg/hgc/bamClick.c	26 Nov 2009 00:29:11 -0000	1.12
@@ -157,37 +157,33 @@
     }
 else
     fileName = bamFileNameFromTable(database, tdb->tableName, seqNameForBam);
 bamFetch(fileName, posForBam, oneBam, &btd);
-if (isPaired && hashNumEntries(pairHash) > 0)
+if (isPaired)
     {
-    char *setting = trackDbSettingOrDefault(tdb, "pairSearchRange", "1000");
+    char *setting = trackDbSettingOrDefault(tdb, "pairSearchRange", "20000");
     int pairSearchRange = atoi(setting);
-    struct hashEl *hel;
-    struct hashCookie cookie = hashFirst(pairHash);
-    while ((hel = hashNext(&cookie)) != NULL)
+    if (pairSearchRange > 0 && hashNumEntries(pairHash) > 0)
 	{
+	// Repeat the search for item in a larger window:
 	struct hash *newPairHash = hashNew(0);
-	btd.itemName = hel->name;
 	btd.pairHash = newPairHash;
 	safef(posForBam, sizeof(posForBam), "%s:%d-%d", seqNameForBam,
-	      winStart-pairSearchRange, winEnd+pairSearchRange);
+	      max(0, winStart-pairSearchRange), winEnd+pairSearchRange);
 	bamFetch(fileName, posForBam, oneBam, &btd);
-	if (hashNumEntries(newPairHash) > 0)
-	    {
-	    struct hashCookie cookie2 = hashFirst(pairHash);
-	    while ((hel = hashNext(&cookie2)) != NULL)
+	}
+    struct hashEl *hel;
+    struct hashCookie cookie = hashFirst(btd.pairHash);
+    while ((hel = hashNext(&cookie)) != NULL)
 		{
 		bam1_t *bam = hel->val;
 		const bam1_core_t *core = &bam->core;
-		if (core->flag & BAM_FPROPER_PAIR)
-		    printf("<B>Note: </B>unable to find paired end "
-			   "for %s within +-%d of viewing window<BR>\n",
-			   hel->name, pairSearchRange);
+	if (! (core->flag & BAM_FMUNMAP))
+	    printf("<B>Note: </B>unable to find paired end for %s "
+		   "within +-%d bases of viewing window %s<BR>\n",
+		   item, pairSearchRange, addCommasToPos(database, cartString(cart, "position")));
 		singleBamDetails(bam);
 		}
 	    }
-	}
-    }
 }
 
 #endif//def USE_BAM