6ec399788beeb064f90f425e1b99b5635d85699a rhead Tue May 8 19:36:29 2012 -0700 Moved two functions from qaUtils to qaGbTracks, and got rid of a duplicated function from qaUtils. diff --git src/utils/qa/qaGbTracks src/utils/qa/qaGbTracks index 4c2e773..4a7e1a4 100755 --- src/utils/qa/qaGbTracks +++ src/utils/qa/qaGbTracks @@ -23,30 +23,41 @@ genePredCheck pslCheck featureBits (a version of) countPerChrom creates 3 files: outFile.summary, outFile.log, outFile.chrom """) parser.add_argument('db', help='the database to check') parser.add_argument('-s, --single', help ='tableList is the name of a single table', action="store_true", dest="single") parser.add_argument('tableList', help= 'a file listing the tables to check, or the name of a single table') parser.add_argument('outFile', help='base name to give results files') return parser.parse_args() +def tableExists(db, table): + """True if the table exists in the given database.""" + sqlResult = qaUtils.callHgsql(db, "show tables like '" + table + "'") + return sqlResult.strip() == table + +def checkTablesExist(db, tables): + """Raises an exception if any table in the tables list does not exist in the database.""" + for name in tables: + if not tableExists(db, name): + raise Exception("Table " + name + " in " + db + " does not exist") + def getTableList(): if args.single: return [args.tableList] else: with open(args.tableList, "r") as f: raw = f.readlines() return [name.strip() for name in raw] delimiterLine = "===============================================" def runTests(): """Runs validate() and statistics() methods on each table. Writes log output.""" reporter.writeTimestamp() reporter.writeBlankLine() for table in tableList: reporter.writeLine(delimiterLine) @@ -59,30 +70,30 @@ reporter.writeTimestamp() def writeSummaryFile(): sumFile.write(sumTable.tabSeparated()) def runChromCounts(): chromFile.write(time.asctime() + "\n") chromFile.write("Database: " + args.db + "\n\n") tableSet = set(tableList) output, tablecounts = tableCheck.countPerChrom(args.db, tableSet) for line in output: chromFile.write(line + "\n") args = parseCommandLine() tableList = getTableList() -qaUtils.checkTablesExist(args.db, tableList) +checkTablesExist(args.db, tableList) logFile = open(args.outFile + ".log", "w") chromFile = open(args.outFile + ".chroms", "w") sumFile = open(args.outFile + ".summary", "w") reporter = reporter.Reporter(logFile) sumTable = summary.SumTable() runTests() runChromCounts() writeSummaryFile() logFile.close() sumFile.close() chromFile.close()