def plot_multiple_regions_coverage(samples, out_file, data, region_bed=None, stem_bed=None):
    """
    given a list of bcbio samples and a bed file or BedTool of regions,
    makes a plot of the coverage in the regions for the set of samples

    if given a bed file or BedTool of locations in stem_bed with a label,
    plots lollipops at those locations
    """
    mpl.use('Agg', force=True)
    PAD = 100
    if file_exists(out_file):
        return out_file
    in_bams = [dd.get_align_bam(x) for x in samples]
    samplenames = [dd.get_sample_name(x) for x in samples]
    if isinstance(region_bed, six.string_types):
        region_bed = pybedtools.BedTool(region_bed)
    if isinstance(stem_bed, six.string_types):
        stem_bed = pybedtools.BedTool(stem_bed)
    if stem_bed is not None:  # tabix indexed bedtools eval to false
        stem_bed = stem_bed.tabix()
    plt.clf()
    plt.cla()
    with file_transaction(out_file) as tx_out_file:
        with backend_pdf.PdfPages(tx_out_file) as pdf_out:
            sns.despine()
            for line in region_bed:
                for chrom, start, end in _split_regions(line.chrom, max(line.start - PAD, 0),
                                                        line.end + PAD):
                    df = _combine_regional_coverage(in_bams, samplenames, chrom,
                                                    start, end, os.path.dirname(tx_out_file), data)
                    plot = sns.tsplot(df, time="position", unit="chrom",
                                      value="coverage", condition="sample")
                    if stem_bed is not None:  # tabix indexed bedtools eval to false
                        interval = pybedtools.Interval(chrom, start, end)
                        _add_stems_to_plot(interval, stem_bed, samples, plot)
                    plt.title("{chrom}:{start}-{end}".format(**locals()))
                    pdf_out.savefig(plot.get_figure())
                    plt.close()
    return out_file
def plot_multiple_regions_coverage ( samples , out_file , data , region_bed = None , stem_bed = None ) : mpl . use ( 'Agg' , force = True ) PAD = 100 if file_exists ( out_file ) : return out_file in_bams = [ dd . get_align_bam ( x ) for x in samples ] samplenames = [ dd . get_sample_name ( x ) for x in samples ] if isinstance ( region_bed , six . string_types ) : region_bed = pybedtools . BedTool ( region_bed ) if isinstance ( stem_bed , six . string_types ) : stem_bed = pybedtools . BedTool ( stem_bed ) if stem_bed is not None : stem_bed = stem_bed . tabix ( ) plt . clf ( ) plt . cla ( ) with file_transaction ( out_file ) as tx_out_file : with backend_pdf . PdfPages ( tx_out_file ) as pdf_out : sns . despine ( ) for line in region_bed : for chrom , start , end in _split_regions ( line . chrom , max ( line . start - PAD , 0 ) , line . end + PAD ) : df = _combine_regional_coverage ( in_bams , samplenames , chrom , start , end , os . path . dirname ( tx_out_file ) , data ) plot = sns . tsplot ( df , time = "position" , unit = "chrom" , value = "coverage" , condition = "sample" ) if stem_bed is not None : interval = pybedtools . Interval ( chrom , start , end ) _add_stems_to_plot ( interval , stem_bed , samples , plot ) plt . title ( "{chrom}:{start}-{end}" . format ( ** locals ( ) ) ) pdf_out . savefig ( plot . get_figure ( ) ) plt . close ( ) return out_file
given a list of bcbio samples and a bed file or BedTool of regions,
    makes a plot of the coverage in the regions for the set of samples

    if given a bed file or BedTool of locations in stem_bed with a label,
    plots lollipops at those locations