Loading [MathJax]/jax/output/HTML-CSS/jax.js
  • Load and clean the GWAS results
  • Table of significant groups of linked variants

Last updated: 2021-03-02

Checks: 6 1

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.


The R Markdown file has unstaged changes. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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 c386787. 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:  analysis/plot_models_variant_effects.Rmd
    Untracked:  code/GO_and_KEGG_gsea.R
    Untracked:  code/make_sites_files_for_ARGweaver.R
    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:   analysis/GWAS_tables.Rmd
    Modified:   analysis/TWAS.Rmd
    Modified:   analysis/checking_mashr_results.Rmd
    Modified:   analysis/eQTL_analysis.Rmd
    Modified:   analysis/get_predicted_line_means.Rmd
    Modified:   analysis/gwas_adaptive_shrinkage.Rmd
    Modified:   analysis/index.Rmd
    Modified:   analysis/make_annotation_database.Rmd
    Modified:   analysis/perform_gwas.Rmd
    Modified:   analysis/plot_line_means.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
    Deleted:    figures/figure1.eps
    Deleted:    figures/figure1.png
    Deleted:    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/GWAS_tables.Rmd) and HTML (docs/GWAS_tables.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 a7f5146 Luke Holman 2019-01-01 Lots of work on eQTLs
Rmd 8d54ea5 Luke Holman 2018-12-23 Initial commit
html 8d54ea5 Luke Holman 2018-12-23 Initial commit

Load and clean the GWAS results

library(tidyverse)
library(kableExtra)
library(DT)

kable_table <- function(df) {
  kable(df, "html") %>%
  kable_styling() %>%
  scroll_box(height = "300px")
}

my_data_table <- function(df){ # Make html tables:
  datatable(
    df, rownames=FALSE,
    autoHideNavigation = TRUE,
    extensions = c("Scroller",  "Buttons"),
    options = list(
      dom = 'Bfrtip',
      deferRender=TRUE,
      scrollX=TRUE, scrollY=400,
      scrollCollapse=TRUE,
      buttons = 
        list('pageLength', 'colvis', 'csv', list(
          extend = 'pdf',
          pageSize = 'A4',
          orientation = 'landscape',
          filename = 'GWAS_sig_loci')),
      pageLength = 50
    )
  )
}

db <- DBI::dbConnect(RSQLite::SQLite(), "data/derived/annotations.sqlite3")


# Load the SNP-clumped GWAS results, created with GEMMA and clumped with PLINK
xx <- bind_rows(
  read_tsv("data/derived/female_early_SNP_clumps.txt"),
  read_tsv("data/derived/female_late_SNP_clumps.txt"),
  read_tsv("data/derived/male_early_SNP_clumps.txt"),
  read_tsv("data/derived/male_late_SNP_clumps.txt")) %>%
  distinct(index_SNP, .keep_all = TRUE) %>%
  mutate(FBIDs = str_remove_all(FBIDs, ", NA"),
         FBIDs = replace(FBIDs, is.na(FBIDs), "")) %>%
  mutate(genes = str_remove_all(genes, ", NA"),
         genes = replace(genes, is.na(genes), "")) %>%
  mutate(`Index variant log10 p` = round(-1 * log10(index_SNP_p_value), 2)) %>%
  select(index_SNP, other_snps, FBIDs, genes, `Index variant log10 p`) 

# Because we clumped separately for the 4 traits, some of the "index SNPs" appear inside the ranges
# tagged by other index SNPs, so there is some redundancy. The following ugly code sorts this out 
# by putting index SNPs that appear inside the range of another index SNP into the 'other SNPs' 
# column for that index SNP
ranges <- xx$other_snps %>% 
  str_extract_all("[_][:digit:]+") %>% 
  map(~ as.numeric(str_remove_all(.x, "_"))) %>% 
    map(~ c(min(.x), max(.x)))

ranges <- map_df(1:nrow(xx), 
                 ~ data.frame(index = xx$index_SNP[.x], 
                              min =ranges[[.x]][1], 
                              max = ranges[[.x]][2]))%>%
  filter(!is.na(min)) %>% 
  mutate(chr = substr(index, 1,2))

to_modify <- lapply(1:nrow(xx), function(i){
  chr <- substr(xx$index_SNP[i],1,2) # get chr and pos
  pos <- as.numeric(str_remove_all(str_extract_all(xx$index_SNP[i], "_[:digit:]+"), "_"))
  foc_ranges <- ranges[ranges$chr == chr & 
                         ranges$min <= pos & 
                         ranges$max >= pos &
                         ranges$index != xx$index_SNP[i], ]
  if(nrow(foc_ranges) > 0) {
    return(data.frame(index_SNP = foc_ranges$index, 
                      to_add = xx$index_SNP[i]))
  }
  return(NULL)
}) %>% bind_rows()

xx <- xx %>% 
  filter(!(index_SNP %in% to_modify$to_add)) %>% 
  left_join(to_modify) %>% 
  mutate(to_add = replace(to_add, is.na(to_add), "NA"))

xx <- xx %>% 
  mutate(other_snps = str_split(str_c(xx$other_snps, to_add, sep = ", "), ", "),
              other_snps = map_chr(other_snps, 
                                   ~ paste0(.x[.x != "NA"], collapse = ", "))) %>%
  select(-to_add) %>%
  mutate(other_snps = str_replace_all(other_snps, "NA", ""))

# Now get the mashr-ED adjusted effect sizes for the index SNPs, 
# and their mixture assignment probs.
univariate_lmm_results <- 
  tbl(db, "univariate_lmm_results") %>%
  filter(SNP %in% !! xx$index_SNP) %>%
  select(-contains("canonical"), 
         -contains("raw")) %>% 
  inner_join(tbl(db, "variants") %>% 
               select(-chr, -position), 
             by = "SNP") %>%
  left_join(
    tbl(db, "genes") %>% 
      select(FBID, gene_name), by = "FBID") %>%
  collect(n=Inf) %>%
  arrange(LFSR_female_early_mashr_ED) %>%
  mutate_at(vars(contains("LFSR")), ~ -log10(.x)) %>%
  mutate_if(is.numeric, ~ round(.x, 2)) %>%
  rename_all(~ gsub("beta_", "", .x)) %>%
  rename_all(~ gsub("_mashr_ED", "", .x)) %>%
  arrange(-P_equal_effects) %>%
  select(SNP, starts_with("female"), 
         starts_with("male"), starts_with("P_")) %>%
  distinct()

GWAS_table <- xx %>%
  left_join(univariate_lmm_results, by = c("index_SNP" = "SNP")) %>%
  arrange(index_SNP) %>%
  rename(`Index variant` = index_SNP,
         `Other variants` = other_snps,
         `Genes` = genes, 
         `Female early` = female_early,
         `Female late` = female_late,
         `Male early` = male_early,
         `Male late` = male_late) %>%
  rename_all(~ str_replace_all(.x, "_", " "))

Table of significant groups of linked variants

This table shows loci (i.e. groups of linked variants) that passed the arbitrary statistical significance threshold of p<105 for one or more of the four phenotypes (in a linear mixed model GWAS implemented in GEMMA). The loci were identified using the SNP clumping method of PLINK, and each group of variants contains one or more variants that met the significance threshold. The third and fourth columns identify the gene(s) whose exons and introns overlap the focal locus. Columns 6-9 show the estimated effect size of the index variant on the four phenotypes (corrected by mashr using the data-driven method), while the final columns show the mixture proportions estimated by mashr using the canonical method.

GWAS_table %>%
  my_data_table()

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] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] DT_0.13          kableExtra_1.1.0 forcats_0.5.0    stringr_1.4.0   
 [5] dplyr_1.0.0      purrr_0.3.4      readr_1.3.1      tidyr_1.1.0     
 [9] tibble_3.0.1     ggplot2_3.3.2    tidyverse_1.3.0 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      lubridate_1.7.8   lattice_0.20-41   assertthat_0.2.1 
 [5] rprojroot_1.3-2   digest_0.6.25     R6_2.4.1          cellranger_1.1.0 
 [9] backports_1.1.7   reprex_0.3.0      RSQLite_2.2.0     evaluate_0.14    
[13] httr_1.4.1        pillar_1.4.4      rlang_0.4.6       readxl_1.3.1     
[17] rstudioapi_0.11   whisker_0.4       blob_1.2.1        rmarkdown_2.5    
[21] webshot_0.5.2     htmlwidgets_1.5.1 bit_1.1-15.2      munsell_0.5.0    
[25] broom_0.5.6       compiler_4.0.3    httpuv_1.5.3.1    modelr_0.1.8     
[29] xfun_0.19         pkgconfig_2.0.3   htmltools_0.5.0   tidyselect_1.1.0 
[33] workflowr_1.6.2   fansi_0.4.1       viridisLite_0.3.0 crayon_1.3.4     
[37] dbplyr_1.4.4      withr_2.2.0       later_1.0.0       grid_4.0.3       
[41] nlme_3.1-149      jsonlite_1.7.0    gtable_0.3.0      lifecycle_0.2.0  
[45] DBI_1.1.0         git2r_0.27.1      magrittr_2.0.1    scales_1.1.1     
[49] cli_2.0.2         stringi_1.5.3     fs_1.4.1          promises_1.1.0   
[53] xml2_1.3.2        ellipsis_0.3.1    generics_0.0.2    vctrs_0.3.0      
[57] tools_4.0.3       bit64_0.9-7       glue_1.4.2        crosstalk_1.1.0.1
[61] hms_0.5.3         yaml_2.2.1        colorspace_1.4-1  rvest_0.3.5      
[65] memoise_1.1.0     knitr_1.30        haven_2.3.1