Edinburgh-Genome-Foundry / DnaFeaturesViewer

:eye: Python library to plot DNA sequence features (e.g. from Genbank files)
https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/
MIT License
584 stars 90 forks source link

plot_with_bokeh gives BAD_COLUMN_NAME errors and uses default font when using bokeh 2.3.0 #56

Closed kiramt closed 2 years ago

kiramt commented 3 years ago

When using plot_with_bokeh the labels are plotted with the default font instead of Arial, and errors are printed:

ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name. This could either be due to a misspelling or typo, or due to an expected column being missing. : key "text_font" value "arial" [renderer: GlyphRenderer(id='1037', ...)]

This happens when using bokeh 2.3.0 but not earlier versions. The problem is that the most recent bokeh has changed how the text_font value is interpreted (see https://github.com/bokeh/bokeh/issues/11044) and in the plot_with_bokeh function the plot.text call needs to use text_font=value("arial") instead of text_font="arial".

veghp commented 3 years ago

Thank you very much -- I posted a fix in https://github.com/Edinburgh-Genome-Foundry/DnaFeaturesViewer/pull/57. Using value() is not compatible with bokeh v2.2, so to make it backward compatible, I added code that checks the version. If no objections from @Zulko, then I'll go ahead and merge to dev. Working example:

import dna_features_viewer

from dna_features_viewer import GraphicFeature, GraphicRecord
features=[
    GraphicFeature(start=20, end=500, strand=0, color="#ffcccc",
                   label="Gene 1: start < end"),
    GraphicFeature(start=750, end=600, strand=0, color="orange",
                   label="Gene 4: start > end"),
    GraphicFeature(start=400, end=700, strand=-1, color="#cffccc",
                   label="Gene 2"),
    GraphicFeature(start=600, end=900, strand=+1, color="#ccccff",
                   label="Gene 3")
]
record = GraphicRecord(sequence_length=1000, features=features)

import bokeh
bokeh.io.output_notebook()

bokeh_figure = record.plot_with_bokeh()
bokeh.plotting.show(bokeh_figure)

from bokeh.embed import file_html
from bokeh.resources import CDN
with open("plot_with_bokeh.html", "w+") as f:
    f.write(file_html(bokeh_figure, CDN, "Example Sequence"))