Last updated: 2019-04-03

Checks: 5 1

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.


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(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/

Untracked files:
    Untracked:  analysis/20190321_Check-Kinship-And-PopulationStructure.Rmd
    Untracked:  analysis/20190325_MergingRNASeqLanes.Rmd
    Untracked:  analysis/20190326_Admixture.Rmd
    Untracked:  analysis/20190326_PCA.Rmd
    Untracked:  analysis/20190327_MakeFamAndCovariateFiles.Rmd
    Untracked:  analysis/20190327_MakeFamPhenotypeFile.Rmd
    Untracked:  docs/figure/20190321_Check-Kinship-And-PopulationStructure.Rmd/
    Untracked:  docs/figure/20190325_MergingRNASeqLanes.Rmd/
    Untracked:  docs/figure/20190326_PCA.Rmd/

Unstaged changes:
    Deleted:    ._workflowr.yml.swp
    Modified:   analysis/20190320_Check-RNAseq-PCs.Rmd
    Modified:   analysis/index.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.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


library(corrplot)
library(ggfortify)
library(readxl)
library(tidyverse)
library(psych)
library(ggrepel)
library(knitr)
library(reshape2)
library(gplots)

The RNA-seq libraries were sequenced across many sequencing lanes on a few different flow cells. Here want to check that the data clusters by RNA-seq library (biological sample) rather than flow cell or sequencing lane. This is just a QC-check before I merge fastq files by biological sample, which is perhaps the most straightforward way to process the data.

The data below were processed by individual fastq file (1 file for every individual:flowcell:lane). Gene expression was quantified with kallisto for each fastq and merged into a single matrix of TPM values.

# Read in count table, filtering out rows that are all zeros
CountTable <- read.table(gzfile('../output/CountTable.SeparatedByFastq.tpm.txt.gz'), header=T, check.names=FALSE, row.names = 1) %>%
  filter_all(any_vars(.>0)) %>% rename_all(funs(basename(.)))

# Read in metadata
Metadata <- as.data.frame(read_excel("../data/Metadata.xlsx"))

# Read in lane info
LaneInfo <- read.table('../output/RNA_seq_FlowCellInfo.txt', header=T, stringsAsFactors = F, sep='\t' )
LaneInfo$basename <- basename(LaneInfo$file)

# Read in fastq to sample dictionary
FastqToSample <- read.table('../code/snakemake_workflow/RNASeqFileList.tsv', header=T, stringsAsFactors = F)
FastqToSample$basename <- basename(FastqToSample$fastq)

In total I had 191 fastq files from 39 libraries (1 per biological sample/ individual) which were collectively spread across 22 lanes across 3 HiSeq flow cells.

# Create spearman correlation matrix of log(TPM) for top 1000 expressed genes.
CorMatrix <- CountTable %>%
  +0.1 %>%
  mutate(sumVar = rowSums(.)) %>%
  arrange(desc(sumVar)) %>%
  head(1000) %>%
  select(-sumVar) %>%
  log() %>%
  scale() %>%
  cor(method = c("spearman"))

BiologicalSample <- as.character(unclass(factor(plyr::mapvalues(row.names(CorMatrix), from=FastqToSample$basename, to=FastqToSample$sample))))

FlowCell <- as.character(unclass(factor(plyr::mapvalues(row.names(CorMatrix), from=LaneInfo$basename, to=LaneInfo$flowcellid))))

# Biological samples colored columns. FlowCell colored as rows.
heatmap.2(CorMatrix, trace="none", ColSideColors=BiologicalSample, RowSideColors = FlowCell)

The samples segregate by biological sample rather than flow cell or lane. For downstream processing, I simply combined fastq files from different flow cells and lanes by biological sample and remapped the combined-by-sample fastq files to make new count table.



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] gplots_3.0.1    reshape2_1.4.3  knitr_1.22      ggrepel_0.8.0  
 [5] psych_1.8.10    forcats_0.4.0   stringr_1.4.0   dplyr_0.8.0.1  
 [9] purrr_0.3.2     readr_1.3.1     tidyr_0.8.2     tibble_2.1.1   
[13] tidyverse_1.2.1 readxl_1.1.0    ggfortify_0.4.5 ggplot2_3.1.0  
[17] corrplot_0.84  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1         lubridate_1.7.4    lattice_0.20-38   
 [4] gtools_3.8.1       assertthat_0.2.1   rprojroot_1.3-2   
 [7] digest_0.6.18      R6_2.4.0           cellranger_1.1.0  
[10] plyr_1.8.4         backports_1.1.3    evaluate_0.13     
[13] httr_1.4.0         pillar_1.3.1       rlang_0.3.3       
[16] lazyeval_0.2.2     rstudioapi_0.10    gdata_2.18.0      
[19] rmarkdown_1.11     foreign_0.8-71     munsell_0.5.0     
[22] broom_0.5.1        compiler_3.5.1     modelr_0.1.4      
[25] xfun_0.6           pkgconfig_2.0.2    mnormt_1.5-5      
[28] htmltools_0.3.6    tidyselect_0.2.5   gridExtra_2.3     
[31] workflowr_1.2.0    crayon_1.3.4       withr_2.1.2       
[34] bitops_1.0-6       grid_3.5.1         nlme_3.1-137      
[37] jsonlite_1.6       gtable_0.3.0       git2r_0.24.0      
[40] magrittr_1.5       scales_1.0.0       KernSmooth_2.23-15
[43] cli_1.1.0          stringi_1.4.3      fs_1.2.6          
[46] xml2_1.2.0         generics_0.0.2     tools_3.5.1       
[49] glue_1.3.1         hms_0.4.2          parallel_3.5.1    
[52] yaml_2.2.0         colorspace_1.4-1   caTools_1.17.1.1  
[55] rvest_0.3.2        haven_2.1.0