Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ Imports:
dplyr,
stats,
parallel,
data.table
data.table,
plotly
Suggests:
MSstats,
MSstatsTMT,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ export(MSstatsPrepareDoseResponseFit)
export(convertGroupToNumericDose)
export(doseResponseFit)
export(futureExperimentSimulation)
export(plot_tpr_power_curve)
export(predictIC50)
export(predictIC50Parallel)
export(run_tpr_simulation)
export(visualizeResponseProtein)
import(dplyr)
importFrom(BiocParallel,bplapply)
Expand All @@ -15,6 +17,7 @@ importFrom(dplyr,arrange)
importFrom(dplyr,distinct)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,if_else)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
Expand All @@ -35,13 +38,16 @@ importFrom(ggplot2,scale_fill_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,theme_classic)
importFrom(ggplot2,theme_minimal)
importFrom(ggplot2,ylim)
importFrom(parallel,clusterExport)
importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(plotly,ggplotly)
importFrom(plotly,layout)
importFrom(stats,approx)
importFrom(stats,p.adjust)
importFrom(stats,pf)
Expand Down
25 changes: 16 additions & 9 deletions R/ExperimentalDesignSimulation.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,30 @@ futureExperimentSimulation = function(N_proteins = 300,
))
}

# Get mean profile across proteins
# Get mean profile across proteins using string-based grouping to avoid floating point precision issues
profile = drug_data %>%
filter(protein %in% protein_ids) %>%
mutate(dose_nM = round(dose * 1e9)) %>% # Convert M to nM and round to handle precision
group_by(dose_nM) %>%
mutate(dose_str = as.character(dose)) %>%
group_by(dose_str) %>%
summarise(
LogIntensities = mean(response, na.rm = TRUE),
dose_numeric = dose[1],
.groups = 'drop'
) %>%
rename(dose = dose_nM)
)

# Create complete profile with all concentrations
# Match profile doses to target concentrations using nearest-neighbor on log scale.
# This handles unit mismatches without assuming a fixed conversion factor.
complete_profile = data.frame(dose = concentrations)

# Merge with existing data
if (nrow(profile) > 0 && !any(profile$dose_numeric != 0)) {
stop("No non-zero dose measurements found for the selected protein.")
}

# Match by string representation to avoid floating point issues
complete_profile = complete_profile %>%
left_join(profile, by = "dose")
mutate(dose_str = as.character(dose)) %>%
left_join(profile %>% select(dose_str, LogIntensities), by = "dose_str") %>%
select(-dose_str)

# Fill missing values with interpolation or nearest neighbor
for (i in which(is.na(complete_profile$LogIntensities))) {
Expand Down Expand Up @@ -306,7 +313,7 @@ futureExperimentSimulation = function(N_proteins = 300,
return(complete_profile)
}

# Extract templates for each category
# Extract templates: use user data for specified proteins, baseline for others
template = list(
strong_interaction = .getMeanProfile(strong_proteins, drug_data, concentrations),
Comment thread
tonywu1999 marked this conversation as resolved.
weak_interaction = .getMeanProfile(weak_proteins, drug_data, concentrations),
Expand Down
Loading
Loading