• Get the annotations for each DGRP variant
  • Get the annotations for each Drosophila gene
    • Table to convert among gene IDs and names
    • KEGG annotations
    • GO annotations
    • GO term meanings
  • Create the SQLite database and add various tables of annotations
    • View the table of variant annotations
    • View the table of gene annotations

Last updated: 2021-02-03

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:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    .httr-oauth
    Ignored:    .pversion
    Ignored:    analysis/.DS_Store
    Ignored:    analysis/correlations_SNP_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:  analysis/GO_KEGG_enrichment.Rmd
    Untracked:  analysis/correlations_SNP_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_for_mashr_SO.rds

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
    Modified:   figures/figure1.eps
    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/make_annotation_database.Rmd) and HTML (docs/make_annotation_database.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 8d54ea5 Luke Holman 2018-12-23 Initial commit
html 8d54ea5 Luke Holman 2018-12-23 Initial commit

library(dplyr)
library(stringr)
library(future.apply)
library(org.Dm.eg.db) # install via source("https://bioconductor.org/biocLite.R"); biocLite("org.Dm.eg.db")
library(GO.db)
options(future.globals.maxSize = 2000 * 1024 ^ 2, 
        stringsAsFactors = FALSE)

# Helper function to split a vector into chunks 
chunker <- function(x, max_chunk_size) split(x, ceiling(seq_along(x) / max_chunk_size))

# database of D. mel annotations from bioconductor
con <- dbconn(org.Dm.eg.db)

Get the annotations for each DGRP variant

The following function temporarily loads the >1GB annotation file provided on the DGRP website at http://dgrp2.gnets.ncsu.edu/data/website/dgrp.fb557.annot.txt. We then extract the following variables for each variant, and save them in a SQLite database for memory-efficient searching inside R:

  • The Flybase ID(s), if the variant is within or close to one or more genes
  • The site class of the variant (e.g. intron, 5’-UTR…)
  • The distance-to-gene in nucleotides (for UPSTREAM and DOWNSTREAM variants only)
get_variant_annotations <- function(){
  
  # Load up the big annotation file, get pertinent info. It's stored in some sort of text string format
  annot <- read.table("data/input/dgrp.fb557.annot.txt", header = FALSE, stringsAsFactors = FALSE)
  
  get.info <- function(rows){
    lapply(rows, function(row){
      site.class.field <- strsplit(annot$V3[row], split = "]")[[1]][1]
      num.genes <- str_count(site.class.field, ";") + 1
      output <- cbind(rep(annot$V1[row], num.genes), 
                      do.call("rbind", lapply(strsplit(site.class.field, split = ";")[[1]], 
                                              function(x) strsplit(x, split = "[|]")[[1]])))
      if(ncol(output) == 5) return(output[,c(1,2,4,5)]) # only return SNPs that have some annotation. Don't get the gene symbol
      else return(NULL)
    }) %>% do.call("rbind", .)
  }
  
  plan("multisession")
  variant.details <- future_lapply(chunker(1:nrow(annot), max_chunk_size = 10000), get.info) %>% 
    do.call("rbind", .) %>% as.data.frame()
  
  names(variant.details) <- c("SNP", "FBID", "site.class", "distance.to.gene")
  variant.details$FBID <- unlist(str_extract_all(variant.details$FBID, "FBgn[:digit:]+")) # clean up text strings for Flybase ID
  variant.details %>%
    dplyr::filter(site.class != "FBgn0003638") %>% # NB this is a bug in the DGRP's annotation file
    mutate(chr = str_remove_all(substr(SNP, 1, 2), "_")) # get chromosome now for faster sorting later
}

Get the annotations for each Drosophila gene

The following function gets the annotations for the all the genes covered by DGRP variants, from the org.Dm.eg.db database object from Bioconductor. I don’t like the select interface to those objects (it messes with any R code that uses dplyr), so here I save the info into the SQLite database for later access.

Table to convert among gene IDs and names

get_gene_annotations <- function(){
  tbl(con, "genes") %>%
    left_join(tbl(con, "flybase"), by = "_id") %>%
    left_join(tbl(con, "gene_info"), by = "_id") %>% 
    dplyr::select(flybase_id, gene_name, symbol, gene_id) %>%
    dplyr::rename(FBID = flybase_id, gene_symbol = symbol, entrez_id = gene_id) %>%
    collect(n = Inf)
}

KEGG annotations

get_KEGG <- function(){
  tbl(dbconn(org.Dm.eg.db), "kegg") %>%
    left_join(tbl(con, "flybase"), by = "_id") %>% 
    dplyr::select(flybase_id, path_id) %>%
    dplyr::rename(FBID = flybase_id, kegg_id = path_id) %>%
    collect(n = Inf)
}

GO annotations

get_GO <- function(){
  tbl(dbconn(org.Dm.eg.db), "go_all") %>%
    left_join(tbl(con, "flybase"), by = "_id") %>% 
    dplyr::select(flybase_id, go_id, ontology) %>%
    dplyr::rename(FBID = flybase_id) %>%
    collect(n = Inf)
}
GO <- get_GO()

GO term meanings

go_meanings <- suppressMessages(
  AnnotationDbi::select(GO.db, 
                        GO$go_id, c("GOID", "ONTOLOGY", "TERM")))
names(go_meanings) <- c("GO", "ontology", "term")
go_meanings <- distinct(go_meanings)

Create the SQLite database and add various tables of annotations

if(file.exists("data/derived/annotations.sqlite3")) unlink("data/derived/annotations.sqlite3")

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


db %>% copy_to(get_variant_annotations(), 
               "variants", temporary = FALSE, 
               indexes = list("SNP", "FBID", "chr", "site.class")) 

db %>% copy_to(get_gene_annotations(), 
               "genes", temporary = FALSE)

db %>% copy_to(GO, "GO", temporary = FALSE)

db %>% copy_to(get_KEGG(), 
               "KEGG", temporary = FALSE)

db %>% copy_to(go_meanings, 
               "go_meanings", temporary = FALSE)

View the table of variant annotations

The variants table is expanded upon in the script perform_gwas.Rmd, which also adds the minor allele frequencies, the alleles that were treated as the reference and alternate, etc.

db %>% tbl("variants")
# Source:   table<variants> [?? x 5]
# Database: sqlite 3.30.1 [data/derived/annotations.sqlite3]
   SNP             FBID        site.class            distance.to.gene chr  
   <chr>           <chr>       <chr>                 <chr>            <chr>
 1 2L_10000016_SNP FBgn0051755 NON_SYNONYMOUS_CODING 0                2L   
 2 2L_10000016_SNP FBgn0051875 INTRON                0                2L   
 3 2L_10000023_SNP FBgn0051755 NON_SYNONYMOUS_CODING 0                2L   
 4 2L_10000023_SNP FBgn0051875 INTRON                0                2L   
 5 2L_10000029_SNP FBgn0051755 NON_SYNONYMOUS_CODING 0                2L   
 6 2L_10000029_SNP FBgn0051875 INTRON                0                2L   
 7 2L_10000033_SNP FBgn0051755 SYNONYMOUS_CODING     0                2L   
 8 2L_10000033_SNP FBgn0051875 INTRON                0                2L   
 9 2L_10000089_SNP FBgn0051875 INTRON                0                2L   
10 2L_10000089_SNP FBgn0051755 NON_SYNONYMOUS_CODING 0                2L   
# … with more rows

View the table of gene annotations

db %>% tbl("genes")
# Source:   table<genes> [?? x 4]
# Database: sqlite 3.30.1 [data/derived/annotations.sqlite3]
   FBID        gene_name               gene_symbol entrez_id
   <chr>       <chr>                   <chr>       <chr>    
 1 FBgn0040373 uncharacterized protein CG3038      30970    
 2 FBgn0040372 G9a                     G9a         30971    
 3 FBgn0261446 uncharacterized protein CG13377     30972    
 4 FBgn0000316 cinnamon                cin         30973    
 5 FBgn0005427 erect wing              ewg         30975    
 6 FBgn0040370 uncharacterized protein CG13375     30976    
 7 FBgn0040371 uncharacterized protein CG12470     30977    
 8 FBgn0029521 Odorant receptor 1a     Or1a        30978    
 9 FBgn0024989 uncharacterized protein CG3777      30979    
10 FBgn0004034 yellow                  y           30980    
# … with more rows

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

other attached packages:
 [1] GO.db_3.11.4         org.Dm.eg.db_3.11.4  AnnotationDbi_1.50.0
 [4] IRanges_2.22.2       S4Vectors_0.26.1     Biobase_2.48.0      
 [7] BiocGenerics_0.34.0  future.apply_1.5.0   future_1.17.0       
[10] stringr_1.4.0        dplyr_1.0.0         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6     dbplyr_1.4.4     compiler_4.0.3   pillar_1.4.4    
 [5] later_1.0.0      git2r_0.27.1     workflowr_1.6.2  tools_4.0.3     
 [9] bit_1.1-15.2     digest_0.6.25    memoise_1.1.0    RSQLite_2.2.0   
[13] evaluate_0.14    lifecycle_0.2.0  tibble_3.0.1     pkgconfig_2.0.3 
[17] rlang_0.4.6      cli_2.0.2        DBI_1.1.0        yaml_2.2.1      
[21] xfun_0.19        knitr_1.30       generics_0.0.2   fs_1.4.1        
[25] vctrs_0.3.0      globals_0.12.5   bit64_0.9-7      rprojroot_1.3-2 
[29] tidyselect_1.1.0 glue_1.4.2       listenv_0.8.0    R6_2.4.1        
[33] fansi_0.4.1      rmarkdown_2.5    blob_1.2.1       purrr_0.3.4     
[37] magrittr_2.0.1   whisker_0.4      backports_1.1.7  promises_1.1.0  
[41] codetools_0.2-16 htmltools_0.5.0  ellipsis_0.3.1   assertthat_0.2.1
[45] httpuv_1.5.3.1   utf8_1.1.4       stringi_1.5.3    crayon_1.3.4