Пример #1
0
    def _get_series_multiselect(self):

        list_slct = self.cols_pos + self.cols_neg
        slct = MultiSelect(size=len(list_slct),
                           value=list_slct, options=list_slct)

        self.callback.args['slct_dataseries'] = slct
        slct.js_on_change('value', self.callback)

        return slct
Пример #2
0
    def _get_multiselects(self):

        selects = []
        for nind, ind in enumerate(self.ind_slct):
            list_slct = list(map(str, self.slct_list_dict[ind]))
            value = [list_slct[self._initial_selection_index[nind]]]
            slct = MultiSelect(size=1, value=value,
                               options=list_slct, title=ind)
            self.callback.args['slct_%s'%ind] = slct
            slct.js_on_change('value', self.callback)
            selects.append(slct)

        return selects
Пример #3
0
def hypersliceplorer(vertices, config, mn, mx, n_fpoint, method='sobol', width=-1, height=-1, output=None, title=None):
    calc_data = hypersliceplorer_core(vertices, config, mn, mx, n_fpoint, method=method)

    # These will be the tooltips shown in our figures while hovering on the glyphs
    tooltips = [
        ("(x,y)", "($x, $y)"),
        ("focus point", "@fp")
    ]
    circle_tooltips = [
        ("(x,y)", "(@x, @y)")
    ]

    # every dictionaries here have their string key of (i, j) referring to d1, d2
    # meaning each trace, source, ray are assigned according to the dimensional pair.
    # So, we can plot only (d1, d2) = (0, 0) by plotting trace(0, 0).
    #   - source(i, j) will be an array containing the data from each fp
    #   - ray(i, j) is used in callback, so we can access the segments via CustomJS
    source = {}
    trace = {}
    ray = {}
    circle = {}
    colors = [
        '#e6194B', '#f58231', '#ffe119', '#bfef45', '#3cb44b', '#42d4f4',
        '#4363d8', '#911eb4', '#f032e6', '#000075', '#e6beff', '#800000'
    ]
    for i in range(0, calc_data.dim - 1):
        for j in range(i, calc_data.dim):
            # create a figure at (d1, d2) = (i, j)
            if (i, j) == (0, 0):
                trace[str((i, j))] = figure(
                    tools="wheel_zoom",
                    x_range=(mn, mx),
                    y_range=(mn, mx)
                )
            else:
                trace[str((i, j))] = figure(
                    tools="wheel_zoom",
                    x_range=trace[str((0, 0))].x_range,
                    y_range=trace[str((0, 0))].y_range
                )

            # each source(i, j) contains data at focus points, we create the sources as variable
            # just in case that we might need them later
            source[str((i, j))] = []
            ray[str((i, j))] = []
            circle[str((i, j))] = []
            for point in calc_data.data_by_axes(i, j):
                data = {
                    'fp': [],
                    'x0': [],
                    'y0': [],
                    'x1': [],
                    'y1': []
                }
                for seg in calc_data.data_by_axes(i, j)[point]:
                    data['fp'].append(str(point))
                    data['x0'].append(seg['p1_1'])
                    data['y0'].append(seg['p1_2'])
                    data['x1'].append(seg['p2_1'])
                    data['y1'].append(seg['p2_2'])
                source[str((i, j))].append(ColumnDataSource(data=data))
                circle[str((i, j))].append(trace[str((i, j))].circle(
                    x=[point[i]],
                    y=[point[j]],
                    size=6,
                    color="black",
                    alpha=0.1,
                    visible=False
                ))
                circle_hover = HoverTool(tooltips=circle_tooltips, renderers=[circle[str((i, j))][-1]])
                trace[str((i, j))].add_tools(circle_hover)

            # now plot those sources in the figure
            for s in source[str((i, j))]:
                ray[str((i, j))].append(trace[str((i, j))].segment(
                    x0='x0',
                    x1='x1',
                    y0='y0',
                    y1='y1',
                    source=s,
                    line_color="black",
                    line_alpha=0.1,
                    line_width=2
                ))
                hover = HoverTool(tooltips=tooltips, renderers=[ray[str((i, j))][-1]])
                trace[str((i, j))].add_tools(hover)

    # set up a tool to toggle visibility
    multi_menu = []
    for point in calc_data.data_by_axes(0, 0):
        multi_menu.append((str(point), str(point)))
    sorted_menu = sorted(multi_menu)
    # menu index is irrelevant, but just in case that we want the color to
    # be faithful to the indices of the focus points
    menu_ind = {}
    cnt = 0
    for m in sorted_menu:
        menu_ind[m[0]] = cnt
        cnt += 1
    # making the segments visible according to selected focus points can be simpler
    # but here we go for the different colors for each selected lines, therefore,
    # the code will be longer and more complex
    multi_select_callback = CustomJS(args=dict(rays=ray, circles=circle, colors=colors, ind=menu_ind), code="""
        var color_count = 0;
        if (cb_obj.value.length > 0) {
            for (var i=0; i<cb_obj.value.length; i++) {
                for (r in rays) {
                    for (var j=0; j<rays[r].length; j++) {
                        var diffFp = cb_obj.value[i].localeCompare(rays[r][j].data_source.data['fp'][0]);
                        var isActive = cb_obj.value.includes(rays[r][j].data_source.data['fp'][0]);

                        if (isActive) {
                            rays[r][j].visible = true;
                            if (!diffFp) {
                                rays[r][j].glyph.line_color = colors[color_count%12];
                                rays[r][j].glyph.line_alpha = 0.8;

                                circles[r][j].visible = true;
                                circles[r][j].glyph.fill_color = colors[color_count%12];
                                circles[r][j].glyph.fill_alpha = 0.8;
                            }
                        } else {
                            rays[r][j].visible = false;
                            rays[r][j].glyph.line_color = 'black';
                            rays[r][j].glyph.line_alpha = 0.1;

                            circles[r][j].visible = false;
                            circles[r][j].glyph.fill_color = 'black';
                            circles[r][j].glyph.fill_alpha = 0.1;
                        }
                    }
                }
                color_count++;
            }
        } else {
            for (r in rays) {
                for (var j=0; j<rays[r].length; j++) {
                    rays[r][j].visible = false;
                    rays[r][j].glyph.line_color = 'black';
                    rays[r][j].glyph.line_alpha = 0.1;

                    circles[r][j].visible = false;
                    circles[r][j].glyph.fill_color = 'black';
                    circles[r][j].glyph.fill_alpha = 0.1;
                }
            }
        }
    """)
    multi_select = MultiSelect(title="Select Focus Points:", value=[], options=sorted_menu, disabled=True, size=25)
    multi_select.js_on_change('value', multi_select_callback)
    toggle_callback = CustomJS(args=dict(plots=ray, check=multi_select), code="""
        if (cb_obj.active == true) {
            check.disabled = false;
            cb_obj.label = "Local View Mode";
            for (p in plots) {
                for (var i=0; i<plots[p].length; i++) {
                    plots[p][i].visible = false;
                }
            }
        } else {
            check.disabled = true;
            check.value = [];
            cb_obj.label = "Global View Mode";
            for (p in plots) {
                for (var i=0; i<plots[p].length; i++) {
                    plots[p][i].visible = true;
                }
            }
        }
    """)
    toggle = Toggle(label="Global View Mode", button_type="success", callback=toggle_callback)

    # set up the grid
    trace_grid = []
    for j in range(calc_data.dim - 1, 0, -1):
        trace_row = []
        for i in range(0, j):
            if i != j:
                trace_row.append(trace[str((i, j))])
                if j == calc_data.dim - 1:
                    trace[str((i, j))].add_layout(Title(text=("x" + str(i + 1)), align="center"), "above")
                if i == 0:
                    trace[str((i, j))].add_layout(Title(text=("x" + str(j + 1)), align="center"), "left")
        trace_grid.append(trace_row)

    grid = gridplot(trace_grid)

    if width > 0:
        for i in range(0, calc_data.dim - 1):
            for j in range(i, calc_data.dim):
                trace[str((i, j))].plot_width = width

    if height > 0:
        for i in range(0, calc_data.dim - 1):
            for j in range(i, calc_data.dim):
                trace[str((i, j))].plot_height = height

    if output:
        output_file(output)
    save(row(grid, widgetbox(toggle, multi_select)), title=title if title else 'Hypersliceplorer')
Пример #4
0
def home():

    #Access the SQL database
    engine = create_engine('sqlite:///../tapestation.db', echo=False)

    #Make a plot of strongest peaks, sizes and peak molarity

    #Get the data
    peak_df = pd.read_sql('SELECT * FROM peaks', engine)

    #Get region data
    region_df = pd.read_sql('SELECT * from regions', engine)
    region_cols = ['ts_data_id', 'well_id', 'avg_size']
    region_size_df = region_df[region_cols]

        
    #Choose only the first peak as well as from samples only
    first_peak_mask = (peak_df['samp_desc'] != 'Electronic Ladder') & (peak_df['peak_id'] == 1)
    first_peak_df = peak_df[first_peak_mask].copy()
    first_peak_cols = ['ts_data_id', 'well_id', 'peak_mol', 'int_area', 'size', 'cal_conc']
    first_peak_df = first_peak_df[first_peak_cols]

    #Merging the data
    combined_df = pd.merge(first_peak_df, region_size_df, on=['ts_data_id', 'well_id'], how='outer')
    #print(combined_df)
    source_data = ColumnDataSource(combined_df)

    #Have two instances of the data so for callback purposes
    #Because we are essentially filtering the data
    #We don't want to lose the data when altering widgets, keep an 'unchanged' copy
    unchanged_data = ColumnDataSource(combined_df)

    first_peak_plot = figure()
    first_peak_plot.circle(x='size', y='peak_mol', source=source_data)

    first_peak_plot.title.text = 'Size vs Peak Molarity of Strongest Peaks'
    first_peak_plot.xaxis.axis_label = 'Size [bp]'
    first_peak_plot.yaxis.axis_label = 'Peak Molarity [pmol/l]'

    #Add a hover tool for the relevant information from peaks table
    hover_first_peak = HoverTool()
    hover_first_peak.tooltips=[
            ('TS Data ID', '@ts_data_id'),
            ('Well', '@well_id'),
            ('Size [bp]','@size'),
            ('Peak Molarity [pmol/l]', '@peak_mol'),
            ('Calibrated Concentration [pg/mul]', '@cal_conc'),
            ('% Integrated Area', '@int_area')
            ]
    first_peak_plot.add_tools(hover_first_peak)


    #Make a plot comparing well size to average size
    size_plot = figure(match_aspect=True) #match_aspect keep aspect ratio the same
    size_plot.circle(x='size', y='avg_size', source=source_data)

    size_plot.title.text = 'Size of Strongest Peak vs Avg Size of Region [bp]'
    size_plot.xaxis.axis_label = 'Size of Strongest Peak [bp]'
    size_plot.yaxis.axis_label = 'Avg Size of Region [bp]'

    size_plot.ray(x=[0,2,3], y=[0,2,3], length=0, angle=[45], angle_units='deg', color="#FB8072")
    #Add a hover tool for the relevant information
    hover_size = HoverTool()
    hover_size.tooltips = [
            ('TS Data ID', '@ts_data_id'),
            ('Well', '@well_id'),
            ('Size [bp]', '@size'),
            ('Avg size [bp]', '@avg_size')
            ]

    size_plot.add_tools(hover_size)


    #Slider callbacks with CustomJS
    callback_JS="""
    //Get the value from out int area slider
    var int_area_cutoff = int_area_slider.value;

    //Get the range of our calibrated concentration slider
    var conc_min = conc_slider.value[0];
    var conc_max = conc_slider.value[1];

    //Get the values from ts data multi_select
    var ts_data_list = ts_data_multi_select.value;
    //console.log(ts_data_list);

    //Call the unchanged data
    var uc_data = unchanged_data.data;
    var uc_ts_data_id_data = uc_data['ts_data_id'];
    var uc_well_id_data = uc_data['well_id'];
    var uc_cal_conc_data = uc_data['cal_conc'];
    var uc_int_area_data = uc_data['int_area'];
    var uc_size_data = uc_data['size'];
    var uc_peak_mol_data = uc_data['peak_mol'];
    var uc_avg_size = uc_data['avg_size'];

    //Call the data that we'll change
    var data = source_data.data;

    //The four columns we will change are cal_conc, int_area, size, and peak_mol
    var cal_conc=[];
    var int_area=[];
    var size=[];
    var peak_mol=[];
    var ts_data_id = [];
    var well_id = [];
    var avg_size = [];

    //Filter the data
    for(var i=0; i<uc_cal_conc_data.length;i++){
        if(uc_int_area_data[i] >= int_area_cutoff){
            if(uc_cal_conc_data[i] >= conc_min && uc_cal_conc_data[i] <= conc_max){
                if(ts_data_list.includes(uc_ts_data_id_data[i])){
                cal_conc.push(uc_cal_conc_data[i]);
                int_area.push(uc_int_area_data[i]);
                size.push(uc_size_data[i]);
                peak_mol.push(uc_peak_mol_data[i]);
                ts_data_id.push(uc_ts_data_id_data[i]);
                well_id.push(uc_well_id_data[i]);
                avg_size.push(uc_avg_size[i]);
                }
            }
        }
    }

    //Change the index too, since lengths are not the same any longer
    var index=[];
    for(var j=0; j<cal_conc.length;j++){
        index.push(j);
    }

    //Replace the data and emit it to source
    data['ts_data_id'] = ts_data_id;
    data['well_id'] = well_id;
    data['cal_conc'] = cal_conc;
    data['int_area'] = int_area;
    data['size'] = size;
    data['peak_mol'] = peak_mol;
    data['index'] = index;
    data['avg_size'] = avg_size;
    //console.log(data)

    source_data.change.emit();
    """
    callback = CustomJS(args=dict(source_data=source_data, unchanged_data=unchanged_data), code=callback_JS)

    # Want to make a slider for integrate_area cutoff
    int_area_N = 0
    int_area_slider = Slider(start=0, end=100, step=1, value = int_area_N, title="% Integrated Area Cutoff")
    int_area_slider.js_on_change('value', callback)
    #Want to make a rangeslider for calibrated concentration
    cal_conc_min = first_peak_df['cal_conc'].min()
    cal_conc_max = first_peak_df['cal_conc'].max()
    conc_slider = RangeSlider(start=cal_conc_min, end=cal_conc_max, value=(cal_conc_min, cal_conc_max),step=(cal_conc_max - cal_conc_min) / 100, title='Range of Calibrated Concentration [pg/mul]')
    conc_slider.js_on_change('value',callback)


    #Make a Multiselect tool
    ts_data_list = first_peak_df['ts_data_id'].unique().tolist()
    ts_data_multi_select = MultiSelect(title='Select Data: ', value=ts_data_list, options=ts_data_list, height=130)
    ts_data_multi_select.js_on_change('value',callback)


    #Callback arguments
    callback.args['int_area_slider'] = int_area_slider
    callback.args['conc_slider'] = conc_slider
    callback.args['ts_data_multi_select'] = ts_data_multi_select


    #Create a paragraph to discuss first two plots
    readme = Paragraph(text = """
    These first two plots correspond to the strongest peaks of the datasets.  The first plot showing the size vs peak molarity, where the second plot shows the size vs the average size of the region. 

    The user can use the following tools to filter the data being plotted.  
    'Select Data' is a MultiSelect Table,from which users can select which data to plot. 
    'Range of Calibrated Concentration allows users to choose the range of calibrated concentration.
    '% Integrated Area Cutoff allows user to choose the minimum required % Integrated Area for the strongest peak.
    """, width=1000)

    #Make another plot of the lower markers and the upper markers
    #marker_df = pd.read_sql('SELECT * FROM markers', engine)
    #marker_cols = ['ts_data_id', 'well_id', 'peak_mol', 'int_area', 'size', 'cal_conc', 'marker_id']
    #marker_df = marker_df[marker_cols]

    #Separate the two
    #lower_mask = marker_df['marker_id'] == 'Lower Marker'
    #upper_mask = marker_df['marker_id'] == 'Upper Marker'

    #lower_df = marker_df[lower_mask].copy()
    #upper_df = marker_df[upper_mask].copy()

    #sc_data_lower = ColumnDataSource(lower_df)
    #uc_data_lower = ColumnDataSource(lower_df)
    #sc_data_upper = ColumnDataSource(upper_df)

    #Plot the two's sizes vs 





    l = layout(
            [WidgetBox(readme)],
            [ts_data_multi_select],
            [conc_slider],
            [int_area_slider],
            [first_peak_plot, size_plot]
            )

    script, div_dict = components(l)
    return render_template('homepage.html', script=script, div=div_dict, bokeh_version=BOKEH_VERSION)
Пример #5
0
                 parse_dates=False,
                 skiprows=skip)
source = ColumnDataSource(data=dict(x=pd.to_datetime(df.index, dayfirst=True),
                                    do=df.iloc[:, (react - 1)].values,
                                    ph=df.iloc[:, (react + 7)].values,
                                    acid=df.iloc[:, (14 + react * 2)].values,
                                    base=df.iloc[:, (15 + react * 2)].values))

# create some widgets
select = MultiSelect(title="Date:",
                     value=sel,
                     options=list(HAL_dict.keys()),
                     height=300)
select.js_on_change(
    "value",
    CustomJS(code="""
    console.log('select: value=' + this.value, this.toString())
"""))
select2 = Select(title="Reactor:",
                 value=reactor,
                 options=['1', '2', '3', '4', '5', '6', '7', '8'])
select3 = TextInput(title="Read every Nth line:", value=str(read_every_n))
button = Button(label="Look up")
#multi_choice = MultiChoice(value=[sel_list[-1]], options=sel_list)

p = figure(x_axis_type='datetime')
p.extra_y_ranges = {}
p.extra_y_ranges['do'] = Range1d(start=0, end=100)
p.extra_y_ranges['pH'] = Range1d(start=0, end=14)
p.add_layout(LinearAxis(y_range_name='pH', axis_label='pH'), 'right')
p.line('x',