-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 19 KB
/
.Rhistory
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
sparrows <- readData('/Users/dominiquefastus/tax_dxy_chrZ/', format = "VCF", outgroup = 'Naxos2')
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
# only creating a dataframe with the absolute differentiation
# select data of interest
hs <- sparrow_data %>% select(mid, PDMS_PHESP_dxy, PDMS_PKXX_dxy, PHESP_PKXX_dxy)
# use gather to rearrange everything
hs_g <- gather(hs, -mid, key = "stat", value = "value")
# construct a plot with facets
dxy_fcts <- ggplot(hs_g, aes(mid/10^6, value, colour = stat)) + geom_line(show.legend = FALSE)
dxy_fcts <- dxy_fcts + facet_grid(stat~., scales = "free_y")
dxy_fcts <- dxy_fcts + xlab("Position (Mb)")
dxy_fcts + theme_light() + theme(legend.position = "none")
dxy_fcts
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
# gather the data
dxy1 <- sparrow_data %>% select(contains("dxy")) %>% gather(key = "species", value = "dxy")
# use gather to rearrange everything
hs_g1 <- gather(hs, -mid, key = "stat", value = "value")
source("~/.active-rstudio-document", echo=TRUE)
# VCF_split_into_scaffolds('/Users/dominiquefastus/tax_dxy/ProjTaxa.vcf','/Users/dominiquefastus/tax_dxy_split/')
sparrows <- readData('/Users/dominiquefastus/tax_dxy_chrZ///', format = "VCF", outgroup = 'Naxos2')
# get information about sites distribution
get.sum.data(sparrows)
#
# check for population data
sparrows@populations
# read the sparrow population info
sparrow_info <- read_delim("/Users/dominiquefastus/population_file.txt", delim = "\t")
# now get the data for the populations
# three populations with the each 5 taxas
populations <- split(sparrow_info$Ind, sparrow_info$Pop)
# use the population with the taxa as vectors to set the populations in our sparrow dataset
sparrows <- set.populations(sparrows, populations, diploid = T)
# check that it worked
sparrows@populations
# check that it worked
sparrows@populations
# next split the genome into windows of a particular size and then calculate
# the mean for a statistic within that window.
# set chromosome size
chr_size <- 68732756
# set window size and window jump
window_size <- 100000
window_jump <- 25000
# use seq to find the start points of each window
window_start <- seq(from = 1, to = chr_size, by = window_jump)
# add the size of the window to each start point
window_stop <- window_start + window_size
# no windows start before the end of the chromosome
sum(window_start > chr_size)
# but some window stop positions do occur past the final point
sum(window_stop > chr_size)
# remove windows from the start and stop vectors
window_start <- window_start[which(window_stop < chr_size)]
window_stop <- window_stop[which(window_stop < chr_size)]
chr_size - window_stop[length(window_stop)]
# save as a data.frame
windows <- data.frame(start = window_start, stop = window_stop,
mid = window_start + (window_stop-window_start)/2)
# make a sliding window dataset
sparrows_sw <- sliding.window.transform(sparrows, width = 100000, jump = 25000, type = 2)
# calculate diversity statistics pi
sparrows_sw <- diversity.stats(sparrows_sw, pi = TRUE)
# calculate diversity statistics
sparrows_sw <- F_ST.stats(sparrows_sw, mode = "nucleotide")
# extract nucleotide diversity and correct for window size
nd <- [email protected]/100000
# make population name vector
pops <- c("PDMS","PHESP","PKXX")
# set population names
colnames(nd) <- paste0(pops, "_pi")
# extract fst values
fst <- t([email protected]_ST.pairwise)
# extract dxy - pairwise absolute nucleotide diversity
dxy <- get.diversity(sparrows_sw, between = T)[[2]]/10000
# get column names
x <- colnames(fst)
# does the same thing as above but by indexing the pops vector
x <- sub("pop1", pops[1], x)
x <- sub("pop2", pops[2], x)
x <- sub("pop3", pops[3], x)
# replace forward slash
x <- sub("/", "_", x)
# look at x to confirm the replacement has occurred
x
colnames(fst) <- paste0(x, "_fst")
colnames(dxy) <- paste0(x, "_dxy")
# data frame for windows, nd, fst, dxy
# add windows
sparrow_data <- as.tibble(data.frame(windows, nd, fst, dxy))
# select nucleotide diversity data and calculate means
sparrow_data %>% select(contains("pi")) %>% summarise_all(mean)
# gather the data
dxy <- sparrow_data %>% select(contains("dxy")) %>% gather(key = "species", value = "dxy")
# make a boxplot
dxy_bxplt <- ggplot(dxy, aes(species, dxy, colour = species)) + geom_boxplot(show.legend = FALSE) + theme_light() + xlab(NULL)
dxy_bxplt <- dxy_bxplt
dxy_bxplt
# only creating a dataframe with the absolute differentiation
# select data of interest
hs <- sparrow_data %>% select(mid, PDMS_PHESP_dxy, PDMS_PKXX_dxy, PHESP_PKXX_dxy)
# use gather to rearrange everything
hs_g <- gather(hs, -mid, key = "stat", value = "value")
# construct a plot with facets
dxy_fcts <- ggplot(hs_g, aes(mid/10^6, value, colour = stat)) + geom_line(show.legend = FALSE)
dxy_fcts <- dxy_fcts + facet_grid(stat~., scales = "free_y")
dxy_fcts <- dxy_fcts + xlab("Position (Mb)")
dxy_fcts + theme_light() + theme(legend.position = "none")
dxy_fcts
plot <- ggarrange(dxy_bxplt, dxy_fcts,
labels = c("A", "B"),
ncol = 1, nrow = 2)
annotate_figure(plot, top = text_grob("Destribution of dxy in Chr5 between sparrow populations",
face = "bold", size = 14))
# gather the data
dxy2 <- sparrow_data %>% select(contains("dxy")) %>% gather(key = "species", value = "dxy")
# use gather to rearrange everything
hs_g2 <- gather(hs, -mid, key = "stat", value = "value")
source("~/.active-rstudio-document", echo=TRUE)
# make a boxplot
dxy_bxplt1 <- ggplot(dxy1, aes(species, dxy, colour = species)) + geom_boxplot(show.legend = FALSE) + theme_light() + xlab(NULL)
# construct a plot with facets
dxy_fcts1 <- ggplot(hs_g1, aes(mid/10^6, value, colour = stat)) + geom_line(show.legend = FALSE)
dxy_fcts1 <- dxy_fcts + facet_grid(stat~., scales = "free_y")
dxy_fcts1 <- dxy_fcts + xlab("Position (Mb)")
dxy_fcts1 + theme_light() + theme(legend.position = "none")
# make a boxplot
dxy_bxplt2 <- ggplot(dxy2, aes(species, dxy, colour = species)) + geom_boxplot(show.legend = FALSE) + theme_light() + xlab(NULL)
# construct a plot with facets
dxy_fcts2 <- ggplot(hs_g2, aes(mid/10^6, value, colour = stat)) + geom_line(show.legend = FALSE)
dxy_fcts2 <- dxy_fcts + facet_grid(stat~., scales = "free_y")
dxy_fcts2 <- dxy_fcts + xlab("Position (Mb)")
dxy_fcts2 + theme_light() + theme(legend.position = "none")
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
# make a boxplot
dxy_bxplt1 <- ggplot(dxy, aes(species, dxy, colour = species)) + geom_boxplot(show.legend = FALSE) + theme_light() + xlab(NULL)
dxy_bxplt1 <- dxy_bxplt
dxy_bxplt1
# construct a plot with facets
dxy_fcts1 <- ggplot(hs_g, aes(mid/10^6, value, colour = stat)) + geom_line(show.legend = FALSE)
dxy_fcts1 <- dxy_fcts + facet_grid(stat~., scales = "free_y")
dxy_fcts1 <- dxy_fcts + xlab("Position (Mb)")
dxy_fcts1 + theme_light() + theme(legend.position = "none")
dxy_fcts1
# VCF_split_into_scaffolds('/Users/dominiquefastus/tax_dxy/ProjTaxa.vcf','/Users/dominiquefastus/tax_dxy_split/')
sparrows <- readData('/Users/dominiquefastus/tax_dxy_chr5///', format = "VCF", outgroup = 'Naxos2')
# get information about sites distribution
get.sum.data(sparrows)
source("~/variant calling analysis/pop_gen_analysis.R", echo=TRUE)
plot <- ggarrange(dxy_bxplt1, dxy_fcts1, dxy_bxplt2, dxy_fcts2,
labels = c("A", "B","C","D"),
ncol = 2, nrow = 2)
annotate_figure(plot, top = text_grob("Destribution of dxy in Chr5 between sparrow populations",
face = "bold", size = 14))
# load required packaged
library(shiny)
library(tidyverse)
library(openxlsx)
library(shinydashboard)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian", cols = c(1:2, 11:13, 19:21, 25))
clinvar <- read.delim('/Users/dominiquefastus/ClinPop/raw/variant_summary.txt', sep = "\t")
# filter the clinvar data with un
filtered_clinvar <- clinvar %>%
filter(ClinicalSignificance == "Pathogenic" |
ClinicalSignificance == "Likely Pathogenic")
pheno_choices = unique(filtered_clinvar$PhenotypeList)
print(pheno_choices)
View(clinvar)
View(populations)
# Define server logic
server <- function(input, output) {
# Create reactive data frame based on input values
data <- reactive({
# Generate fake data for demonstration purposes
data.frame(
Population = rep(input$Populations, 1000),
Frequency = rnorm(1000, mean = 500, sd = 100),
ClinVAR_marker = rep(input$ClinVAR_marker, 1000),
Time = input$range
)
})
# Create plot based on reactive data
output$plot <- renderPlot({
ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations))
})
# Print selected input values to sidebar
output$value <- renderPrint({
paste("You have selected", input$ClinVAR_marker, "in", input$Populations,
"from time", input$range[1], "to", input$range[2])
})
# Download plot as PDF
output$downloadPDF <- downloadHandler(
filename = "plot.pdf",
content = function(file) {
pdf(file)
print(ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations)))
dev.off()
}
)
}
# Run app
shinyApp(ui = ui, server = server)
runApp('~/ClinPop/ClinPOP.R')
View(clinvar)
View(populations)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian")
View(populations)
View(filtered_clinvar)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian", cols = c(1:2,11:13,19:21,25,33))
# filter the clinvar data with un
filtered_clinvar <- clinvar %>%
filter(ClinicalSignificance == "Pathogenic" |
ClinicalSignificance == "Likely Pathogenic" &
RS...dbSNP. != -1)
# assign countries to continent regions to group them into populations
egnations <- populations$Country
populations$Country <- countrycode(sourcevar = egnations, origin = "country.name",
destination = "region")
View(populations)
# load required packaged
library(shiny)
library(tidyverse)
library(openxlsx)
library(shinydashboard)
library(countrycode)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian", cols = c(1:2,11:13,19:21,25,33))
clinvar <- read.delim('/Users/dominiquefastus/ClinPop/raw/variant_summary.txt', sep = "\t")
# filter the clinvar data with un
filtered_clinvar <- clinvar %>%
filter(ClinicalSignificance == "Pathogenic" |
ClinicalSignificance == "Likely Pathogenic" &
RS...dbSNP. != -1)
# assign countries to continent regions to group them into populations
egnations <- populations$Country
populations$Country <- countrycode(sourcevar = egnations, origin = "country.name",
destination = "region")
View(populations)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian", cols = c(1:2,11,12,19:21,25,33))
# filter the clinvar data with un
filtered_clinvar <- clinvar %>%
filter(ClinicalSignificance == "Pathogenic" |
ClinicalSignificance == "Likely Pathogenic" &
RS...dbSNP. != -1)
# assign countries to continent regions to group them into populations
egnations <- populations$Country
populations$Country <- countrycode(sourcevar = egnations, origin = "country.name",
destination = "region")
View(populations)
populations <- read.xlsx('/Users/dominiquefastus/ClinPop/raw/Eurasian - Dataset_tims.xlsx',
sheet = "Eurasian", cols = c(1:2,11:13,19,21,25,33))
# filter the clinvar data with un
filtered_clinvar <- clinvar %>%
filter(ClinicalSignificance == "Pathogenic" |
ClinicalSignificance == "Likely Pathogenic" &
RS...dbSNP. != -1)
# assign countries to continent regions to group them into populations
egnations <- populations$Country
populations$Country <- countrycode(sourcevar = egnations, origin = "country.name",
destination = "region")
View(populations)
# Define UI
ui <- dashboardPage (
skin = "black",
dashboardHeader(title = "ClinPOP - ClinVAR marker visualization in populations",
titleWidth = 600),
dashboardSidebar(
width = 300,
# selection option for ClinVAR marker
selectInput("ClinVAR_marker", "Select ClinVAR marker:",
choices = unique(filtered_clinvar$RS...dbSNP.)),
# selection option for populations
selectInput("Populations", "Select Population:",
choices = unique(populations$Country)),
# Input: Specification of range within an interval ----
sliderInput("range", "Time to show frequencies:",
min = 1, max = 1000,
value = c(200,500)),
div(style="display:inline-block; align-items: normal;",actionButton("action", label = "Apply")),
div(style="display:inline-block; align-items: normal;",downloadButton("downloadPDF", label = "Download plot as PDF"))
),
dashboardBody(
# Main panel with plot
fluidRow(
box(
width = 12,
title = "Frequency plot",
plotOutput("plot")
)
)
)
)
# Define server logic
server <- function(input, output) {
# Create reactive data frame based on input values
data <- reactive({
# Generate fake data for demonstration purposes
data.frame(
Population = rep(input$Populations, 1000),
Frequency = rnorm(1000, mean = 500, sd = 100),
ClinVAR_marker = rep(input$ClinVAR_marker, 1000),
Time = input$range
)
})
# Create plot based on reactive data
output$plot <- renderPlot({
ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population"))
})
# Print selected input values to sidebar
output$value <- renderPrint({
paste("You have selected", input$ClinVAR_marker, "in", input$Populations,
"from time", input$range[1], "to", input$range[2])
})
# Download plot as PDF
output$downloadPDF <- downloadHandler(
filename = "plot.pdf",
content = function(file) {
pdf(file)
print(ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population")))
dev.off()
}
)
}
# Run app
shinyApp(ui = ui, server = server)
# Define UI
ui <- dashboardPage (
skin = "black",
dashboardHeader(title = "ClinPOP - ClinVAR marker visualization in populations",
titleWidth = 600),
dashboardSidebar(
width = 300,
# selection option for ClinVAR marker
selectInput("ClinVAR_marker", "Select ClinVAR marker:",
choices = c("rs2255773", "rs4845911", "rs3094315", "rs6696609")),
# selection option for populations
selectInput("Populations", "Select Population:",
choices = unique(populations$Country)),
# Input: Specification of range within an interval ----
sliderInput("range", "Time to show frequencies:",
min = 1, max = 1000,
value = c(200,500)),
div(style="display:inline-block; align-items: normal;",actionButton("action", label = "Apply")),
div(style="display:inline-block; align-items: normal;",downloadButton("downloadPDF", label = "Download plot as PDF"))
),
dashboardBody(
# Main panel with plot
fluidRow(
box(
width = 12,
title = "Frequency plot",
plotOutput("plot")
)
)
)
)
# Define server logic
server <- function(input, output) {
# Create reactive data frame based on input values
data <- reactive({
# Generate fake data for demonstration purposes
data.frame(
Population = rep(input$Populations, 1000),
Frequency = rnorm(1000, mean = 500, sd = 100),
ClinVAR_marker = rep(input$ClinVAR_marker, 1000),
Time = input$range
)
})
# Create plot based on reactive data
output$plot <- renderPlot({
ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population"))
})
# Print selected input values to sidebar
output$value <- renderPrint({
paste("You have selected", input$ClinVAR_marker, "in", input$Populations,
"from time", input$range[1], "to", input$range[2])
})
# Download plot as PDF
output$downloadPDF <- downloadHandler(
filename = "plot.pdf",
content = function(file) {
pdf(file)
print(ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population")))
dev.off()
}
)
}
# Run app
shinyApp(ui = ui, server = server)
# Define UI
ui <- dashboardPage (
skin = "black",
dashboardHeader(title = "ClinPOP - ClinVAR marker visualization in populations",
titleWidth = 600),
dashboardSidebar(
width = 300,
# selection option for ClinVAR marker
selectInput("ClinVAR_marker", "Select ClinVAR marker:",
choices = c("rs2255773", "rs4845911", "rs3094315", "rs6696609")),
# selection option for populations
selectInput("Populations", "Select Population:",
choices = unique(populations$Country)),
# Input: Specification of range within an interval ----
sliderInput("range", "Time to show frequencies:",
min = 1, max = 1000,
value = c(200,500)),
div(style="display:inline-block; align-items: normal;",actionButton("action", label = "Apply")),
div(style="display:inline-block; align-items: normal;",downloadButton("downloadPDF", label = "Download plot as PDF"))
),
dashboardBody(
# Main panel with plot
fluidRow(
box(
width = 12,
title = "Frequency plot",
plotOutput("plot")
)
)
)
)
# Define server logic
server <- function(input, output) {
# Create reactive data frame based on input values
data <- reactive({
# Generate fake data for demonstration purposes
data.frame(
Population = rep(input$Populations, 1000),
Frequency = rnorm(1000, mean = 500, sd = 100),
ClinVAR_marker = rep(input$ClinVAR_marker, 1000),
Time = input$range
)
})
# Create plot based on reactive data
output$plot <- renderPlot({
ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population"))
})
# Print selected input values to sidebar
output$value <- renderPrint({
paste("You have selected", input$ClinVAR_marker, "in", input$Populations,
"from time", input$range[1], "to", input$range[2])
})
# Download plot as PDF
output$downloadPDF <- downloadHandler(
filename = "plot.pdf",
content = function(file) {
pdf(file)
print(ggplot(data(), aes(x = Time, y = Frequency, color = Population)) +
geom_line() +
ggtitle(paste("Frequency of", input$ClinVAR_marker, "in", input$Populations,
"population")))
dev.off()
}
)
}
# Run app
shinyApp(ui = ui, server = server)
rm(list = ls())
gc()
gc()
library(shiny); runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
library(shiny); runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
runApp('~/ClinPop/ClinPoPapp.R')
library(shiny); runApp('~/ClinPop/ClinPoPapp.R')