本文整理汇总了Python中AnyQt.QtGui.QStandardItemModel.setSortRole方法的典型用法代码示例。如果您正苦于以下问题:Python QStandardItemModel.setSortRole方法的具体用法?Python QStandardItemModel.setSortRole怎么用?Python QStandardItemModel.setSortRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QStandardItemModel
的用法示例。
在下文中一共展示了QStandardItemModel.setSortRole方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __on_enrichment_finished
# 需要导入模块: from AnyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from AnyQt.QtGui.QStandardItemModel import setSortRole [as 别名]
def __on_enrichment_finished(self, results):
assert QThread.currentThread() is self.thread()
self.__state &= ~OWSetEnrichment.RunningEnrichment
query, reference, results = results
if self.annotationsChartView.model():
self.annotationsChartView.model().clear()
nquery = len(query)
nref = len(reference)
maxcount = max((len(e.query_mapped) for _, e in results),
default=1)
maxrefcount = max((len(e.reference_mapped) for _, e in results),
default=1)
nspaces = int(math.ceil(math.log10(maxcount or 1)))
refspaces = int(math.ceil(math.log(maxrefcount or 1)))
query_fmt = "%" + str(nspaces) + "s (%.2f%%)"
ref_fmt = "%" + str(refspaces) + "s (%.2f%%)"
def fmt_count(fmt, count, total):
return fmt % (count, 100.0 * count / (total or 1))
fmt_query_count = partial(fmt_count, query_fmt)
fmt_ref_count = partial(fmt_count, ref_fmt)
linkFont = QFont(self.annotationsChartView.viewOptions().font)
linkFont.setUnderline(True)
def item(value=None, tooltip=None, user=None):
si = QStandardItem()
if value is not None:
si.setData(value, Qt.DisplayRole)
if tooltip is not None:
si.setData(tooltip, Qt.ToolTipRole)
if user is not None:
si.setData(user, Qt.UserRole)
else:
si.setData(value, Qt.UserRole)
return si
model = QStandardItemModel()
model.setSortRole(Qt.UserRole)
model.setHorizontalHeaderLabels(
["Category", "Term", "Count", "Reference count", "p-value",
"FDR", "Enrichment"])
for i, (gset, enrich) in enumerate(results):
if len(enrich.query_mapped) == 0:
continue
nquery_mapped = len(enrich.query_mapped)
nref_mapped = len(enrich.reference_mapped)
row = [
item(", ".join(gset.hierarchy)),
item(gsname(gset), tooltip=gset.link),
item(fmt_query_count(nquery_mapped, nquery),
tooltip=nquery_mapped, user=nquery_mapped),
item(fmt_ref_count(nref_mapped, nref),
tooltip=nref_mapped, user=nref_mapped),
item(fmtp(enrich.p_value), user=enrich.p_value),
item(), # column 5, FDR, is computed in filterAnnotationsChartView
item(enrich.enrichment_score,
tooltip="%.3f" % enrich.enrichment_score,
user=enrich.enrichment_score)
]
row[0].geneset = gset
row[0].enrichment = enrich
row[1].setData(gset.link, gui.LinkRole)
row[1].setFont(linkFont)
row[1].setForeground(QColor(Qt.blue))
model.appendRow(row)
self.annotationsChartView.setModel(model)
self.annotationsChartView.selectionModel().selectionChanged.connect(
self.commit
)
if not model.rowCount():
self.warning(0, "No enriched sets found.")
else:
self.warning(0)
allnames = set(gsname(geneset)
for geneset, (count, _, _, _) in results if count)
allnames |= reduce(operator.ior,
(set(word_split(name)) for name in allnames),
set())
self.filterCompleter.setModel(None)
self.completerModel = QStringListModel(sorted(allnames))
self.filterCompleter.setModel(self.completerModel)
if results:
max_score = max((e.enrichment_score for _, e in results
if np.isfinite(e.enrichment_score)),
default=1)
self.annotationsChartView.setItemDelegateForColumn(
#.........这里部分代码省略.........
示例2: OWSetEnrichment
# 需要导入模块: from AnyQt.QtGui import QStandardItemModel [as 别名]
# 或者: from AnyQt.QtGui.QStandardItemModel import setSortRole [as 别名]
#.........这里部分代码省略.........
sp = gui.doubleSpin(
fdrfilterbox, self, "maxFDR", 0.0, 1.0, 0.0001,
tooltip="Maximum False discovery rate",
callback=self.filterAnnotationsChartView,
callbackOnReturn=True,
)
sp.setEnabled(self.useMaxFDRFilter)
cb.toggled[bool].connect(sp.setEnabled)
fdrfilterbox.layout().setAlignment(cb, Qt.AlignRight)
fdrfilterbox.layout().setAlignment(sp, Qt.AlignLeft)
self.filterLineEdit = QLineEdit(self, placeholderText="Search ...")
self.filterCompleter = QCompleter(self.filterLineEdit)
self.filterLineEdit.setCompleter(self.filterCompleter)
hLayout.addWidget(self.filterLineEdit)
self.mainArea.layout().addWidget(hWidget)
self.filterLineEdit.textChanged.connect(
self.filterAnnotationsChartView)
self.annotationsChartView = QTreeView(
alternatingRowColors=True,
sortingEnabled=True,
selectionMode=QTreeView.ExtendedSelection,
rootIsDecorated=False,
editTriggers=QTreeView.NoEditTriggers,
)
self.source_model = QStandardItemModel()
self.source_model.setSortRole(Qt.UserRole)
self.source_model.setHorizontalHeaderLabels(
["Category", "Term", "Count", "Reference count", "p-value",
"FDR", "Enrichment"])
self.proxy_model = CustomFilterModel(self.annotationsChartView)
self.proxy_model.setFilterKeyColumn(1) # filter only by name (second column).
self.annotationsChartView.setModel(self.proxy_model)
self.annotationsChartView.viewport().setMouseTracking(True)
self.mainArea.layout().addWidget(self.annotationsChartView)
contextEventFilter = gui.VisibleHeaderSectionContextEventFilter(
self.annotationsChartView)
self.annotationsChartView.header().installEventFilter(contextEventFilter)
self.groupsWidget.itemClicked.connect(self.subsetSelectionChanged)
gui.auto_commit(self.controlArea, self, "autocommit", "Commit")
self.setBlocking(True)
task = EnsureDownloaded(
[(taxonomy.Taxonomy.DOMAIN, taxonomy.Taxonomy.FILENAME),
(geneset.sfdomain, "index.pck")]
)
task.finished.connect(self.__initialize_finish)
self.setStatusMessage("Initializing")
self._executor = ThreadExecutor(
parent=self, threadPool=QThreadPool(self))
self._executor.submit(task)