Logo Search packages:      
Sourcecode: python-biopython version File versions  Download package


# Copyright 2001 by Katharine Lindner.  All rights reserved.
# Copyright 2006 by PeterC.  All rights reserved.
# Copyright 2007 by Michiel de Hoon.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.
"""Parser for files from NCBI's Gene Expression Omnibus (GEO).


import Record

def _read_key_value(line):
    words = line[1:].split("=", 1)
        key, value = words
        value = value.strip()
    except ValueError:
        key = words[0]
        value = ""
    key = key.strip()
    return key, value

def parse(handle):
    record = None
    for line in handle:
        line = line.strip('\n').strip('\r')
        if not line: continue # Ignore empty lines
        c = line[0]
        if c=='^':
            if record: yield record
            record = Record.Record()
            record.entity_type, record.entity_id = _read_key_value(line)
        elif c=='!':
            if line in ('!Sample_table_begin',
            key, value = _read_key_value(line)
            if key in record.entity_attributes:
                if type(record.entity_attributes[key])==list:
                    existing = record.entity_attributes[key]
                    record.entity_attributes[key] = [existing, value]
                record.entity_attributes[key] = value
        elif c=='#':
            key, value = _read_key_value(line)
            assert key not in record.col_defs
            record.col_defs[key] = value
            row = line.split("\t")
    yield record

Generated by  Doxygen 1.6.0   Back to index