Marko Toplak avatar Marko Toplak committed bf2cdd7

Converted documentation of obiGeneSets to rst.

Comments (0)

Files changed (5)

docs/rst/index.rst

    reference/ontology.rst
    reference/dictybase.rst
    reference/gene.rst
+   reference/genesets.rst
 
 Installation
 ------------

docs/rst/reference/genesets.rst

+.. py:currentmodule:: Orange.bio.obiGeneSets
+
+.. index:: gene set
+.. index:: gene sets
+
+********************************************************
+Gene sets (:mod:`obiGeneSets`)
+********************************************************
+
+:mod:`obiGeneSets` can load gene sets distributed with Orange (through ServerFiles) 
+and also in GMT file format.
+
+Load gene sets from KEGG and GO for mouse::
+
+    obiGeneSets.collections((("KEGG",), "10090"), (("GO",), "10090"))
+
+Open gene sets from ``specific.gmt`` file in the current working directory::
+
+    obiGeneSets.collections("specific.gmt")
+
+The above examples combined::
+
+    obiGeneSets.collections((("KEGG",), "10090"), (("GO",), "10090"), "specific.gmt")
+
+
+Loading gene sets
+=================
+
+.. autofunction:: list_all
+
+.. autofunction:: collections
+
+
+Supporting functionality
+========================
+
+.. autoclass:: GeneSets
+   :members:
+
+.. autoclass:: GeneSet
+   :members:
+
+.. autofunction:: register
+

orangecontrib/bio/geneset.py

 class GenesetRegException(Exception): pass
 
 class GeneSet(object):
+    """ A single set of genes.
+    """
 
-    def __init__(self, genes=None, name=None, id=None, \
+    def __init__(self, genes=[], name=None, id=None, \
         description=None, link=None, organism=None, hierarchy=None, pair=None):
         """
-        pair can be (id, listofgenes) - it is used before anything else.
+        :param pair: Backward compatibility: convert a tuple (name, genes)
+            into this object.
         """
-        if genes == None:
-            genes = []
 
         self.hierarchy = hierarchy     
+        """ Hierarchy should be formated as a tuple, for example ``("GO", "biological_process")``"""
+
         self.genes = set(genes)
+        """ A set of genes. Genes are strings. """
+
         self.name = name
+        """ Gene set name. """
+
         self.id = id
+        """ Short gene set ID. """
+
         self.description = description
+        """ Gene set description. """
+
         self.link = link
+        """ Link to further information about this gene set. """
+
         self.organism = organism
+        """ Organism as a NCBI taxonomy ID. """
 
         if pair:
             self.id, self.genes = pair[0], set(pair[1])
         return len(self.genes)
 
     def cname(self, source=True, name=True):
-        """ Constructs a gene set name with the hierarchy. """
+        """ Return a gene set name with hieararchy. """
         oname = self.id
         if source and self.hierarchy:
             oname = "[ " + ", ".join(self.hierarchy) + " ] " + oname
 
     def to_odict(self, source=True, name=True):
         """
-        Returns a pair (id, listofgenes), like in old format.
+        Backward compatibility: returns a gene set as a tuple
+        (id, list of genes).
         """
         return self.cname(source=source, name=name), self.genes
 
     pass
 
 class GeneSets(set):
+    """ A collection of gene sets: contains :class:`GeneSet` objects. 
+    It is a subclass of Python's :obj:`set`. 
+    """
     
     def __init__(self, input=None):
         """
-        odict are genesets in old dict format.
-        gs are genesets in new format
+        If input is a dictionary, the gene sets are converted to the current format.
         """
         if input != None and len(input) > 0:
             self.update(input)
         return dict(gs.to_odict() for gs in self)
 
     def set_hierarchy(self, hierarchy):
-        """ Sets hierarchy for all gene sets """
+        """ Sets hierarchy for all gene sets. """
         for gs in self:
             gs.hierarchy = hierarchy
 
         return "GeneSets(" + set.__repr__(self) + ")"
 
     def common_org(self):
-        """ Returns the common organism. """
+        """ Return a common organism. """
         if len(self) == 0:
             raise GenesetRegException("Empty gene sets.")
 
             raise GenesetRegException("multiple organisms: " + str(organisms))
 
     def hierarchies(self):
-        """ Returns all hierachies """
+        """ Return all hierarchies. """
         if len(self) == 0:
             raise GenesetRegException("Empty gene sets.")
         return set(a.hierarchy for a in self)
 
     def common_hierarchy(self):
+        """ Return a common hierarchy. """
         hierarchies = self.hierarchies()
 
         def common_hierarchy1(hierarchies):
         return common_hierarchy1(hierarchies)
 
     def split_by_hierarchy(self):
-        """ Splits gene sets by hierarchies. """
+        """ Split gene sets by hierarchies. Return a list of :class:`GeneSets` objects. """
         hd = dict((h,GeneSets()) for h in  self.hierarchies())
         for gs in self:
             hd[gs.hierarchy].add(gs)

orangecontrib/bio/obiGeneSetSig.py

         gene_sets = select_genesets(nm, self.gene_sets, self.min_size, self.max_size, self.min_part)
 
         #build a new domain
-        print "WHOLE"
+        #print "WHOLE"
         newfeatures = self.build_features(data, gene_sets)
         newdomain = Orange.data.Domain(newfeatures, data.domain.class_var)
 
                 cvi = self.cv(data)
             data_cv = [ [] for _ in range(len(data)) ]
             for f in set(cvi):
-                print "FOLD", f
+                #print "FOLD", f
                 learn = data.select(cvi, f, negate=True)
                 test = data.select(cvi, f)
                 lf = self.build_features(learn, gene_sets)
                 for ex, pos in \
                     zip(trans_test, [ i for i,n in enumerate(cvi) if n == f ]):
                     data_cv[pos] = ex.native(0)
-            print data_cv[0]
             return Orange.data.Table(newdomain, data_cv)
 
     def build_features(self, data, gene_sets):

orangecontrib/bio/obiGeneSets.py

 
 def list_all():
     """
-    return a list of (hier, org, avalable_locally)
-    If something for a specific (hier, org) is not downloaded
-    yet, show it as not-local. """
+    Return gene sets available in the local and ServerFiles repositories. 
+    It returns a list of tuples of (hierarchy, organism, available_locally)
+    """
     flist = list_local() + list_serverfiles()
     d = {}
     for h,o,local in flist:
     update_server_list(serverFiles)
 
 def register(genesets, serverFiles=None):
-    """
-    Hierarchy is induced from the gene set names.
+    """ Registers given :class:`GeneSets` locally.  The gene set is registered
+    by the common hierarchy or organism (None if organisms are different).
+
+    If :obj:`serverFiles` as a authenticated ServerFiles connection,
+    the given gene sets are uploaded to the ServerFiles repository.  
     """
     if serverFiles == None:
         _register_local(genesets)
     return out
 
 def load(hierarchy, organism):
-    """ First try to load from the local registred folder. If the file
+    """ First try to load from the local registered folder. If the file
     is not available, load it from the server files. """
     try:
         return load_local(hierarchy, organism)
 
 def collections(*args):
     """
-    Input is a list of collections.
-    Collection can either be a tuple (hierarchy, orgranism), where
-    hierarchy is a tuple also.
+    Load gene sets from various sources: GMT file, GO, KEGG, and others. 
+    Return an instance of :class:`GeneSets`. 
+    
+    Each arguments specifies a gene set and can be either:
+    
+    * a filename of a GMT file,
+    * a tuple (hierarchy, organism) (for example ``(("KEGG",), "10090")``), or
+    * an instance of :class:`GeneSets`
     """
     result = GeneSets()
 
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.