class GenericTable(QtCore.QAbstractTableModel): def __init__(self, data, headers, parent=None, *args): QtCore.QAbstractTableModel.__init__(self, parent, *args) self.arraydata = data self.headerdata = headers def rowCount(self, parent): return len(self.arraydata) def columnCount(self, parent): if len(self.arraydata) > 0: return len(self.arraydata[0]) else: return -1 def data(self, index, role): if index.isValid() and role == QtCore.Qt.DisplayRole: return QtCore.QVariant(self.arraydata[index.row()][index.column()]) return QtCore.QVariant() def headerData(self, col, orientation, role): if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole: return QtCore.QVariant(self.headerdata[col]) return QtCore.QVariant() def sort(self, Ncol, order): ''' Sort table by given column number. ''' if len(self.arraydata) == 0: return self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()")) dataIsNumeric = isNumber(self.arraydata[0][Ncol]) if dataIsNumeric: self.arraydata = SortTableNumericStrCol(self.arraydata, Ncol) else: self.arraydata = SortTableStrCol(self.arraydata, Ncol) if order == QtCore.Qt.DescendingOrder: self.arraydata.reverse() self.emit(QtCore.SIGNAL("layoutChanged()")) def save(self, filename): fout = open(filename, 'w') for header in self.headerdata: fout.write(str(header) + '\t') fout.write('\n') for row in self.arraydata: for item in row: fout.write(str(item) + '\t') fout.write('\n') fout.close()
def sort(self, Ncol, order): ''' Sort table by given column number. ''' if len(self.arraydata) == 0: return self.emit(QtCore.SIGNAL("layoutAboutToBeChanged()")) dataIsNumeric = isNumber(self.arraydata[0][Ncol]) if dataIsNumeric: self.arraydata = SortTableNumericStrCol(self.arraydata, Ncol) else: self.arraydata = SortTableStrCol(self.arraydata, Ncol) if order == QtCore.Qt.DescendingOrder: self.arraydata.reverse() self.emit(QtCore.SIGNAL("layoutChanged()"))
# Prepare table # ['Benjamini-Hochberg FDR', 'Bonferroni', 'No correction', 'Sidak', 'Storey FDR'] print 'Sidak table:', groupMultCompMethodIndex = 3 # 'No correction' groupMultCompMethod = groupMultCompMethodOptions[groupMultCompMethodIndex] # run significance test groupStatsTest.run(test, groupSignTestType, groupConfIntervMethod, float(groupNominalCoverage), groupProfile) # apply multiple test correction groupStatsTest.results.performMultCompCorrection(multCompDict[groupMultCompMethod]) groupStatsTest.results.setSelectedFeatures(selectedFeatures) groupStatsTest.results.filterFeatures(groupSignLevelFilter, groupSeqFilter, group1Filter, group2Filter, groupParentSeqFilter, groupParentGroup1Filter, groupParentGroup2Filter, groupEffectSizeMeasure1, groupMinEffectSize1, effectSizeOperator, groupMinEffectSize2, groupMinEffectSize2) tableData, tableHeadings = groupStatsTest.results.tableData(False) tableData = SortTableStrCol(tableData, 0) filename = os.path.join(saveFolder, saveTableTemplate.format(g1=groupName1, g2=groupName2)) print '"{0}"'.format(filename), fout = open(filename, 'w') for heading in tableHeadings: fout.write(heading + '\t') fout.write('\n') for row in tableData: for entry in row: fout.write(str(entry) + '\t') fout.write('\n') fout.close() print 'DONE.' else: print 'No Active Data, SKIP.'