@transform( "*.intervals", suffix(".intervals"), "_intervals.import" )
    def importIntervals( infile, outfile ):

        ## add the bed intervals back to table
        track = infile[:-len(".intervals")]

        tmpfile = tempfile.NamedTemporaryFile(delete=False)
        tmpfilename = tmpfile.name
        map_id2coords = {}
        for line in open( track + ".bed", "r" ):
            contig, start, end, id = line[:-1].split("\t")[:4]
            map_id2coords[id] = (contig, start, end )

        for line in open( infile ):
            if line.startswith( "interval_id"):
                tmpfile.write( "%s\t%s\t%s\t%s\n" % ((line[:-1],"contig","start","end") ) )
            else:
                id = line[:-1].split( "\t")[0]
                try:
                    tmpfile.write( "%s\t%s\t%s\t%s\n" % ((line[:-1],) +  map_id2coords[id]))
                except KeyError:
                    P.warn( "%s -> interval %s - omitted due to mapping problems" % (infile, id) )

        tmpfile.close()

        statement = '''
       python %(scriptsdir)s/csv2db.py %(csv2db_options)s \
                  --index=interval_id \
                  --table=%(track)s_intervals \
        < %(tmpfilename)s > %(outfile)s
        '''

        P.run()

        os.unlink( tmpfile.name )

    # @transform( importIntervals, suffix("_intervals.import"), ".bed" )
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/importIntervals/original