def export():
    with pp(r"E:\Instagram\new.pdf") as new:
        g = f.Date_reported[10169:10315]
        h = f.New_cases[10169:10315]
        mt.plot(h, g, color="red", marker="o")
        mt.grid(True)
        mt.title("COVID-19 Daily Updates in INDIA")
        mt.ylabel("Date")
        mt.xlabel("No. of cases")
        new.savefig()
        mt.close()
Beispiel #2
0
    def write(self, subdirectory, filename):

        pl.legend(fontsize="x-small", ncol=self.legend_columns,
                  mode="expand", title=self.legend_title)
        if not self.pdf:
            pdf_path = os.path.join(self.get_base_path(), "all.pdf")
            self.pdf = pp(pdf_path)
            print("wrote: {}".format(pdf_path))
        self.pdf.savefig(transparent=True)
        figure_path = self.get_full_path(subdirectory, filename)
        pl.savefig(figure_path)
        print("wrote: {}".format(figure_path))
        pl.close('all')
Beispiel #3
0
def plot_throughput(args):

    df = pd.read_csv(args.csvfile)

    plot_groups = list(df.groupby(by=['testcase', 'symbol_size', 'type']))

    if args.outfile:
        pdf = pp(args.outfile)

    # Group the plots
    for (test, symbol_size, type), df in plot_groups:

        def density_to_string(density):
            if not np.isnan(density):
                return "density {}".format(density)
            else:
                return ""

        # Combine the testcase and benchmark columns into one (used for labels)
        if not 'density' in df:
            df['test'] = df['testcase'].map(str) + '.' + df['benchmark']

            df = df.drop(['testcase', 'benchmark'], axis=1)
        else:
            df['test'] = df['testcase'].map(str) + '.' + df['benchmark'] +\
                         ' ' + df['density'].map(density_to_string)
            df = df.drop(['testcase', 'benchmark', 'density'], axis=1)

        group = df.groupby(by=['test', 'symbols'])

        def compute_throughput(group):
            s = group['throughput']
            s = pd.Series([s.mean(), s.std()], ['mean', 'std'])
            return s

        df = group.apply(compute_throughput)
        df = df.unstack(level=0)

        df['mean'].plot(title="Throughput {} {} p={}B".format(
            test, type, symbol_size),
                        kind='bar')

        if args.outfile:
            pdf.savefig(transparent=True)

    if args.outfile:
        pdf.close()
    else:
        plt.show()
def plot_metric(df,metric,varying_parameter,fixed_parameters,cases,density):

    df_group = df.groupby(by=fixed_parameters)
    all_figures_filename = "all_" + density + "_" + metric + "_vs_" + \
                           varying_parameter + ".pdf"
    pdf = pp(all_figures_filename)
    for keys, group in df_group:

        p = group.pivot_table(metric,cols=cases,rows=varying_parameter).plot(
            kind=pltkind[(metric,varying_parameter)])

        plt.title(get_plot_title(fixed_parameters,keys),fontsize=font_size)
        set_axis_properties(p,metric,varying_parameter,group)
        set_plot_legend(p,metric,varying_parameter)
        filename = get_filename(metric,varying_parameter,
                                fixed_parameters,keys,density)
        plt.savefig(filename,bbox_inches='tight')
        pdf.savefig(bbox_inches='tight')
        plt.close()

    pdf.close()
Beispiel #5
0
def main():

    usage = 'usage: %prog [options] '
    parser = OptionParser(usage)
    parser.add_option('-r',
                      dest='runName',
                      default='spt6',
                      type=str,
                      help='Name of the run')
    parser.add_option(
        '-s',
        dest='save_path',
        type=str,
        default='/Users/umut/Projects/intragenicTranscription/results/')
    parser.add_option(
        '-a',
        dest='annotation',
        type=str,
        default=
        '/Users/umut/Projects/intragenicTranscription/data/annotation/ScerTSSannot.csv'
    )
    parser.add_option("-o", action="store_true", dest="overwrite")
    (options, args) = parser.parse_args()

    # options.save_path = options.save_path+options.runName+'/peaks_motifs/'
    options.save_path = \
        options.save_path + options.runName + '/peaks_motifs_p_thresh_0.05/'

    gdb = genome.db.GenomeDB(
        path='/Users/umut/Projects/genome/data/share/genome_db',
        assembly='sacCer3')

    # open data 'tracks' for DNase and MNase
    gerp = gdb.open_track('phyloP')

    pl.ioff()

    df = pd.read_csv(options.save_path + options.runName +
                     '_intragenic_peaks.csv',
                     index_col=0)

    consScoreSE = np.zeros((df[df['orientation'] == 'sense'].shape[0], 1000))

    print('getting conservation score for sense')
    for i in tq(range(len(df[df['orientation'] == 'sense']))):
        chname = df[df['orientation'] == 'sense']['chr'].iloc[i]
        st = df[df['orientation'] == 'sense']['peak_position'].iloc[i]
        strand = df[df['orientation'] == 'sense']['strand'].iloc[i]

        if strand == '+':
            consScoreSE[i, :] = gerp.get_nparray(chname, st - 500 + 1,
                                                 st + 500)
        else:
            consScoreSE[i, :] = np.flipud(
                gerp.get_nparray(chname, st - 500 + 1, st + 500))

    consScoreAS = np.zeros(
        (df[df['orientation'] == 'antisense'].shape[0], 1000))
    print('getting conservation score for antisense')

    for i in tq(range(len(df[df['orientation'] == 'antisense']))):
        chname = df[df['orientation'] == 'antisense']['chr'].iloc[i]
        st = df[df['orientation'] == 'antisense']['peak_position'].iloc[i]
        strand = df[df['orientation'] == 'antisense']['strand'].iloc[i]

        if strand == '-':
            consScoreAS[i, :] = gerp.get_nparray(chname, st - 500 + 1,
                                                 st + 500)
        else:
            consScoreAS[i, :] = np.flipud(
                gerp.get_nparray(chname, st - 500 + 1, st + 500))

    print('plotting...')
    pfile = pp(options.save_path + 'Figures/intragenic_conservation_sense.pdf')
    xran = np.arange(-500, 500)
    tmth = 0.1

    for wn in [3, 50, 75]:
        fig = pl.figure()
        pl.plot(xran,
                tm(np.apply_along_axis(sm.smooth, 1, consScoreSE,
                                       wn)[:, (wn - 1):-(wn - 1)],
                   tmth,
                   axis=0),
                'r',
                label='Sense')
        pl.xlabel('Position from intragenic TSS (bp)')
        pl.ylabel('Average GERP score (a.u.)')
        pl.title('Smoothing window: ' + str(wn) + 'bp')
        pl.legend(loc='center left', bbox_to_anchor=(1, 0.5))
        pfile.savefig()
        pl.close(fig)

    pfile.close()

    pfile = pp(options.save_path +
               'Figures/intragenic_conservation_antisense.pdf')
    xran = np.arange(-500, 500)
    tmth = 0.1

    for wn in [3, 50, 75]:
        fig = pl.figure()
        pl.plot(xran,
                tm(np.apply_along_axis(sm.smooth, 1, consScoreAS,
                                       wn)[:, (wn - 1):-(wn - 1)],
                   tmth,
                   axis=0),
                'r',
                label='Antisense')
        pl.xlabel('Position from intragenic TSS (bp)')
        pl.ylabel('Average GERP score (a.u.)')
        pl.title('Smoothing window: ' + str(wn) + 'bp')
        pl.legend(loc='center left', bbox_to_anchor=(1, 0.5))
        pfile.savefig()
        pl.close(fig)

    pfile.close()

    np.savetxt(options.save_path + 'ConservationScoreGERP_sense.csv',
               consScoreSE)
    np.savetxt(options.save_path + 'ConservationScoreGERP_antisense.csv',
               consScoreAS)

    gerp.close()