Skip to content

Commit

Permalink
minor edits in predict_most_similar_cluster()
Browse files Browse the repository at this point in the history
  • Loading branch information
yunzhang813 committed Jul 21, 2021
1 parent d45fba7 commit d9f0159
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions R/predict_most_similar_cluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,29 @@
#' For more options, please see \code{\link[stats]{p.adjust.methods}}.
#'
#' @return A data frame of the most similar reference cluster for each query cluster,
#' which is the "match" with the highest adjusted p-value.
#' which is the "match" with the highest adjusted p-value. If there are tied p-values, all will be returned.
#'
#' @export

predict_most_similar_cluster <- function(rst.FRmatch, p.adj.method="BY"){
pmat <- rst.FRmatch$pmat
pmat.adj <- padj.FRmatch(pmat, p.adj.method=p.adj.method)
df.most.similar.cluster <- data.frame("query_cluster"=colnames(pmat),
"most_similar_ref_cluster"=rownames(pmat)[apply(pmat, 2, which.max)], #use the original pmat, independent of p.adj.method
"padj"=colMaxs(pmat.adj)) %>% arrange(desc(padj)) #return padj here

## return ALL maximum p-values if there are multiple
cmax <- colMaxs(pmat.adj)
query_cluster <- most_similar_ref_cluster <- padj <- c()
for(j in 1:length(cmax)){
ind.j <- pmat.adj[,j] == cmax[j]
query_cluster <- c(query_cluster, rep(colnames(pmat.adj)[j], sum(ind.j)))
most_similar_ref_cluster <- c(most_similar_ref_cluster, rownames(pmat.adj)[ind.j])
padj <- c(padj, rep(cmax[j], sum(ind.j)))
}
df.most.similar.cluster <- data.frame(query_cluster, most_similar_ref_cluster, padj) %>% arrange(desc(padj))

# ## return the first maximum p-value
# df.most.similar.cluster <- data.frame("query_cluster"=colnames(pmat),
# "most_similar_ref_cluster"=rownames(pmat)[apply(pmat, 2, which.max)], #use the original pmat, independent of p.adj.method
# "padj"=colMaxs(pmat.adj)) %>% arrange(desc(padj)) #return padj here

return(df.most.similar.cluster)
}
2 changes: 1 addition & 1 deletion man/predict_most_similar_cluster.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9f0159

Please sign in to comment.