@transform( (importRegionsOfInterest, importGWAS, importMergedGWAS), suffix(".import"), ".bed")
def exportRegionsOfInterest( infile, outfile ):

    dbhandle = sqlite3.connect( PARAMS["database"] )
    cc = dbhandle.cursor()
        
    outs = open(outfile, "w")
    tablename = outfile[:-len(".bed")]

    tracks = [x[0] for x in cc.execute( "SELECT DISTINCT class FROM %(tablename)s" % locals() ).fetchall()]
    
    for track in tracks:
        
        outs.write( "track name=%s\n" % track )

        statement = locals() % "SELECT contig, max(0,start), end, roi_id FROM %(tablename)s WHERE class = '%(track)s' ORDER by contig, start"
        cc.execute( statement )
        for contig, start, end, roi_id in cc:
            outs.write("%s\t%i\t%i\t%s\n" % (contig, start, end, roi_id) )
    outs.close()

############################################################
############################################################
############################################################
## import reference intervals
############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/exportRegionsOfInterest/swapped operands of `%`