sjspielman / pyvolve

Python library to simulate evolutionary sequence data
Other
78 stars 23 forks source link

Bio.Alphabet #19

Closed Becheler closed 3 years ago

Becheler commented 3 years ago

Hello :) Thanks again for this wonderful resource that is pyvolve. I just had this error, which I never had before, and I was wondering how to fix it:

File "/home/becheler/.local/lib/python3.8/site-packages/pyvolve/evolver.py", line 216, in __call__
    self._write_sequences(self.leaf_seqs)
  File "/home/becheler/.local/lib/python3.8/site-packages/pyvolve/evolver.py", line 284, in _write_sequences
    from Bio.Alphabet import generic_alphabet
  File "/home/becheler/.local/lib/python3.8/site-packages/Bio/Alphabet/__init__.py", line 20, in <module>
    raise ImportError(
ImportError: Bio.Alphabet has been removed from Biopython. In many cases, the alphabet can simply be ignored and removed from scripts. In a few cases, you may need to specify the ``molecule_type`` as an annotation on a SeqRecord for your script to work correctly. Please see https://biopython.org/wiki/Alphabet for more information.

I'm using pyvolve v1.0.2 and biopython 1.78. Thanks ! Edit: Here a page concerning the replacement of alphabet https://biopython.org/wiki/Alphabet

sjspielman commented 3 years ago

Hi @Becheler, can you please send me the code and all necessary files to reproduce this error? I can only look into this error with that information. Thanks, Stephanie

Becheler commented 3 years ago

Hey @sjspielman thanks fro your answer, I will clear things a bit before to send you a reproducible example ;)

Becheler commented 3 years ago

Hi again, Here is a minimal script:

example.py

import pyvolve

def evolve(tree, sequence_size, scale_tree):

    my_model = pyvolve.Model("nucleotide")
    partition = pyvolve.Partition(models = my_model, size = sequence_size)
    tree = pyvolve.read_tree(tree = tree, scale_tree = scale_tree)
    my_evolver = pyvolve.Evolver(tree = tree, partitions = partition)
    my_evolver(seqfile="seq.fasta", seqfmt = "fasta", ratefile = None, infofile = None)
    return

tree = "(t4:0.785,(t3:0.380,(t2:0.806,(t5:0.612,t1:0.660):0.762):0.921):0.207);"
sequences = evolve(tree, 500, 2.5)

Running in the terminal python3 example.py:

Traceback (most recent call last):
  File "example.py", line 14, in <module>
    sequences = evolve(tree, 500, 2.5)
  File "example.py", line 9, in evolve
    my_evolver(seqfile="seq.fasta", seqfmt = "fasta", ratefile = None, infofile = None)
  File "/home/becheler/.local/lib/python3.8/site-packages/pyvolve/evolver.py", line 216, in __call__
    self._write_sequences(self.leaf_seqs)
  File "/home/becheler/.local/lib/python3.8/site-packages/pyvolve/evolver.py", line 284, in _write_sequences
    from Bio.Alphabet import generic_alphabet
  File "/home/becheler/.local/lib/python3.8/site-packages/Bio/Alphabet/__init__.py", line 20, in <module>
    raise ImportError(
ImportError: Bio.Alphabet has been removed from Biopython. In many cases, the alphabet can simply be ignored and removed from scripts. In a few cases, you may need to specify the ``molecule_type`` as an annotation on a SeqRecord for your script to work correctly. Please see https://biopython.org/wiki/Alphabet for more information.
guilhermetabordaribas commented 3 years ago

Hello dear @Becheler, how are you?

Please, verify the installed biopython version. The "Bio.Alphabet" has been removed from the new biopython version 1.78, as you can see detailed here (https://biopython.org/wiki/Alphabet) . If 1.78 is the version installed in your environment, try replace it to biopython 1.77 version.

Att.

sjspielman commented 3 years ago

Hi all,

Ok, looks like pyvolve needs some updating if Alphabet has been removed from the current version of Biopython. I will hopefully be able to get to this resolved in the nearish future so that pyvolve can be compatible with all versions. It's a real shame that such a minor Biopython update from 1.77--> 1.78 led to code that is NOT backwards compatible....

-Stephanie

Becheler commented 3 years ago

@guilhermetabordaribas I'm doing well thanks :) I hope everyone is holding up with covid ! Thanks for the downgrade idea, I'll do that meanwhile pyvolve receives the fix ! @sjspielman thanks for your answer. Yeah I totally agree it is kind of weird, if the backward compatibility is broken it should have been a major version change. I guess mistakes happen even at biopython ^^ ! Take care!

sjspielman commented 3 years ago

Finally, winter break has given me some time to deal with this. The issue should be fixed now - I have confirmed pyvolve is now compatible with BOTH <=1.77 and >=1.78 (unless Bio does more funky things ¯_(ツ)_/¯ ).

Upgrading to a new patch release that fixes this bug now. Look for version 1.0.3!

Becheler commented 3 years ago

Awesome :+1: I wish you all wonderful holidays!