def read_sequences(seqfilename, qualityfilename, colorspace, fileformat):
    """
	Read sequences and (if available) quality information from either:
	* seqfilename in FASTA format (qualityfilename must be None)
	* seqfilename in FASTQ format (qualityfilename must be None)
	* seqfilename in .csfasta format and qualityfilename in .qual format
	  (SOLiD color space)

	Return a generator over tuples (description, sequence, qualities).
	qualities is None if no qualities are available.
	qualities are ASCII-encoded (chr(quality) + 33).
	"""
    #if ftype == 'FASTQ' and qualityfilename is not None:
    #raise ValueError("If a FASTQ file is given, no quality file can be provided.")

    if qualityfilename is not None:
        if colorspace:
            # read from .(CS)FASTA/.QUAL
            return seqio.ColorspaceFastaQualReader(seqfilename,
                                                   qualityfilename)
        else:
            return seqio.FastaQualReader(seqfilename, qualityfilename)
    else:
        # read from FASTA or FASTQ
        return seqio.SequenceReader(seqfilename, colorspace, fileformat)
Example #2
0
def test_sequence_reader():
    # test the autodetection
    with seqio.SequenceReader("tests/data/simple.fastq") as f:
        reads = list(f)
    assert reads == simple_fastq

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

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

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

    f = StringIO(open("tests/data/simple.fasta").read())
    reads = list(seqio.SequenceReader(f))
    assert reads == simple_fasta
Example #3
0
def test_context_manager():
    filename = "tests/data/simple.fasta"
    with open(filename) as f:
        assert not f.closed
        reads = list(seqio.SequenceReader(f))
        assert not f.closed
    assert f.closed

    with seqio.FastaReader(filename) as sr:
        tmp_sr = sr
        assert not sr.fp.closed
        reads = list(sr)
        assert not sr.fp.closed
    assert tmp_sr.fp.closed