def draw_exon_intron_profile_plots(metaexon_breaks,avg_metaexons,metaintron_breaks,avg_metaintrons,elowers, euppers, ilowers, iuppers, legends=[]):
    
    n_rows = 3  # number of rows per page
    rscript = ''

    # ge the global minimum and global maximum
    ylim = [0, 0]
    temp_metaexons = map(lambda x: filter(lambda y: y, x), avg_metaexons)
    temp_metaexons = filter(lambda x: x,temp_metaexons)
    if temp_metaexons:            
        mins_avg_metaexons = map(min, map(min_row_by_row, temp_metaexons,[True]*len(temp_metaexons)))
        maxs_avg_metaexons = map(max, map(max_row_by_row, temp_metaexons,[True]*len(temp_metaexons)))
    else:
        mins_avg_metaexons = []
        maxs_avg_metaexons = []
    
    temp_metaintrons = map(lambda x: filter(lambda y: y, x), avg_metaintrons)
    temp_metaintrons = filter(lambda x: x,temp_metaintrons)
    if temp_metaintrons:
        mins_avg_metaintrons = map(min, map(min_row_by_row, temp_metaintrons,[True]*len(temp_metaintrons)))
        maxs_avg_metaintrons = map(max, map(max_row_by_row, temp_metaintrons,[True]*len(temp_metaintrons))) 
    else:
        mins_avg_metaintrons = []
        maxs_avg_metaintrons = []
    
    try:
        ylim[0] = min(mins_avg_metaexons + mins_avg_metaintrons)
    except ValueError:
        ylim[0] = 0
        
    try:
        ylim[1] = max(maxs_avg_metaexons + maxs_avg_metaintrons)
    except ValueError:
        ylim[1] = 0
        
    #ylim = [min(map(min, map(min_row_by_row, avg_metaexons,[True]*n_ranges)) + map(min, map(min_row_by_row, avg_metaintrons,[True]*n_ranges))), max(map(max, map(max_row_by_row, avg_metaexons,[True]*n_ranges)) + map(max, map(max_row_by_row, avg_metaintrons,[True]*n_ranges)))]
    ylim = [ylim[0], ylim[1]+0.2*ylim[1]]
    rows = 0
    #for metaexon_break, metaintron_break, ame, ami, elower, eupper, ilower, iupper in itertools.izip(metaexon_breaks, metaintron_breaks, avg_metaexons, avg_metaintrons, elowers, euppers, ilowers, iuppers):
    for metaexon_break, metaintron_break, ame, ami, elower, eupper, ilower, iupper in map(None, metaexon_breaks, metaintron_breaks, avg_metaexons, avg_metaintrons, elowers, euppers, ilowers, iuppers): 
        if rows % n_rows == 0: rscript+=R.par(mar=[4,4,5,3.8],oma=[4,2,4,2],mfrow=[n_rows,2])
        if ame:
            rscript+=draw_multiple_profiles(metaexon_break,ame,main='Average Exon Profiles\n(%d <= length < %d bp)' %(elower, eupper),xlab='Relative Location (%)',ylab='Average Profile',ylim=ylim,cols=[],legends=legends)
        else:
            rscript+=draw_nullbar()
            
        if ami:
            rscript+=draw_multiple_profiles(metaintron_break,ami,main='Average Intron Profiles\n(%d <= length < %d bp)' %(ilower, iupper),xlab='Relative Location (%)',ylab='Average Profile',ylim=ylim,cols=[],legends=legends)
        else:
            rscript+=draw_nullbar()
        rows += 1
        
    return rscript
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/draw_exon_intron_profile_plots/original