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 does not work with features without labels #7

Closed joost823 closed 6 years ago

joost823 commented 6 years ago

Small example:

from bokeh.resources import CDN
from bokeh.embed import file_html
from dna_features_viewer import GraphicFeature, GraphicRecord

features_label = [GraphicFeature(start=1, end=11, strand=1, color='green', label='some label')]
features_no_label =  [GraphicFeature(start=1, end=11, strand=1, color='green')]

record_label = GraphicRecord(sequence_length=15, features=features_label, first_index = 0)
record_no_label = GraphicRecord(sequence_length=15, features=features_no_label, first_index = 0)

plot_label = record_label.plot_with_bokeh(figure_width=8)
plot_no_label = record_no_label.plot_with_bokeh(figure_width=8)

Error: File "test.py", line 12, in plot_no_label = record_no_label.plot_with_bokeh(figure_width=8) File "C:\Users\user\Desktop\venv\lib\site-packages\dna_features_viewer\GraphicRecord.py", line 428, in plot_with_bokeh max_y = max([data["annotation_y"] for f, data in plot_data.items()]) ValueError: max() arg is an empty sequence

Which, after some trial and error seems to originate in line 213 in GraphicRecord.py

 if feature.label is not None:

I'm not sure if this is part of the design, or a bug. But in either case, I't be nice to have a 'you need labels' error message so you know what to change instead of just trying by trial and error.

Apart from that, great package!

Zulko commented 6 years ago

Thanks for the report ! That was a bug. My last commits fix this problem (hopefully for good, I have added a scenario with no labels to the test suite).