def exportIntervalsAsBed( infile, outfile ):

    dbhandle = sqlite3.connect( PARAMS["database"] )

    if infile.endswith("_macs.import"):
        track = infile[:-len("_macs.import")]
    else:
        track = infile[:-len("_intervals.import")]
        
    if track.startswith("control"): return

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

    outs = open( outfile, "w")

    for result in cc:
        contig, start, end, interval_id,peakval = result
        peakval = int(min(peakval,1000))
        outs.write( "%s\t%i\t%i\t%s\t%i\n" % (contig, start, end, str(interval_id), peakval) )

    cc.close()
    outs.close()

############################################################
############################################################
############################################################
Context manager to create and clean up a temporary directory.
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD_intervals.py/exportIntervalsAsBed--crossover with--dataset/ETHPy150Open enthought/traits/traits/etsconfig/tests/test_etsconfig.py/temporary_directory