@transform( [ "%s.bed" % x for x in TRACKS_MOTIFS ],
            suffix(".bed"),
            ".fasta" )
def exportMotifSequences( infile, outfile ):
    '''export sequences for all intervals.
    '''
    
    track = infile[:-len(".bed")]
    dbhandle = sqlite3.connect( PARAMS["database"] )

    fasta = IndexedFasta.IndexedFasta( PARAMS["genome"] )

    cc = dbhandle.cursor()
    statement = "SELECT interval_id, contig, start, end FROM %s_intervals" % track
    cc.execute( statement )

    outs = open( outfile, "w")

    for result in cc:
        interval, contig, start, end = result
        id = "%s_%s %s:%i..%i" % (track, str(interval), contig, start, end)
        
        seq = fasta.getSequence( contig, "+", start, end)
        outs.write( ">%s\n%s\n" % (id, seq))

    cc.close()
    outs.close()

############################################################
############################################################
############################################################
# (importCombinedIntervals, exportIntervalsAsBed ),
# TODO: fix, causes a problem due to exportIntervalsAsBed
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/exportMotifSequences/original