Last updated: 2022-08-20
Checks: 6 1
Knit directory: RatXcan_Training/
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 is untracked by Git. 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(20220711)
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 4f1a0e2. 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: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/.Rhistory
Untracked files:
Untracked: .DS_Store
Untracked: .gitignore
Untracked: README.html
Untracked: analysis/EN_Prediction_Model.Rmd
Untracked: analysis/PrediXcan.Rmd
Untracked: analysis/Process_Geno_Gex_Data.Rmd
Untracked: analysis/Rat_PTRS.Rmd
Untracked: rsconnect/
Untracked: scripts/
Unstaged changes:
Modified: code/.DS_Store
Deleted: output/README.md
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.
There are no past versions. Publish this analysis with
wflow_publish()
to start tracking its development.
Data from here - genoGex.Rdata has everything we need in it There are 5 ‘gex’ RDS files which are the gene expressions for the 5 different tissues, the ‘gtf’ is the gene annotation, ‘phyMap’ is the snp annotation, and ‘geno’ is the genotype matrix
Our pipeline predicts expressions from the gene expression data and genotypes of the rats from the study.
library(tidyverse)
library(data.table)
load("~/Box/imlab-data/Projects/PTRS-PGRS-Rosetta/Data-From-Abe-Palmer-Lab/Rdata/genoGex.RData")
First, we transpose each tissue’s gene expression file to fit the format expected by the PrediXcan pipeline scripts.
#transposing gene expression files for the 5 tissues
n = gexAc$EnsemblGeneID
gexAc_transpose <- as.data.frame(t(gexAc[,-1]))
colnames(gexAc_transpose) <- n
n = gexIl$EnsemblGeneID
gexIl_transpose <- as.data.frame(t(gexIl[,-1]))
colnames(gexIl_transpose) <- n
n = gexLh$EnsemblGeneID
gexLh_transpose <- as.data.frame(t(gexLh[,-1]))
colnames(gexLh_transpose) <- n
n = gexPl$EnsemblGeneID
gexPl_transpose <- as.data.frame(t(gexPl[,-1]))
colnames(gexPl_transpose) <- n
n = gexVo$EnsemblGeneID
gexVo_transpose <- as.data.frame(t(gexVo[,-1]))
colnames(gexVo_transpose) <- n
# Running inverse normalization on each gene expression
invnorm = function(x) {
if(is.null(dim(x))) res = invnorm.vector(x) else
res=apply(x,2,invnorm.vector)
res
}
invnorm.vector = function(x) {yy = rank(x)/(length(x)+1); qnorm(yy)}
gexAc_transpose = invnorm(gexAc_transpose)
gexIl_transpose = invnorm(gexIl_transpose)
gexLh_transpose = invnorm(gexLh_transpose)
gexPl_transpose = invnorm(gexPl_transpose)
gexVo_transpose = invnorm(gexVo_transpose)
Write to file.
# Writing the gene expression files to csv files to be used for PEER Factor analysis
write.table(gexAc_transpose, file = '/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/gexAc.csv', sep = ",", col.names = TRUE, row.names = FALSE)
write.table(gexIl_transpose, file = '/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/gexIl.csv', sep = ",", col.names = TRUE, row.names = FALSE)
write.table(gexLh_transpose, file = '/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/gexLh.csv', sep = ",", col.names = TRUE, row.names = FALSE)
write.table(gexPl_transpose, file = '/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/gexPl.csv', sep = ",", col.names = TRUE, row.names = FALSE)
write.table(gexVo_transpose, file = '/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/gexVo.csv', sep = ",", col.names = TRUE, row.names = FALSE)
The prediction model pipeline also requires a gene annotation file as input. The code below generates it from the gene annotations provided by Palmer lab in ‘gtf’. We also collect snp info.
gtf$gene_type = sub(".*?gene_biotype(.*?);.*", "\\1", gtf$Attr)
gtf$gene_name = sub(".*?gene_name(.*?);.*", "\\1", gtf$Attr)
gene_annotation = subset(gtf, select = -c(Source, Feature, Score, Strand, Attr, Frame) )
gene_annotation = gene_annotation[, c("Chr","Gene", "gene_name", "Start", "End", "gene_type" )]
colnames(gene_annotation) = c("chr", "gene_id", "gene_name", "start", "end")
rownames(gene_annotation) = gene_annotation$gene_id
We have all the information needed to generate the predictions models. We are left to reorganize it to fit the pipeline. The specifics of each step is commented at the top of each block.
# Making the snp annotation in the correct format for the pipeline
phyMap <- within(phyMap, varID <- paste(Chr, Pos, Ref, Alt, sep="_"))
rownames(phyMap) = phyMap$varID
phyMap$rsid = phyMap$varID
colnames(phyMap) = c("snp", "chr", "pos", "refAllele", "effectAllele", 'varID', "rsid")
# Splitting the snp annotation file by chromosome
s <- setNames(split(phyMap, phyMap$chr), paste0("snp_annot.chr", unique(phyMap$chr)))
list2env(s, globalenv())
The new genotype file combines the provided geno
file
and combines information from the provided snp annotation file,
phyMap
.
# writing the genotype file to a .txt file so that we can separate it by chromosome using our geneotype parse script.
rownames(geno) = rownames(phyMap)
write.table(geno, file = "/Users/sabrinami/Github/Rat_Genomics_Paper_Pipeline/data/genotype.txt", sep = "\t", col.names = TRUE, row.names = TRUE)
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
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_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8.3 rstudioapi_0.11 knitr_1.39 magrittr_1.5
[5] workflowr_1.6.2 R6_2.4.1 rlang_1.0.2 fastmap_1.1.0
[9] stringr_1.4.0 tools_4.0.3 xfun_0.31 cli_3.3.0
[13] git2r_0.27.1 jquerylib_0.1.4 htmltools_0.5.2 ellipsis_0.3.2
[17] rprojroot_1.3-2 yaml_2.2.1 digest_0.6.27 tibble_3.0.4
[21] lifecycle_0.2.0 crayon_1.3.4 later_1.1.0.1 sass_0.4.1
[25] vctrs_0.4.1 fs_1.5.0 promises_1.1.1 glue_1.6.2
[29] evaluate_0.15 rmarkdown_2.14 stringi_1.5.3 compiler_4.0.3
[33] bslib_0.3.1 pillar_1.4.6 backports_1.1.10 jsonlite_1.7.1
[37] httpuv_1.5.4 pkgconfig_2.0.3