@files( PARAMS["filename_intervals"], [ "%s.intervals" % x for x in TRACKS_RAW] )
    def createIntervals( infile, outfiles ):
        '''create intervals files from the input csv file.
        '''
        tmpdir = tempfile.mkdtemp()
        reader = csv.reader( open(infile,"rU") )

        # convert to well formatted file for stats
        output_files_info = IOTools.FilePool( output_pattern = "%s.intervals" )
        output_files_bed = IOTools.FilePool( output_pattern = os.path.join( tmpdir, "%s.bed" ) )

        for row in reader:
            # process header
            row = [ re.sub( "\s", "", x) for x in row ]
            row = [ re.sub( "^#", "n", x) for x in row ]

            if row[0] == 'Sample':
                row = [ re.sub( "^#", "n", x) for x in row ]
                row = [ re.sub( "\s", "", x) for x in row ]
                row[1] = "interval_id"
                # delete coordinates
                del row[2:5]
                output_files_info.setHeader( "\t".join(row[1:])+ "\n" )
            else:
                # convert to 0-based open/closed coordinates
                # start
                row[3] = str(int(row[3]) - 1)
                # PeakCenter
                row[7] = str(1 - int(row[7]))
                # add chr
                row[2] = "chr%s" % row[2]

                run_id, cell, condition, replicate = row[0].split("_")
                id = "run%s%s%s" % (cell, condition, replicate)

                # output coordinates
                output_files_bed.write( id, "\t".join( row[2:5] + row[1:2] ) + "\n" )

                # delete coordinates
                del row[2:5]
                output_files_info.write( id, "\t".join( row[1:])+ "\n" )

        output_files_bed.close()
        output_files_info.close()

        if PARAMS["filename_chain"]:
            chain = PARAMS["filename_chain"]
            statement = '''liftOver %(filename)s %(chain)s %(basename)s %(basename)s.unmapped'''

        else:
            statement = '''cp %(filename)s %(basename)s'''

        for filename in output_files_bed.keys():
            basename = os.path.basename( filename )
            P.run( **dict( locals().items() + PARAMS.items() ) )

        shutil.rmtree( tmpdir )

    ############################################################
    ############################################################
    ############################################################
    ##
    ############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/createIntervals/swapped operands of `-`