def test_autodetect_fastq_format(self): path = os.path.join(self._tmpdir, 'tmp.fastq') fmt = get_format(path) with open_output(path, "w") as f: for seq in simple_fastq: f.write(fmt.format(seq)) assert list(openseq(path)) == simple_fastq
def test_write_qualities_to_fasta(self): path = os.path.join(self._tmpdir, 'tmp.fasta') fmt = get_format(path, qualities=True) assert isinstance(fmt, FastaFormat) with open_output(path, "w") as f: for seq in simple_fastq: f.write(fmt.format(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_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(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')) ] 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): 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'))] 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