Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import shutil
from textwrap import dedent
import pytest
from nose.tools import raises
from tempfile import mkdtemp
from cutadapt.seqio import (Sequence, FormatError,
FastaReader, FastqReader, InterleavedSequenceReader,
FastaWriter, FastqWriter, InterleavedSequenceWriter, open as openseq,
sequence_names_match, find_fastq_record_end,
read_paired_chunks, read_chunks_from_file)
from cutadapt._seqio import two_fastq_heads # re-exported
# files tests/data/simple.fast{q,a}
simple_fastq = [
Sequence("first_sequence", "SEQUENCE1", ":6;;8<=:<"),
Sequence("second_sequence", "SEQUENCE2", "83
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(self):
reads = [
(Sequence('A/1 comment', 'TTA', '##H'),
Sequence('A/2 comment', 'GCT', 'HH#')),
(Sequence('B/1', 'CC', 'HH'),
Sequence('B/2', 'TG', '#H'))
]
sio = StringIO()
with InterleavedSequenceWriter(sio) as writer:
for read1, read2 in reads:
writer.write(read1, read2)
assert sio.getvalue() == '@A/1 comment\nTTA\n+\n##H\n@A/2 comment\nGCT\n+\nHH#\n@B/1\nCC\n+\nHH\n@B/2\nTG\n+\n#H\n'
def test(self):
reads = [
(Sequence('A/1 comment', 'TTA', '##H'),
Sequence('A/2 comment', 'GCT', 'HH#')),
(Sequence('B/1', 'CC', 'HH'),
Sequence('B/2', 'TG', '#H'))
]
sio = StringIO()
with InterleavedSequenceWriter(sio) as writer:
for read1, read2 in reads:
writer.write(read1, read2)
assert sio.getvalue() == '@A/1 comment\nTTA\n+\n##H\n@A/2 comment\nGCT\n+\nHH#\n@B/1\nCC\n+\nHH\n@B/2\nTG\n+\n#H\n'
def match(name1, name2):
seq1 = Sequence(name1, 'ACGT')
seq2 = Sequence(name2, 'AACC')
return sequence_names_match(seq1, seq2)
def match(name1, name2):
seq1 = Sequence(name1, 'ACGT')
seq2 = Sequence(name2, 'AACC')
return sequence_names_match(seq1, seq2)
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'