Skip to content
Snippets Groups Projects
Commit eec01585 authored by Martin Larralde's avatar Martin Larralde
Browse files

Fix tests to work with new versions of Biopython

parent a240a18b
No related branches found
No related tags found
No related merge requests found
......@@ -45,7 +45,9 @@ affect the `name` attribute of the hits returned for a query.*
### 🔬 [Biopython](https://github.com/biopython/biopython)
Biopython does not let us access to the sequence directly, so we need to
convert it to bytes first with the `encode` method.
convert it to bytes first with the `bytes` builtin function. For older
versions of Biopython (earlier than 1.79), use `record.seq.encode()`
instead of `bytes(record.seq).`
```python
import pyfastani
......@@ -55,12 +57,12 @@ m = pyfastani.Mapper()
# add a single draft genome to the mapper, and index it
ref = list(Bio.SeqIO.parse("vendor/FastANI/data/Shigella_flexneri_2a_01.fna", "fasta"))
m.add_draft("Shigella_flexneri_2a_01", (record.seq.encode() for record in ref))
m.add_draft("Shigella_flexneri_2a_01", (bytes(record.seq) for record in ref))
m.index()
# read the query and query the mapper
query = Bio.SeqIO.read("vendor/FastANI/data/Escherichia_coli_str_K12_MG1655.fna", "fasta")
hits = m.query_sequence(query.seq.encode())
hits = m.query_sequence(bytes(query.seq))
for hit in hits:
print("Escherichia_coli_str_K12_MG1655", hit.name, hit.identity, hit.matches, hit.fragments)
......
......@@ -57,15 +57,16 @@ class TestMapperSkbio(_TestMapper, unittest.TestCase):
return sequence.values.view('B')
try:
from Bio import SeqIO
import Bio.SeqIO
except ImportError:
SeqIO = None
Bio = None
@unittest.skipUnless(SeqIO, "Biopython is required for this test suite")
@unittest.skipUnless(Bio, "Biopython is required for this test suite")
class TestMapperBiopython(_TestMapper, unittest.TestCase):
def _load_fasta(self, path):
return list(SeqIO.parse(path, "fasta"))
return list(Bio.SeqIO.parse(path, "fasta"))
def _get_sequence(self, sequence):
return sequence.seq.encode()
def _get_sequence(self, record):
version = tuple(map(int, Bio.__version__.split(".")))
return record.seq.encode() if version < (1, 79) else bytes(record.seq)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment