今天在使用Seurat包的时候,想看看Findmarker的源代码写了什么,于是用了
getAnywhere(FindMarkers)
来查看源代码,但是却反回了:
A single object matching ‘FindMarkers’ was found
It was found in the following places
package:Seurat
namespace:Seurat
with value
function (object, ...)
{
UseMethod(generic = "FindMarkers", object = object)
}
<bytecode: 0x1185eaf0>
<environment: namespace:Seurat>
没有具体显示Findmarker的内容。
以下是解决办法:
FindMarkers
是一个泛型函数,需要找到适用于特定对象类型的方法。
使用getMethod
函数获取特定方法的实现,然后查看其源代码。
# 列出FindMarkers泛型函数的所有方法
methods("FindMarkers")
# [1] FindMarkers.Assay* FindMarkers.default* FindMarkers.DimReduc*
# FindMarkers.SCTAssay* FindMarkers.Seurat*
# see '?methods' for accessing help and source code
这将显示所有可用的FindMarkers
函数的方法。
一旦确定了特定方法,就可以使用getMethod
来查看其源代码。例如,如果使用的是Seurat
对象:
# 获取Seurat类的特定方法
method <- getMethod("FindMarkers", "Seurat")
# 打印方法的源代码
print(method)
或者:
getAnywhere(FindMarkers.Seurat)
最终得到结果:
A single object matching ‘FindMarkers.Seurat’ was found
It was found in the following places
registered S3 method for FindMarkers from namespace Seurat
namespace:Seurat
with value
function (object, ident.1 = NULL, ident.2 = NULL, group.by = NULL,
subset.ident = NULL, assay = NULL, slot = "data", reduction = NULL,
features = NULL, logfc.threshold = 0.25, test.use = "wilcox",
min.pct = 0.1, min.diff.pct = -Inf, verbose = TRUE, only.pos = FALSE,
max.cells.per.ident = Inf, random.seed = 1, latent.vars = NULL,
min.cells.feature = 3, min.cells.group = 3, mean.fxn = NULL,
fc.name = NULL, base = 2, densify = FALSE, ...)
{
if (!is.null(x = group.by)) {
if (!is.null(x = subset.ident)) {
object <- subset(x = object, idents = subset.ident)
}
Idents(object = object) <- group.by
}
if (!is.null(x = assay) && !is.null(x = reduction)) {
stop("Please only specify either assay or reduction.")
}
if (length(x = ident.1) == 0) {
stop("At least 1 ident must be specified in `ident.1`")
}
if (is.null(x = reduction)) {
assay <- assay %||% DefaultAssay(object = object)
data.use <- object[[assay]]
cellnames.use <- colnames(x = data.use)
}
else {
data.use <- object[[reduction]]
cellnames.use <- rownames(x = data.use)
}
cells <- IdentsToCells(object = object, ident.1 = ident.1,
ident.2 = ident.2, cellnames.use = cellnames.use)
if (!is.null(x = latent.vars)) {
latent.vars <- FetchData(object = object, vars = latent.vars,
cells = c(cells$cells.1, cells$cells.2))
}
norm.command <- paste0("NormalizeData.", assay)
norm.method <- if (norm.command %in% Command(object = object) &&
is.null(x = reduction)) {
Command(object = object, command = norm.command, value = "normalization.method")
}
else if (length(x = intersect(x = c("FindIntegrationAnchors",
"FindTransferAnchors"), y = Command(object = object)))) {
command <- intersect(x = c("FindIntegrationAnchors",
"FindTransferAnchors"), y = Command(object = object))[1]
Command(object = object, command = command, value = "normalization.method")
}
else {
NULL
}
de.results <- FindMarkers(object = data.use, slot = slot,
cells.1 = cells$cells.1, cells.2 = cells$cells.2, features = features,
logfc.threshold = logfc.threshold, test.use = test.use,
min.pct = min.pct, min.diff.pct = min.diff.pct, verbose = verbose,
only.pos = only.pos, max.cells.per.ident = max.cells.per.ident,
random.seed = random.seed, latent.vars = latent.vars,
min.cells.feature = min.cells.feature, min.cells.group = min.cells.group,
mean.fxn = mean.fxn, base = base, fc.name = fc.name,
densify = densify, norm.method = norm.method, ...)
return(de.results)
}
<bytecode: 0xc38b748>
<environment: namespace:Seurat>