Skip to content

Commit

Permalink
- clean up lasso experiment remnants
Browse files Browse the repository at this point in the history
- sync package loading with req.txt file
  • Loading branch information
thomas-enzlein committed May 22, 2024
1 parent 2eecbce commit a6ed1dc
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 134 deletions.
1 change: 0 additions & 1 deletion components/mainpanel.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
source("components/mainTab.R")
source("components/qcTab.R")
source("components/pcaTab.R")
source("components/lassoTab.R")
source("components/hcTab.R")

appMainPanel <- function(defaults) {
Expand Down
1 change: 0 additions & 1 deletion components/qcTab.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ qcTab <- function() {
"Selected-mz",
"PC-x",
"PC-y",
"LASSO-error",
"Outlier-mz",
"Outlier-all"),
multiple = FALSE,
Expand Down
103 changes: 1 addition & 102 deletions components/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ server <- function(input, output, session) {
appData <<- emptyAppDataObject()
vol <- getVolumes()

#defaults <- defaultsSettingsHandler(userSavedSettings = "settings.csv")

# check if "dir" is set in defaults
if (!is.null(defaults$dir)) {
appData$selected_dir <- defaults$dir
Expand Down Expand Up @@ -434,97 +432,10 @@ server <- function(input, output, session) {
}
})

#### LASSO tab #####
# inital dummy text output
output$mixture <- renderText({
paste("Mixture = 1")
})
output$glmTruePred <- renderPlotly({
# dummy plot
p <- dummyPlot("Fit model\nto display plot")

return(ggplotly(p))
})

output$glmVi <- renderPlotly({
# dummy plot
p <- dummyPlot("Fit model\nto display plot")
return(ggplotly(p))
})

observeEvent(input$doGLM, {
if (appData$info_state == "processed") {

message("starting model fit...\n")
show_spinner()
appData$model <- fitGLM(appData$res,
sigmoid = input$sigmoidModel,
elasticNet = input$elasticNet,
corFilter = input$corFilter)
updateSliderInput(inputId = "penalty",
value = log10(appData$model$penalty))
if (input$elasticNet) {
output$mixture <- renderText({
paste("Mixture =", round(appData$model$mixture, 2))
})
} else {
output$mixture <- renderText({
paste("Mixture = 1")
})
}

message("model fitted.\n")
hide_spinner()

output$glmTruePred <- renderPlotly({
p <- glmRegPlot(model = appData$model, penalty = input$penalty)

return(ggplotly(p))
})

observeEvent(input$penalty, {
output$glmVi <- renderPlotly({

p <- viPlot(getVi(appData$model, input$penalty))

return(ggplotly(p))
})
})
}
})

observeEvent(input$resetPenalty, {
if (!is.null(appData$model)) {
updateSliderInput(inputId = "penalty",
value = log10(appData$model$penalty))
} else {
message("appData$model was NULL\n")
}
})

observeEvent(input$lasso2peaksTable, {
if (!is.null(appData$model)) {

vi <- getVi(appData$model, penalty = input$penalty) %>%
perpareVi()

appData$stats <- appData$stats_original %>%
left_join(vi, by = join_by(mzIdx))

message("Updated peak table with lasso data.\n")
}
})

#### HClust tab #####
observeEvent(input$doHC, {
if (appData$show_plot) {
show_spinner()
# appData$hc <- doHClust(appData$res,
# cut = input$num_cluster,
# dist = input$hcDist,
# clustMethod = input$hcMethod,
# useFittedCurves = input$hcUseFitted)
# p <- plotDendro(appData$hc$dend)

appData$hc <- clusterCurves(appData$res, nClusters = 15)
hide_spinner()
Expand All @@ -541,15 +452,10 @@ server <- function(input, output, session) {
}
})




output$clustCurvesPlot <- renderPlotly({
if (appData$show_plot & !is.null(appData$hc)) {
show_spinner()
# p <- plotClusterCurves(dend = appData$hc$dend,
# tintmat = appData$hc$tintmat,
# useFittedCurves = input$hcUseFitted)

p <- plotTraj(appData$hc, k = input$num_cluster) +
labs(y = "rel. Intensity [arb. u.]",
x = "Log10 Concentration",
Expand All @@ -563,8 +469,6 @@ server <- function(input, output, session) {
output$optNumClust <- renderPlotly({
if (appData$show_plot & !is.null(appData$hc)) {
show_spinner()
# p <- optimalNumClustersPlot(appData$hc$opt,
# sel_k = input$num_cluster)
p <- plotClusterMetrics(appData$hc) +
hide_spinner()
return(ggplotly(p))
Expand All @@ -574,11 +478,6 @@ server <- function(input, output, session) {

observeEvent(input$hc2peaksTable, {
if (appData$show_plot & !is.null(appData$hc)) {
# clusters <- extractClusters(appData$hc$dend) %>%
# mutate(mzIdx = match.closest(x = mz,
# table = getAllMz(appData$res),
# tolerance = 0.1)) %>%
# select(-mz)

clusters <- extractLaClusters(appData$hc, k = input$num_cluster)
appData$stats <- appData$stats_original %>%
Expand Down
9 changes: 2 additions & 7 deletions functions/checkInstalledPackages.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
checkInstalledPackages <- function() {
checkInstalledPackages <- function(req_file = "req.txt") {
#### package check on start up ####
# If a package is installed, it will be loaded. If any
# are not, the missing package(s) will be installed
# from CRAN and then loaded.

## First specify the packages of interest
packages = c("tidyverse", "shiny", "shinyFiles",
"MALDIquant", "MALDIquantForeign", "DT", "plotly",
"shinycssloaders", "shinyhelper", "knitr", "shinybusy",
"shinythemes", "shinyWidgets", "devtools",
"proxy", "sparsepca", "platetools", "zoo",
"fs", "cluster", "shinyjs", "latrend", "dtwclust")
packages = read.csv(req_file)

## Now load or install&load all
package.check <- lapply(
Expand Down
23 changes: 0 additions & 23 deletions functions/plotFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ plateMapPlot <- function(appData,
"Selected-mz",
"PC-x",
"PC-y",
"LASSO-error",
"Outlier-mz",
"Outlier-all"),
PCs,
Expand Down Expand Up @@ -263,28 +262,6 @@ plateMapPlot <- function(appData,
spot = spots)
}
},
"LASSO-error" = {
if(!is.null(appData$model)) {
df <- appData$model$model %>%
finalize_model(tibble(penalty = 10^penalty)) %>%
fit(data = appData$model$prepData, formula = conc ~.) %>%
predict(appData$model$prepData) %>%
mutate(truth = pull(appData$model$prepData, conc)) %>%
mutate(val = abs(truth - .pred),
spot = spots)

if(log10) {
lab <- "log10(Abs. error)"
} else {
lab <- "Abs. error"
}
} else {
lab <- "No LASSO data"
df <- tibble(
val = rep(NA_integer_, length(spots)),
spot = spots)
}
},
"Outlier-mz" = {
lab <- paste0("Chauvenet\nCriterion\n",
"m/z=", round(getMzFromMzIdx(res, mzIdx = mz_idx), digits = 2))
Expand Down

0 comments on commit a6ed1dc

Please sign in to comment.