Changeset 1350:63636452235c in orange-bioinformatics for obiArrayExpress.py


Ignore:
Timestamp:
03/16/11 12:01:41 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
99878bf68b9b65dc5229896df3f673461869e6b1
Message:

Added more documentation.
Removed the unused caching parameters.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • obiArrayExpress.py

    r1347 r1350  
    11""" 
     2obiArrayExpress 
     3=============== 
     4 
     5A python module for accessing the ArrayExpress and GeneExpressionAtlas 
     6web services. 
     7 
     8 
    29Array Express 
    310------------- 
    411 
    5 A python module for accessing the ArrayExpress and GeneExpressionAtlas web services. 
    6  
    7 Example:: 
     12`Array Express Archive <http://www.ebi.ac.uk/arrayexpress/>`_ is a database of gene expression experiments that you 
     13can query and download. 
     14 
     15Example of an Array Express query :: 
    816 
    917    >>> import obiArrayExpress 
     
    1422    XMLNode(... 
    1523    
    16 .. note: Currently querying ArrayExpress files only works with the xml format. 
    17   
     24.. note:: Currently querying ArrayExpress files only works with the xml format. 
     25 
     26.. note:: See the documentation of `query_experiments` for a full set of 
     27          parameters that these functions accept. 
     28 
    1829""" 
    1930 
     
    3546    tree = parse(stream) 
    3647    return tree 
    37      
    38 #    raise NotImplementedError() 
    3948 
    4049 
     
    6776 
    6877class ArrayExpressConnection(object): 
    69     """ A connection to the ArrayExpress database with query caching. 
    70     """ 
    71      
    72     try: 
    73         DEFAULT_CACHE = shelve.open(os.path.join(orngEnviron.bufferDir, "ArrayExpressCache.shelve")) 
    74     except ImportError: 
    75         warnings.warn("Could not load persistent cache!") 
    76         DEFAULT_CACHE = {} 
     78    """ A connection to the ArrayExpress. Used for query construction, 
     79    and user login.  
     80     
     81    .. todo:: Implement user login. 
     82    """ 
    7783     
    7884    DEFAULT_ADDRESS = "http://www.ebi.ac.uk/arrayexpress/{format}/v2/" 
     
    8288    _ARGS_ORDER = ["keywords", "species", "array"] 
    8389     
    84     def __init__(self, address=None, cache=None, timeout=30, 
     90    def __init__(self, address=None, timeout=30, 
    8591                 username=None, password=None): 
    8692        """ Initialize the connection object. 
    8793         
    88         :param address: address of the ArrayExpress API 
    89         :param cache: a dict like object to use for caching 
    90         :param timeout: timeout for the socket connection 
    91          
    92         .. todo: implement user login (see Accessing Private Data in API docs) 
     94        :param address: Address of the ArrayExpress API 
     95        :param timeout: Timeout for the socket connection 
     96         
     97        .. todo:: Implement user login (see Accessing Private Data in API docs) 
    9398         
    9499        """ 
    95100        self.address = address if address is not None else self.DEFAULT_ADDRESS 
    96         self.cache = cache if cache is not None else self.DEFAULT_CACHE 
    97101        self.timeout = timeout 
    98102         
     
    100104        """ Format the query arguments. 
    101105         
    102         Example:: 
     106        Example :: 
     107         
    103108            >>> conn.format_query(gxa=True, efcount=(1, 5)) 
    104109            'efcount=[1 TO 5]&gxa=true' 
     
    172177        """ Return a formated query URL for the query arguments 
    173178         
    174         Example:: 
     179        Example :: 
    175180            >>> conn.query_url(accession="E-MEXP-31") 
    176181            'http://www.ebi.ac.uk/arrayexpress/json/v2/experiments?accession=E-MEXP-31' 
     
    198203        """ Return an open stream to the experiments query results. 
    199204         
    200         .. note: This member function takes the same arguments as the module 
    201                  level query_experiemnts function. 
     205        .. note:: This member function takes the same arguments as the module 
     206                  level `query_experiemnts` function. 
    202207           
    203208        """ 
     
    209214        """ Return an open stream to the files query results. 
    210215         
    211         .. note: This member function takes the same arguments as the module 
    212                  level query_files function. 
     216        .. note:: This member function takes the same arguments as the module 
     217                  level `query_files` function. 
    213218        """ 
    214219        url = self.query_url_files(**kwargs) 
     
    226231            - mageml: MAGE-ML file 
    227232             
    228         Example:: 
     233        Example :: 
    229234         
    230235            >>> raw_file = conn.open_file("E-TABM-1087", kind="raw") 
     
    331336--------------------- 
    332337 
     338`Gene Expression Atlas <http://www.ebi.ac.uk/gxa/>`_ is a curated subset of  
     339gene expression experiments in Array Express Archive. 
     340 
    333341Use `query_atlas_simple` for simple querys. 
    334342 
    335 Example (query human genes for experiments in which they are up regulated):: 
     343Example (query human genes for experiments in which they are up regulated) :: 
     344 
    336345    >>> obiArrayExpress.query_atlas_simple(genes=["SORL1", "PSIP1", "CDKN1C"], regulation="up", organism="Homo sapiens") 
    337346    {u'... 
    338347     
     348Or use the `AtlasCondition` subclasses in this module to construct a more 
     349advanced query and use the `query_atlas` function. 
     350 
     351Example (query human genes annotated to the GO term 'transporter activity' 
     352that are up regulated in the liver in at least three experiments) :: 
     353 
     354    >>> go_cond = AtlasConditionGeneProperty("Goterm", "Is", "transporter activity") 
     355    >>> liver_cond = AtlasConditionExperimentalFactor("Organism_part", "up", 3, "liver") 
     356    >>> org_cond = AtlasConditionOrganism("Homo sapiens") 
     357    >>> cond_list = AtlasConditionList([go_cond, liver_cond, org_cond]) 
     358    >>> query_atlas(cond_list) 
     359    {u'... 
     360     
    339361""" 
    340362 
     
    342364    """ A connection to Gene Expression Atlas database. 
    343365    """ 
    344     try: 
    345         DEFAULT_CACHE = shelve.open(os.path.join(orngEnviron.bufferDir, "GeneExpressionAtlasCache.shelve")) 
    346     except ImportError: 
    347         warnings.warn("Could not load persistent cache!") 
    348         DEFAULT_CACHE = {} 
    349      
    350366    DEFAULT_ADDRESS = "http://www.ebi.ac.uk:80/gxa/" 
    351367     
    352     def __init__(self, address=None, cache=None, timeout=30): 
     368    def __init__(self, address=None, timeout=30): 
    353369        """ Initialize the conenction. 
    354370         
    355         :param address: Address of the server 
    356         :param cache: A dict like object to use for caching 
     371        :param address: Address of the server. 
    357372        :timeout: Socket timeout. 
    358373         
    359374        """ 
    360375        self.address = address if address is not None else self.DEFAULT_ADDRESS 
    361         self.cache = cache if cache is not None else self.DEFAULT_CACHE 
    362376        self.timeout = timeout 
    363          
    364     def format_query(self,): 
    365         pass 
    366377     
    367378    def query(self, condition, format="json", start=None, rows=None, indent=False): 
     
    376387        return response 
    377388     
     389# Names of all Gene Property filter names 
    378390GENE_FILTERS = \ 
    379391    ["Name", # Gene name 
     
    410422     ] 
    411423     
     424# Valid Gene Property filter qualifiers  
    412425GENE_FILTER_QUALIFIERS =\ 
    413426    ["Is", 
     
    415428     ] 
    416429 
     430# Organisms in the Atlas 
    417431ATLAS_ORGANISMS = \ 
    418432    ["Anopheles gambiae", 
     
    436450     
    437451def ef_ontology(): 
    438     """ Return the EF (Experimental Factor) ontology 
     452    """ Return the `EF <http://www.ebi.ac.uk/efo/>`_ (Experimental Factor) ontology 
    439453    """ 
    440454    import obiOntology 
     
    555569def query_atlas_simple(genes=None, regulation=None, organism=None, 
    556570                       condition=None, format="json", start=None, 
    557                        rows=None, indent=False): 
     571                       rows=None): 
    558572    """ A simple Atlas query. 
    559573     
     
    566580    :param condition: An EFO factor value (e.g. "brain") 
    567581     
    568     Example:: 
     582    Example :: 
    569583         
    570584        >>> query_atlas_simple(genes=['Pou5f1', 'Dppa3'], organism="Mus musculus") 
     
    579593    """ 
    580594    conditions = AtlasConditionList() 
    581     conditions.append(AtlasConditionGeneProperty("Gene", "Is", genes)) 
     595    if genes: 
     596        conditions.append(AtlasConditionGeneProperty("Gene", "Is", genes)) 
    582597    if regulation or condition: 
    583598        regulation = "any" if regulation is None else regulation 
     
    596611 
    597612"""\ 
    598 .. TODO: can this be implemented query_atlas(organism="...", Locuslink="...", Chebi="...", up3InCompound="..." downInEFO="...") 
     613.. todo:: can this be implemented query_atlas(organism="...", Locuslink="...", Chebi="...", up3InCompound="..." downInEFO="...") 
    599614      Need a full list of accepted factors  
    600615""" 
     
    603618    """ Query Atlas based on a `condition` (instance of AtlasCondition) 
    604619     
    605     Example:: 
     620    Example :: 
    606621         
    607622        >>> condition1 = AtlasConditionGeneProperty("Goterm", "Is", "p53 binding") 
     
    633648    and down regulated experiments. 
    634649     
    635     Example:: 
     650    Example :: 
    636651     
    637652        >>> get_atlas_summary(["RUNX1"], "Homo sapiens") 
Note: See TracChangeset for help on using the changeset viewer.