scout/parse/hpo.py
def parse_hpo_obo(hpo_lines):
    """Parse a .obo formated hpo line"""
    term = {}
    for line in hpo_lines:
        if len(line) == 0:
            continue
        line = line.rstrip()
        # New term starts with [Term]
        if line == '[Term]':
            if term:
                yield term
            term = {}
        
        elif line.startswith('id'):
            term['hpo_id'] = line[4:]

        elif line.startswith('name'):
            term['description'] = line[6:]

        elif line.startswith('alt_id'):
            if 'aliases' not in term:
                term['aliases'] = []
            term['aliases'].append(line[8:])
        
        elif line.startswith('is_a'):
            if 'ancestors' not in term:
                term['ancestors'] = []
            term['ancestors'].append(line[6:16])

    if term:
        yield term
def parse_hpo_obo(hpo_lines):
    term = {}
    for line in hpo_lines:
        if len(line) == 0:
            continue
        line = line.rstrip()
        # New term starts with [Term]
        if line == '[Term]':
            if term:
                yield term
            term = {}
        
        elif line.startswith('id'):
            term['hpo_id'] = line[4:]

        elif line.startswith('name'):
            term['description'] = line[6:]

        elif line.startswith('alt_id'):
            if 'aliases' not in term:
                term['aliases'] = []
            term['aliases'].append(line[8:])
        
        elif line.startswith('is_a'):
            if 'ancestors' not in term:
                term['ancestors'] = []
            term['ancestors'].append(line[6:16])

    if term:
        yield term
def parse_hpo_obo ( hpo_lines ) : term = { } for line in hpo_lines : if len ( line ) == 0 : continue line = line . rstrip ( ) # New term starts with [Term] if line == '[Term]' : if term : yield term term = { } elif line . startswith ( 'id' ) : term [ 'hpo_id' ] = line [ 4 : ] elif line . startswith ( 'name' ) : term [ 'description' ] = line [ 6 : ] elif line . startswith ( 'alt_id' ) : if 'aliases' not in term : term [ 'aliases' ] = [ ] term [ 'aliases' ] . append ( line [ 8 : ] ) elif line . startswith ( 'is_a' ) : if 'ancestors' not in term : term [ 'ancestors' ] = [ ] term [ 'ancestors' ] . append ( line [ 6 : 16 ] ) if term : yield term
Parse a .obo formated hpo line
Parse a . obo formated hpo line