@transform( loadCapseqComposition, suffix(".replicated.capseq.composition.load"), ".replicated.cpg.export" )
def exportCapseqCpGObsExp( infile, outfile ):
    # Connect to DB
    dbhandle = sqlite3.connect( PARAMS["database"] )
    track = P.snip( os.path.basename( infile ), ".replicated.capseq.composition.load" ).replace("-","_").replace(".","_")
    # Extract data from db
    cc = dbhandle.cursor()
    query = '''SELECT c.gene_id, c.CpG_ObsExp, cc.CpG_ObsExp, c3.CpG_ObsExp, c5.CpG_ObsExp 
               FROM %(track)s_replicated_capseq_composition c
               left join %(track)s_replicated_composition_control cc on c.gene_id=cc.gene_id
               left join %(track)s_replicated_composition_flanking3 c3 on c.gene_id=c3.gene_id
               left join %(track)s_replicated_composition_flanking5 c5 on c.gene_id=c5.gene_id;''' % locals()
    cc.execute( query )
    # Write to file
    outs = open( outfile, "w")
    for result in cc:
        pre = ""
        for r in result:
            outs.write("%s%s" % (pre, str(r)) )
            pre = "\t"
        outs.write("\n")
    cc.close()
    outs.close()

############################################################
Enable the use of automatic spinners as context managers.
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_proj007.py/exportCapseqCpGObsExp--crossover with--dataset/ETHPy150Open xolox/python-humanfriendly/humanfriendly/__init__.py/AutomaticSpinner.__exit__