~ubuntu-branches/ubuntu/natty/python-cogent/natty

« back to all changes in this revision

Viewing changes to cogent/parse/fastq.py

  • Committer: Bazaar Package Importer
  • Author(s): Steffen Moeller
  • Date: 2010-12-04 22:30:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101204223035-j11kinhcrrdgg2p2
Tags: 1.5-1
* Bumped standard to 3.9.1, no changes required.
* New upstream version.
  - major additions to Cookbook
  - added AlleleFreqs attribute to ensembl Variation objects.
  - added getGeneByStableId method to genome objects.
  - added Introns attribute to Transcript objects and an Intron class.
  - added Mann-Whitney test and a Monte-Carlo version
  - exploratory and confirmatory period estimation techniques (suitable for
    symbolic and continuous data)
  - Information theoretic measures (AIC and BIC) added
  - drawing of trees with collapsed nodes
  - progress display indicator support for terminal and GUI apps
  - added parser for illumina HiSeq2000 and GAiix sequence files as 
    cogent.parse.illumina_sequence.MinimalIlluminaSequenceParser.
  - added parser to FASTQ files, one of the output options for illumina's
    workflow, also added cookbook demo.
  - added functionality for parsing of SFF files without the Roche tools in
    cogent.parse.binary_sff
  - thousand fold performance improvement to nmds
  - >10-fold performance improvements to some Table operations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
__author__ = "Gavin Huttley, Anuj Pahwa"
 
2
__copyright__ = "Copyright 2007-2009, The Cogent Project"
 
3
__credits__ = ["Gavin Huttley", "Anuj Pahwa"]
 
4
__license__ = "GPL"
 
5
__version__ = "1.5.0"
 
6
__maintainer__ = "Gavin Huttley"
 
7
__email__ = "Gavin.Huttley@anu.edu.au"
 
8
__status__ = "Development"
 
9
 
 
10
def MinimalFastqParser(data, strict=True):
 
11
    """yields name, seq, qual from fastq file
 
12
 
 
13
    Arguments:
 
14
        - strict: checks the quality and sequence labels are the same
 
15
    """
 
16
    if type(data) == str:
 
17
        data = open(data)
 
18
 
 
19
    # fastq format is very simple, defined by blocks of 4 lines
 
20
    line_num = -1
 
21
    record = []
 
22
    for line in data:
 
23
        line_num += 1
 
24
        if line_num == 4:
 
25
            if strict: # make sure the seq and qual labels match
 
26
                assert record[0][1:] == record[2][1:], \
 
27
                  'Invalid format: %s -- %s' % (record[0][1:], record[2][1:])
 
28
            yield record[0][1:], record[1], record[3]
 
29
            
 
30
            line_num = 0
 
31
            record = []
 
32
        
 
33
        record.append(line.strip())
 
34
    
 
35
    if record:
 
36
        if strict and record[0]: # make sure the seq and qual labels match
 
37
            assert record[0][1:] == record[2][1:], 'Invalid format'
 
38
        
 
39
        if record[0]: # could be just an empty line at eof
 
40
            yield record[0][1:], record[1], record[3]
 
41
        
 
42
    
 
43
    if type(data) == file:
 
44
        data.close()
 
45