Beispiel #1
0
	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
Beispiel #2
0
 def test_write_to_file_like_object(self):
     sio = StringIO()
     with FastqWriter(sio) as fq:
         fq.writeseq("name", "CCATA", "!#!#!")
         fq.writeseq("name2", "HELLO", "&&&!&&")
     assert sio.getvalue(
     ) == '@name\nCCATA\n+\n!#!#!\n@name2\nHELLO\n+\n&&&!&&\n'
Beispiel #3
0
 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
Beispiel #4
0
 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'
Beispiel #5
0
	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'
Beispiel #6
0
    def test(self):
        with FastaReader("tests/data/simple.fasta") as f:
            reads = list(f)
        assert reads == simple_fasta

        fasta = StringIO(">first_sequence\nSEQUENCE1\n>second_sequence\nSEQUENCE2\n")
        reads = list(FastaReader(fasta))
        assert reads == simple_fasta
Beispiel #7
0
def test_wrong_fasta_format():
    fasta = StringIO(
        dedent("""
		# a comment
		# another one
		unexpected
		>first_sequence
		SEQUENCE1
		>second_sequence
		SEQUENCE2
		"""))
    reads = list(seqio.FastaReader(fasta))
Beispiel #8
0
def test_fastareader_with_comments():
    fasta = StringIO(
        dedent("""
		# a comment
		# another one
		>first_sequence
		SEQUENCE1
		>second_sequence
		SEQUENCE2
		"""))
    reads = list(seqio.FastaReader(fasta))
    assert reads == simple_fasta
Beispiel #9
0
def test_sequence_reader():
    # test the autodetection
    with seqio.open("tests/data/simple.fastq") as f:
        reads = list(f)
    assert reads == simple_fastq

    with seqio.open("tests/data/simple.fasta") as f:
        reads = list(f)
    assert reads == simple_fasta

    with open("tests/data/simple.fastq") as f:
        reads = list(seqio.open(f))
    assert reads == simple_fastq

    # make the name attribute unavailable
    f = StringIO(open("tests/data/simple.fastq").read())
    reads = list(seqio.open(f))
    assert reads == simple_fastq

    f = StringIO(open("tests/data/simple.fasta").read())
    reads = list(seqio.open(f))
    assert reads == simple_fasta
Beispiel #10
0
def test_quiet_is_quiet():
    captured_standard_output = StringIO()
    captured_standard_error = StringIO()
    old_stdout = sys.stdout
    old_stderr = sys.stderr
    try:
        sys.stdout = captured_standard_output
        sys.stderr = captured_standard_error
        cutadapt.main(['-o', '/dev/null', '--quiet', '-a', 'XXXX', datapath('illumina.fastq.gz')])
    finally:
        sys.stdout = old_stdout
        sys.stderr = old_stderr
    assert captured_standard_output.getvalue() == ''
    assert captured_standard_error.getvalue() == ''
Beispiel #11
0
def test_fastq_incomplete():
    fastq = StringIO("@name\nACGT+\n")
    with seqio.FastqReader(fastq) as fq:
        list(fq)
Beispiel #12
0
def test_invalid_quality_value():
    fasta = StringIO(">name\nACG")
    qual = StringIO(">name\n3 xx 7")
    list(seqio.FastaQualReader(fasta, qual))
Beispiel #13
0
def test_mismatching_read_names():
    fasta = StringIO(">name\nACG")
    qual = StringIO(">nome\n3 5 7")
    list(seqio.FastaQualReader(fasta, qual))
Beispiel #14
0
 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())
Beispiel #15
0
 def test_incorrectly_paired(self):
     s = StringIO('@r1/1\nACG\n+\nHHH\n@wrong_name\nTTT\n+\nHHH')
     list(InterleavedSequenceReader(s))
Beispiel #16
0
 def test_missing_partner(self):
     s = StringIO('@r1\nACG\n+\nHHH')
     list(InterleavedSequenceReader(s))