Aleš Erjavec avatar Aleš Erjavec committed b8ee066

Added columns from the gene info view to the output.

Comments (0)

Files changed (1)

widgets/OWGeneInfo.py

 """
 from __future__ import with_statement
 
+import Orange
+
 import obiGene, obiTaxonomy
 import orange
 import orngServerFiles
     def setRoleData(self, role, row, col, data):
         self._roleData[role][row][col] = data
         
-    def data(self, index, role):
+    def data(self, index, role=Qt.DisplayRole):
         row, col = index.row(), index.column()
         return self._roleData[role][row][col]
         
     def parent(self, index):
         return QModelIndex()
     
-    def rowCount(self, index):
+    def rowCount(self, index=QModelIndex()):
         if index.isValid():
             return 0
         else:
             return len(self._data)
         
-    def columnCount(self, index):
+    def columnCount(self, index=QModelIndex()):
         return len(self._header)
 
-    def headerData(self, section, orientation, role):
+    def headerData(self, section, orientation, role=Qt.DisplayRole):
         if role==Qt.DisplayRole:
             return QVariant(self._header[section])
         return QVariant()
     def commit(self):
         if not self.data:
             return
-        
-        mapToSource = self.treeWidget.model().mapToSource
+        model = self.treeWidget.model()
+        mapToSource = model.mapToSource
         selectedIds = [self.cells[mapToSource(index).row()][0] for index in self.treeWidget.selectedIndexes()]
         selectedRows = self.treeWidget.selectedIndexes()
         selectedRows = [mapToSource(index).row() for index in selectedRows]
+        model = model.sourceModel()
         
         selectedGeneids = [self.row2geneinfo[row] for row in selectedRows]
         selectedIds = [self.geneinfo[i][0] for i in selectedGeneids]
         selectedIds = set(selectedIds)
+        gene2row = dict((self.geneinfo[self.row2geneinfo[row]][0], row) \
+                        for row in selectedRows)
         
         if self.useAttr:
             def is_selected(attr):
             attr = self.attributes[self.geneAttr]
             geneinfo = dict(self.geneinfo)
             examples = [ex for ex in self.data if str(ex[attr]) in selectedIds]
+            if True:  # Add gene info
+                domain = orange.Domain(self.data.domain, self.data.domain.classVar)
+                domain.addmetas(self.data.domain.getmetas())
+                n_columns = model.columnCount()
+
+                headers = [str(model.headerData(i, Qt.Horizontal, Qt.DisplayRole).toString()) \
+                           for i in range(n_columns)]
+                new_meta_attrs = [(orange.newmetaid(), orange.StringVariable(name)) \
+                                  for name in headers]
+                domain.addmetas(dict(new_meta_attrs))
+                examples = [orange.Example(domain, ex) for ex in examples]
+                for ex in examples:
+                    for i, (_, meta) in enumerate(new_meta_attrs):
+                        row = gene2row[str(ex[attr])]
+                        ex[meta] = str(model.data(model.index(row, i), Qt.DisplayRole).toString())
+
             if examples:
                 newdata = orange.ExampleTable(examples)
             else:
         
 if __name__ == "__main__":
     app = QApplication(sys.argv)
-    data = orange.ExampleTable("../../orange/doc/datasets/brown-selected.tab")
+    data = orange.ExampleTable("brown-selected.tab")
     w = OWGeneInfo()
     w.show()
     w.setData(data)
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.