@files( PARAMS["filename_mappability"], PARAMS["annotator_mappability"] ) 
def exportUCSCMappabilityTrackToBed( infile, outfile ):
    '''convert wiggle track with mappability information to a bed-formatted file
    with only the mappable regions in the genome.'''
    
    infile = gzip.open( infile, "r" )

    outf = open( outfile, "w" )
    
    for line in infile:
        if line.startswith("fixedStep" ):
            contig, start, step = re.match( "fixedStep chrom=(\S+) start=(\d+) step=(\d+)", line ).groups()
            start, step = int(start)-1, int(step)
            end = start + step
            last_val = None
        else:
            val = int(line)
            if last_val != val:
                if last_val == 1:
                    outf.write( "\t".join( (contig, str(start), str(end ) ) ) + "\n" )
                start = end
                end = start + step
            else:
                end += step
            last_val = val
    outf.close()
    
############################################################
############################################################
############################################################
## export UCSC encode tracks as bed
############################################################
dataset/ETHPy150Open CGATOxford/cgat/obsolete/pipeline_vitaminD.py/exportUCSCMappabilityTrackToBed/original