@files( PARAMS["filename_repeats"], TARGET_REPEATS)
def buildRepeats( infile, outfile ):
    '''import ucsc repeat tracks.
    '''

    instream = gzip.open( infile )
    tmpfile = tempfile.NamedTemporaryFile(delete=False)
    tmpfilename = tmpfile.name

    gff = GFF.Entry()
    gff.feature = "exon"
    gff.source = "repeat"
    
    for line in instream:
        if line.startswith("#bin"): continue
        (bin,swScore,milliDiv,milliDel,milliIns,\
         genoName,genoStart,genoEnd,genoLeft,\
         strand,repName,repClass,repFamily,repStart,repEnd,repLeft,id) =\
         line[:-1].split("\t")
         
        if repClass not in REPEATS: continue

        gff.strand = strand
        gff.contig = genoName
        gff.start = int(genoStart)-1
        gff.end = int(genoEnd)
        gff.addAttribute( "name", repName )
        gff.addAttribute( "class", repClass )
        gff.addAttribute( "family", repFamily )
        
        tmpfile.write ( str(gff) + "\n" )
         
    tmpfile.close()

    E.info( "created temporary file" )
    statement = """sort -k1,1 -k4,4n < %(tmpfilename)s |\
	python %(scriptsdir)s/gff2gff.py --merge-features=0,10,0,0 --log=%(outfile)s.log \
	> %(outfile)s"""

    P.run( **dict( locals().items() + PARAMS.items() ) )
    
    os.unlink( tmpfile.name )
        
############################################################
############################################################
############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/buildRepeats/original