|
8 | 8 | #' For more options, please see \code{\link[stats]{p.adjust.methods}}.
|
9 | 9 | #'
|
10 | 10 | #' @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. |
12 | 12 | #'
|
13 | 13 | #' @export
|
14 | 14 |
|
15 | 15 | predict_most_similar_cluster <- function(rst.FRmatch, p.adj.method="BY"){
|
16 | 16 | pmat <- rst.FRmatch$pmat
|
17 | 17 | 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 | + |
21 | 35 | return(df.most.similar.cluster)
|
22 | 36 | }
|
0 commit comments