5588e67ae646721ca185a79f68afac19ea5fa20c
rhead
  Tue Apr 10 15:27:55 2012 -0700
Added getTrackType(), which uses tdbQuery to determine the track type for a table, if there is one.
diff --git python/lib/ucscgenomics/qa.py python/lib/ucscgenomics/qa.py
index f0be336..c0d203c 100644
--- python/lib/ucscgenomics/qa.py
+++ python/lib/ucscgenomics/qa.py
@@ -25,30 +25,47 @@
     """ Remove tables that aren't pointers to Gbdb files."""
     sep = "','"
     tablestr = sep.join(tableset)
     tablestr = "'" + tablestr + "'"
     hgsqlOut = callHgsql(database, "select table_name from information_schema.columns where table_name in ("
                                    + tablestr + ") and column_name = 'fileName'")
     gbdbtableset = set(hgsqlOut.split())
     return gbdbtableset
 
 def sorted_nicely(l):
     """ Sort the given iterable in the way that humans expect."""
     convert = lambda text: int(text) if text.isdigit() else text
     alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
     return sorted(l, key = alphanum_key)
 
+def getTrackType(database, table):
+    """ Use tdbQuery to get the track type associated with this table, if any.
+    Returns None on split tables."""
+    cmd = ["tdbQuery", "select type from " + database + " where track='" + table +
+           "' or table='" + table + "'"]
+    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    cmdout, cmderr = p.communicate()
+    if p.returncode != 0:
+        # keep command arguments nicely quoted
+        cmdstr = " ".join([pipes.quote(arg) for arg in cmd])
+        raise Exception("Error from: " + cmdstr + ": " + cmderr)
+    if cmdout:
+        tableType = cmdout.split()[1]
+    else:
+        tableType = None
+    return tableType
+
 def countPerChrom(database, tables):
     """ Count the amount of rows per chromosome."""
     notgbdbtablelist = tables - getGbdbTables(database, tables)
     tablecounts = dict()
     output = []
     globalseen = set()
     localseen = dict()
 
     hgsqlOut = callHgsql(database, "select chrom from chromInfo")
     chrlist = set(hgsqlOut.split())
 
     notPositionalTable = set()
     if not notgbdbtablelist:
         output.append("No tables to count chroms")
         output.append("")