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

Add a minimal FASTA parser to run tests without Biopython or scikit-bio

parent 244e76f2
No related branches found
No related tags found
No related merge requests found
......@@ -72,9 +72,8 @@ jobs:
path: dist
- name: Install built wheel
run: python -m pip install --no-index --find-links=dist pyfastani
- name: Install numpy
run: python -m pip install numpy
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
- name: Get FastANI test files
run: git clone https://github.com/ParBLiSS/FastANI vendor/FastANI
- name: Run tests without coverage
run: python -m unittest pyfastani.tests -vv
......@@ -136,9 +135,8 @@ jobs:
path: dist
- name: Install built wheel
run: python -m pip install --no-index --find-links=dist pyfastani
- name: Install numpy
run: python -m pip install numpy
if: ${{ !startsWith(matrix.python-version, 'pypy') }}
- name: Get FastANI test files
run: git clone https://github.com/ParBLiSS/FastANI vendor/FastANI
- name: Run tests without coverage
run: python -m unittest pyfastani.tests -vv
......
import collections
class Record(collections.namedtuple("Record", ["id", "seq", "description"])):
pass
def parse(path):
if isinstance(path, str):
file = open(path)
else:
file = path
with file:
id_ = None
for line in file:
if line.startswith(">"):
if id_ is not None:
yield Record(id_, "".join(seq), desc)
id_ = line[1:].split()[0].strip()
desc = " ".join(line[1:].split(maxsplit=1))
seq = []
else:
seq.append(line.strip())
if id_ is not None:
yield Record(id_, "".join(seq), desc)
biopython
biopython ; implementation_name == "cpython"
scikit-bio ; implementation_name == "cpython"
......@@ -3,11 +3,12 @@ import unittest
import pyfastani
from . import minifasta
PROJECT_PATH = os.path.realpath(os.path.join(__file__, "..", "..", ".."))
FASTANI_PATH = os.path.join(PROJECT_PATH, "vendor", "FastANI")
class _TestMapper(object):
def _load_fasta():
......@@ -42,6 +43,15 @@ class _TestMapper(object):
self.assertAlmostEqual(hits[0].identity, 97.664, places=4)
class TestMapper(_TestMapper, unittest.TestCase):
def _load_fasta(self, path):
return list(minifasta.parse(path))
def _get_sequence(self, record):
return record.seq.encode()
try:
from skbio import io as skbio_io
except ImportError:
......
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