Skip to content

Commit 7127f1d

Browse files
committed
Update correlation functions to work with the latest version of Hmisc
1 parent 53c2c53 commit 7127f1d

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Imports:
2424
ComplexHeatmap,
2525
grDevices,
2626
ggpubr,
27-
Hmisc (== 5.1-3),
27+
Hmisc (>= 5.2-3),
2828
immunedeconv (>= 2.1.0),
2929
matrixStats,
3030
omnideconv (>= 0.1.0),

R/cell_deconvolution.R

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ compute_subgroups = function(deconvolution, thres_corr, file_name){
888888
correlation <- function(data) {
889889

890890
M <- Hmisc::rcorr(as.matrix(data), type = "pearson")
891-
Mdf <- purrr::map(M, ~data.frame(.x))
891+
Mdf <- purrr::map(M[c("r", "P", "n")], ~data.frame(.x))
892892

893893
corr_df = Mdf %>%
894894
purrr::map(~tibble::rownames_to_column(.x, var="measure1")) %>%
@@ -1939,21 +1939,26 @@ compute.benchmark = function(deconvolution, groundtruth, cells_extra = NULL, cor
19391939
deconvolution_combinations = gsub("(BPRNACan3DProMet|BPRNACanProMet|BPRNACan)", "\\1_", deconvolution_combinations)
19401940

19411941
###Correlation function
1942-
corr_bench <- function(data, corr, pval) {
1942+
corr_bench <- function(data, corr = "pearson", pval = 0.05) {
19431943
M <- Hmisc::rcorr(as.matrix(data), type = corr)
1944-
Mdf <- purrr::map(M, ~data.frame(.x))
19451944

1946-
corr_df = Mdf %>%
1947-
purrr::map(~tibble::rownames_to_column(.x, var="measure1")) %>%
1945+
# Only keep the three matrix elements: r, P, n
1946+
Mdf <- purrr::map(M[c("r", "P", "n")], ~data.frame(.x))
1947+
1948+
corr_df <- Mdf %>%
1949+
purrr::map(~tibble::rownames_to_column(.x, var = "measure1")) %>%
19481950
purrr::map(~tidyr::pivot_longer(.x, -measure1, names_to = "measure2")) %>%
19491951
dplyr::bind_rows(.id = "id") %>%
19501952
tidyr::pivot_wider(names_from = id, values_from = value) %>%
1951-
dplyr::mutate(sig_p = ifelse(P < pval, T, F),
1952-
p_if_sig = ifelse(sig_p, P, NA),
1953-
r_if_sig = ifelse(sig_p, r, NA))
1953+
dplyr::mutate(
1954+
r = as.numeric(r),
1955+
P = as.numeric(P),
1956+
sig_p = ifelse(P < pval, TRUE, FALSE),
1957+
p_if_sig = ifelse(sig_p, P, NA),
1958+
r_if_sig = ifelse(sig_p, r, NA)
1959+
)
19541960

19551961
return(corr_df)
1956-
19571962
}
19581963

19591964
#####Scatter plot function

0 commit comments

Comments
 (0)