e3520506d7e3aaebb93f497a7115902aff7971a6 angie Wed Jun 10 15:31:42 2015 -0700 annoStreamDbFactorSource assumes that 'type factorSource' implies a particular set of fields -- but on hgwdev it doesn't because there is an older 'type factorSource' table that has BED15 fields. So if the fields aren't what we expect for 'type factorSource', just treat it as a plain old db table. refs #14579 notes 145 & 146. diff --git src/hg/lib/hAnno.c src/hg/lib/hAnno.c index 62eb3e2..89eef13 100644 --- src/hg/lib/hAnno.c +++ src/hg/lib/hAnno.c @@ -1,22 +1,23 @@ /* hAnno -- helpers for creating anno{Streamers,Grators,Formatters,Queries} */ #include "common.h" #include "hAnno.h" #include "basicBed.h" #include "bigGenePred.h" #include "customTrack.h" +#include "factorSource.h" #include "grp.h" #include "hdb.h" #include "hubConnect.h" #include "hui.h" #include "jksql.h" #include "pgSnp.h" #include "trackHub.h" #include "vcf.h" #include "annoGratorQuery.h" #include "annoGratorGpVar.h" #include "annoStreamBigBed.h" #include "annoStreamBigWig.h" #include "annoStreamDb.h" #include "annoStreamDbFactorSource.h" #include "annoStreamDbKnownGene.h" @@ -130,30 +131,44 @@ { char *bigDataUrl = trackDbSetting(tdb, "bigDataUrl"); if (isNotEmpty(bigDataUrl)) { return bigDataUrl; } else { struct sqlConnection *conn = hAllocConn(db); char *fileOrUrl = bbiNameFromSettingOrTableChrom(tdb, conn, selTable, chrom); hFreeConn(&conn); return fileOrUrl; } } +static boolean dbTableMatchesAutoSql(char *db, char *table, struct asObject *asObj) +/* Return true if table exists and its fields match the columns of asObj. */ +{ +boolean matches = FALSE; +struct sqlConnection *conn = hAllocConn(db); +if (sqlTableExists(conn, table)) + { + struct sqlFieldInfo *fieldList = sqlFieldInfoGet(conn, table); + matches = columnsMatch(asObj, fieldList); + } +hFreeConn(&conn); +return matches; +} + struct annoStreamer *hAnnoStreamerFromTrackDb(struct annoAssembly *assembly, char *selTable, struct trackDb *tdb, char *chrom, int maxOutRows) /* Figure out the source and type of data and make an annoStreamer. */ { struct annoStreamer *streamer = NULL; char *db = assembly->name, *dataDb = db, *dbTable = selTable; if (chrom == NULL) chrom = hDefaultChrom(db); if (isCustomTrack(selTable)) { dbTable = trackDbSetting(tdb, "dbTableName"); if (dbTable != NULL) // This is really a database table, not a bigDataUrl CT. dataDb = CUSTOM_TRASH; } @@ -171,31 +186,32 @@ } else if (sameString("bam", tdb->type)) { warn("Sorry, BAM is not yet supported"); } else if (startsWith("bigBed", tdb->type) || sameString("bigGenePred", tdb->type)) { char *fileOrUrl = getBigDataFileName(dataDb, tdb, selTable, chrom); streamer = annoStreamBigBedNew(fileOrUrl, assembly, maxOutRows); } else if (startsWith("bigWig", tdb->type)) { char *fileOrUrl = getBigDataFileName(dataDb, tdb, selTable, chrom); streamer = annoStreamBigWigNew(fileOrUrl, assembly); //#*** no maxOutRows support } -else if (sameString("factorSource", tdb->type)) +else if (sameString("factorSource", tdb->type) && + dbTableMatchesAutoSql(dataDb, tdb->table, factorSourceAsObj())) { char *sourceTable = trackDbSetting(tdb, "sourceTable"); char *inputsTable = trackDbSetting(tdb, "inputTrackTable"); streamer = annoStreamDbFactorSourceNew(dataDb, tdb->track, sourceTable, inputsTable, assembly, maxOutRows); } else if (sameString("knownGene", tdb->track)) { struct sqlConnection *conn = hAllocConn(dataDb); if (sqlTableExists(conn, "knownGene") && sqlTableExists(conn, "kgXref")) streamer = annoStreamDbKnownGeneNew(dataDb, assembly, maxOutRows); hFreeConn(&conn); } else if (trackHubDatabase(db)) errAbort("Unrecognized type '%s' for hub track '%s'", tdb->type, tdb->track); @@ -300,31 +316,32 @@ // BED with no + fields; parse bed field count out of type line. int bedFieldCount = 3; char typeCopy[PATH_LEN]; safecpy(typeCopy, sizeof(typeCopy), tdb->type); char *words[8]; int wordCount = chopLine(typeCopy, words); if (wordCount > 1) bedFieldCount = atoi(words[1]); asObj = asParseText(bedAsDef(bedFieldCount, bedFieldCount)); } else if (sameString(tdb->track, "knownGene")) { if (hTableExists(db, "knownGene") && hTableExists(db, "kgXref")) asObj = annoStreamDbKnownGeneAsObj(); } -else if (sameString("factorSource", tdb->type)) +else if (sameString("factorSource", tdb->type) && + dbTableMatchesAutoSql(db, tdb->table, factorSourceAsObj())) { asObj = annoStreamDbFactorSourceAsObj(); } return asObj; } struct asObject *hAnnoGetAutoSqlForTdb(char *db, char *chrom, struct trackDb *tdb) /* If possible, return the asObj that a streamer for this track would use, otherwise NULL. */ { struct asObject *asObj = getAutoSqlForType(db, chrom, tdb); if (!asObj && !isHubTrack(tdb->track)) { // If none of the above, it must be a database table; deduce autoSql from sql fields. char *dataDb = db, *dbTable = tdb->table;