def test_Square() -> None: marker = Square() check_marker_properties(marker) check_line_properties(marker) check_fill_properties(marker) check_hatch_properties(marker) check_properties_existence(marker, MARKER, LINE, FILL, HATCH, GLYPH, ["marker"])
def test_Square(): marker = Square() assert marker.angle == "angle" yield check_marker, marker yield check_fill, marker yield check_line, marker yield check_props, marker, ["angle"], MARKER, FILL, LINE
def test_Square() -> None: marker = Square() check_marker_properties(marker) check_fill_properties(marker) check_line_properties(marker) check_properties_existence(marker, MARKER, FILL, LINE, GLYPH)
def test_Square(): marker = Square() yield check_marker_properties, marker yield check_fill_properties, marker yield check_line_properties, marker yield check_properties_existence, marker, MARKER, FILL, LINE, GLYPH
def mann_only_interactive(data, cut1, cut2, chrs_plot=None, ms=6, color_sequence=['#7fc97f', "#beaed4", '#fdc086']): ''' Generate interactive dots. :param data: :param cut1: :param cut2: :param ms: Marker size. Default 6. :return: ''' # Defining DataFrame for bokeh ts = DataFrame({ 'snp': data['snp'], 'pos': data['pos'], 'chr': data['chr'], 'color': np.zeros(len(data), dtype='S20'), 'abspos': data['pos'], 'pval1': -np.log10(data['pval1']), 'pval1_q': -np.log10(data['pval1_q']), 'pval2': -np.log10(data['pval2']), 'pval2_q': -np.log10(data['pval2_q']) }) # Calculating proper positions if chrs_plot is None: chrs = np.unique(ts['chr']) if type(chrs[0]) == str: chrs = sorted_nicely(chrs) else: chrs.sort() else: chrs = chrs_plot print(chrs) temp_pos = 0 xtixks_pos = np.zeros(len(chrs) + 1) print(chrs) for i in range(len(chrs)): # Can be optimized here temp = ts['abspos'][ts['chr'] == chrs[i]] if len(temp) > 0: temp = np.max(temp) else: temp = 1000 print(temp) xtixks_pos[i + 1] = temp # temp_pos += temp # xtixks_pos[i+1] = temp_pos # ts['abspos'][ts['chr'] == chrs[i+1]] += temp_pos print(xtixks_pos) xtixks_pos = np.cumsum(xtixks_pos) print(xtixks_pos) for i in range(len(chrs)): ts['abspos'][ts['chr'] == chrs[i]] += xtixks_pos[i] print(xtixks_pos) xtixks_pos = (xtixks_pos[1:] + xtixks_pos[:-1]) / 2.0 print(xtixks_pos) print(chrs) # Old color selection # for i in range(len(chrs)): # if i % 2 == 0: # ts['color'][ts['chr'] == chrs[i]] = '#FA8072' # else: # ts['color'][ts['chr'] == chrs[i]] = '#00BFFF' for i in range(len(chrs)): ts['color'][ts['chr'] == chrs[i]] = color_sequence[i % len(color_sequence)] # Defining hover tools hover1 = HoverTool(tooltips=[ ("chr", "@chr"), ("snp", "@snp"), ("pos", "@pos"), ("-log10(pval1,pval2)", "(@pval1, @pval2)"), ]) hover2 = HoverTool(tooltips=[ ("chr", "@chr"), ("snp", "@snp"), ("pos", "@pos"), ("-log10(pval1,pval2)", "(@pval1, @pval2)"), ]) hoverq = HoverTool(tooltips=[ ("chr", "@chr"), ("snp", "@snp"), ("pos", "@pos"), ("-log10(pval1,pval2)", "(@pval1, @pval2)"), ]) tools1 = ['reset', 'xwheel_zoom', 'xpan', 'box_select', hover1] tools2 = ['reset', 'xwheel_zoom', 'xpan', 'box_select', hover2] toolsq = ['reset', 'wheel_zoom', 'pan', 'box_select', hoverq] source = ColumnDataSource(data=ts) # original_source = ColumnDataSource(data=ts) source_filt = ColumnDataSource( data=dict(snp=[], pos=[], pval1=[], pval2=[])) source.callback = CustomJS(args=dict(source_filt=source_filt), code=""" var inds = cb_obj.get('selected')['1d'].indices; var d1 = cb_obj.get('data'); var d2 = source_filt.get('data'); d2['snp'] = [] d2['pos'] = [] d2['chr'] = [] d2['pval1'] = [] d2['pval2'] = [] for (i = 0; i < inds.length; i++) { d2['snp'].push(d1['snp'][inds[i]]) d2['pos'].push(d1['pos'][inds[i]]) d2['chr'].push(d1['chr'][inds[i]]) d2['pval1'].push(d1['pval1'][inds[i]]) d2['pval2'].push(d1['pval2'][inds[i]]) } source_filt.trigger('change'); // data_table_filt.trigger('change'); """) selection_glyph = Circle(fill_color='firebrick', line_color=None, size=ms) nonselection_glyph = Circle(fill_color='gray', fill_alpha=0.1, line_color=None, size=ms) selection_glyph_2 = Square(fill_color='firebrick', line_color=None, size=ms) nonselection_glyph_2 = Square(fill_color='gray', fill_alpha=0.1, line_color=None, size=ms) upper_bound = np.ceil( np.max([np.max(ts['pval1']), np.max(ts['pval2'])]) + .51) p1 = figure(responsive=True, plot_width=900, plot_height=300, tools=tools1, x_range=[0, np.max(ts['abspos'])], y_range=[-0.12 * upper_bound, upper_bound], webgl=True) r1 = p1.circle('abspos', 'pval1', source=source, line_color=None, color='color', size=ms) r1.selection_glyph = selection_glyph r1.nonselection_glyph = nonselection_glyph p1.patch([0, np.max(ts['abspos']), np.max(ts['abspos']), 0], [0, 0, -np.log10(cut1), -np.log10(cut1)], alpha=0.5, line_color=None, fill_color='gray', line_width=2) p2 = figure(responsive=True, plot_width=900, plot_height=300, tools=tools2, x_range=p1.x_range, y_range=p1.y_range, webgl=True) r2 = p2.square('abspos', 'pval2', source=source, line_color=None, color='color', size=ms) r2.selection_glyph = selection_glyph_2 r2.nonselection_glyph = nonselection_glyph_2 p2.patch([0, np.max(ts['abspos']), np.max(ts['abspos']), 0], [0, 0, -np.log10(cut1), -np.log10(cut1)], alpha=0.5, line_color=None, fill_color='gray', line_width=2) pq1 = figure(responsive=True, plot_width=400, plot_height=400, tools=toolsq, webgl=True) pq1.line([0, 7], [0, 7], line_width=3, color="black", alpha=0.5, line_dash=[4, 4]) rq1 = pq1.circle('pval1_q', 'pval1', source=source, line_color=None, size=ms) # err_x = -np.log10(np.concatenate([data['pval1_q'][:100], data['pval1_q'][100::-1]])) # err_y = -np.log10(np.concatenate([data['pval1_q_top'][:100], data['pval1_q_bot'][100::-1]])) # er1 = pq1.patch(err_x, err_y, alpha=0.2, color='blue') rq2 = pq1.square('pval2_q', 'pval2', source=source, line_color=None, size=ms, color="red") # err_x = -np.log10(np.concatenate([data['pval2_q'][:100], data['pval2_q'][100::-1]])) # err_y = -np.log10(np.concatenate([data['pval2_q_top'][:100], data['pval2_q_bot'][100::-1]])) # er2 = pq1.patch(err_x, err_y, alpha=0.2, color='olive') rq1.selection_glyph = selection_glyph rq1.nonselection_glyph = nonselection_glyph rq2.selection_glyph = selection_glyph_2 rq2.nonselection_glyph = nonselection_glyph_2 # Labels for axes pq1.yaxis.axis_label = "Experimental quantiles, -log10(p)" pq1.xaxis.axis_label = "Theoretical quantiles, -log10(p)" p1.yaxis.axis_label = "-log10(p)" p1.xaxis.axis_label = "Chromosomes" p2.yaxis.axis_label = "-log10(p)" p2.xaxis.axis_label = "Chromosomes" p1.xgrid.grid_line_color = None p2.xgrid.grid_line_color = None # print(xtixks_pos) p1.xaxis[0].ticker = FixedTicker(ticks=[]) p2.xaxis[0].ticker = FixedTicker(ticks=[]) p1.text(xtixks_pos, xtixks_pos * 0 - 0.12 * upper_bound, [str(chrs[i]) for i in range(len(chrs))], text_align='center') p2.text(xtixks_pos, xtixks_pos * 0 - 0.12 * upper_bound, [str(chrs[i]) for i in range(len(chrs))], text_align='center') # p1.xaxis[0].ti columns = [ TableColumn(field="chr", title="chr"), TableColumn(field="snp", title="snp"), TableColumn(field="pos", title="pos"), TableColumn(field="pval1", title="pval1"), TableColumn(field="pval2", title="pval2"), ] data_table = DataTable(source=source, columns=columns, width=300, height=280) p3 = vform(data_table) data_table_filt = DataTable(source=source_filt, columns=columns, width=500, height=500) p4 = vform(data_table_filt) return p1, p2, p3, p4, pq1
fill_color="#B3DE69")), ] markers = [ ("circle", Circle(x="x", y="y", radius=0.1, fill_color="#3288BD")), ("circle_x", CircleX(x="x", y="y", size="sizes", line_color="#DD1C77", fill_color=None)), ("circle_cross", CircleCross(x="x", y="y", size="sizes", line_color="#FB8072", fill_color=None, line_width=2)), ("square", Square(x="x", y="y", size="sizes", fill_color="#74ADD1")), ("square_x", SquareX(x="x", y="y", size="sizes", line_color="#FDAE6B", fill_color=None, line_width=2)), ("square_cross", SquareCross(x="x", y="y", size="sizes", line_color="#7FC97F", fill_color=None, line_width=2)), ("diamond",
def test_Square(): marker = Square() yield check_marker, marker yield check_fill, marker yield check_line, marker yield check_props, marker, MARKER, FILL, LINE