src/hg/utils/tdbQuery/tdbQuery.c 1.15
1.15 2009/12/05 02:32:49 kent
Fixing bug in -strict logic for parent tables.
Index: src/hg/utils/tdbQuery/tdbQuery.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/tdbQuery/tdbQuery.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -B -U 4 -r1.14 -r1.15
--- src/hg/utils/tdbQuery/tdbQuery.c 4 Dec 2009 22:15:16 -0000 1.14
+++ src/hg/utils/tdbQuery/tdbQuery.c 5 Dec 2009 02:32:49 -0000 1.15
@@ -3,8 +3,9 @@
#include "linefile.h"
#include "hash.h"
#include "options.h"
#include "localmem.h"
+#include "dystring.h"
#include "obscure.h"
#include "portable.h"
#include "errabort.h"
#include "tdbRecord.h"
@@ -129,9 +130,8 @@
{
/* Do checks that tags are all legitimate and with correct types. */
char tagTypeFile[PATH_LEN];
safef(tagTypeFile, sizeof(tagTypeFile), "%s/%s", clRoot, "tagTypes.tab");
-uglyf("tagTypeFile %s, clRoot %s\n", tagTypeFile, clRoot);
struct hash *tagTypeHash = readTagTypeHash(tagTypeFile);
struct tdbRecord *record;
for (record = recordList; record != NULL; record = record->next)
{
@@ -172,8 +172,23 @@
/* Get list of all "database" directories with any trackDb.ra files two under us. */
{
struct dbPath *pathList = NULL, *path;
struct fileInfo *org, *orgList = listDirX(root, "*", TRUE);
+
+/* If in strict mode avoid looking up databases that aren't in mysql. */
+struct hash *dbStrictHash = NULL;
+if (clStrict)
+ {
+ struct sqlConnection *conn = sqlConnect("mysql");
+ struct slName *db, *dbList = sqlGetAllDatabase(conn);
+ dbStrictHash = hashNew(0);
+ for (db = dbList; db != NULL; db = db->next)
+ hashAdd(dbStrictHash, db->name, NULL);
+ sqlDisconnect(&conn);
+ slFreeList(&dbList);
+ }
+
+
for (org = orgList; org != NULL; org = org->next)
{
if (org->isDir)
{
@@ -185,17 +200,21 @@
char trackDbPath[PATH_LEN];
safef(trackDbPath, sizeof(trackDbPath), "%s/trackDb.ra", db->name);
if (fileExists(trackDbPath))
{
- AllocVar(path);
- path->dir = cloneString(db->name);
char *s = strrchr(db->name, '/');
assert(s != NULL);
- path->db = cloneString(s+1);
+ char *fileOnly = s+1;
+ if (dbStrictHash == NULL || hashLookup(dbStrictHash, fileOnly) != NULL)
+ {
+ AllocVar(path);
+ path->db = cloneString(fileOnly);
+ path->dir = cloneString(db->name);
slAddHead(&pathList, path);
}
}
}
+ }
slFreeList(&dbList);
}
}
slFreeList(&orgList);
@@ -821,18 +840,35 @@
}
fprintf(out, "\n");
}
-static boolean tableExistsInSelfOrOffspring(char *db, struct tdbRecord *record)
+
+static boolean tableExistsInSelfOrOffspring(char *db, struct tdbRecord *record,
+ int level, struct slRef *parent)
/* Return TRUE if table corresponding to track exists in database db. If a parent
* track look for tables in kids too. */
{
if ( hTableOrSplitExists(db, record->key))
return TRUE;
struct tdbRecord *child;
-for (child = record->children; child != NULL; child = child->next)
+if (level > 5)
+ {
+ struct slRef *ancestor;
+ struct dyString *err = dyStringNew(0);
+ dyStringPrintf(err, "Heirarchy too deep from %s", record->key);
+ for (ancestor=parent; ancestor != NULL; ancestor = ancestor->next)
{
- if (tableExistsInSelfOrOffspring(db, child))
+ struct tdbRecord *a = ancestor->val;
+ dyStringPrintf(err, " to %s", a->key);
+ }
+ recordAbort(record, "%s", err->string);
+ }
+struct slRef me;
+me.next = parent;
+me.val = record;
+for (child = record->children; child != NULL; child = child->olderSibling)
+ {
+ if (tableExistsInSelfOrOffspring(db, child, level+1, &me))
return TRUE;
}
return FALSE;
}
@@ -873,8 +910,9 @@
verbose(2, "Composed %d records from %s\n", slCount(recordList), db);
inheritFromParents(recordList, "subTrack", "noInherit", clAlpha, lm);
recordList = filterOnRelease(recordList, clAlpha);
verbose(2, "After filterOnRelease %d records\n", slCount(recordList));
+ linkUpParents(recordList, "subTrack", clAlpha);
checkDupeKeys(recordList, FALSE);
overridePrioritiesAndVisibilities(recordList, p, lm);
@@ -905,9 +943,9 @@
if (rqlStatementMatch(rql, record, lm))
{
- if (!clStrict || tableExistsInSelfOrOffspring(p->db, record))
+ if (!clStrict || tableExistsInSelfOrOffspring(p->db, record, 1, NULL))
{
matchCount += 1;
if (doSelect)
{