Skip to contents

YARN - Yet Another RNa-seq package

The goal of yarn is to expedite large RNA-seq analyses using a combination of previously developed tools. Yarn is meant to make it easier for the user to perform accurate comparison of conditions by leveraging many Bioconductor tools and various statistical and normalization techniques while accounting for the large heterogeneity and sparsity found in very large RNA-seq experiments.

Installation

You can install yarn from github through netZooR with:

if (!requireNamespace("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("netZooR")

Quick Introduction

If you’re here to grab the GTEx version 6.0 data then look no further than this gist that uses yarn to download all the data and preprocess it for you.

Preprocessing

Below are a few of the functions we can use to preprocess a large RNA-seq experiment. We follow a particular procedure where we:

  1. Filter poor quality samples
  2. Merge samples of similar conditions for increased power
  3. Filter genes while preserving tissue or group specificity
  4. Normalize while accounting for global differences in tissue distribution

We will make use of the skin dataset for examples. The skin dataset is a small sample of the full GTEx data that can be downloaded using the downloadGTEx function. The skin dataset looks like this:

skin
## ExpressionSet (storageMode: lockedEnvironment)
## assayData: 40824 features, 20 samples 
##   element names: exprs 
## protocolData: none
## phenoData
##   rowNames: GTEX-OHPL-0008-SM-4E3I9 GTEX-145MN-1526-SM-5SI9T ...
##     GTEX-144FL-0626-SM-5LU43 (20 total)
##   varLabels: SAMPID SMATSSCR ... DTHHRDY (65 total)
##   varMetadata: labelDescription
## featureData
##   featureNames: 48350 48365 ... 7565 (40824 total)
##   fvarLabels: ensembl_gene_id hgnc_symbol ... gene_biotype (6 total)
##   fvarMetadata: labelDescription
## experimentData: use 'experimentData(object)'
## Annotation:

This is a basic workflow. Details will be fleshed out:

  1. First always remember to have the library loaded.
  1. Download the GTEx gene count data as an ExpressionSet object or load the sample skin dataset.

For computational reasons we load the sample skin data instead of having the user download the

library(netZooR)
load("skin.rdata")
  1. Check mis-annotation of gender or other phenotypes using group-specific genes
yarn::checkMisAnnotation(skin,"GENDER",controlGenes="Y",legendPosition="topleft")

  1. Decide what sub-groups should be merged
yarn::checkTissuesToMerge(skin,"SMTS","SMTSD")

  1. Filter lowly expressed genes
skin_filtered = yarn::filterLowGenes(skin,"SMTSD")
dim(skin)
## Features  Samples 
##    40824       20
dim(skin_filtered)
## Features  Samples 
##    19933       20

Or group specific genes

tmp = yarn::filterGenes(skin,labels=c("X","Y","MT"),featureName = "chromosome_name")
# Keep only the sex names
tmp = yarn::filterGenes(skin,labels=c("X","Y","MT"),featureName = "chromosome_name",keepOnly=TRUE)
  1. Normalize in a tissue or group-aware manner
yarn::plotDensity(skin_filtered,"SMTSD",main=expression('log'[2]*' raw expression'))

skin_filtered = yarn::normalizeTissueAware(skin_filtered,"SMTSD")
yarn::plotDensity(skin_filtered,"SMTSD",normalized=TRUE,main="Normalized")
## normalizedMatrix is assumed to already be log-transformed

Helper functions

Other than checkMisAnnotation and checkTissuesToMerge we provide a few plotting function. We include, plotCMDS, plotDensity, plotHeatmap.

plotCMDS - PCoA / Classical Multi-Dimensional Scaling of the most variable genes.

data(skin)
res = yarn::plotCMDS(skin,pch=21,bg=factor(pData(skin)$SMTSD))

plotDensity - Density plots colored by phenotype of choosing. Allows for inspection of global trend differences.

filtData = yarn::filterLowGenes(skin,"SMTSD")
yarn::plotDensity(filtData,groups="SMTSD",legendPos="topleft")

plotHeatmap - Heatmap of the most variable genes.

library(RColorBrewer)
tissues = pData(skin)$SMTSD
heatmapColColors=brewer.pal(12,"Set3")[as.integer(factor(tissues))]
heatmapCols = colorRampPalette(brewer.pal(9, "RdBu"))(50)
yarn::plotHeatmap(skin,normalized=FALSE,log=TRUE,trace="none",n=10,
 col = heatmapCols,ColSideColors = heatmapColColors,cexRow = 0.25,cexCol = 0.25)

Information

## R version 4.2.2 (2022-10-31)
## 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.2/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.2/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] RColorBrewer_1.1-3  netZooR_1.5.0       matrixcalc_1.0-6   
## [4] yarn_1.24.0         pandaR_1.19.6       Biobase_2.58.0     
## [7] BiocGenerics_0.44.0 reticulate_1.32.0   igraph_1.5.1       
## 
## loaded via a namespace (and not attached):
##   [1] utf8_1.2.3                  proto_1.0.0                
##   [3] RUnit_0.4.32                tidyselect_1.2.0           
##   [5] RSQLite_2.3.1               AnnotationDbi_1.60.0       
##   [7] grid_4.2.2                  BiocParallel_1.32.4        
##   [9] munsell_0.5.0               base64url_1.4              
##  [11] codetools_0.2-19            ragg_1.2.5                 
##  [13] preprocessCore_1.60.1       chron_2.3-61               
##  [15] pbdZMQ_0.3-10               colorspace_2.1-0           
##  [17] Category_2.64.0             filelock_1.0.2             
##  [19] knitr_1.44                  uuid_1.1-1                 
##  [21] rstudioapi_0.15.0           stats4_4.2.2               
##  [23] MatrixGenerics_1.10.0       repr_1.1.6                 
##  [25] GenomeInfoDbData_1.2.9      farver_2.1.1               
##  [27] bit64_4.0.5                 rhdf5_2.42.0               
##  [29] rprojroot_2.0.3             downloader_0.4             
##  [31] vctrs_0.6.3                 generics_0.1.3             
##  [33] xfun_0.40                   BiocFileCache_2.6.0        
##  [35] R6_2.5.1                    doParallel_1.0.17          
##  [37] GenomeInfoDb_1.34.4         illuminaio_0.40.0          
##  [39] RJSONIO_1.3-1.8             locfit_1.5-9.8             
##  [41] bitops_1.0-7                rhdf5filters_1.10.0        
##  [43] cachem_1.0.8                reshape_0.8.9              
##  [45] DelayedArray_0.24.0         assertthat_0.2.1           
##  [47] BiocIO_1.8.0                scales_1.2.1               
##  [49] nnet_7.3-19                 gtable_0.3.4               
##  [51] processx_3.8.2              rlang_1.1.1                
##  [53] genefilter_1.80.2           systemfonts_1.0.4          
##  [55] splines_4.2.2               rtracklayer_1.58.0         
##  [57] GEOquery_2.66.0             hexbin_1.28.3              
##  [59] checkmate_2.2.0             abind_1.4-5                
##  [61] reshape2_1.4.4              yaml_2.3.7                 
##  [63] backports_1.4.1             GenomicFeatures_1.50.3     
##  [65] RBGL_1.74.0                 tensorA_0.36.2             
##  [67] tools_4.2.2                 nor1mix_1.3-0              
##  [69] ggplot2_3.4.3               gplots_3.1.3               
##  [71] posterior_1.4.1             jquerylib_0.1.4            
##  [73] ggdendro_0.1.23             siggenes_1.72.0            
##  [75] STRINGdb_2.10.0             gsubfn_0.7                 
##  [77] hash_2.2.6.3                Rcpp_1.0.11                
##  [79] plyr_1.8.8                  base64enc_0.1-3            
##  [81] sparseMatrixStats_1.10.0    progress_1.2.2             
##  [83] zlibbioc_1.44.0             purrr_1.0.2                
##  [85] RCurl_1.98-1.12             ps_1.7.5                   
##  [87] prettyunits_1.1.1           sqldf_0.4-11               
##  [89] openssl_2.1.0               bumphunter_1.40.0          
##  [91] S4Vectors_0.36.1            cluster_2.1.4              
##  [93] SummarizedExperiment_1.28.0 fs_1.6.3                   
##  [95] magrittr_2.0.3              data.table_1.14.8          
##  [97] matrixStats_1.0.0           hms_1.1.3                  
##  [99] evaluate_0.21               xtable_1.8-4               
## [101] XML_3.99-0.14               mclust_6.0.0               
## [103] IRanges_2.32.0              compiler_4.2.2             
## [105] biomaRt_2.54.0              minfi_1.44.0               
## [107] tibble_3.2.1                RCy3_2.18.0                
## [109] KernSmooth_2.23-22          crayon_1.5.2               
## [111] htmltools_0.5.6             GOstats_2.64.0             
## [113] mgcv_1.9-0                  tzdb_0.4.0                 
## [115] tidyr_1.3.0                 DBI_1.1.3                  
## [117] dbplyr_2.3.3                MASS_7.3-60                
## [119] rappdirs_0.3.3              Matrix_1.6-1.1             
## [121] readr_2.1.4                 permute_0.9-7              
## [123] cli_3.6.1                   quantro_1.32.0             
## [125] uchardet_1.1.1              quadprog_1.5-8             
## [127] parallel_4.2.2              GenomicRanges_1.50.2       
## [129] pkgconfig_2.0.3             pkgdown_2.0.7              
## [131] GenomicAlignments_1.34.0    IRdisplay_1.1              
## [133] xml2_1.3.5                  foreach_1.5.2              
## [135] annotate_1.76.0             penalized_0.9-52           
## [137] bslib_0.5.1                 rngtools_1.5.2             
## [139] multtest_2.54.0             beanplot_1.3.1             
## [141] XVector_0.38.0              AnnotationForge_1.40.0     
## [143] doRNG_1.8.6                 scrime_1.3.5               
## [145] distributional_0.3.2        stringr_1.5.0              
## [147] digest_0.6.33               vegan_2.6-4                
## [149] graph_1.76.0                Biostrings_2.66.0          
## [151] rmarkdown_2.25              base64_2.0.1               
## [153] edgeR_3.40.1                DelayedMatrixStats_1.20.0  
## [155] GSEABase_1.60.0             restfulr_0.0.15            
## [157] curl_5.0.2                  Rsamtools_2.14.0           
## [159] gtools_3.9.4                rjson_0.2.21               
## [161] lifecycle_1.0.3             nlme_3.1-163               
## [163] jsonlite_1.8.7              cmdstanr_0.6.1.9000        
## [165] Rhdf5lib_1.20.0             viridisLite_0.4.2          
## [167] desc_1.4.2                  askpass_1.2.0              
## [169] limma_3.54.2                fansi_1.0.4                
## [171] pillar_1.9.0                lattice_0.21-8             
## [173] plotrix_3.8-2               KEGGREST_1.38.0            
## [175] fastmap_1.1.1               httr_1.4.7                 
## [177] survival_3.5-7              GO.db_3.16.0               
## [179] glue_1.6.2                  png_0.1-8                  
## [181] iterators_1.0.14            bit_4.0.5                  
## [183] Rgraphviz_2.42.0            stringi_1.7.12             
## [185] sass_0.4.7                  HDF5Array_1.26.0           
## [187] blob_1.2.4                  textshaping_0.3.6          
## [189] org.Hs.eg.db_3.16.0         caTools_1.18.2             
## [191] memoise_2.0.1               IRkernel_1.3.2             
## [193] dplyr_1.1.3