def toTSV(dbhandle, outfile, statement, remove_none=True):
    cc = dbhandle.cursor()
    cc.execute(statement)
    outfile.write("\t".join([x[0] for x in cc.description]) + "\n")

    def _str(x):
        if x is None:
            return ""
        else:
            return str(x)

    if remove_none:
        f = _str
    else:
        f = str

    outfile.write("\n".join(
        ["\t".join(map(f, x)) for x in cc]))
execute statement and save as tsv file
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Database.py/toTSV