def draw_profile_plot(breaks,avg_upstream,avg_downstream,metagene_breaks,avg_metagene,metacatexon_breaks,avg_metacatexon,metacatintron_breaks,avg_metacatintron,metagene_breaks_lim=[-1000,1000]):
    
    #comment
    R.comment('')
    R.comment('Draw wig profiles')
    R.comment('')
    
    rscript=R.par(mar=[4,4,5,3.8],oma=[4,2,4,2])
    mat=[[1,2],[3,3],[4,5]]
    rscript+=R.layout(mat,widths=[1,1],heights=[1,1,1])
    
    # for metagene plot
    step = breaks[1]-breaks[0]
    start_up,end_up=where2(max(metagene_breaks_lim[0],breaks[0]), 0, breaks, step)
    start_down,end_down=where2(step, min(metagene_breaks_lim[1]+1,breaks[-1]+1), breaks, step)
    
    # KEEP THIS IN MIND: the first and last points of metagene are not used in metagene plots
    comb_breaks=breaks[start_up:end_up] + metagene_breaks[1:-1] + map(lambda b: b + metagene_breaks[-1], breaks[start_down:end_down])
    comb_metagene=avg_upstream[start_up:end_up] + avg_metagene[1:-1] + avg_downstream[start_down:end_down]  
    
    # draw
    #ylim=[min(avg_upstream)-abs(min(avg_upstream))*0.1,max(avg_upstream)+abs(max(avg_upstream))*0.1]
    rscript+=draw_single_profile(breaks,avg_upstream,main='Average Profile near TSS',xlab='Relative Distance to TSS (bp)',ylab='Average Profile',v=0)#,ylim=ylim)
    
    #ylim=[min(avg_downstream)-abs(min(avg_downstream))*0.1,max(avg_downstream)+abs(max(avg_downstream))*0.1]
    rscript+=draw_single_profile(breaks,avg_downstream,main='Average Profile near TTS',xlab='Relative Distance to TTS (bp)',ylab='Average Profile',v=0)#,ylim=ylim)
    
    #ylim=[min(comb_metagene)-abs(min(comb_metagene))*0.1,max(comb_metagene)+abs(max(comb_metagene))*0.1]
    rscript+=draw_single_profile(comb_breaks,comb_metagene,main='Average Gene Profile',xlab='Upstream (bp), %d bp of Meta-gene, Downstream (bp)' %int(metagene_breaks[-1]),ylab='Average Profile')#,ylim=ylim)
    rscript+=R.abline(v=metagene_breaks[0],lty=2,col=['black'])
    rscript+=R.abline(v=metagene_breaks[-1],lty=2,col=['black'])
    
    ylim=[min(min_w_nan(avg_metacatexon),min_w_nan(avg_metacatintron)),max(max_w_nan(avg_metacatexon),max_w_nan(avg_metacatintron))]
    rscript+=draw_single_profile(metacatexon_breaks,avg_metacatexon,main='Average Concatenated Exon Profile',xlab='Relative Location (%)',ylab='Average Profile',ylim=ylim)
    rscript+=draw_single_profile(metacatintron_breaks,avg_metacatintron,main='Average Concatenated Intron Profile',xlab='Relative Location (%)',ylab='Average Profile',ylim=ylim)
    
    return rscript
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/draw_profile_plot/original