Last updated: 2021-03-04
Checks: 7 0
Knit directory: fitnessGWAS/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20180914)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version a16e751. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rapp.history
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: .httr-oauth
Ignored: .pversion
Ignored: analysis/.DS_Store
Ignored: analysis/correlations_SNP_effects_cache/
Ignored: analysis/plot_models_variant_effects_cache/
Ignored: code/.DS_Store
Ignored: code/Drosophila_GWAS.Rmd
Ignored: data/.DS_Store
Ignored: data/derived/
Ignored: data/input/.DS_Store
Ignored: data/input/.pversion
Ignored: data/input/dgrp.fb557.annot.txt
Ignored: data/input/dgrp2.bed
Ignored: data/input/dgrp2.bim
Ignored: data/input/dgrp2.fam
Ignored: data/input/huang_transcriptome/
Ignored: figures/.DS_Store
Untracked files:
Untracked: Rplots.pdf
Untracked: analysis/GO_KEGG_enrichment.Rmd
Untracked: analysis/TWAS_tables.Rmd
Untracked: code/GO_and_KEGG_gsea.R
Untracked: code/eQTL_analysis.Rmd
Untracked: code/make_sites_files_for_ARGweaver.R
Untracked: code/plotting_results.Rmd
Untracked: code/run_argweaver.R
Untracked: code/run_mashr.R
Untracked: data/argweaver/
Untracked: data/input/TF_binding_sites.csv
Untracked: figures/GWAS_mixture_proportions.rds
Untracked: figures/GWAS_stats_figure.pdf
Untracked: figures/TWAS_mixture_proportions.rds
Untracked: figures/TWAS_stats_figure.pdf
Untracked: figures/antagonism_ratios.pdf
Untracked: figures/composite_mixture_figure.pdf
Untracked: figures/eff_size_histos.pdf
Untracked: figures/stats_figure.pdf
Untracked: manuscript/
Unstaged changes:
Modified: .gitignore
Modified: README.md
Modified: analysis/GWAS_tables.Rmd
Modified: analysis/TWAS.Rmd
Modified: analysis/_site.yml
Deleted: analysis/about.Rmd
Deleted: analysis/eQTL_analysis.Rmd
Modified: analysis/gwas_adaptive_shrinkage.Rmd
Modified: analysis/license.Rmd
Modified: analysis/make_annotation_database.Rmd
Modified: analysis/plotting_results.Rmd
Deleted: code/gwas_adaptive_shrinkage.R
Modified: data/input/female_fitness.csv
Modified: data/input/female_fitness_CLEANED.csv
Modified: data/input/male_fitness.csv
Modified: data/input/male_fitness_CLEANED.csv
Modified: figures/figure1.eps
Deleted: figures/figure1.png
Modified: figures/figure2.eps
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/plot_line_means.Rmd
) and HTML (docs/plot_line_means.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | a16e751 | lukeholman | 2021-03-04 | big first commit 2021 |
Rmd | 8d54ea5 | Luke Holman | 2018-12-23 | Initial commit |
html | 8d54ea5 | Luke Holman | 2018-12-23 | Initial commit |
library(ggplot2)
library(ggExtra)
library(dplyr)
library(tidyr)
library(grid)
library(gridExtra)
library(RColorBrewer)
library(showtext) # For fancy Google font in figures
font_add_google(name = "Raleway", family = "Raleway", regular.wt = 400, bold.wt = 700) # Install font from Google Fonts
# Load the predicted line means, as calculated by get_predicted_line_means
predicted_line_means <- read.csv("data/derived/predicted_line_means.csv", stringsAsFactors = FALSE)
Generally there is positive covariance between line means for different traits, and all 4 measures of fitness exhibit considerable phenotypic variance across lines.
lims <- c(1.1*min(apply(predicted_line_means[,2:5], 2, min)),
1.1*max(apply(predicted_line_means[,2:5], 2, max)))
fix.title <- function(x){
x[x == "female.fitness.early" | x == "femalefitnessearly"] <- "Female early-life fitness"
x[x == "male.fitness.early" | x == "malefitnessearly"] <- "Male early-life fitness"
x[x == "female.fitness.late" | x == "femalefitnesslate"] <- "Female late-life fitness"
x[x == "male.fitness.late" | x == "malefitnesslate"] <- "Male late-life fitness"
x
}
make_figure_1 <- function(){
nice.plot <- function(df, v1, v2){
formula <- as.formula(paste(v2, "~", v1))
model <- summary(lm(formula, data = df))
r2 <- format(model$r.squared %>% round(2), nsmall = 2)
slope <- format(model$coefficients[2,1] %>% round(2), nsmall = 2)
se <- format(model$coefficients[2,2] %>% round(2), nsmall = 2)
# print(model$coefficients[2,4]) # print p-value of the correlation
text1 <- paste("R^2 == ", r2, sep = "")
text2 <- paste("β = ", slope, " \u00B1 ", se, sep = "")
pp <- df %>%
ggplot(aes_string(x = v1, y = v2)) +
annotate("text", x=min(lims) + 0.1, y=max(lims), label = text1, parse = TRUE, hjust= 0) +
annotate("text", x=min(lims) + 0.1, y=max(lims)-0.4, label = text2, hjust= 0) +
geom_point(alpha = 0.7) +
stat_smooth(method = "lm", level = 0, colour = "tomato") +
xlab(fix.title(v1)) + ylab(fix.title(v2)) +
theme_classic() +
theme(text = element_text(family = "Raleway")) +
scale_x_continuous(limits = lims) +
scale_y_continuous(limits = lims)
if(v1 == "male.fitness.early" & v2 == "female.fitness.early") cols <- c("lightblue", "pink")
if(v1 == "male.fitness.late" & v2 == "female.fitness.late") cols <- c("steelblue", "deeppink2")
if(v1 == "male.fitness.early" & v2 == "male.fitness.late") cols <- c("lightblue", "steelblue")
if(v1 == "female.fitness.early" & v2 == "female.fitness.late") cols <- c("pink", "deeppink2")
ggExtra::ggMarginal(pp, type = "histogram", bins = 15, xparams = list(fill = cols[1]), yparams = list(fill = cols[2]))
}
p1 <- nice.plot(predicted_line_means, "male.fitness.early", "female.fitness.early")
p2 <- nice.plot(predicted_line_means, "male.fitness.late", "female.fitness.late")
p3 <- nice.plot(predicted_line_means, "male.fitness.early", "male.fitness.late")
p4 <- nice.plot(predicted_line_means, "female.fitness.early", "female.fitness.late")
full_plot <- grid.arrange(p1, p2, p3, p4)
cairo_ps("figures/figure1.eps", height = 9, width = 9)
full_plot
invisible(dev.off())
}
make_figure_1()
Version | Author | Date |
---|---|---|
8d54ea5 | Luke Holman | 2018-12-23 |
Figure 1: Correlations among estimated line means for the four fitness components. The line means were estimated from Bayesian mixed models that account for block effects, and the non-independence of our early- and late-life fitness measurements.
All possible types of lines were observed: some lines are uniformly bad, or uniformly good, or good in one sex or age class but bad in the other.
make_figure_2 <- function(){
out.file <- "figures/figure2.eps"
interaction.plot <- function(predicted_line_means, x1, x2, title, sex.or.age){
if(sex.or.age == "sex"){
x.labs <- c("Female", "Male")
cols <- c("red", "darkgrey", "blue")
} else {
x.labs <- c("Young", "Old")
cols <- c("green", "darkgrey", "purple")
}
df <- predicted_line_means %>% select_(x1, x2)
df$rank.x1 <- rank(df[,1]) / max(abs(rank(df[,1])))
df$rank.x2 <- rank(df[,2]) / max(abs(rank(df[,2])))
df %>% mutate(slope = rank.x1 - rank.x2,
line = 1:length(rank.x1)) %>%
gather(key = sex_or_age, value = fitness, rank.x1, rank.x2) %>%
mutate(fitness = fitness / max(fitness),
title = title) %>%
ggplot(aes(x = sex_or_age, y = fitness, group = line, colour = slope)) +
geom_line(size=0.8, alpha=.7) +
scale_color_gradient2(low = cols[1], mid = cols[2], high = cols[3]) +
scale_x_discrete(expand = c(0.1,0.1), labels = x.labs) +
theme_classic(15) +
theme(strip.background = element_blank(),
strip.text = element_text(hjust =0.1, face = "bold")) +
xlab(NULL) + ylab(NULL) +
facet_wrap(~title) +
theme(legend.position = "none")
}
cairo_ps("figures/figure2.eps", height = 9, width = 9)
grid.arrange(
interaction.plot(predicted_line_means, "female.fitness.early", "male.fitness.early", "Early-life fitness", "sex"),
interaction.plot(predicted_line_means, "female.fitness.late", "male.fitness.late", "Late-life fitness", "sex"),
interaction.plot(predicted_line_means, "female.fitness.early", "female.fitness.late", "Females", "age"),
interaction.plot(predicted_line_means, "male.fitness.early", "male.fitness.late", "Males", "age"),
ncol = 2, left = "Fitness rank among the 115 lines (0 is worst, 1 is best)", bottom = "Sex or age category"
)
invisible(dev.off())
}
make_figure_2()
Warning: `select_()` is deprecated as of dplyr 0.7.0.
Please use `select()` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_warnings()` to see where this warning was generated.
Figure 2: The relative fitness ranks for each line, for four pairs of fitness traits. The y-axis was calculated by taking the adjusted line mean fitnesses, ranking them, and then dividing by the number of lines. The intensity and hue of the colour helps highlight genotypes that rank highly for one fitness component but not the other.
The Mackay lab have collected data on the Wolbachia infection status of each line, and recorded which chromosomal inversions each line carries. It is possible to statistically account for these variables when doing GWAS, but it makes the analysis more complex. Our fitness data are not correlated with the Wolbachia or inversion data, and in light of this we elected not to include them as predictors when writing our GWAS functions below. Additional analyses (not shown) suggest that the results are essentially identical if we run the models with these predictors included. However, including these parameters as random effects slows down the Bayesian GWAS a lot (and it already takes months of CPU time), so we elected to leave them out.
inv.data <- predicted_line_means %>%
left_join(read.csv("data/input/inversion genotypes.csv", stringsAsFactors = FALSE) %>%
mutate(line = paste("line_", line, sep = "")), by = "line") %>%
left_join(read.csv("data/input/wolbachia.csv", stringsAsFactors = FALSE) %>%
mutate(line = paste("line_", line, sep = "")), by = "line") %>% select(-line, -block)
inv.data[inv.data == "homozygous"] <- NA
inv.data[inv.data == "ST"] <- 0
inv.data[inv.data == "INV"] <- 1
inv.data[inv.data == "n"] <- 0
inv.data[inv.data == "y"] <- 1
for(i in 1:ncol(inv.data)) inv.data[,i] <- inv.data[,i] %>% as.numeric()
inversion.cors <- cor(inv.data, use = "pairwise.complete.obs")
heatmap(inversion.cors[!is.na(inversion.cors[,1]), !is.na(inversion.cors[,1])])
Version | Author | Date |
---|---|---|
8d54ea5 | Luke Holman | 2018-12-23 |
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] showtext_0.9-1 showtextdb_3.0 sysfonts_0.8.2 RColorBrewer_1.1-2
[5] gridExtra_2.3 tidyr_1.1.0 dplyr_1.0.0 ggExtra_0.9
[9] ggplot2_3.3.2 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.19 purrr_0.3.4 splines_4.0.3
[5] lattice_0.20-41 colorspace_1.4-1 vctrs_0.3.0 generics_0.0.2
[9] miniUI_0.1.1.1 htmltools_0.5.0 yaml_2.2.1 mgcv_1.8-33
[13] rlang_0.4.6 later_1.0.0 pillar_1.4.4 glue_1.4.2
[17] withr_2.2.0 lifecycle_0.2.0 stringr_1.4.0 munsell_0.5.0
[21] gtable_0.3.0 evaluate_0.14 labeling_0.3 knitr_1.30
[25] fastmap_1.0.1 httpuv_1.5.3.1 curl_4.3 Rcpp_1.0.4.6
[29] xtable_1.8-4 promises_1.1.0 scales_1.1.1 backports_1.1.7
[33] jsonlite_1.7.0 farver_2.0.3 mime_0.9 fs_1.4.1
[37] digest_0.6.25 stringi_1.5.3 shiny_1.4.0.2 rprojroot_1.3-2
[41] tools_4.0.3 magrittr_2.0.1 tibble_3.0.1 crayon_1.3.4
[45] whisker_0.4 pkgconfig_2.0.3 ellipsis_0.3.1 Matrix_1.2-18
[49] rmarkdown_2.5 R6_2.4.1 nlme_3.1-149 git2r_0.27.1
[53] compiler_4.0.3