src/hg/ratStuff/mafSplitPos/mafSplitPos.c 1.6
1.6 2009/06/11 16:01:38 hiram
This didn't work when gap and rmsk were not split tables, fix that up with more extensive MySQL queries
Index: src/hg/ratStuff/mafSplitPos/mafSplitPos.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/ratStuff/mafSplitPos/mafSplitPos.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -b -B -U 4 -r1.5 -r1.6
--- src/hg/ratStuff/mafSplitPos/mafSplitPos.c 3 Sep 2008 19:21:16 -0000 1.5
+++ src/hg/ratStuff/mafSplitPos/mafSplitPos.c 11 Jun 2009 16:01:38 -0000 1.6
@@ -34,27 +34,37 @@
{"minRepeat", OPTION_INT},
{NULL, 0},
};
-char *chrom = NULL;
-int minGap = 100;
-int minRepeat = 100;
+static char *chrom = NULL;
+static int minGap = 100;
+static int minRepeat = 100;
+static char *db = NULL;
int nextGapPos(char *chrom, int desiredPos, struct sqlConnection *conn)
{
/* Find next gap on the chrom and return midpoint */
-char where[256];
struct sqlResult *sr;
char **row;
int pos = -1;
int start, end;
+struct hTableInfo *hti = hFindTableInfo(db, chrom, "gap");
+struct dyString *query = newDyString(1024);
-safef(where, sizeof where,
- "chromStart >= %d and chromEnd-chromStart > %d\
+if (hti == NULL)
+ errAbort("table %s.gap doesn't exist", db);
+dyStringPrintf(query, "select chromStart,chromEnd from ");
+if (hti->isSplit)
+ dyStringPrintf(query, "%s_gap where ", chrom);
+else
+ dyStringPrintf(query, "gap where %s='%s' AND ", hti->chromField, chrom);
+
+dyStringPrintf(query, "(chromStart >= %d and chromEnd-chromStart > %d)\
order by chromStart limit 1",
desiredPos, minGap);
-sr = hExtendedChromQuery(conn, "gap", chrom, where, FALSE,
- "chromStart, chromEnd", NULL);
+sr = sqlGetResult(conn, query->string);
+freeDyString(&query);
+
if ((row = sqlNextRow(sr)) != NULL)
{
start = sqlSigned(row[0]);
end = sqlSigned(row[1]);
@@ -66,22 +76,31 @@
int nextRepeatPos(char *chrom, int desiredPos, struct sqlConnection *conn)
/* Find next 0% diverged repeat on the chrom and return midpoint */
{
-char where[256];
struct sqlResult *sr;
char **row;
int pos = -1;
int start, end;
+struct hTableInfo *hti = hFindTableInfo(db, chrom, "rmsk");
+struct dyString *query = newDyString(1024);
-safef(where, sizeof where,
- "genoStart >= %d and \
- milliDiv=0 and \
- repClass<>'Simple_repeat' and repClass<>'Low_complexity' and \
- genoEnd-genoStart>%d order by genoStart limit 1",
+if (hti == NULL)
+ errAbort("table %s.rmsk doesn't exist", db);
+dyStringPrintf(query, "select genoStart,genoEnd from ");
+if (hti->isSplit)
+ dyStringPrintf(query, "%s_rmsk where ", chrom);
+else
+ dyStringPrintf(query, "rmsk where %s='%s' AND ", hti->chromField, chrom);
+dyStringPrintf(query,
+ "(genoStart >= %d AND \
+ milliDiv=0 AND \
+ repClass<>'Simple_repeat' AND repClass<>'Low_complexity' AND \
+ genoEnd-genoStart>%d) order by genoStart limit 1",
desiredPos, minRepeat);
-sr = hExtendedChromQuery(conn, "rmsk", chrom, where, FALSE,
- "genoStart, genoEnd", NULL);
+sr = sqlGetResult(conn, query->string);
+freeDyString(&query);
+
if ((row = sqlNextRow(sr)) != NULL)
{
start = sqlSigned(row[0]);
end = sqlSigned(row[1]);
@@ -134,8 +153,10 @@
struct hashEl *hel;
struct sqlConnection *conn = sqlConnect(database);
FILE *f;
+db = database;
+
verbose(1, "Finding split positions for %s at ~%s Mbp intervals\n",
database, size);
splitSize = sqlSigned(size) * 1000000;
if (chrom == NULL)