Skip to content

Commit d9f0159

Browse files
committed
minor edits in predict_most_similar_cluster()
1 parent d45fba7 commit d9f0159

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

R/predict_most_similar_cluster.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,29 @@
88
#' For more options, please see \code{\link[stats]{p.adjust.methods}}.
99
#'
1010
#' @return A data frame of the most similar reference cluster for each query cluster,
11-
#' which is the "match" with the highest adjusted p-value.
11+
#' which is the "match" with the highest adjusted p-value. If there are tied p-values, all will be returned.
1212
#'
1313
#' @export
1414

1515
predict_most_similar_cluster <- function(rst.FRmatch, p.adj.method="BY"){
1616
pmat <- rst.FRmatch$pmat
1717
pmat.adj <- padj.FRmatch(pmat, p.adj.method=p.adj.method)
18-
df.most.similar.cluster <- data.frame("query_cluster"=colnames(pmat),
19-
"most_similar_ref_cluster"=rownames(pmat)[apply(pmat, 2, which.max)], #use the original pmat, independent of p.adj.method
20-
"padj"=colMaxs(pmat.adj)) %>% arrange(desc(padj)) #return padj here
18+
19+
## return ALL maximum p-values if there are multiple
20+
cmax <- colMaxs(pmat.adj)
21+
query_cluster <- most_similar_ref_cluster <- padj <- c()
22+
for(j in 1:length(cmax)){
23+
ind.j <- pmat.adj[,j] == cmax[j]
24+
query_cluster <- c(query_cluster, rep(colnames(pmat.adj)[j], sum(ind.j)))
25+
most_similar_ref_cluster <- c(most_similar_ref_cluster, rownames(pmat.adj)[ind.j])
26+
padj <- c(padj, rep(cmax[j], sum(ind.j)))
27+
}
28+
df.most.similar.cluster <- data.frame(query_cluster, most_similar_ref_cluster, padj) %>% arrange(desc(padj))
29+
30+
# ## return the first maximum p-value
31+
# df.most.similar.cluster <- data.frame("query_cluster"=colnames(pmat),
32+
# "most_similar_ref_cluster"=rownames(pmat)[apply(pmat, 2, which.max)], #use the original pmat, independent of p.adj.method
33+
# "padj"=colMaxs(pmat.adj)) %>% arrange(desc(padj)) #return padj here
34+
2135
return(df.most.similar.cluster)
2236
}

man/predict_most_similar_cluster.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)