File: annotation.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 (29 lines) | stat: -rw-r--r-- 1,011 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
"""Contains functions to annotate macromolecular entities."""

from cogent.core.entity import HIERARCHY

__author__ = "Marcin Cieslik"
__copyright__ = "Copyright 2007-2012, The Cogent Project"
__credits__ = ["Marcin Cieslik"]
__license__ = "GPL"
__version__ = "1.5.3"
__maintainer__ = "Marcin Cieslik"
__email__ = "mpc4p@virginia.edu"
__status__ = "Development"

def xtradata(data, entity):
    """Annotates an entity with data from a ``{full_id:data}`` dictionary. The
    ``data`` should also be a dictionary.
    
    Arguments:
        - data: a dictionary, which is a mapping of full_id's (keys) and data
                dictionaries.
        - entity: top-level entity, which contains the entities which will hold 
                  the data."""
    for full_id, data in data.iteritems():
        sub_entity = entity
        strip_full_id = [i for i in full_id if i is not None]
        for short_id in strip_full_id:
            sub_entity = sub_entity[(short_id,)]
        sub_entity.xtra.update(data)