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

Error on BioPython v1.8.0 #73

Closed mbiokyle29 closed 1 year ago

mbiokyle29 commented 1 year ago

We are getting the following error when using DnaFeaturesViewer with BioPython v1.8.0 (tag):

In [5]: from dna_features_viewer import GraphicFeature
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 from dna_features_viewer import GraphicFeature

File .venv/lib/python3.8/site-packages/dna_features_viewer/__init__.py:3, in <module>
      1 """ dna_features_viewer/__init__.py """
----> 3 from .GraphicRecord import GraphicRecord
      4 from .CircularGraphicRecord import CircularGraphicRecord
      5 from .GraphicFeature import GraphicFeature

File .venv/lib/python3.8/site-packages/dna_features_viewer/GraphicRecord/__init__.py:1, in <module>
----> 1 from .GraphicRecord import GraphicRecord
      3 __all__ = ['GraphicRecord']

File .venv/lib/python3.8/site-packages/dna_features_viewer/GraphicRecord/GraphicRecord.py:1, in <module>
----> 1 from ..biotools import find_narrowest_text_wrap
      3 from Bio.Seq import Seq
      4 from Bio.SeqRecord import SeqRecord

File .venv/lib/python3.8/site-packages/dna_features_viewer/biotools.py:38, in <module>
     28     """Return the reverse-complement of the DNA sequence.
     29 
     30     For instance ``complement("ATGCCG")`` returns ``"GCCGTA"``.
     31 
     32     Uses BioPython for speed.
     33     """
     34     return complement(sequence)[::-1]
     37 aa_short_to_long_form_dict = {
---> 38     _aa1: _aa3[0] + _aa3[1:].lower() for (_aa1, _aa3) in zip(aa1 + "*", aa3 + ["*"])
     39 }
     42 def translate(dna_sequence, long_form=False):
     43     """Translate the DNA sequence into an amino-acids sequence MLKYQT...
     44 
     45     If long_form is true, a list of 3-letter amino acid representations
     46     is returned instead (['Ala', 'Ser', ...]).
     47     """

TypeError: can only concatenate tuple (not "str") to tuple

It appears the aa1 and aa3 objects were updated to a different structure.

RealYHD commented 1 year ago

Having this exact issue. I was worried I broke something in my Conda environment. I've confirmed this is also a problem with Biopython version 1.80 as well as 1.79. I didn't test older versions.

A cursory glance makes me think Biopython version 1.79 is the one with the breaking change as they mention changing how sequence objects store their data.

From their changelogs for 1.79,

The Seq and MutableSeq classes in Bio.Seq now store their sequence contents as bytes and bytearray objects, respectively. - Biopython News

mbiokyle29 commented 1 year ago

@RealYHD - interesting that you were experiencing the issue with 1.79, we hard pinned BioPython==1.79 in our requirements file and it resolved the issue for us.

RealYHD commented 1 year ago

@mbiokyle29 Ah my bad, I was using Jupyter Labs and it seems the kernel cached the 1.80 version of biopython. As you said, 1.79 works, in that case, disregard what I said previously.

veghp commented 1 year ago

Thank you all for bringing attention to this, I'll work on it. We have tested the current release against 1.79, and that 1.80 was released on the same day this error surfaced suggests that the issue is with 1.80.

The changelog does not mention this although it may be related to the dict replacement.

In the meantime I agree pinning to 1.79 solves this, or using a separate image / environment. Thanks for understanding.

mbiokyle29 commented 1 year ago

@veghp - thanks for the response and for all your work on this great package. It seems like quite a change for them to include in a minor release, so some fall out is to be expected.

jbloom commented 1 year ago

Just noting that I also have this issue with the new biopython 1.80.

antonkulaga commented 1 year ago

I have the same error, it broke all my code when biopython got updated :( Screenshot from 2022-12-02 01-59-46

antonkulaga commented 1 year ago

Any updates on that? I have a pip package that depends on dna-features-viewer and it is currently broken (cannot have github dependencies in setup.py)

Zulko commented 1 year ago

@antonkulaga Have you tried pinning biopython==1.79 in your dependencies? It's not ideal but should get you going until a fix is released.