6fdc4438857ca3bd736c8f2b57ee0b847c8a92c2 rhead Wed Apr 25 17:25:39 2012 -0700 Started using new classes in ucscgenomics/qa/tables and started putting things into functions. diff --git src/utils/qa/qaGbTracks src/utils/qa/qaGbTracks index 6c46afb..c682c16 100755 --- src/utils/qa/qaGbTracks +++ src/utils/qa/qaGbTracks @@ -1,82 +1,55 @@ #!/usr/bin/env python2.7 import sys -import os -import re import argparse -import subprocess +import logging -from ucscgenomics import qa - -def main(): - - """ Run all the checks, print output""" +from ucscgenomics.qa import qaUtils +from ucscgenomics.qa.tables import factory +from ucscgenomics.qa.tables import reporter +def parseCommandLine(): parser = argparse.ArgumentParser( - prog='qaEncodeTracks2', formatter_class=argparse.RawDescriptionHelpFormatter, - description='A series of checks for QA', - epilog= - """Examples: - -qaEncodeTracks2 hg19 tableList -qaEncodeTracks2 hg19 tableList /path/to/trackDb.ra -qaEncodeTracks2 hg19 tableList ~/kent/src/hg/makeDb/trackDb/human/hg19/wgEncodeSydhTfbs.new.ra - - """ - ) - parser.add_argument('database', help='The database, typically hg19 or mm9') - parser.add_argument('tableList', help='The file containing a list of tables') - parser.add_argument('trackDb', nargs='?', default=0, help='The trackDb file to check') - - if len(sys.argv) == 1: - parser.print_help() - return - - args = parser.parse_args(sys.argv[1:]) - - f = open(args.tableList, "r") - lines = f.readlines() - tables = set() - for i in lines: - tables.add(i.rstrip()) - - output = [] - - output.append("Checking tables for existence of description in tableDescription") - (tableDescOutput, noDescription) = qa.checkTableDescriptions(args.database, tables) - output.extend(tableDescOutput) - - output.append("Checking tables for missing indices") - (tableIndexOut, missingIndex) = qa.checkTableIndex(args.database, tables) - output.extend(tableIndexOut) - - output.append("Checking tables for underscores in the name") - (tableNameOut, badTableNames) = qa.checkTableName(tables) - output.extend(tableNameOut) - - output.append("Checking TrackDb.ra file for short and long label length") - if args.trackDb: - (labelOut, badLabels) = qa.checkLabels(args.trackDb) - output.extend(labelOut) - else: - output.append("Skipped, no trackDb file given") - output.append("") - - output.append("Checking tables for coordinate errors") - (coordsOut, badCoords) = qa.checkTableCoords(args.database, tables) - output.extend(coordsOut) - - output.append("Checking tables for positional errors (sort)") - (posOut, badPos) = qa.positionalTblCheck(args.database, tables) - output.extend(posOut) - - output.append("Counting row per chromosomes per table") - (countChromOut, tableCounts) = qa.countPerChrom(args.database, tables) - output.extend(countChromOut) - - for i in output: - print i - - -if __name__ == "__main__": - main() + description='Runs the New Track Checklist table tests', + epilog=""" +The following tests are run: + genePredCheck + pslCheck + checkTblCoords + positionalTblCheck + runBits.csh + check for the existence of table descriptions + check for shortLabels and longLabels that are too long + check for underscores in table names + check for tables missing an index + (joinerCheck) - not yet implemented + countPerChrom + """) + parser.add_argument('database', help='the database to check') + parser.add_argument('tableList', help='a file listing the tables to check') + parser.add_argument('outFileName', help='name to use to write results files') + parser.add_argument('-v', '--verbose', action='store_true', + help='turn on verbose messages in error log') + return parser.parse_args() + +def getTableListFromFile(): + with open(args.tableList, "r") as f: + raw = f.readlines() + return [name.strip() for name in raw] + +def runTests(reporter, tableList): + reporter.writeTimestamp() + reporter.writeBlankLine() + for table in tableList: + table = factory.tableQaFactory(args.database, table, reporter) + table.validate() + +args = parseCommandLine() +tableList = getTableListFromFile() +qaUtils.checkTablesExist(args.database, tableList) +fh = open(args.outFileName + ".log", "w") +reporter = reporter.Reporter(fh) +runTests(reporter, tableList) + + +fh.close()