def __init__(self, *args, **kwargs): super(ExpressionDisplay, self).__init__(*args, **kwargs) svg = self.svg = canvas.SVGCanvasWidget() svg.add_style("background-color", "cornsilk") svg.svg_width = 550 svg.svg_height = 550 svg.watch_event = "click mousemove" svg.default_event_callback = self.svg_callback cc = self.color_chooser = color_widget.ColorChooser() #cc.svg.visible = False # default set_visibility(cc.svg, False) tdd = self.transform_dropdown = widgets.Dropdown( options=TRANSFORM_TEXTS, value=NO_TRANSFORM ) tdd.on_trait_change(self.draw_click, "value") tdd.layout.width = "100px" self.title_html = widgets.HTML("Expression Heat Map") self.text_assembly = self.make_text_displays() self.match_assembly = self.make_match_assembly() self.genes_assembly = self.make_genes_assembly(tdd) self.info_area = widgets.Textarea(description="status") self.assembly = widgets.VBox(children=[self.title_html, self.text_assembly, self.svg, self.color_chooser.svg, self.match_assembly, self.genes_assembly, self.info_area]) self.dx = 10 self.dy = 2 self.data_heat_map = None self.display_heat_map = None self.row = self.col = None self.drawing = False
def test0(): import pprint import gtf_format from jp_svg_canvas import canvas canvas.load_javascript_support() GB = GenomeBar() f = open("genes.gtf") print("reading file") if 0: L = list(gtf_format.gtf_lines_to_dicts(f)) L = [d for d in L if d.get("feature") == "exon"] else: D = gtf_format.GTFData() D.load(f) GF = D.get_gene_features(["tmc6"]) #pprint.pprint(sorted(D.gene_id_to_dicts.keys())) pprint.pprint(GF) L = GF["tmc6"] print("loading", len(L)) for feature in L: atts = feature["attribute"] kind = feature.get("feature") gene_id = atts.get("gene_id") if kind == "exon" and gene_id: name = gene_id + str(feature["start"]) GB.add_feature(name, feature) svg = canvas.SVGCanvasWidget() GB.fit(svg) print("drawing") GB.draw(svg) print("done") return svg
def __init__(self, *args, **kwargs): super(ColorPicker, self).__init__(*args, **kwargs) svg = self.svg = canvas.SVGCanvasWidget() svg.svg_height = self.palette_side + 2 * self.dy svg.svg_width = self.palette_side svg.set_view_box(0, 0, svg.svg_width, svg.svg_height) svg.watch_event = "click" svg.default_event_callback = self.svg_callback #self.color = color_scale.color(color_scale.color64(0, 0)) self.on_trait_change(self.show_color_choice, "color")
def canvas_test(filename="ex2.wig.gz", width=500, height=100): from jp_svg_canvas import canvas canvas.load_javascript_support() svg = canvas.SVGCanvasWidget() svg.add_style("background-color", "cyan") svg.svg_width = width svg.svg_height = height svg.set_view_box(0, 0, width, height) W = WigData() print ("loading: " + repr(filename)) W.load_filename(filename) print ("loaded " + repr(W.numelts) + " max " + repr(W.maxheight)) W.draw(svg, 3010000, 3010200, width, height) return (svg, W)
def widget(self): from jp_svg_canvas import canvas canvas.load_javascript_support(True) svg_canvas = canvas.SVGCanvasWidget() self.plot_all(svg_canvas) svg_canvas.send_commands() display(svg_canvas) # fit must happen after display. svg_canvas.fit() svg_canvas.send_commands() canvas_side = len(self.dataset.feature_names) * self.side canvas_side = max(canvas_side, 500) svg_canvas.width = canvas_side svg_canvas.height = canvas_side return svg_canvas
def __init__(self, *args, **kwargs): super(ColorChooser, self).__init__(*args, **kwargs) svg = self.svg = canvas.SVGCanvasWidget() svg.svg_width = self.margin * 2 + self.palette_side middle = self.palette_side + self.histogram_region + self.bar_region svg.svg_height = self.margin * 2 + middle svg.set_view_box(- self.margin, - self.margin, self.palette_side + 2 * self.margin, middle + 2 * self.margin) self.scale = color_scale.ColorInterpolator(minvalue=-3.33323, maxvalue=1.3432) svg.watch_event = "click mousemove" svg.default_event_callback = self.svg_callback self.drag_color = None self.drag_circle = None self.histogram = None
def assemble(self): guide = self.guide wigs = self.wigs vertical = [] for wig in wigs: svg = wig.svg = canvas.SVGCanvasWidget() vertical.append(svg) svg.width = self.width svg.height = self.height svg.set_view_box(0, 0, self.width, self.height) svg.add_style("background-color", "cyan") traitlets.link((guide, "start_position"), (wig, "start_position")) traitlets.link((guide, "end_position"), (wig, "end_position")) vertical.append(self.guide.assembly) self.assembly = widgets.VBox(children=vertical) wig.on_trait_change(self.draw, "start_position") self.assembled = True
def canvas(self): svg = canvas.SVGCanvasWidget() svg.add_style("background-color", "cyan") svg.width = 500 svg.height = 10 return svg