Commits

Aleš Erjavec committed 48dc3a3

Fixed docstrings, typos.

Comments (0)

Files changed (1)

obiArrayExpress.py

 obiArrayExpress
 ===============
 
-A python module for accessing the ArrayExpress web services.
+A python module for accessing the ArrayExpress web services and database.
 
 `Array Express Archive <http://www.ebi.ac.uk/arrayexpress/>`_ is a database of gene expression experiments that you
 can query and download.
 
-Example of an Array Express query ::
+Example ::
+
+    >>> # Retrieve the object representing experiment with accession E-TABM-25 
+    >>> experiment = ArrayExpressExperiment("E-TABM-25")
+    >>> print experiment.accession
+    E-TABM-25
+    
+    >>> print experiment.name
+    Transcription profiling of aging in the primate brain
+    
+    >>> print experiment.species
+    ['Pan troglodytes']
+    
+    >>> print experiment.files
+    [{'kind': ...
+    
+    >>> # Retrieve the data matrix for experiment 'E-MEXP-2917'
+    >>> experiment = ArrayExpressExperiment("E-MEXP-2917")
+    >>> table = experiment.fgem_to_table() 
+
+
+Low level Array Express query using REST services::
 
     >>> import obiArrayExpress
     >>> obiArrayExpress.query_experiments(accession='E-MEXP-31')
     {u'experiments': ...
     
     >>> obiArrayExpress.query_files(accession='E-MEXP-32', format="xml")
-    <xml.etree.ElementTree.ElementTree instance...
+    <xml.etree.ElementTree.ElementTree object ...
    
 .. note:: Currently querying ArrayExpress files only works with the xml format.
 
 import os, sys
 import urllib2
 
-import orngEnviron
 import orngServerFiles
 import warnings
 import posixpath
             (row_ref, row_names),
             rows) 
     
-class InvesigationDesign(dict):
+class InvestigationDesign(dict):
     """ Investigation design (contains the contents of the .idf).
     
     Example ::
     instance (assumes all the associated MAGE-TAB files are in the same
     directory.
     
-    .. todo:: Add Characteristics, Factor Values ... to the feture.attributes dict
+    .. todo:: Add Characteristics, Factor Values ... to the feature.attributes dict
     
     """
     import Orange
     dirname = os.path.dirname(idf_filename)
-    idf = InvesigationDesign(idf_filename)
+    idf = InvestigationDesign(idf_filename)
     
     sdrf_filename = os.path.join(dirname, idf.sdrf_file[0])
     sdrf = SampleDataRelationship(sdrf_filename)
     return table
     
 def _dictify(element):
-    """ Dictify and xml.etree.Element.Element instance.
+    """ 'Dictify' and xml.etree.Element.Element instance by taking all
+    subnode tags as keys and the corresponding text values as items i.e. turn
+    `<node><bla>foo</bla><a>b</b></node>` into a {"bla":"foo", "a":b"}
+        
     """
     if element is None:
         element = []
         dict[node.tag] = strip(getattr(node, "text", None))
     return dict
     
+class SearchableList(list):
+    """ A list with a `search` method
+    """
+    def search(self, **kwargs):
+        """ Search the list for elements with members that correspond the
+        supplied keyword arguments.
+        
+            >>> foo.bar = "foo"
+            >>> list = SearchableList([foo, bar])
+            >>> list.search(bar="foo") # Search for objects which have a member named "bar" and that member equals "foo"
+            [<__main__.foo object ...
+            
+        """
+        ret = []
+        for obj in self:
+            for member, value in kwargs.items():
+                if hasattr(obj, member) and getattr(obj, member) == value:
+                    ret.append(obj)
+        return ret
     
 class ArrayExpressExperiment(object):
     """ An convinience class representing an Array Express Experiment.
         ...     print file["name"], file["url"]
         E-MEXP-2917.sdrf.txt http://www.ebi.ac.uk/arrayexpress/files/E-MEXP-2917/E-MEXP-2917.sdrf.txt
         ...
+        
+        >>> table = ae.fgem_to_table() # Retieve the experiment data table 
             
     """
     
         
     def _download_processed(self):
         """ Download the processed matrix file, and associated MAGE-TAB files (idf, sdrf, adf)
+        
+        .. todo:: What about the raw data files (we need converters for other file types) 
         """
         assert(self.fgemdatafiles)
         exp_files = [(f["kind"], f) for f in self.files if f.get("kind") in ["idf", "sdrf"] and f.get("extension") == "txt"]
         if not files:
             raise ValueError("The experiment '{0}' does not have an investigation design file".format(self.accession))
         file = files[0]
-        return InvesigationDesign(self._open(file.get("url")))
+        return InvestigationDesign(self._open(file.get("url")))
         
         
     def sample_data_relationship(self):
         return SampleDataRelationship(self._open(file.get("url")))
         
     def fgem_to_table(self):
+        """ Retrieve the processed matrix from the Array Express ftp
+        server and convert it to an :class:`Orange.data.Table` instance.
+         
+        """
         assert(self.fgemdatafiles)
         repo_dir = orngServerFiles.localpath("ArrayExpress", self.accession)
         # Find the file listing the data matrix files (should be in sdrf but sometimes it is in 2column file only, why?)
         return mage_tab_to_orange(os.path.join(repo_dir, idf_file.get("name")))
         
     
-__doc__ += """\
+"""\
 Gene Expression Atlas
 ---------------------
 
         >>> # Condition on a experiemnt acession
         >>> condition = AtlasConditionExperiment("", "", "E-GEOD-24283")
         >>> # Condition on experiments involving lung
-        >>> condition = AtlasConditionGeneProperty("Organism_part", "Has", "lung")
+        >>> condition = AtlasConditionExperiment("Organism_part", "Has", "lung")
         
     """
 #    EXPERIMENT_FILTERS = [
 def test():    
     conn = ArrayExpressConnection()
     import doctest
-    doctest.testmod(optionflags=doctest.ELLIPSIS, extraglobs={"conn": conn})
+    foo = type("foo", (object,), {})()
+    bar = type("bar", (object,), {})()
+    
+    doctest.testmod(optionflags=doctest.ELLIPSIS,
+                    extraglobs={"conn": conn, "foo": foo,"bar": bar})
     
     
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.