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):
with FastaWriter(self.path) as fw:
fw.write("name", "CCATA")
fw.write("name2", "HELLO")
assert fw._file.closed
with open(self.path) as t:
assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
def test_write_sequence_object(self):
with FastaWriter(self.path) as fw:
fw.write(Sequence("name", "CCATA"))
fw.write(Sequence("name2", "HELLO"))
assert fw._file.closed
with open(self.path) as t:
assert t.read() == '>name\nCCATA\n>name2\nHELLO\n'
def test_write_zero_length_sequence(self):
sio = StringIO()
with FastaWriter(sio) as fw:
fw.write(Sequence("name", ""))
assert sio.getvalue() == '>name\n\n', '{0!r}'.format(sio.getvalue())
def test_write_to_file_like_object(self):
sio = StringIO()
with FastaWriter(sio) as fw:
fw.write(Sequence("name", "CCATA"))
fw.write(Sequence("name2", "HELLO"))
assert sio.getvalue() == '>name\nCCATA\n>name2\nHELLO\n'
assert not fw._file.closed
def test_linelength(self):
with FastaWriter(self.path, line_length=3) as fw:
fw.write("r1", "ACG")
fw.write("r2", "CCAT")
fw.write("r3", "TACCAG")
assert fw._file.closed
with open(self.path) as t:
d = t.read()
assert d == '>r1\nACG\n>r2\nCCA\nT\n>r3\nTAC\nCAG\n'
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