Changeset 1736:b3b664abcfdd in orange-bioinformatics for _bioinformatics/obiKEGG/databases.py


Ignore:
Timestamp:
04/05/13 19:43:36 (13 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Added sphinx rst documentation for obiKEGG.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • _bioinformatics/obiKEGG/databases.py

    r1734 r1736  
    11""" 
    2 DBGET database 
     2DBGET Database Interface 
     3======================== 
     4 
    35""" 
    46from __future__ import absolute_import 
     
    1214 
    1315def iter_take(source_iter, n): 
     16    """ 
     17    Return a list of the first `n` items in `source_iter`. 
     18    """ 
    1419    source_iter = iter(source_iter) 
    1520    return [item for _, item in zip(range(n), source_iter)] 
     
    1722 
    1823def batch_iter(source_iter, n): 
     24    """ 
     25    Split the `source_iter` into batches of size `n`. 
     26    """ 
    1927    source_iter = iter(source_iter) 
    2028    while True: 
     
    4654class DBDataBase(object): 
    4755    """ 
    48     A wrapper for DBGET database. 
    49  
    50     """ 
    51     # ENTRY_TYPE constructor (type) 
     56    Base class for a DBGET database interface. 
     57 
     58    """ 
     59    #: ENTRY_TYPE constructor (a :class:`~.entry.DBEntry` subclass). This 
     60    #: should be redefined in subclasses. 
    5261    ENTRY_TYPE = entry.DBEntry 
    5362 
    54     # A database name/abbreviation (e.g. path). Needs to be set in a 
    55     # subclass or object instance's constructor 
     63    #: A database name/abbreviation (e.g. 'pathway'). Needs to be set in a 
     64    #: subclass or object instance's constructor before calling the base. 
     65    #: __init__ 
    5666    DB = None 
    5767 
     
    6979    def keys(self): 
    7080        """ 
    71         Return a list of database keys. These are unique kegg identifiers 
     81        Return a list of database keys. These are unique KEGG identifiers 
    7282        that can be used to query the database. 
    7383 
     
    7787    def iterkeys(self): 
    7888        """ 
    79         Return an iterator over the `keys` 
     89        Return an iterator over the `keys`. 
    8090        """ 
    8191        return iter(self._keys) 
     
    8393    def items(self): 
    8494        """ 
    85         Return a list of all (key, `ENTRY_TYPE` instance) tuples. 
     95        Return a list of all (key, :obj:`DBDataBase.ENTRY_TYPE` instance) 
     96        tuples. 
     97 
    8698        """ 
    8799        return list(zip(self.keys(), self.batch_get(self.keys()))) 
     
    98110    def values(self): 
    99111        """ 
    100         Return a list of all `ENTRY_TYPE` instances. 
     112        Return a list of all :obj:`DBDataBase.ENTRY_TYPE` instances. 
    101113        """ 
    102114        return self.batch_get(self.keys()) 
     
    104116    def itervalues(self): 
    105117        """ 
    106         Return an iterator over all `ENTRY_TYPE` instances. 
     118        Return an iterator over all :obj:`DBDataBase.ENTRY_TYPE` instances. 
    107119        """ 
    108120        batch_size = 100 
     
    113125    def get(self, key, default=None): 
    114126        """ 
    115         Return an `ENTRY_TYPE` instance for the `key`. Raises `KeyError` if 
    116         not found. 
     127        Return an :obj:`DBDataBase.ENTRY_TYPE` instance for the `key`. 
     128        Raises :class:`KeyError` if not found. 
    117129 
    118130        """ 
     
    160172    def find(self, name): 
    161173        """ 
    162         Find ``name`` using kegg ``find`` api. 
     174        Find `name` using kegg `find` api. 
    163175        """ 
    164176        res = self.api.find(self.DB, name).splitlines() 
     
    167179    def pre_cache(self, keys=None, batch_size=10, progress_callback=None): 
    168180        """ 
    169         Retrieve all the entries and cache them locally. 
    170         """ 
    171         # TODO do this in multiple threads 
    172  
     181        Retrieve all the entries for `keys` and cache them locally for faster 
     182        subsequent retrieval. If `keys` is ``None`` then all entries will be 
     183        retrieved. 
     184 
     185        """ 
    173186        if not isinstance(self.api, api.CachedKeggApi): 
    174187            raise TypeError("Not an instance of api.CachedKeggApi") 
     
    268281        return self.TAXONOMY.taxid 
    269282 
    270 #    def org_code(self): 
    271 #        if self.name is not None: 
    272 #            return self.name.split(",")[0] 
    273 #        else: 
    274 #            return self.entry.split(" ")[0] 
     283    def org_code(self): 
     284        # for backwards compatibility; return the `organism_code` 
     285        return self.organism_code 
    275286 
    276287 
     
    383394 
    384395class Genes(DBDataBase): 
     396    """ 
     397    Interface to the KEGG Genes database. 
     398 
     399    :param org_code: KEGG organism code (e.g. 'hsa'). 
     400    :type org_code: str 
     401 
     402    """ 
    385403    DB = None  # Needs to be set in __init__ 
    386404    ENTRY_TYPE = GeneEntry 
Note: See TracChangeset for help on using the changeset viewer.