@transform( loadCapseqTranscriptTSSDistance, suffix(".transcript.tss.distance.load"), ".transcript.tss.distance.export" )
def exportCapseqTSSTranscriptList( infile, outfile ):
    track = P.snip( os.path.basename( infile ), ".transcript.tss.distance.load" ).replace("-","_").replace(".","_")
    geneset_name = PARAMS["geneset_name"]
    # Connect to DB
    dbhandle = sqlite3.connect( PARAMS["database"] )
    cc = dbhandle.cursor()
    statement = "ATTACH DATABASE '%s' AS annotations; "  % (PARAMS["geneset_database"])
    cc.execute(statement)
    # Extract data from db
    query = '''SELECT distinct gene_id, closest_id FROM %(track)s_%(geneset_name)s_transcript_tss_distance
               WHERE closest_id is not null ''' % locals()
    cc.execute( query )
    E.info( query )
    # Write to file
    outs = open( outfile, "w")
    outs.write("interval_id\ttranscript_id\n")
    for result in cc:
        pre = ""
        interval_id,transcripts = result
        transcript_list = transcripts.split(",")
        for t in transcript_list:
            outs.write("%s\t%s\n" % (interval_id, str(t)) )
    cc.close()
    outs.close()

############################################################
Export list of transcripts closest to CAPseq intervals
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/exportCapseqTSSTranscriptList