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 ignores strand=0 and still plots arrowhead #55

Closed kiramt closed 2 years ago

kiramt commented 3 years ago

Using the GraphicRecord::plot with strand=0 plots a feature without an arrowhead but GraphicRecord::plot_with_bokeh treats strand=0 as the same as strand=+1.

Looks like an easy fix in BokehPlottableMixin::bokeh_feature_patch?

        if strand > 0:
            head_base = max(x1, x2 - delta)
        elif strand < 0:
            head_base = min(x1, x2 + delta)
        else:
            head_base = x2
veghp commented 3 years ago

Thank you very much for bringing attention to this, and providing a solution. It is now part of the dev branch and will be included in the next release. Reproducible example (for Jupyter):

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)
record.plot(figure_width=5)

import bokeh
bokeh.io.output_notebook()
bokeh_figure = record.plot_with_bokeh()
bokeh.plotting.show(bokeh_figure)