Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test(self):
expected = [
(Sequence('read1/1 some text', 'TTATTTGTCTCCAGC', '##HHHHHHHHHHHHH'),
Sequence('read1/2 other text', 'GCTGGAGACAAATAA', 'HHHHHHHHHHHHHHH')),
(Sequence('read3/1', 'CCAACTTGATATTAATAACA', 'HHHHHHHHHHHHHHHHHHHH'),
Sequence('read3/2', 'TGTTATTAATATCAAGTTGG', '#HHHHHHHHHHHHHHHHHHH')),
(Sequence('read5', 'TTATTTGTCTCCAGC', '#####HHHHHHHHHH'),
Sequence('read5', 'CAACAGGCCACATTAGACATATCGGATGGT', 'HHHHHHHH##HHHHHHHHHHHHHHHHHHHH')),
]
reads = list(InterleavedSequenceReader("tests/cut/interleaved.fastq"))
for (r1, r2), (e1, e2) in zip(reads, expected):
print(r1, r2, e1, e2)
assert reads == expected
with openseq("tests/cut/interleaved.fastq", interleaved=True) as f:
reads = list(f)
assert reads == expected
def test_autodetect_fasta_format(self):
path = os.path.join(self._tmpdir, 'tmp.fasta')
with openseq(path, mode='w') as f:
assert isinstance(f, FastaWriter)
for seq in simple_fastq:
f.write(seq)
assert list(openseq(path)) == simple_fasta
def test_sequence_reader(self):
# test the autodetection
with openseq("tests/data/simple.fastq") as f:
reads = list(f)
assert reads == simple_fastq
with openseq("tests/data/simple.fasta") as f:
reads = list(f)
assert reads == simple_fasta
with open("tests/data/simple.fastq") as f:
reads = list(openseq(f))
assert reads == simple_fastq
# make the name attribute unavailable
f = StringIO(open("tests/data/simple.fastq").read())
reads = list(openseq(f))
assert reads == simple_fastq
f = StringIO(open("tests/data/simple.fasta").read())
reads = list(openseq(f))
assert reads == simple_fasta
def test_sequence_reader(self):
# test the autodetection
with openseq("tests/data/simple.fastq") as f:
reads = list(f)
assert reads == simple_fastq
with openseq("tests/data/simple.fasta") as f:
reads = list(f)
assert reads == simple_fasta
with open("tests/data/simple.fastq") as f:
reads = list(openseq(f))
assert reads == simple_fastq
# make the name attribute unavailable
f = StringIO(open("tests/data/simple.fastq").read())
reads = list(openseq(f))
assert reads == simple_fastq
def test_fastq_qualities_missing(self):
path = os.path.join(self._tmpdir, 'tmp.fastq')
openseq(path, mode='w', qualities=False)
def test_context_manager(self):
filename = "tests/data/simple.fastq"
with open(filename) as f:
assert not f.closed
reads = list(openseq(f))
assert not f.closed
assert f.closed
with FastqReader(filename) as sr:
tmp_sr = sr
assert not sr._file.closed
reads = list(sr)
assert not sr._file.closed
assert tmp_sr._file is None
def test_sequence_reader(self):
# test the autodetection
with openseq("tests/data/simple.fastq") as f:
reads = list(f)
assert reads == simple_fastq
with openseq("tests/data/simple.fasta") as f:
reads = list(f)
assert reads == simple_fasta
with open("tests/data/simple.fastq") as f:
reads = list(openseq(f))
assert reads == simple_fastq
# make the name attribute unavailable
f = StringIO(open("tests/data/simple.fastq").read())
reads = list(openseq(f))
assert reads == simple_fastq
f = StringIO(open("tests/data/simple.fasta").read())
reads = list(openseq(f))
assert reads == simple_fasta
def test_autodetect_fasta_format(self):
path = os.path.join(self._tmpdir, 'tmp.fasta')
with openseq(path, mode='w') as f:
assert isinstance(f, FastaWriter)
for seq in simple_fastq:
f.write(seq)
assert list(openseq(path)) == simple_fasta
def test_write_qualities_to_fasta(self):
path = os.path.join(self._tmpdir, 'tmp.fasta')
with openseq(path, mode='w', qualities=True) as f:
assert isinstance(f, FastaWriter)
for seq in simple_fastq:
f.write(seq)
assert list(openseq(path)) == simple_fasta
def test_autodetect_fastq_format(self):
path = os.path.join(self._tmpdir, 'tmp.fastq')
with openseq(path, mode='w') as f:
assert isinstance(f, FastqWriter)
for seq in simple_fastq:
f.write(seq)
assert list(openseq(path)) == simple_fastq