File: illumina_sequence.py

package info (click to toggle)
python-cogent 1.5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,424 kB
  • ctags: 24,343
  • sloc: python: 134,200; makefile: 100; ansic: 17; sh: 10
file content (32 lines) | stat: -rw-r--r-- 858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
"""Tests of Illumina sequence file parser.
"""

__author__ = "Greg Caporaso"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__credits__ = ["Greg Caporaso", "Gavin Huttley"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Greg Caporaso"
__email__ = "gregcaporaso@gmail.com"
__status__ = "Production"

def MinimalIlluminaSequenceParser(data):
    """ Yields (header, sequence, quality strings) given an Illumina sequence file
    """
    if hasattr(data,'lower'):
        # passed a string so open filepath
        data = open(data,'U')
    
    for line in data:
        fields = line.strip().split(':')
        yield fields[:-2], fields[-2], fields[-1]
    
    try:
        # if data is a file, close it
        data.close()
    except AttributeError:
        # otherwise do nothing
        pass
    
    return