-
Notifications
You must be signed in to change notification settings - Fork 0
/
straf_analysis.R
149 lines (118 loc) · 5.69 KB
/
straf_analysis.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#### R shiny application ####
#### PopGen Tool for AFUM ####
# Load shiny
library(shiny)
library(shinydashboard)
library(adegenet)
library(DT)
library(ggfortify)
library(shinycssloaders)
#### Data ####
db <- read.csv(file = "~/Documents/Imperial/R_folder/Shiny/STRAF/straf_db_shiny_only_2.csv")
#db <- read.csv(file = "~/Desktop/R_folder/Shiny/STRAF/straf_db_shiny_only.csv")
#head(db)
db <- db[,2:12]
head(db)
straf <- c("X2A", "X2B", "X2C", "X3A", "X3B", "X3C", "X4A", "X4B", "X4C")
#### UI ####
ui = dashboardPage(
dashboardHeader(title = "Afum"),
dashboardSidebar(
selectInput("source", "Choose a Source:",
choices = c(levels(db$Source))),
selectInput("country", "Choose a Country:",
choices = c(levels(db$Country))),
#selectInput("country", "Choose a Continent:",
#choices = c(levels(db$Continent))),
#selectInput("pop", "Choose a Population:",
#choices = c(levels(db$Population), "C")),
#selectInput("country", "Choose a Mutation:",
#choices = c(levels(db$Mutation))),
numericInput(inputId = "straf2a", label="Allele 2A", value="17", width = 180, min = 0, max = 400),
numericInput(inputId = "straf2b", label="Allele 2B", value="55", width = 180, min = 0, max = 400),
numericInput(inputId = "straf2c", label="Allele 2C", value="18", width = 180, min = 0, max = 400),
numericInput(inputId = "straf3a", label="Allele 3A", value="55", width = 180, min = 0, max = 400),
numericInput(inputId = "straf3b", label="Allele 3B", value="89", width = 180, min = 0, max = 400),
numericInput(inputId = "straf3c", label="Allele 3C", value="11", width = 180, min = 0, max = 400),
numericInput(inputId = "straf4a", label="Allele 4A", value="55", width = 180, min = 0, max = 400),
numericInput(inputId = "straf4b", label="Allele 4B", value="20", width = 180, min = 0, max = 400),
numericInput(inputId = "straf4c", label="Allele 4C", value="18", width = 180, min = 0, max = 400),
actionButton("goButton","Enter :)")),
dashboardBody(
tabsetPanel(type = "tabs",
tabPanel("Table", dataTableOutput("table")),
tabPanel("Genind", verbatimTextOutput("genind")),
tabPanel("Print", withSpinner(verbatimTextOutput("print"), type = 7, color = "#3C8DBC")),
tabPanel("PCA", withSpinner(plotOutput("pca"), type = 7, color = "#3C8DBC")),
tabPanel("DAPC", plotOutput("dapc")),
tabPanel("Result", verbatimTextOutput("result"))
)
)
)
#### Server ####
server <- function(input, output) {
# The important part of reactiveValues()
values <- reactiveValues()
values$df <- db
addData <- observe({
# your action button condition
if(input$goButton > 0) {
# create the new line to be added from your inputs
newLine <- isolate(c(input$source, input$country, input$straf2a, input$straf2b,
input$straf2c, input$straf3a, input$straf3b,
input$straf3c, input$straf4a, input$straf4b, input$straf4c, input$pop))
# update your data
# note the unlist of newLine, this prevents a bothersome warning message that the rbind will return regarding rownames because of using isolate.
#isolate(values$df <- rbind(as.data.frame(values$df), unlist(newLine)))
values$df <- isolate(rbind(values$df, newLine))
#values$df <- data.frame(values$df, stringsAsFactors = FALSE)
}
})
obj <- reactive({df2genind(values$df[,3:11], ploidy = 1, NA.char = "NA", sep = "")})
#obj()@pop <- reactive({values$df$Alelle})
#obj@pop <- reactive({values$df})
#reactive({pop(obj()) <- db$Allele})
snap <- reactive({snapclust(obj(), k = 2, hybrids = TRUE, parent.lab = c("Pop_A", "Pop_B"))})
# str <- reactive({cbind(Population = c(as.data.frame(snap()$group), values$df)}))
str <- reactive({cbind(setNames(as.data.frame(snap()$group), nm = "Population"), values$df)})
#colnames(str()[1]) <- "Population"
x <- reactive({scaleGen(obj(), NA.method="mean")})
pca <- reactive({prcomp(x())})
#dapc <- reactive({dapc.genind(obj(), n.pca = 3, n.da = nPop(obj()))})
output$table <- renderDataTable({values$df})
output$pca <- renderPlot({autoplot(pca(), x = 3, y = 1, frame = TRUE, frame.type = 'norm',
data = str(), colour = "Population", shape = "Source")})
#output$dapc <- renderPlot({scatter(dapc(), cell = 1, mstree = T, lwd = 3, lty = 1, cex = 0.8, solid = 1, legend = T)})
#output$print <- renderPrint({print(dapc())})
output$print <- renderPrint({print(tail(str()))})
output$genind <- renderPrint({print(obj())})
output$result <- renderPrint({print("if else thingy --- Your strain fits into Genetic cluster \
?? and has a higher chance of being resistant to azole antifungals")})
}
#### ShinyApp ####
shinyApp(ui = ui, server = server)
#### Spares ####
lapply(straf, function(i) {numericInput(inputId = paste0(straf, i),
label = paste0("Allele ", i),
value = 0,
min = 0,
max = 300,
width = 200)})
for(i in 1:9) values$df[,i] <- as.character(floor(as.numeric(as.character(values$df[,i]))))
values <- reactiveValues()
values$df <- db
tail(db)
newLine <- isolate(c(20,20,20,20,20,20,20,20,20))
newLine
view <- isolate(values$df <- rbind(as.matrix(values$df), unlist(newLine)))
tail(view)
obj <- df2g
enind(view, ploidy = 1, sep = "")
obj
obj <- df2genind(view, ploidy = 1)
obj
tail(db)
### addd to plots
class(x)
dim(x)
s.class(pca1$li, pop(str.gen), xax = 3, yax = 1)