1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
from io import StringIO
import pytest
from weblogo.seq import protein_alphabet
from weblogo.seq_io import clustal_io, nexus_io, plain_io
from . import data_stream
def test_read() -> None:
f = data_stream("nexus/protein.nex")
seqs = nexus_io.read(f)
# print seqs
assert len(seqs) == 10
assert seqs[0].name == "Cow"
assert len(seqs[1]) == 234
assert str(seqs[0][0:10]) == "MAYPMQLGFQ"
f.close()
def test_parse_StringIO() -> None:
# Bio.Nexus cannot read from a StringIO object.
f0 = data_stream("nexus/protein.nex")
f = StringIO(f0.read())
nexus_io.read(f)
f0.close()
def test_parse_fasta_fail() -> None:
with pytest.raises(ValueError):
with data_stream("globin.fa") as f:
nexus_io.read(f)
def test_parse_clustal_fail() -> None:
# should fail with parse error
with pytest.raises(ValueError):
f = StringIO(clustal_io.example)
nexus_io.read(f, protein_alphabet)
def test_parse_plain_fail() -> None:
# should fail with parse error
f = StringIO(plain_io.example)
with pytest.raises(ValueError):
nexus_io.read(f)
def test_iterseq() -> None:
f = data_stream("nexus/protein.nex")
for seq in nexus_io.iterseq(f):
pass
def test_read_alphabet() -> None:
f = data_stream("nexus/protein.nex")
seqs = nexus_io.read(f, alphabet=protein_alphabet)
# print seqs
assert len(seqs) == 10
|