Skip to content

Commit

Permalink
added MDS
Browse files Browse the repository at this point in the history
  • Loading branch information
agouy committed Feb 9, 2021
1 parent af46e98 commit e1a3ce7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
25 changes: 25 additions & 0 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ suppressPackageStartupMessages({
library(car)
library(plotly)
library(openxlsx)
library(ggplot2)
library(ggrepel)
})

options(stringsAsFactors = FALSE)
Expand Down Expand Up @@ -849,6 +851,29 @@ shinyServer(function(input, output) {
plotOutput('runPCA', width = paste(input$width,"%",sep = ""),
height = input$height, click = "plot_click")
})
output$plotMDS <- renderUI({
plotOutput('runMDS', width = paste(input$width,"%",sep = ""),
height = input$height)
})
output$runMDS <- renderPlot({
if (!input$displayMDS) return(NULL)
dat2 <- getgenind()

obj <- genind2genpop(dat2)
dst <- dist.genpop(obj, method = 1)
# hc <- hclust(dst)
# plot(as.dendrogram(hc), horiz=T, xlab = "", sub = "", main = "Nei's distance between populations")

MDS <- cmdscale(dst)
MDS <- data.frame(ax1 = MDS[, 1], ax2 = MDS[, 2], pop = rownames(MDS))
# plot(MDS, xlab = "MDS Axis 1", ylab = "MDS Axis 2", pch = 16, col = dat2@pop)
p <- ggplot(MDS, aes(x=ax1, y=ax2, color = pop, label = pop)) +
geom_point() +
geom_text_repel() +
labs( x = "MDS Axis 1", y = "MDS Axis 2", title = "MDS based on Nei's distance") +
theme_minimal()
plot(p)
})

# DL principal components
output$dlPCAeigen <- downloadHandler(
Expand Down
24 changes: 21 additions & 3 deletions ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,13 @@ shinyUI(
downloadButton('dlFstMatXL', 'Download as Excel (.xlsx)')
),

tags$hr(),
tags$hr()

h4("Principal Component Analysis"),
),
tabPanel(
"PCA - MDS",

h4("Principal Component Analysis (PCA)"),

checkboxInput(
'displayPCA',
Expand Down Expand Up @@ -333,7 +337,20 @@ shinyUI(

),

tags$hr()
tags$hr(),

h4("Multidimensional Scaling (MDS) based on Nei's distance"),

checkboxInput(
'displayMDS',
"Compute Nei's genetic distance between populations and run MDS",
FALSE
),
conditionalPanel(

condition = "input.displayMDS == true",
uiOutput('plotMDS')
)

),
tabPanel(
Expand Down Expand Up @@ -465,6 +482,7 @@ shinyUI(
h3("Updates"),

tags$ul(
tags$li("1.4.0 (09/02/2021) – STRAF can now perform an MDS. All results can be downloaded as Excel files. Minor bug fixes in file conversion."),
tags$li("1.3.3 (03/02/2021) – Minor bug fixes in file conversion and PIC computation. Improved graphics."),
tags$li("1.3.0 (01/02/2021) – STRAF can convert files to the Genepop and Familias formats. A File conversion tab has been added."),
tags$li("1.2.2 (09/01/2021) – STRAF has moved to an AWS server (without any changes in the License)."),
Expand Down

0 comments on commit e1a3ce7

Please sign in to comment.