src/hg/instinct/mapProbesToGenes/mapProbesToGenes.c 1.9
1.9 2009/11/16 18:37:00 sbenz
Fix to prevent query from timing out if there's lots of probes
Index: src/hg/instinct/mapProbesToGenes/mapProbesToGenes.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/mapProbesToGenes/mapProbesToGenes.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -b -B -U 4 -r1.8 -r1.9
--- src/hg/instinct/mapProbesToGenes/mapProbesToGenes.c 19 Nov 2008 00:34:15 -0000 1.8
+++ src/hg/instinct/mapProbesToGenes/mapProbesToGenes.c 16 Nov 2009 18:37:00 -0000 1.9
@@ -233,9 +233,9 @@
if (isCgh)
{
if (rangeBothStrandOverlap(gene, probe) >0 )
{
- if ((probe->chromEnd - probe->chromStart) < 15)
+ if ((probe->chromEnd - probe->chromStart) < 1)
{
printf("%s %s %c too short dis=%d\n",
gene->name, probe->name, gene->strand[0],
probe->chromEnd- probe->chromStart);
@@ -315,19 +315,32 @@
return;
char query[512];
safef(query, sizeof(query),
- "select * from %s" , table);
+ "select COUNT(*) from %s" , table);
/* "db" is remote database connection, where "refGene" lives */
struct sqlConnection *conn = hAllocConnProfile("db", database);
struct sqlResult *sr = sqlGetResult(conn, query);
+int curr = 0;
char **row = NULL;
-struct genePred *gp;
-struct bed *gene;
-while ((row = sqlNextRow(sr)) != NULL)
+row = sqlNextRow(sr);
+unsigned i,count = sqlUnsigned(row[0]);
+sqlFreeResult(&sr);
+
+for(i = 0; i < count; i += 100)
+ {
+ safef(query, sizeof(query),
+ "select * from %s LIMIT %d,100" , table,i);
+
+ sr = sqlGetResult(conn, query);
+ struct genePred *gp;
+ struct bed *gene;
+ while ((row = sqlNextRow(sr)) != NULL)
{
+ //printf(">");
+ //fflush(stdout);
if (row[10])
{
char *tmp = row[12];
row[12] = row[1];
@@ -337,10 +350,20 @@
gp = genePredLoad(row+1);
gene = bedFromGenePred(gp);
genePredFree(&gp);
reportOverlap(gene, probeList);
+
+ if((++curr % 100) == 0)
+ {
+ printf(".");
+ fflush(stdout);
}
-hFreeConn(&conn);
+ }
+ sqlFreeResult(&sr);
+ }
+ printf("done.\n");
+ hFreeConn(&conn);
+
}
void mapProbesToGenes(char *db, char *table)
/* mapProbesToGenes - Will maps probes in BED format to overlapping gene(s). */
@@ -359,8 +382,9 @@
{
tuple = bedLoadN(row+1, 15);
slAddHead(&tupleList, tuple);
}
+sqlFreeResult(&sr);
slReverse(&tupleList);
overlapWithTable(db, tupleList, "refGene");
hFreeConn(&conn);