Esempio n. 1
0
 def plot_pddf(self, sasbdb: str, df: pd.DataFrame):
     '''
     p(r) plot, deprecated function 
     '''
     output_file(self.ID + sasbdb + "pddf.html", mode="inline")
     source = ColumnDataSource(df)
     p = figure(plot_height=500,
                plot_width=500,
                title="Pair distance distribution function (" + sasbdb +
                ")")
     p.circle(x='R',
              y='P',
              source=source,
              color='blue',
              fill_alpha=0.3,
              size=5)
     p.multi_line('err_x',
                  'err_y',
                  source=source,
                  color='gray',
                  line_width=1.5)
     p.xaxis.major_label_text_font_size = "14pt"
     p.yaxis.major_label_text_font_size = "14pt"
     p.title.text_font_size = '12pt'
     p.title.align = "center"
     p.title.vertical_align = 'top'
     p.xaxis.axis_label = "r [nm]"
     p.xaxis.axis_label_text_font_size = '14pt'
     p.yaxis.axis_label = 'P(r)'
     p.yaxis.axis_label_text_font_size = '14pt'
     p.output_backend = "svg"
     save(p, filename=self.filename + '/' + self.ID + sasbdb + "pddf.html")
     export_svgs(p,
                 filename=self.filename + '/' + self.ID + sasbdb +
                 "pddf.svg")
Esempio n. 2
0
 def plot_porod_debye(self, sasbdb: str, df: pd.DataFrame):
     '''
     porod debye plot for flexibility 
     '''
     output_file(self.ID + sasbdb + "porod.html", mode="inline")
     source = ColumnDataSource(df)
     p = figure(plot_height=500,
                plot_width=500,
                title="Porod-Debye plot (" + sasbdb + ")")
     p.circle(x='Px',
              y='Py',
              source=source,
              color='blue',
              fill_alpha=0.3,
              size=5)
     p.xaxis.major_label_text_font_size = "14pt"
     p.yaxis.major_label_text_font_size = "14pt"
     p.title.text_font_size = '12pt'
     p.title.align = "center"
     p.title.vertical_align = 'top'
     p.xaxis.axis_label = 'q \u2074'
     p.xaxis.axis_label_text_font_size = '14pt'
     p.yaxis.axis_label = 'q\u2074 I(q)'
     p.yaxis.axis_label_text_font_size = '14pt'
     p.output_backend = "svg"
     save(p, filename=self.filename + '/' + self.ID + sasbdb + "porod.html")
     export_svgs(p,
                 filename=self.filename + '/' + self.ID + sasbdb +
                 "porod.svg")
Esempio n. 3
0
 def plot_kratky(self, sasbdb: str, df: pd.DataFrame):
     '''
     plot dimensionless kratky 
     '''
     output_file(self.ID + sasbdb + "Kratky.html", mode="inline")
     source = ColumnDataSource(df)
     p = figure(plot_height=500,
                plot_width=500,
                title="Dimensionless Kratky plot (" + sasbdb + ")")
     p.circle(x='Kx',
              y='Ky',
              source=source,
              color='blue',
              fill_alpha=0.3,
              size=5)
     #vline = Span(location=0.1732, dimension='height', line_color='red', line_width=3)
     #hline = Span(location=0.1104, dimension='width', line_color='green', line_width=3)
     #p.renderers.extend([vline, hline])
     p.xaxis.major_label_text_font_size = "14pt"
     p.yaxis.major_label_text_font_size = "14pt"
     p.title.text_font_size = '12pt'
     p.title.align = "center"
     p.title.vertical_align = 'top'
     p.xaxis.axis_label = 'qRg'
     p.xaxis.axis_label_text_font_size = '14pt'
     p.yaxis.axis_label = 'q\u00B2 Rg\u00B2 I(q)/I(0)'
     p.yaxis.axis_label_text_font_size = '14pt'
     save(p,
          filename=self.filename + '/' + self.ID + sasbdb + "Kratky.html")
     p.output_backend = "svg"
     export_svgs(p,
                 filename=self.filename + '/' + self.ID + sasbdb +
                 "Kratky.svg")
Esempio n. 4
0
 def plot_kratky_dep(self, sasbdb: str, df: pd.DataFrame):
     '''
     plot kratky plot, deprecated function
     '''
     output_file(self.ID + sasbdb + "Kratky_dep.html", mode="inline")
     source = ColumnDataSource(df)
     p = figure(plot_height=500,
                plot_width=500,
                title="Kratky plot (" + sasbdb + ")")
     p.circle(x='Q',
              y='Ky',
              source=source,
              color='blue',
              fill_alpha=0.3,
              size=5)
     p.xaxis.major_label_text_font_size = "14pt"
     p.yaxis.major_label_text_font_size = "14pt"
     p.title.text_font_size = '12pt'
     p.title.align = "center"
     p.title.vertical_align = 'top'
     p.xaxis.axis_label = 'Log q [nm\u207B\u00B9]'
     p.xaxis.axis_label_text_font_size = '14pt'
     p.yaxis.axis_label = 'q\u00B2 I(q)'
     p.yaxis.axis_label_text_font_size = '14pt'
     save(p,
          filename=self.filename + '/' + self.ID + sasbdb +
          "Kratky_dep.html")
     p.output_backend = "svg"
     export_svgs(p,
                 filename=self.filename + '/' + self.ID + sasbdb +
                 "Kratky_dep.svg")
def plot_bioact_dist_quad(fasta_fl_path, interval, dataset_name):
    import bokeh
    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
    from bokeh.io import export_svgs
    from bokeh.io import export_png
    from bokeh.models import HoverTool
    from bokeh.models import SingleIntervalTicker, LinearAxis

    df_bioactivity = pd.read_csv("{}/comp_targ_affinity.csv".format(comp_tar_training_dataset_path), header=None)
    sorted_bioactivities_list = sorted(df_bioactivity.iloc[:,2].values)

    tools = "pan,wheel_zoom,box_zoom,reset"
    p = figure(tools=tools, plot_width=1400, plot_height=700,
               title="Distribution of Bioactivity Values - {} Dataset".format(dataset_name),
               # x_axis_label='Bioacitivity Value (-log(Ki/Kd))',
               y_axis_label='Number of Bioactivities')

    p.title.text_font_size = '20pt'
    p.title.align = "center"

    # print((sorted_seq_len_list))
    arr_hist, edges = np.histogram(sorted_bioactivities_list,
                                   bins=list(np.arange(5, 12.0, interval)),
                                   range=[5, 12.0])

    delays = pd.DataFrame({'arr_length': arr_hist,
                           'left': edges[:-1],
                           'right': edges[1:]})
    delays['f_interval'] = ['%d - %d' % (left, right) for left, right in zip(delays['left'], delays['right'])]
    delays['f_count'] = ['%d' % (count) for count in delays['arr_length']]

    src = ColumnDataSource(delays)
    print(src.data.keys())
    p.quad(bottom=0, left="left", right="right", top="arr_length",  source=src,
           fill_color='red', line_color='black')

    hover = HoverTool(tooltips=[('Bioactivity Value Range', '@f_interval'), ('Count', '@f_count')])
    p.add_tools(hover)

    p.xgrid.grid_line_color = None
    # p.x_range.start = 0
    p.y_range.start = 0
    ticker = SingleIntervalTicker(interval=interval, num_minor_ticks=5)
    p.xaxis.ticker = ticker
    #xaxis = LinearAxis(ticker=ticker)
    #p.xaxis
    p.xaxis.axis_label = 'Bioacitivity Value (-log(Ki/Kd))'
    p.xaxis.axis_label_text_font_size = "20pt"
    p.xaxis.major_label_text_font_size = "10pt"
    p.yaxis.axis_label = 'Number of Bioactivities'
    p.yaxis.axis_label_text_font_size = "20pt"
    p.yaxis.major_label_text_font_size = "15pt"

    show(p)

    p.output_backend = "svg"
    export_svgs(p, filename="../figures/{}_{}_bioact_val_dist.svg".format(dataset_name, interval))
    export_png(p, filename="../figures/{}_{}_bioact_val_dist.png".format(dataset_name, interval))
Esempio n. 6
0
def detailsMonthperSector(client, typePalette, startMonth=201910):
    pp = pprint.PrettyPrinter(indent=4)

    measurements = {
        'web': query_detail_web_Month_Sector,
        'mail': query_detail_mail_Month_Sector
    }

    for sector in typePalette.keys():
        for i, (measurement, query) in enumerate(measurements.items()):
            if measurement in measurements_db:
                print('Detailed {0} scores for {1} ({2})'.format(
                    measurement, sector, Nr2M(startMonth)))
                df = query_to_dataframe(client,
                                        query.format(startMonth,
                                                     sector), measurement)
                df.sort_values(by=['score', 'domain'],
                               ascending=False,
                               inplace=True)
                df.reset_index(inplace=True, drop=True)
                p = returnHeatmap(df,
                                  title='Details {0} ({1}, {2})'.format(
                                      measurement, sector, Nr2M(startMonth)))
                p.output_backend = "svg"
                export_svgs(p,
                            filename='Details-{0}-{1}.svg'.format(
                                sector, measurement))
                export_png(p,
                           filename='Details-{0}-{1}.png'.format(
                               sector, measurement))
def export_svg(plot, fname):
    ''' This doesn't work. It would be very useful. '''
    ''' export holoview object to filename fname '''
    from bokeh.io import export_svgs
    p = hv.render(plot, backend='bokeh')
    p.output_backend = "svg"
    export_svgs(p, filename=fname)
Esempio n. 8
0
def scoreLastQ_X(client, startQ=20183, groupby='type', palette=paletteHeatmap):
    pp = pprint.PrettyPrinter(indent=4)

    dfW = pd.DataFrame()
    dfM = pd.DataFrame()

    print('Scores of {0} for all sectors (by {1})'.format(
        Nr2Q(startQ), groupby))
    # Take the quarter for both web and mail
    if 'web' in measurements_db:
        dfW = query_to_dataframe(client,
                                 query_web_lastQ_X.format(startQ, groupby),
                                 'web',
                                 doPrint=False)
    if 'mail' in measurements_db:
        dfM = query_to_dataframe(client,
                                 query_mail_lastQ_X.format(startQ, groupby),
                                 'mail',
                                 doPrint=False)

    # Now combine the two dataframes
    # Drop 'type' column first on Mail dataframe
    if 'web' in measurements_db:
        if groupby in dfM.columns:
            dfM.drop(groupby, axis=1, inplace=True)
    df = pd.concat([dfW, dfM], axis=1)

    p = returnBarGraph(df,
                       title='Resultaten O&O afhankelijk van {0} ({1})'.format(
                           groupby, Nr2Q(startQ)),
                       palette=palette)
    p.output_backend = "svg"
    export_svgs(p, filename="Scores-overall-per-{}.svg".format(groupby))
    export_png(p, filename="Scores-overall-per-{}.png".format(groupby))
    return
Esempio n. 9
0
    def is_phantomjs_installed(self):
        if self.phantomjs_installed is not None:
            return self.phantomjs_installed

        # prepare some data
        x = [1, 2, 3, 4, 5]
        y = [6, 7, 2, 4, 5]

        # output to static HTML file
        # output_file("lines.html")

        # create a new plot with a title and axis labels
        p = figure(title="simple line example",
                   x_axis_label='x',
                   y_axis_label='y')

        # add a line renderer with legend and line thickness
        p.line(x, y, legend="Temp.", line_width=2)

        p.output_backend = "svg"
        try:
            test_file_name = "fivepseq.phantom.test.svg"
            export_svgs(p, filename=test_file_name)
            self.phantomjs_installed = True
            os.remove(test_file_name)
        except:
            self.phantomjs_installed = False
            # TODO in the future fivepseq should attempt to install phantomjs from the very beginning
            logging.getLogger(config.FIVEPSEQ_PLOT_LOGGER).warning(
                "It seems like phantomjs is not installed no your system. "
                "Files may not be exported in svg and png formats, while html will still be available for viewing."
                "To install phantomjs, run 'conda install phantomjs selenium pillow'"
            )
        return self.phantomjs_installed
Esempio n. 10
0
def dateVsAppSize(csv_data):
    # format data string
    csv_data['Original Release Date'] = pd.to_datetime(
        csv_data['Original Release Date'], format='%d/%m/%Y')

    # just get column of Original Release Date
    date_size = pd.DataFrame({'size': csv_data['Size']})
    date_size = date_size.set_index(csv_data['Original Release Date'])
    date_size = date_size.sort_values(by=['Original Release Date'])
    date_size.head()

    # compute monthly number for each app
    monthly_size = date_size.resample('M').mean()
    tmp = date_size.resample('M')
    monthly_size['min'] = tmp.min()
    monthly_size['max'] = tmp.max()
    monthly_size.head()

    p = figure(x_axis_type='datetime',
               plot_height=250,
               plot_width=750,
               title='Date vs App Size (Monthly)')
    p.line(y='size',
           x='Original Release Date',
           source=monthly_size,
           line_width=2,
           line_color='Green')
    p.output_backend = 'svg'
    export_svgs(p, filename="dataVsAppSize.svg")
    return 'success'
Esempio n. 11
0
def scoreLastQs(client, startQ=20183, endQ=20193):
    pp = pprint.PrettyPrinter(indent=4)

    dfW = pd.DataFrame()
    dfM = pd.DataFrame()
    print('Scores {0} - {1} for all types'.format(Nr2Q(startQ), Nr2Q(endQ)))
    # Take the last X quarters (the one specified and later) for both web and mail (if present)

    if 'web' in measurements_db:
        dfW = query_to_dataframe(client,
                                 query_web_lastQs.format(startQ, endQ),
                                 'web',
                                 doPrint=False)
    if 'mail' in measurements_db:
        dfM = query_to_dataframe(client,
                                 query_mail_lastQs.format(startQ, endQ),
                                 'mail',
                                 doPrint=False)

    # Now combine the two dataframes
    # Drop 'quarter' column first on Mail dataframe
    if 'web' in measurements_db:
        if 'quarter' in dfM.columns:
            dfM.drop('quarter', axis=1, inplace=True)
    df = pd.concat([dfW, dfM], axis=1)

    p = returnBarGraph(df,
                       title='Results overall ({0}-{1})'.format(
                           Nr2Q(startQ), Nr2Q(endQ)),
                       palette=paletteBR)
    p.output_backend = "svg"
    export_svgs(p, filename="Scores-overall.svg")
    export_png(p, filename="Scores-overall.png")
    return
Esempio n. 12
0
def plot_predicted_vs_real_figures(method_name, dataset_name):
    from bokeh.plotting import figure, show, output_file
    import numpy as np
    from bokeh.io import export_svgs
    from bokeh.io import export_png
    method_name_corrected = ""
    method_name_corrected = "MDeePred" if method_name=="mbapred" else method_name_corrected
    method_name_corrected = "DeepDTA" if method_name == "deepdta" else method_name_corrected
    method_name_corrected = "SimBoost" if method_name == "simboost" else method_name_corrected
    method_name_corrected = "CGKronRLS" if method_name == "simboost" else method_name_corrected

    df = pd.read_csv("../result_files/{}_predictions/{}/{}_test_label_predicted_fold_1.tsv".format(method_name, dataset_name, method_name), sep="\t")
    # print(df)
    p = figure(plot_width=1400, plot_height=1400, title="{} - {}".format(method_name_corrected, dataset_name))
    p.circle(df["Label"], df["Pred"], size=20, color="navy", alpha=0.5)
    p.line(list(np.arange(2.0,11.0, 0.5)),list(np.arange(2.0,11.0, 0.5)), line_color='red', line_width=5, line_dash="dashed")

    p.xaxis.axis_label = 'Measured Bioactivity Value (pKd)'
    p.xaxis.axis_label_text_font_size = "40pt"
    p.xaxis.major_label_text_font_size = "40pt"
    p.yaxis.axis_label = 'Predicted Bioactivity Value (pKd)'
    p.yaxis.axis_label_text_font_size = "40pt"
    p.yaxis.major_label_text_font_size = "40pt"
    p.title.text_font_size = '40pt'
    p.title.align = "center"
    show(p)
    p.output_backend = "svg"
    export_svgs(p, filename="../figures/{}_{}_measured_predicted.svg".format(method_name, dataset_name))
    export_png(p, filename="../figures/{}_{}_measured_predicted.png".format(method_name, dataset_name))
    def plot_pca_apexbio_asinex(self, parameter, a, b):
        result = self.result
        print(a, b)
        source1 = column_source(result, "APEXBIO")
        source2 = column_source(result, "Asinex")
        hover = HoverTool(tooltips=[
            ("PCA 1", "$x"),
            ("PCA 2", "$y"),
            ("ID", "@N"),
        ])
        p = figure(
            # title="PCA based on: " + parameter,
            x_axis_label="PC 1 " + str(a) + "%",
            y_axis_label="PC 2 " + str(b) + "%",
            x_range=(-2, 6),
            y_range=(-4, 4.1),
            tools=[hover],
            plot_width=1000,
            plot_height=800,
        )
        p.add_tools(LassoSelectTool(), ZoomInTool(), ZoomOutTool(), SaveTool(),
                    PanTool())
        APEXBIO_plot = p.circle(x="x",
                                y="y",
                                source=source1,
                                color="mediumvioletred",
                                size=5)
        Asinex_plot = p.circle(x="x",
                               y="y",
                               source=source2,
                               color="mediumslateblue",
                               size=5)

        legend = Legend(
            items=[
                ("APEXBIO", [APEXBIO_plot]),
                ("Asinex", [Asinex_plot]),
            ],
            location="center",
            orientation="vertical",
            click_policy="hide",
        )
        p.add_layout(legend, place="right")
        p.xaxis.axis_label_text_font_size = "20pt"
        p.yaxis.axis_label_text_font_size = "20pt"
        p.xaxis.axis_label_text_color = "black"
        p.yaxis.axis_label_text_color = "black"
        p.xaxis.major_label_text_font_size = "18pt"
        p.yaxis.major_label_text_font_size = "18pt"
        p.title.text_font_size = "22pt"
        #
        show(p)
        # save
        p.output_backend = "svg"
        export_svgs(
            p,
            filename="/Users/eurijuarez/Desktop/Alexis/Plots/SVG_files/" +
            "ChemSpace_PCA_APEXBIO_Asinex" + ".svg",
        )
Esempio n. 14
0
def plot_performance_results_based_on_channels():
    from bokeh.plotting import figure, show, output_file
    import numpy as np
    from bokeh.io import export_svgs
    from bokeh.io import export_png
    from bokeh.io import show, output_file
    from bokeh.models import ColumnDataSource
    from bokeh.palettes import Spectral7
    from bokeh.transform import factor_cmap


    output_file("colormapped_bars.html")

    """
    encoding_ZHAC000103_GRAR740104LEQ500_SIMK990101LEQ500_blosum62LEQ500
    sequencematrix500_ZHAC000103LEQ500_GRAR740104LEQ500
    sequencematrix500_ZHAC000103LEQ500_blosum62LEQ500
    sequencematrix500_GRAR740104LEQ500_SIMK990101LEQ500
    sequencematrix500_GRAR740104LEQ500_blosum62LEQ500
    sequencematrix500_blosum62LEQ500
    sequencematrix500
    """

    fruits = ["proposed_encoding+ZHAC000103+GRAR740104+SIMK990101+blosum62", "proposed_encoding+GRAR740104+SIMK990101", "proposed_encoding+ZHAC000103+blosum62", "proposed_encoding+GRAR740104+blosum62", "proposed_encoding+ZHAC000103+GRAR740104",  "proposed_encoding+blosum62", "proposed_encoding"]
    #fruits = ["encoding_ZHAC000103_GRAR740104LEQ500_SIMK990101LEQ500_blosum62LEQ500", "2",
    #          "3", "4",
    #          "5", "6", "7"]
    counts = [2.494448545, 2.532216751, 2.563455896, 2.625423895, 2.635092517,  2.653060487, 2.695833344]

    source = ColumnDataSource(data=dict(fruits=fruits, counts=counts))

    p = figure(x_range=fruits, plot_height=1500, plot_width=2800, toolbar_location=None, title="")
    p.vbar(x='fruits', top='counts', width=0.9, source=source,
           line_color='white', legend="fruits", fill_color=factor_cmap('fruits', palette=Spectral7, factors=fruits))

    p.xgrid.grid_line_color = None
    p.y_range.start = 2.45
    p.y_range.end = 2.75
    p.xaxis.axis_label = 'Input Channel'
    p.xaxis.axis_label_text_font_size = "30pt"
    p.xaxis.major_label_text_font_size = "30pt"
    p.yaxis.axis_label = 'Mean Squared Error'
    p.yaxis.axis_label_text_font_size = "30pt"
    p.yaxis.major_label_text_font_size = "30pt"
    p.title.text_font_size = '30pt'
    p.title.align = "center"
    p.legend.label_text_font_size = "20pt"

    p.xaxis.major_label_text_font_size = '0pt'
    # p.legend.location = (660, 0)
    # p.legend.orientation = "horizontal"
    # p.legend.location = "top_center"

    show(p)

    p.output_backend = "svg"
    export_svgs(p, filename="../figures/pdbbind_refined_channel_error_bars.svg")
    export_png(p, filename="../figures/pdbbind_refined_channel_error_bars.png")
Esempio n. 15
0
def topImproversMonth(client, firstMonth=201909, lastMonth=201910, topX=5):
    pp = pprint.PrettyPrinter(indent=4)

    measurements = {
        'web': query_detail_web_Month,
        'mail': query_detail_mail_Month
    }

    for i, (measurement, query) in enumerate(measurements.items()):
        if measurement in measurements_db:
            print('Top {0} improvers {1} ({2} - {3})'.format(
                topX, measurement, Nr2M(firstMonth), Nr2M(lastMonth)))

            df1 = query_to_dataframe(client, query.format(firstMonth),
                                     measurement)
            df1.sort_values(by=['domain'], ascending=True, inplace=True)
            df2 = query_to_dataframe(client, query.format(lastMonth),
                                     measurement)
            df2.sort_values(by=['domain'], ascending=True, inplace=True)

            # Multiply everything but the score by 2 for the last one
            # Then deduct the first one from the second
            # This will give possible 'passed' values of:
            # 0->false, 1->was True and is True, 2-> was False but now True
            # for this to work we have to set the domain as index
            # (so they will be ignored for the subtraction)
            df1 = df1.set_index('domain')
            df2 = df2.set_index('domain')
            df2 = df2 * 2
            df2.score = round(df2.score / 2)
            df2 = df2.astype({"score": int})
            df = df2.subtract(df1)
            df['score'].fillna(0, inplace=True)
            df = df.astype({"score": int})

            # Now sort by score
            df.sort_values(by=['score', 'domain'],
                           ascending=False,
                           inplace=True)

            # Drop all after the first five (we want a top 5)
            if topX > 0:
                df.drop(df.index[topX:], inplace=True)
            # Make domains a column again (otherwise Heatmap will fail)
            df.reset_index(level=0, inplace=True)

            # Create a heatmap for this
            p = returnHeatmap(df,
                              palette=paletteTop5,
                              rangemin=-1,
                              rangemax=2,
                              title='Top {0} ({1}, {2}-{3})'.format(
                                  topX, measurement, Nr2M(firstMonth),
                                  Nr2M(lastMonth)),
                              incsign=True)
            p.output_backend = "svg"
            export_svgs(p, filename='Top{0} {1}.svg'.format(topX, measurement))
            export_png(p, filename='Top{0} {1}.png'.format(topX, measurement))
def save_plot(p, file_name, path='../static/images/'):
    """
    Saves Bokeh plot figure as svg
    :param p: Bokeh plot figure
    :param file_name: name for the plot
    :param path: path where file is saved
    """
    p.output_backend = "svg"
    export_svgs(p, filename=path + file_name + '.svg')
Esempio n. 17
0
    def plot_linker_dist_S(self, df, struc=1, key='Structured'):
        '''
		plot distance distribution per linker
		based on structured/unstrcutured/between struc&unstruc
		'''
        for i in df['Linker'].unique():
            df_c = df[df['Linker'] == i]
            if i == 'DSS':
                loc = 30
            elif i == 'EDC':
                loc = 20
            else:
                loc = 30
            output_file(self.ID + i + "linker.html", mode="inline")
            measured = df_c[df_c['Structured'] == struc]['dist']
            hist, edges = np.histogram(measured, density=False, bins=50)
            #hist_l, edges_l = np.histogram(measured, density=False, bins=25)
            p = figure(title=key + ' regions/Linker ' + i,
                       plot_height=350,
                       plot_width=350)
            p.quad(top=hist,
                   bottom=0,
                   left=edges[:-1],
                   right=edges[1:],
                   fill_color="navy",
                   line_color="white",
                   alpha=0.3)
            #p.line(edges, hist, line_color="navy", line_width=4, alpha=0.7, legend_label=key+"/"+i)
            vline = Span(location=loc,
                         dimension='height',
                         line_color='red',
                         line_width=3,
                         line_dash='dashed')
            p.renderers.extend([vline])
            p.xaxis.major_label_text_font_size = "14pt"
            p.yaxis.major_label_text_font_size = "14pt"
            p.title.text_font_size = '12pt'
            p.title.align = "center"
            p.title.vertical_align = 'top'
            p.xaxis.axis_label = 'Distance \u212B'
            p.xaxis.axis_label_text_font_size = '14pt'
            p.yaxis.axis_label = 'Number of cross-links'
            p.yaxis.axis_label_text_font_size = '14pt'
            p.output_backend = "svg"
            save(p,
                 filename=self.filename + '/' + self.ID + i + key +
                 "linker.html")
            export_svgs(p,
                        filename=self.filename + '/' + self.ID + i + key +
                        "linker.svg")
            save(p,
                 filename=self.filename_add + '/' + self.ID + i + key +
                 "linker.html")
            export_svgs(p,
                        filename=self.filename_add + '/' + self.ID + i + key +
                        "linker.svg")
Esempio n. 18
0
def export_as_svg(figure, name):
    if isinstance(figure, Row) or isinstance(figure, Column):
        for i, p in enumerate(figure.children):
            export_as_svg(p, name + '.' + str(i))
        return
    backend = figure.output_backend
    figure.output_backend = 'svg'
    figure.toolbar_location = None
    export_svgs(figure, filename=name + '.svg')
    figure.output_backend = backend
Esempio n. 19
0
def save(fig, path):
    utils.debug("saving bokeh figure: {}".format(path))
    if path.endswith(".png"):
        export_png(fig, filename=path)
    elif path.endswith(".svg"):
        export_svgs(fig, filename=path)
    elif path.endswith(".html"):
        bokeh.io.output_file(path)
        bokeh.io.save(fig)
    else:
        utils.error("unsupported bokeh output type {}".format(path))
Esempio n. 20
0
def get_number_of_bioactivity_distribution_based_on_seq_len():
    import bokeh
    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
    from bokeh.io import export_svgs
    from bokeh.io import export_png

    seq_len_list, seq_len_dict = get_prot_seq_lengths_given_fasta(
        "{}/targets.fasta".format(helper_fl_path))
    df_bioactivity = pd.read_csv(
        "{}/comp_targ_affinity.csv".format(comp_tar_training_dataset_path),
        header=None)
    print(df_bioactivity)
    len_list = ["<=500", "501-1000", "1001-1500", ">1500"]
    count_list = [0, 0, 0, 0]
    for ind, row in df_bioactivity.iterrows():
        # print(row)
        comp_id = row[0]
        tar_id = row[1]
        seq_len = seq_len_dict[tar_id]
        if seq_len <= 500:
            count_list[0] += 1
        elif seq_len > 500 and seq_len <= 1000:
            count_list[1] += 1
        elif seq_len > 1000 and seq_len <= 1500:
            count_list[2] += 1
        else:
            count_list[3] += 1
    print(count_list)

    p = figure(
        x_range=len_list,
        title=
        "# of Bioactivities Based on Lengths of Sequences - Kiba Dataset",  #.format(dataset_name),
        toolbar_location=None,
        tools="")

    p.xaxis.axis_label = 'Sequence Length'
    p.xaxis.axis_label_text_font_size = "20pt"
    p.xaxis.major_label_text_font_size = "15pt"
    p.yaxis.axis_label = 'Number of Bioactivities'
    p.yaxis.axis_label_text_font_size = "20pt"
    p.yaxis.major_label_text_font_size = "15pt"
    p.vbar(x=len_list, top=count_list, width=0.9)

    show(p)
    p.output_backend = "svg"
    export_svgs(p,
                filename="../figures/{}_{}_seq_length_dist.svg".format(
                    dataset_name, interval))
    export_png(p,
               filename="../figures/{}_{}_seq_length_dist.png".format(
                   dataset_name, interval))
Esempio n. 21
0
 def save_plot(self, file_name):
     if self.plot is None:
         print("There is nothing to save. You must load a plot first...")
         return
     try:
         self.plot.output_backend = "svg"
         export_svgs(self.plot, filename=file_name)
     except Exception as e:
         print(
             "There was an error exporting the plot. Please verify that both "
             + f"Selenium and Geckodriver are installed: {e}")
Esempio n. 22
0
def save_fig(fig, directory, name, sub_figs=None):
    export_png(fig, filename=os.path.join(directory, name + ".png"))
    if sub_figs is None:
        fig.output_backend = "svg"
        export_svgs(fig, filename=os.path.join(directory, name + ".svg"))
    else:
        # Bokeh does not support saving plot with more figures in svg format
        for i, sf in enumerate(sub_figs):
            sf.output_backend = "svg"
            export_svgs(sf,
                        filename=os.path.join(directory,
                                              name + str(i + 1) + ".svg"))
Esempio n. 23
0
def plot_seq_length_quad(fasta_fl_path, interval, dataset_name):
    import bokeh
    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.models import ColumnDataSource, FixedTicker, PrintfTickFormatter
    from bokeh.io import export_svgs
    from bokeh.io import export_png
    from bokeh.models import HoverTool

    sorted_seq_len_list, _ = get_prot_seq_lengths_given_fasta(fasta_fl_path)
    tools = "pan,wheel_zoom,box_zoom,reset"
    p = figure(tools=tools, plot_width=1400, plot_height=700,
               title="Distribution of Sequence Lenghts - {} Dataset".format(dataset_name),
               x_axis_label='Sequence Length',
               y_axis_label='Number of Protein Sequences')


    p.title.text_font_size = '20pt'
    p.title.align = "center"
    # print((sorted_seq_len_list))
    arr_hist, edges = np.histogram(sorted_seq_len_list,
                                   bins=list(range(0, 2750, interval)),
                                   range=[0, 2750])

    delays = pd.DataFrame({'arr_length': arr_hist,
                           'left': edges[:-1],
                           'right': edges[1:]})
    delays['f_interval'] = ['%d - %d' % (left, right) for left, right in zip(delays['left'], delays['right'])]
    delays['f_count'] = ['%d' % (count) for count in delays['arr_length']]

    src = ColumnDataSource(delays)
    print(src.data.keys())
    p.quad(bottom=0, left="left", right="right", top="arr_length",  source=src,
           fill_color='red', line_color='black')

    hover = HoverTool(tooltips=[('Sequence Length', '@f_interval'), ('Count', '@f_count')])
    p.add_tools(hover)

    p.xgrid.grid_line_color = None
    # p.x_range.start = 0
    p.y_range.start = 0
    p.xaxis.axis_label = 'Sequence Length'
    p.xaxis.axis_label_text_font_size = "20pt"
    p.xaxis.major_label_text_font_size = "15pt"
    p.yaxis.axis_label = 'Number of Protein Sequences'
    p.yaxis.axis_label_text_font_size = "20pt"
    p.yaxis.major_label_text_font_size = "15pt"

    show(p)
    p.output_backend = "svg"
    export_svgs(p, filename="../figures/{}_{}_seq_length_dist.svg".format(dataset_name, interval))
    export_png(p, filename="../figures/{}_{}_seq_length_dist.png".format(dataset_name, interval))
Esempio n. 24
0
    def plot_intra_summary_deprecated(self):
        '''
		plot summary of intra/inter xl-ms satisfaction
		'''
        for model_id, df in self.model_df.items():
            factors = self.get_factors(df)
            regions = ['Satisfied', 'Violated']
            source = ColumnDataSource(data=dict(
                x=factors,
                Satisfied=self.get_satisfied(df, factors),
                Violated=self.get_violated(df, factors),
            ))
            fig_id = figure(x_range=FactorRange(*factors),
                            plot_height=400,
                            plot_width=500,
                            title='CX-MS Satisfaction for model:' +
                            str(model_id))

            fig_id.vbar_stack(regions,
                              x='x',
                              width=0.9,
                              alpha=0.5,
                              color=["blue", "red"],
                              source=source,
                              legend_label=regions)
            fig_id.xaxis.major_label_text_font_size = "14pt"
            fig_id.yaxis.major_label_text_font_size = "14pt"
            fig_id.yaxis.axis_label_text_font_size = '14pt'
            fig_id.title.text_font_size = '12pt'
            fig_id.title.align = "center"
            fig_id.title.vertical_align = 'top'
            fig_id.yaxis.axis_label = 'Number of cross-links'
            fig_id.y_range.start = 0
            fig_id.y_range.end = df.shape[0]
            fig_id.x_range.range_padding = 0.1
            fig_id.xaxis.major_label_orientation = 1
            fig_id.xgrid.grid_line_color = None
            fig_id.legend.location = "top_center"
            fig_id.legend.orientation = "horizontal"
            fig_id.output_backend = "svg"
            save(fig_id,
                 filename=self.filename + '/' + self.ID + str(model_id) +
                 "IS.html")
            export_svgs(fig_id,
                        filename=self.filename + '/' + self.ID +
                        str(model_id) + "IS.svg")
            save(fig_id,
                 filename=self.filename_add + '/' + self.ID + str(model_id) +
                 "IS.html")
            export_svgs(fig_id,
                        filename=self.filename_add + '/' + self.ID +
                        str(model_id) + "IS.svg")
Esempio n. 25
0
def labelled_config(infile, index):
    """Plot an input configuration indicating the labelling scheme.

    This plots the configuration with an overlay indicating the regions in which
    particles are classified as liquid (blue) and the regions where they are classified
    as crystal (red).

    """
    with gsd.hoomd.open(infile) as trj:
        snap = HoomdFrame(trj[index])

    fig = plot_labelled_config(snap)

    fig.output_backend = "svg"
    export_svgs(fig, "figures/labelled_config.png", height=1600, width=3200)
def plot_loss_per_epoch(history, model_name=None, file_name=None):
    if model_name is None:
        model_name = ""
    else:
        model_name += ": "

    p = figure(
        plot_width=600,
        plot_height=400,
        title=f"{model_name}Loss per Epoch",
        x_axis_label="# Epochs",
        y_axis_label="Loss",
    )

    source = ColumnDataSource(
        data=dict(
            index=range(len(history.history["loss"])),
            loss=history.history["loss"],
            val_loss=history.history["val_loss"],
        )
    )
    _ = p.line(
        x="index",
        y="loss",
        color="black",
        line_dash="dotted",
        legend_label="Training Loss",
        source=source,
    )
    _ = p.line(
        x="index",
        y="val_loss",
        color="coral",
        line_width=1.5,
        legend_label="Validation Loss",
        source=source,
    )

    p.xgrid.grid_line_color = None
    p.legend.label_text_font_size = "8pt"
    p.legend.location = "top_right"
    p.legend.click_policy = "hide"
    p.title.align = "center"
    p.title.text_font_size = "12pt"

    p.add_tools(
        HoverTool(
            tooltips=[
                ("epoch", "@index"),
                ("training loss", "@loss"),
                ("validation loss", "@val_loss"),
            ]
        )
    )
    show(p)

    if file_name is not None:
        p.output_backend = "svg"
        _ = export_svgs(p, filename=file_name)
Esempio n. 27
0
def avgUserRating(csv_data):
    # just get column of ave rating
    aur = csv_data['Average User Rating'].value_counts().sort_index()
    # create bokeh figure for containing bar chart
    p = figure(x_range=list(map(str, aur.index.values)),
               plot_height=250,
               title="Average User Rating",
               toolbar_location=None,
               tools="")

    # create bar chart with x (rating 4.0 4.5...) and y (numbers)
    p.vbar(x=list(map(str, aur.index.values)), top=aur.values, width=0.9)
    p.xgrid.grid_line_color = None
    p.y_range.start = 0
    p.output_backend = 'svg'
    export_svgs(p, filename="avgUserRating.svg")
    return read_svg("avgUserRating.svg")
Esempio n. 28
0
    def save(self, filename=None, file_type='html'):
        self.draw()
        if filename is None:
            filename = self.save_address(file_type)

        if file_type == 'html':
            from bokeh.plotting import output_file, save
            output_file(filename)
            save(self.p)
        elif file_type == 'png':
            from bokeh.io import export_png
            export_png(self.p, filename=filename)
        elif file_type == 'svg':
            from bokeh.io import export_svgs
            export_svgs(self.p, filename=filename)
        else:
            raise Exception('Unsupported file_type: ' + str(file_type))
def save_bokeh_svg(obj, fname):
    if not fname[-4:] == '.svg':
        fname += '.svg'
    plot = render(obj)
    figs = list(plot.select(dict(type=Figure)))
    for k, _ in enumerate(figs):
        figs[k].output_backend = 'svg'
    return export_svgs(plot, filename=fname)
Esempio n. 30
0
def categoryChart(csv_data):

    category = computeUniq(csv_data)

    # create dataframe for category
    data = pd.Series(category).reset_index(name='value').rename(
        columns={'index': 'category'})

    data['angle'] = data['value'] / data['value'].sum() * 2 * pi
    data['color'] = Category20c[20] + Category20c[3]
    #    data["value"] = data['value']

    # create figure for containing pie chart
    p = figure(plot_height=350,
               plot_width=750,
               title="Numbers of Different Genres",
               toolbar_location=None,
               tools="hover",
               tooltips="@category: @value")

    # create pie chart auto compute angle for each category
    p.wedge(x=0,
            y=1,
            radius=0.4,
            start_angle=cumsum('angle', include_zero=True),
            end_angle=cumsum('angle'),
            line_color="white",
            fill_color='color',
            legend='category',
            source=data)

    # source = ColumnDataSource(data)

    # labels = LabelSet(x=0, y=1, text='value', level='glyph',
    #         angle=cumsum('angle', include_zero=True), source=source, render_mode='canvas')

    # p.add_layout(labels)

    # p.axis.axis_label=None
    # p.axis.visible=False
    # p.grid.grid_line_color = None

    p.output_backend = 'svg'
    export_svgs(p, filename="categoryChart.svg")
    return read_svg("categoryChart.svg")
Esempio n. 31
0
    def subplot():
        ## Make sure we are accessing the chromosomes in the correct order
        for key in range(1,23):
            print "Building subplot {}".format(key)
            TOOLTIPS=[
                #( "index", "$index"      ),
                ( 'X',   '$x'            ),
                ( 'Y',   '$y'            ),
            ]
            local_vars = vars()
            local_vars['p{}'.format(key)] = figure(plot_height=500, plot_width=500, output_backend="webgl", title="Chromosome {}".format(key))
            local_vars['p{}'.format(key)].circle(x = data_dict[key].index.values, y = data_dict[key]['CEU'], color = "grey"   )
            local_vars['p{}'.format(key)].circle(x = data_dict[key].index.values, y = data_dict[key]['CDX'], color = "skyblue"  )
            local_vars['p{}'.format(key)].circle(x = data_dict[key].index.values, y = data_dict[key]['YRI'], color = "goldenrod"  )
            local_vars['p{}'.format(key)].circle(x = data_dict[key].index.values, y = data_dict[key]['Khoisan'], color = "salmon"  )
            local_vars['p{}'.format(key)].xaxis.major_label_orientation = "vertical"
            local_vars['p{}'.format(key)].xaxis[0].formatter.use_scientific = False
            local_vars['p{}'.format(key)].xaxis[0].ticker = [int(data_dict[key].first_valid_index()) ,int(data_dict[key].last_valid_index())]
            local_vars['p{}'.format(key)].x_range = Range1d(int(data_dict[key].first_valid_index()) ,int(data_dict[key].last_valid_index()))
            

            #output_file("Rf_chr{}.html".format(key))
            export_svgs(local_vars['p{}'.format(key)], filename="Rfmix_intro_{}.svg".format(key))
            #save(local_vars['p{}'.format(key)])
                
        
        plot_list = [local_vars['p{}'.format(i)] for i in data_dict.keys()]
        #Make one figure out of the 22 subplots
        p =gridplot(plot_list, ncols=10) 
        #p = row(plot_list)
       
         


        output_file("Rfmix_introgression.html")
        print "Saving to output - this could take a while.."
        save(p)