Skip to content

Commit

Permalink
fix crash within PCA when low numbers of entities selected; unsure if…
Browse files Browse the repository at this point in the history
… this was full rank error #357
  • Loading branch information
LeaSeep committed Nov 6, 2024
1 parent 00499bf commit 91047ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
19 changes: 15 additions & 4 deletions program/shinyApp/R/pca/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,21 @@ pca_Server <- function(id, data, params, row_select){
)
#LoadingsDF$Loading=scale(LoadingsDF$Loading)
LoadingsDF <- LoadingsDF[order(LoadingsDF$Loading,decreasing = T),]
LoadingsDF <- rbind(
LoadingsDF[nrow(LoadingsDF):(nrow(LoadingsDF) - input$bottomSlider),],
LoadingsDF[input$topSlider:1,]
)

# need to test if default of slider is below the number of entities
if(input$topSlider + input$bottomSlider > nrow(LoadingsDF)){
LoadingsDF
output$PCA_Info <- renderText({
paste0("Within Loadings visualisations:
the requested number of entities to show is higher than the number of entities in the data.
Hence, all entities are shown. The total number of entities is: ", length(rownames(pca$rotation)))})
}else{
LoadingsDF <- rbind(
LoadingsDF[nrow(LoadingsDF):(nrow(LoadingsDF) - input$bottomSlider),],
LoadingsDF[input$topSlider:1,]
)
}

LoadingsDF$entitie <- factor(LoadingsDF$entitie,levels = rownames(LoadingsDF))
if(!is.null(input$EntitieAnno_Loadings)){
req(data_input_shiny())
Expand Down
12 changes: 10 additions & 2 deletions program/shinyApp/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1040,14 +1040,22 @@ server <- function(input,output,session){
shinyjs::click("PCA-refreshUI",asis = T)
shinyjs::click("sample_correlation-refreshUI",asis = T)
paste0(
addWarning,
"The data has the dimensions of: ",
paste0(dim(res_tmp[[session$token]]$data),collapse = ", "),
"<br>","Be aware that depending on omic-Type, basic pre-processing has been done anyway even when selecting none",
"<br","If log10 was chosen, in case of 0's present log10(data+1) is done",
"<br","If logX was chosen, in case of 0's present logX(data+1) is done",
"<br","See help for details",
"<br>",ifelse(any(as.data.frame(assay(res_tmp[[session$token]]$data)) < 0),"Be aware that processed data has negative values, hence no log fold changes can be calculated",""))
})
# set the warning as toast
show_toast(
title = "Attention",
text = HTML(addWarning),
position = "top",
timer = 2500,
timerProgressBar = T
)

output$raw_violin_plot <- renderPlot({
violin_plot(res_tmp[[session$token]]$data_original[par_tmp[[session$token]][['entities_selected']],par_tmp[[session$token]][['samples_selected']]],
color_by = input$violin_color)
Expand Down

0 comments on commit 91047ab

Please sign in to comment.