Last updated: 2019-05-02
Checks: 6 0
Knit directory: Comparative_eQTL/analysis/
This reproducible R Markdown analysis was created with workflowr (version 1.2.0). The Report 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(20190319)
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! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.
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: data/.DS_Store
Ignored: data/PastAnalysesDataToKeep/.DS_Store
Ignored: docs/.DS_Store
Untracked files:
Untracked: analysis/20190502_Check_eQTLs.Rmd
Untracked: data/PastAnalysesDataToKeep/20190428_log10TPM.txt.gz
Untracked: docs/assets/
Untracked: docs/figure/20190429_RNASeqSTAR_quantifications.Rmd/
Untracked: docs/figure/20190502_Check_eQTLs.Rmd/
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 R Markdown and HTML files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view them.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | db7c847 | Benjmain Fair | 2019-04-27 | Added PCA of normalized data, new covariates R script |
Rmd | f47ec35 | Benjmain Fair | 2019-04-25 | updated site |
html | f47ec35 | Benjmain Fair | 2019-04-25 | updated site |
After checking previous QC analyses of genotypes and RNA-seq data, this markdown will describe covariates used in gene expression modeling and the associated Rscript will output those covariates in the format required for MatrixEQTL. Specifically, the covariates that will be output are {NumGenotypePCs}, {NumRNASeqPCs}, sex, and perhaps RIN score.
The Rscript version of this R markdown is included in the snakemake workflow to generate the [{NumGenotypePCs}.{NumRNASeqPCs}.covariates] file using the knitr::purl()
function.
library(plyr)
library(tidyverse)
library(knitr)
library(readxl)
Run this command to write this [.Rmd] into a [.R] that is included in the snakemake workflow for eQTL mapping:
# knitr::purl(input="../analysis/20190327_MakeCovariateFiles.Rmd", output="../analysis/20190327_MakeCovariateFiles.R")
# Use command line input to specify input and output if this is the Rscript version of this file (as opposed to Rmarkdown).
if(commandArgs()[4] == "--file=../../analysis/20190327_MakeCovariateFiles.R"){
args <- commandArgs(trailingOnly = T)
EmptyFamFilepath <- args[1]
MetadataExcel <- args[2]
CountFilepath <- args[3]
NumRS.PCs <- args[4]
GenotypePCs <- args[5]
NumGenotype.PCs <- args[6]
OutputFile <- args[7]
print (args)
} else {
CountFilepath <- '../data/PastAnalysesDataToKeep/CountTable.tpm.txt.gz'
EmptyFamFilepath <- '../output/ForAssociationTesting.temp.fam'
MetadataExcel <- '../data/Metadata.xlsx'
GenotypePCs <- '../output/PopulationStructure/pca.eigenvec'
NumGenotype.PCs <- 3
NumRS.PCs <- 3
}
Read in data:
CountTable <- read.table(gzfile(CountFilepath), header=T, check.names=FALSE, row.names = 1)
# dimensions of count table
CountTable %>% dim()
[1] 50434 39
kable(head(CountTable))
4X0095 | 4X0212 | 4X0267 | 4X0333 | 4X0339 | 4X0354 | 4X0357 | 4X0550 | 4x0025 | 4x0043 | 4x373 | 4x0430 | 4x0519 | 4x523 | 88A020 | 95A014 | 295 | 317 | 338 | 389 | 438 | 456 | 462 | 476 | 495 | 503 | 522 | 529 | 537 | 549 | 554 | 554_2 | 558 | 570 | 623 | 676 | 724 | Little_R | MD_And | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ENSPTRT00000098376.1 | 0.0377317 | 0.272220 | 0.283268 | 0.0768681 | 0.0241551 | 0.489356 | 0.149515 | 0.0338373 | 0.159397 | 0.2715600 | 0.0718747 | 0.508540 | 0.487206 | 0.4750030 | 0.0341022 | 0.138268 | 0.2475900 | 0.0435386 | 0.299943 | 0.0288987 | 0.0332317 | 0.0316096 | 0.0338501 | 0.153948 | 0 | 0.1674910 | 0.2284390 | 0.245499 | 0.258301 | 0.1090800 | 0.0415181 | 0.1853400 | 0.034166 | 0.10919 | 0.0405918 | 0.0690902 | 0.0339912 | 0.0376673 | 0 |
ENSPTRT00000091526.1 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.0279624 | 0.000000 | 0.000000 | 0.0000000 | 0.000000 | 0.0000000 | 0.1664070 | 0.000000 | 0.000000 | 0.3142130 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.000000 | 0 | 0.0553974 | 0.0000000 | 0.243596 | 0.108732 | 0.1894100 | 0.0000000 | 0.0000000 | 0.000000 | 0.00000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
ENSPTRT00000091354.1 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.000000 | 0.0741825 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.2960420 | 0.149597 | 0 | 0.0000000 | 0.0713518 | 0.000000 | 0.000000 | 0.0596237 | 0.0907759 | 0.0000000 | 0.000000 | 0.00000 | 0.0000000 | 0.0755299 | 0.0000000 | 0.0000000 | 0 |
ENSPTRT00000080032.1 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.000000 | 0.1268190 | 0.0000000 | 0.000000 | 0.000000 | 0.4753460 | 0.0000000 | 0.000000 | 0.0495538 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.000000 | 0 | 0.0000000 | 0.0000000 | 0.196541 | 0.000000 | 0.0764113 | 0.0000000 | 0.2077310 | 0.000000 | 0.00000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
ENSPTRT00000096913.1 | 0.0781316 | 0.000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.000000 | 0.0937206 | 0.0000000 | 0.000000 | 0.000000 | 0.2810280 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.000000 | 0 | 0.0000000 | 0.0337880 | 0.145246 | 0.000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.00000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
ENSPTRT00000079752.1 | 0.0873579 | 0.236346 | 0.000000 | 0.0000000 | 0.0000000 | 0.000000 | 0.000000 | 0.0000000 | 0.000000 | 0.7335140 | 0.0000000 | 0.098116 | 0.000000 | 0.1571070 | 0.0000000 | 0.000000 | 0.0409451 | 0.0000000 | 0.173610 | 0.0000000 | 0.0769393 | 0.0000000 | 0.0000000 | 0.000000 | 0 | 0.0000000 | 0.2266680 | 1.055580 | 0.000000 | 0.0631367 | 0.0000000 | 0.0858213 | 0.000000 | 0.00000 | 0.0000000 | 0.0000000 | 0.0000000 | 0.0000000 | 0 |
EmptyFamFile <- read.table(EmptyFamFilepath, col.names=c("FID", "IID", "Father", "Mother", "SX", "Pheno"), stringsAsFactors = F) %>%
select(-Pheno)
GenotypePCs.df <- read.table(GenotypePCs, header=T) %>%
select(-c("FID")) %>%
rename_all(paste0, ".GT")
kable(head(GenotypePCs.df))
IID.GT | PC1.GT | PC2.GT | PC3.GT | PC4.GT | PC5.GT | PC6.GT | PC7.GT | PC8.GT | PC9.GT | PC10.GT | PC11.GT | PC12.GT | PC13.GT | PC14.GT | PC15.GT | PC16.GT | PC17.GT | PC18.GT | PC19.GT | PC20.GT |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
549 | -0.1085980 | -0.0184943 | 0.0047314 | -0.0150498 | -0.0319818 | -0.0004605 | 0.0584162 | -0.0021767 | 0.0057926 | -0.0138491 | -0.0006760 | 0.0014917 | 0.0024960 | 0.0444586 | 0.0005304 | 0.0067183 | 0.0025586 | 0.0015872 | -0.0116857 | 0.0076842 |
570 | -0.0945827 | -0.0228220 | -0.0140236 | 0.1793750 | 0.0671347 | -0.0111882 | -0.1524830 | -0.0101299 | -0.0614712 | 0.2670480 | -0.0468162 | 0.0399717 | 0.0258174 | -0.0527277 | 0.0278379 | -0.3333410 | -0.1546580 | -0.1739510 | 0.1237160 | -0.0771322 |
389 | -0.1101630 | -0.0206061 | 0.0032451 | 0.0219085 | -0.1004940 | 0.0090560 | -0.3750780 | 0.0213782 | 0.0000433 | 0.0097597 | 0.0015130 | -0.0013585 | -0.0072876 | -0.0176905 | -0.0047013 | 0.0317992 | -0.0091693 | 0.0133724 | 0.0038605 | -0.0039837 |
456 | -0.1080570 | -0.0178108 | 0.0044597 | -0.0103130 | -0.0185596 | -0.0001795 | 0.0344615 | -0.0021105 | 0.0026981 | -0.0058951 | 0.0012633 | -0.0013892 | 0.0002392 | -0.0089160 | 0.0013406 | -0.0064834 | 0.0081531 | -0.0025395 | -0.0120499 | 0.0088498 |
623 | -0.1098320 | -0.0206678 | 0.0041903 | -0.0137927 | -0.1012860 | 0.0118115 | -0.2853820 | 0.0216451 | 0.0220789 | -0.0857080 | 0.0177347 | -0.0161525 | -0.0149519 | 0.0154757 | -0.0131564 | 0.1546820 | 0.0570773 | 0.0793976 | -0.0569467 | 0.0363648 |
438 | -0.1081420 | -0.0177823 | 0.0045724 | -0.0108220 | -0.0197756 | -0.0009599 | 0.0394830 | -0.0029283 | 0.0016249 | -0.0085211 | 0.0021596 | -0.0016848 | -0.0013350 | 0.0038822 | 0.0014313 | -0.0008248 | 0.0071914 | 0.0016188 | -0.0128241 | 0.0102553 |
OtherMetadata <- as.data.frame(read_excel(MetadataExcel))
kable(head(OtherMetadata))
Individual.ID | Source | Individual.Name | Yerkes.ID | Label | Notes | FileID.(Library_Species_CellType_FlowCell) | SX | RNA.Library.prep.batch | RNA.Sequencing.Lane | Sequencing.Barcode | RNA.Extract_date | DNASeq_FastqIdentifier | DNA.library.prep.batch | DNA.Sequencing.Lane | DNA.Sequencin.Barcode | DNA.Extract_date | Age | X__1 | Post.mortem.time.interval | RIN | Viral.status | RNA.total.reads.mapped.to.genome | RNA.total.reads.mapping.to.ortho.exons | Subspecies | DOB | DOD | DOB Estimated | Age (DOD-DOB) | OldLibInfo. RIN,RNA-extractdate,RNAbatch |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
295 | Yerkes | Duncan | 295 | 295 | NA | 24_CM_3_L006.bam | M | 5 | 6 | 18 | 2018-10-10 | YG3 | 1 | 1 | NA | 2018-09-01 | 40 | NA | 0.5 | 7.3 | NA | 45.67002 | 17.51562 | verus/ellioti | 24731 | 39386 | NA | 40 | 6.3,6/14/2016,2 |
317 | Yerkes | Iyk | 317 | 317 | NA | 11_CM_3_L004.bam | M | 3 | 4 | 4 | 2016-06-07 | YG2 | 1 | 1 | NA | 2018-09-01 | 44 | NA | 2.5 | 7.6 | NA | 42.75617 | 17.18811 | verus | 22859 | 38832 | NA | 43 | NA |
338 | Yerkes | Maxine | 338 | 338 | NA | 8_CF_3_L008.bam | F | 3 | 8 | 6 | 2016-06-07 | YG1 | 1 | 1 | NA | 2018-09-01 | 53 | NA | NA | 7.2 | NA | 50.52632 | 19.49295 | verus | 20821 | 40179 | Yes | 53 | NA |
389 | Yerkes | Rogger | 389 | 389 | NA | NA | M | 4 | NA | 23 | 2018-10-10 | YG39 | 2 | 2 | NA | 2018-10-01 | 45 | NA | NA | 5.7 | NA | NA | NA | verus | 25204 | 41656 | NA | 45 | NA |
438 | Yerkes | Cheeta | 438 | 438 | NA | 155_CF_3_L004.bam | F | 2 | 4 | 8 | 2016-06-22 | YG22 | 1 | 1 | NA | 2018-09-01 | 55 | NA | NA | 5.6 | NA | 55.30614 | 18.06375 | verus | 20821 | 40909 | Yes | 55 | NA |
456 | Yerkes | Mai | 456 | 456 | NA | 156_CF_3_L001.bam | F | 2 | 1 | 15 | 2016-06-22 | YG23 | 1 | 1 | NA | 2018-09-01 | 49 | NA | NA | 5.5 | NA | 54.00665 | 20.13760 | verus | 23377 | 41275 | Yes | 49 | NA |
# RNA-seq PCA
pca_results <- CountTable %>%
+0.1 %>%
mutate(sumVar = rowSums(.)) %>%
arrange(desc(sumVar)) %>%
head(2500) %>%
select(-sumVar) %>%
log() %>%
t() %>%
prcomp(center=T, scale. = T)
RNASeqPCs.df <- pca_results$x %>%
as.data.frame %>%
rownames_to_column() %>%
rename_all(paste0, ".RS")
Covariates <- EmptyFamFile %>%
select(IID) %>%
left_join(RNASeqPCs.df[0:NumRS.PCs+1], by=c("IID" = "rowname.RS")) %>%
left_join(GenotypePCs.df[0:NumGenotype.PCs+1], by=c("IID" = "IID.GT")) %>%
left_join(
OtherMetadata %>% select(Individual.ID, SX),
by = c("IID" = "Individual.ID")
) %>%
mutate(SX = plyr::mapvalues(SX, from=c("M", "F"), to=c(0,1))) %>%
t()
Warning: Column `IID`/`IID.GT` joining character vector and factor,
coercing into character vector
kable(head(Covariates))
IID | 549 | 570 | 389 | 456 | 623 | 438 | 724 | 522 | 338 | 476 | 495 | 558 | 503 | 4x0430 | 317 | 676 | 4x373 | 4X0333 | 4X0095 | 554 | 4x523 | 88A020 | 95A014 | 4x0043 | 529 | 4X0550 | 4X0267 | 4X0357 | 462 | 554_2 | 4X0212 | 4x0025 | 4x0519 | 295 | Little_R | 537 | 4X0339 | 4X0354 |
PC1.RS | -4.6671389 | -26.1710828 | -11.1101394 | -12.6404247 | -4.3640984 | -1.4498584 | -21.0578454 | -12.4893238 | -24.9572534 | -11.9529579 | 50.9788389 | 84.9548137 | -0.2127408 | -35.1478044 | -20.9478859 | -18.0083558 | -14.5603875 | -24.9379189 | -8.8393599 | -24.3314095 | -33.2376632 | -11.2296681 | -16.3502202 | -16.9671933 | 41.7608044 | -25.0626524 | -29.0210945 | 4.6571111 | -1.6699147 | -10.7351772 | -16.9547828 | -39.5164346 | -37.5044833 | -4.4506068 | 108.2370478 | 113.2855069 | 72.4481625 | 64.4069774 |
PC2.RS | -4.3375035 | -21.6697827 | 8.3594629 | 7.7149310 | 11.4830846 | 15.0424731 | 0.1968575 | 8.8510347 | -5.7497750 | 14.6417858 | -10.8136469 | 3.0086759 | 24.7673589 | -10.3794142 | -0.1866276 | -0.2689843 | -8.5411432 | -9.9294523 | 4.4755158 | 4.1510345 | -26.0707696 | 12.9561345 | 1.3257869 | -11.4492868 | -7.1557796 | 1.5507298 | 3.3727728 | 13.1198594 | 2.5833339 | 10.0813352 | 2.3004992 | -32.2372103 | -12.8248016 | 15.2199047 | -35.4712198 | -14.5526529 | 42.8206393 | -0.9346548 |
PC3.RS | 4.2139684 | 9.7196123 | 0.9078538 | 2.5241961 | 13.6712695 | 3.0373196 | 0.9699229 | 5.1954610 | 6.5689672 | -0.8687375 | 12.3040061 | -1.0172486 | 10.2526758 | -1.3376464 | 1.1315354 | 3.3802363 | -8.0894655 | -0.2424765 | 1.9887210 | 5.4549860 | 0.5869073 | 3.5973730 | -2.0260809 | -8.4029382 | 1.6618992 | -8.1996543 | 0.8435924 | -12.3538209 | 8.0436919 | -2.7301627 | -7.1071920 | -12.3115231 | 1.9554952 | 9.3873162 | 16.0991363 | 3.1108955 | -0.5672118 | -46.8640748 |
PC1.GT | -0.1085980 | -0.0945827 | -0.1101630 | -0.1080570 | -0.1098320 | -0.1081420 | -0.0378419 | -0.1083980 | -0.1081500 | -0.1083960 | 0.0133693 | -0.1090570 | -0.1107340 | -0.0422648 | -0.1089490 | -0.1051800 | -0.1092620 | -0.1094040 | -0.1083620 | -0.0522406 | -0.0548972 | -0.1083140 | -0.1083140 | -0.1081420 | -0.0745853 | -0.1082120 | -0.1086980 | -0.1090900 | 0.0696170 | -0.1083110 | -0.1085550 | -0.1083620 | -0.0691744 | -0.0819553 | -0.1082080 | -0.1077380 | -0.1097850 | 0.1400900 |
PC2.GT | -0.0184943 | -0.0228220 | -0.0206061 | -0.0178108 | -0.0206678 | -0.0177823 | -0.0298039 | -0.0179836 | -0.0179254 | -0.0182646 | -0.0312946 | -0.0192725 | -0.0214998 | -0.0288509 | -0.0190248 | -0.0222267 | -0.0189720 | -0.0193025 | -0.0184038 | 0.0408846 | -0.0254363 | -0.0178967 | -0.0184395 | -0.0181587 | 0.0431692 | -0.0186956 | -0.0185368 | -0.0191630 | 0.1020240 | -0.0182602 | -0.0185807 | -0.0180731 | -0.0264851 | 0.0484042 | -0.0182170 | -0.0182431 | -0.0196049 | -0.0831354 |
Write table if this is the Rscript form of this Rmarkdown
if(commandArgs()[4] == "--file=../../analysis/20190327_MakeCovariateFiles.R"){
write.table(Covariates, col.names = F, sep='\t', file=OutputFile, row.names=T, quote=F)
}
sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.14
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/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
other attached packages:
[1] readxl_1.1.0 knitr_1.22 forcats_0.4.0 stringr_1.4.0
[5] dplyr_0.8.0.1 purrr_0.3.2 readr_1.3.1 tidyr_0.8.2
[9] tibble_2.1.1 ggplot2_3.1.0 tidyverse_1.2.1 plyr_1.8.4
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 highr_0.8 cellranger_1.1.0 compiler_3.5.1
[5] pillar_1.3.1 git2r_0.24.0 workflowr_1.2.0 tools_3.5.1
[9] digest_0.6.18 lubridate_1.7.4 jsonlite_1.6 evaluate_0.13
[13] nlme_3.1-137 gtable_0.3.0 lattice_0.20-38 pkgconfig_2.0.2
[17] rlang_0.3.3 cli_1.1.0 rstudioapi_0.10 yaml_2.2.0
[21] haven_2.1.0 xfun_0.6 withr_2.1.2 xml2_1.2.0
[25] httr_1.4.0 hms_0.4.2 generics_0.0.2 fs_1.2.6
[29] rprojroot_1.3-2 grid_3.5.1 tidyselect_0.2.5 glue_1.3.1
[33] R6_2.4.0 rmarkdown_1.11 modelr_0.1.4 magrittr_1.5
[37] whisker_0.3-2 backports_1.1.3 scales_1.0.0 htmltools_0.3.6
[41] rvest_0.3.2 assertthat_0.2.1 colorspace_1.4-1 stringi_1.4.3
[45] lazyeval_0.2.2 munsell_0.5.0 broom_0.5.1 crayon_1.3.4