Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Benchmarking #66

Open
wants to merge 18 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updates to return structure of benchmark_plot_composite_exposures and…
… benchmark_plot_duplicate_exposures
Natasha Gurevich authored and Natasha Gurevich committed Jun 28, 2024
commit f4c6277e96fdc063e0ac00b4fbcc7efdf94b6e2f
74 changes: 30 additions & 44 deletions R/benchmarking.R
Original file line number Diff line number Diff line change
@@ -670,7 +670,7 @@ benchmark_plot_exposures <- function(full_benchmark, method_id, prediction){
#' @param method_id The identifier for the \code{\linkS4class{single_benchmark}}
#' object of interest
#'
#' @return A ggplot object
#' @return A list of ggplot objects
#' @export
benchmark_plot_duplicate_exposures <- function(full_benchmark, method_id){

@@ -701,7 +701,7 @@ benchmark_plot_duplicate_exposures <- function(full_benchmark, method_id){
freq <- table(comparison$y_sig_name)
duplicated_signatures <- names(freq[freq > 1])

count <- 1
final_figures <- list()

for (duplicated_sig in duplicated_signatures){

@@ -773,26 +773,14 @@ benchmark_plot_duplicate_exposures <- function(full_benchmark, method_id){
theme(legend.title=element_blank())

#print(after_plot)
figure <- ggpubr::ggarrange(before_plot, after_plot, ncol = 2, nrow = 1)

if (count == 1){
full_figure <- figure
}
else{
full_figure <- ggpubr::ggarrange(full_figure, figure, ncol = 1, heights = c(count - 1,1))
}

count <- count + 1

#print(figure)
figure <- ggpubr::ggarrange(before_plot, after_plot, ncol = 2, nrow = 1)

final_figures <- append(final_figures, list(figure))

}

#print(full_figure)
if (count != 1){
return(full_figure)
}
return(final_figures)

}

@@ -809,7 +797,7 @@ benchmark_plot_duplicate_exposures <- function(full_benchmark, method_id){
#' @param method_id The identifier for the \code{\linkS4class{single_benchmark}}
#' object of interest
#'
#' @return A ggplot object
#' @return A list of ggplot objects
#' @export
benchmark_plot_composite_exposures <- function(full_benchmark, method_id){

@@ -842,6 +830,8 @@ benchmark_plot_composite_exposures <- function(full_benchmark, method_id){

count <- 1

final_figures <- list()

for (composite_sig in composite_signatures){

before_exposures <- NULL
@@ -879,7 +869,7 @@ benchmark_plot_composite_exposures <- function(full_benchmark, method_id){
geom_smooth(method = "lm") +
theme(legend.title=element_blank())

print(before_plot)
#print(before_plot)

colnames <- NULL
for (component in sig_components){
@@ -920,27 +910,15 @@ benchmark_plot_composite_exposures <- function(full_benchmark, method_id){
geom_smooth(method = "lm") +
theme(legend.title=element_blank())

print(after_plot)
#print(after_plot)

figure <- ggpubr::ggarrange(before_plot, after_plot, ncol = 2, nrow = 1)

if (count == 1){
full_figure <- figure
}
else{
full_figure <- ggpubr::ggarrange(full_figure, figure, ncol = 1, heights = c(count - 1,1))
}

count <- count + 1
final_figures <- append(final_figures, list(figure))

}

#combined_plot<- gridExtra::grid.arrange(before_plot, after_plot, ncol = 2)
#return(combined_plot)

if (count != 1){
return(full_figure)
}

return(final_figures)

}

@@ -1311,23 +1289,31 @@ benchmark_plot_composite_exposures <- function(full_benchmark, method_id){
high_threshold_comp <- comparison[comparison$cosine > adjustment_threshold,]

indexes_to_keep <- c()
for (index in 1:dim(low_threshold_comp)[1]){
if (low_threshold_comp[index,4] %in% high_threshold_comp$x_sig_name == FALSE){
indexes_to_keep <- c(indexes_to_keep, index)
}
else{
existing_cs <- high_threshold_comp[high_threshold_comp$x_sig_name == low_threshold_comp[index,4], 1][1]
diff <- abs(existing_cs - low_threshold_comp[index,1])
if (diff < 0.05){
if (dim(low_threshold_comp)[1] > 0){
for (index in 1:dim(low_threshold_comp)[1]){
if (low_threshold_comp[index,4] %in% high_threshold_comp$x_sig_name == FALSE){
indexes_to_keep <- c(indexes_to_keep, index)
}
else{
existing_cs <- high_threshold_comp[high_threshold_comp$x_sig_name == low_threshold_comp[index,4], 1][1]
diff <- abs(existing_cs - low_threshold_comp[index,1])
if (diff < 0.05){
indexes_to_keep <- c(indexes_to_keep, index)
}
}
}
}


comparison_adj <- rbind(high_threshold_comp, low_threshold_comp[indexes_to_keep,])

return(comparison_adj)

}

else{
return(comparison)
}

}

# Function for claculating RE
2 changes: 1 addition & 1 deletion man/benchmark_plot_composite_exposures.Rd

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

2 changes: 1 addition & 1 deletion man/benchmark_plot_duplicate_exposures.Rd

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

2 changes: 1 addition & 1 deletion vignettes/articles/benchmarking_tutorial.Rmd
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ count_table <- synthetic_breast_counts
musica <- create_musica_from_counts(count_table, "SBS96")

# prediction
res2 <- discover_signatures(musica, "SBS96", num_signatures = 9, algorithm = "nmf")
res2 <- discover_signatures(musica, "SBS96", num_signatures = 8, algorithm = "nmf")

```