Aleš Erjavec avatar Aleš Erjavec committed 2a17616 Merge

Merged biolab/orange-bioinformatics into default

Fixed conflicts in orangecontrib/bio/widgets/OWSetEnrichment.py

Comments (0)

Files changed (3)

orangecontrib/bio/obiGeneSets.py

 
 from Orange.bio.geneset import GeneSet, GeneSets, GenesetRegException
 
+class NoGenesetsException(Exception): pass
+
 def goGeneSets(org):
     """Returns gene sets from GO."""
     ontology = obiGO.Ontology()
     return hierd
 
 def load_local(hierarchy, organism):
-    files = map(lambda x: x[:2], list_local())
-    hierd = build_hierarchy_dict(files)
-
-    out = GeneSets()
-    for (h, o) in [ files[i] for i in hierd[(hierarchy, organism)]]:
-        fname = os.path.join(local_path(), filename(h, o))
-        out.update(pickle.load(open(fname, 'r')))
-    return out
+    return load_fn(hierarchy, organism, list_local, 
+        lambda h,o: os.path.join(local_path(), filename(h, o)))
 
 def load_serverfiles(hierarchy, organism):
-    files = map(lambda x: x[:2], list_serverfiles())
+    return load_fn(hierarchy, organism, list_serverfiles, 
+        lambda h,o: orngServerFiles.localpath_download(sfdomain, filename(h, o)))
+
+def load_fn(hierarchy, organism, fnlist, fnget):
+    files = map(lambda x: x[:2], fnlist())
     hierd = build_hierarchy_dict(files)
     out = GeneSets()
+    matches = hierd[(hierarchy, organism)]
+    if not matches:
+        exstr = "No gene sets for " + str(hierarchy) + \
+                " (org " + str(organism) + ")"
+        raise NoGenesetsException(exstr)
     for (h, o) in [ files[i] for i in hierd[(hierarchy, organism)]]:
-        fname = orngServerFiles.localpath_download(sfdomain,
-            filename(h, o))
+        fname = fnget(h, o)
         out.update(pickle.load(open(fname, 'r')))
     return out
 
 def load(hierarchy, organism):
     """ First try to load from the local registred folder. If the file
     is not available, load it from the server files. """
-    ret = load_local(hierarchy, organism)
-    if len(ret) == 0:
-        ret.update(load_serverfiles(hierarchy, organism))
-    return ret
+    try:
+        return load_local(hierarchy, organism)
+    except NoGenesetsException:
+        return load_serverfiles(hierarchy, organism)
 
 def collections(*args):
     """

orangecontrib/bio/widgets/OWSetEnrichment.py

 REPLACES = ["_bioinformatics.widgets.OWSetEnrichment.OWSetEnrichment"]
 
 
+def gsname(geneset):
+    return geneset.name if geneset.name else geneset.id
+
+
 def _toPyObject(variant):
     val = variant.toPyObject()
     if isinstance(val, type(NotImplemented)): # PyQt 4.4 converts python int, floats ... to C types
 
 #            print self.speciesIndex
 
-            self.setHierarchy(self.getHierarchy(taxid=self.taxid_list[self.speciesIndex]))
+            self.setHierarchy(*self.getHierarchy(taxid=self.taxid_list[self.speciesIndex]))
 
             self.loadedGenematcher = "None"
             self.updateAnnotations()
         for hierarchy, t_id, _ in self.genesets:
             collect(collection[t_id], hierarchy)
 
-        #add genesets without species identifiers
-        collection[taxid].update(collection[None])
-        return collection[taxid]
+        return (taxid, collection[taxid]), (None, collection[None])
 
-    def setHierarchy(self, hierarchy):
+    def setHierarchy(self, hierarchy, hierarchy_noorg):
         self.groupsWidgetItems = {}
-        def fill(col, parent, full=()):
+        def fill(col, parent, full=(), org=""):
             for key, value in sorted(col.items()):
                 full_cat = full + (key,)
                 item = QTreeWidgetItem(parent, [key])
                 item.setData(0, Qt.CheckStateRole, QVariant(self.categoriesCheckState.get(full_cat, Qt.Checked)))
                 item.setExpanded(True)
                 item.category = full_cat
+                item.organism = org
                 self.groupsWidgetItems[full_cat] = item
-                fill(value, item, full_cat)
+                fill(value, item, full_cat, org=org)
 
-        fill(hierarchy, self.groupsWidget)
+        fill(hierarchy[1], self.groupsWidget, org=hierarchy[0])
+        fill(hierarchy_noorg[1], self.groupsWidget, org=hierarchy_noorg[0])
 
 #    def updateCategoryCounts(self):
 #        for cat, item in self.groupWidgetItem:
 #            item.setData(1, QVariant(), Qt.DisplayRole)
 
     def selectedCategories(self):
-        taxid = self.taxid_list[self.speciesIndex]
-        return [(key, taxid) for key, check in self.getHierarchyCheckState().items() if check == Qt.Checked]
+        return [(key, org) for (key, org), check in self.getHierarchyCheckState().items() if check == Qt.Checked]
 
     def getHierarchyCheckState(self):
         def collect(item, full=()):
             checked = item.checkState(0)
             name = str(item.data(0, Qt.DisplayRole).toString())
             full_cat = full + (name,)
-            result = [(full_cat, checked)]
+            result = [((full_cat, item.organism), checked)]
             for i in range(item.childCount()):
                 result.extend(collect(item.child(i), full_cat))
             return result
         return dict(states)
 
     def subsetSelectionChanged(self, item, column):
+        #FIXME this should also recompute FDR
         self.categoriesCheckState = self.getHierarchyCheckState()
-
         categories = self.selectedCategories()
         if not set(categories) <= set(self.currentAnnotatedCategories):
             self.updateAnnotations()
         self.treeItems = []
         for i, (geneset, (cmapped, rmapped, p_val, enrichment)) in enumerate(results):
             if len(cmapped) > 0:
-                item = MyTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), geneset.name])
+                item = MyTreeWidgetItem(self.annotationsChartView, [" ".join(geneset.hierarchy), gsname(geneset)])
                 item.setData(2, Qt.DisplayRole, QVariant(countFmt % (len(cmapped), 100.0*len(cmapped)/countAll)))
                 item.setData(2, Qt.ToolTipRole, QVariant(len(cmapped))) # For filtering
                 item.setData(3, Qt.DisplayRole, QVariant(refFmt % (len(rmapped), 100.0*len(rmapped)/len(referenceGenes))))
             self.warning(0)
 
         replace = lambda s:s.replace(",", " ").replace("(", " ").replace(")", " ")
-        self._completerModel = completerModel = QStringListModel(sorted(reduce(set.union, [[geneset.name] + replace(geneset.name).split() for geneset, (c, _, _, _) in results if c], set())))
+        self._completerModel = completerModel = QStringListModel(sorted(reduce(set.union, [[gsname(geneset)] + replace(gsname(geneset)).split() for geneset, (c, _, _, _) in results if c], set())))
         self.filterCompleter.setModel(completerModel)
 
         self.annotationsChartView.setItemDelegateForColumn(5, BarItemDelegate(self, scale=(0.0, max(t[1][3] for t in results))))
         for item in self.treeItems:
             item_cat = str(item.data(0, Qt.EditRole).toString())
             count, pval = _toPyObject(item.data(2, Qt.ToolTipRole)), _toPyObject(item.data(4, 42))
-            geneset = item.geneset.name.lower()
+            geneset = gsname(item.geneset).lower()
             hidden = item_cat not in categories or (self.useMinCountFilter and count < self.minClusterCount) or \
                      (self.useMaxPValFilter and pval > self.maxPValue) or filterString not in geneset
             item.setHidden(hidden)
 NAME = 'Orange-Bioinformatics'
 DOCUMENTATION_NAME = 'Orange Bioinformatics'
 
-VERSION = '2.5a9'
+VERSION = '2.5a10'
 
 DESCRIPTION = 'Orange Bioinformatics add-on for Orange data mining software package.'
 LONG_DESCRIPTION = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
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.