Skip to content

Commit

Permalink
Move more SFF tests to test_SffIO.py
Browse files Browse the repository at this point in the history
  • Loading branch information
peterjc committed Jan 8, 2016
1 parent b3d52cd commit f4d9503
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
37 changes: 0 additions & 37 deletions Bio/SeqIO/SffIO.py
Expand Up @@ -1311,47 +1311,10 @@ def write_record(self, record):
with open(filename, "rb") as handle:
metadata = ReadRocheXmlManifest(handle)

from Bio._py3k import StringIO
from io import BytesIO

with open(filename, "rb") as handle:
sff = list(SffIterator(handle))

with open("../../Tests/Roche/E3MFGYR02_alt_index_at_end.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
assert len(sff) == len(sff2)
for old, new in zip(sff, sff2):
assert old.id == new.id
assert str(old.seq) == str(new.seq)

with open("../../Tests/Roche/E3MFGYR02_alt_index_at_start.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
assert len(sff) == len(sff2)
for old, new in zip(sff, sff2):
assert old.id == new.id
assert str(old.seq) == str(new.seq)

with open("../../Tests/Roche/E3MFGYR02_alt_index_in_middle.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
assert len(sff) == len(sff2)
for old, new in zip(sff, sff2):
assert old.id == new.id
assert str(old.seq) == str(new.seq)

with open("../../Tests/Roche/E3MFGYR02_index_at_start.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
assert len(sff) == len(sff2)
for old, new in zip(sff, sff2):
assert old.id == new.id
assert str(old.seq) == str(new.seq)

with open("../../Tests/Roche/E3MFGYR02_index_in_middle.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
assert len(sff) == len(sff2)
for old, new in zip(sff, sff2):
assert old.id == new.id
assert str(old.seq) == str(new.seq)

with open(filename, "rb") as handle:
sff_trim = list(SffIterator(handle, trim=True))

Expand Down
45 changes: 45 additions & 0 deletions Tests/test_SffIO.py
Expand Up @@ -4,6 +4,7 @@
# license. Please see the LICENSE file that should have been included
# as part of this package.

import sys
import re
import unittest
from io import BytesIO
Expand Down Expand Up @@ -263,6 +264,50 @@ def test_both_ways(self):
self.assertEqual(len(index1), len(list(SffIterator(BytesIO(handle.read())))))


class TestAlternativeIndexes(unittest.TestCase):
filename = "Roche/E3MFGYR02_random_10_reads.sff"
with open(filename, "rb") as handle:
sff = list(SffIterator(handle))

def check_same(self, new_sff):
self.assertEqual(len(self.sff), len(new_sff))
for old, new in zip(self.sff, new_sff):
self.assertEqual(old.id, new.id)
self.assertEqual(str(old.seq), str(new.seq))

def test_alt_index_at_end(self):
with open("Roche/E3MFGYR02_alt_index_at_end.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
self.check_same(sff2)

def test_alt_index_at_start(self):
with open("Roche/E3MFGYR02_alt_index_at_start.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
self.check_same(sff2)

def test_alt_index_in_middle(self):
with open("Roche/E3MFGYR02_alt_index_in_middle.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
self.check_same(sff2)

def test_index_at_start(self):
with open("Roche/E3MFGYR02_index_at_start.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
self.check_same(sff2)

def test_index_in_middle(self):
with open("Roche/E3MFGYR02_index_in_middle.sff", "rb") as handle:
sff2 = list(SffIterator(handle))
self.check_same(sff2)

def test_trim(self):
with open(self.filename, "rb") as handle:
sff_trim = list(SffIterator(handle, trim=True))
self.assertEqual(len(self.sff), len(sff_trim))
for old, new in zip(self.sff, sff_trim):
self.assertEqual(old.id, new.id)


class TestConcatenated(unittest.TestCase):
def test_parses_gzipped_stream(self):
import gzip
Expand Down

0 comments on commit f4d9503

Please sign in to comment.