forked from MarineOmics/marineomics.github.io
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFUN-01-DGE_comparison_v2.html
2241 lines (2033 loc) · 96.5 KB
/
FUN-01-DGE_comparison_v2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
<title>Fitting Multifactorial Models of Differential Expression</title>
<script src="site_libs/header-attrs-2.20/header-attrs.js"></script>
<script src="site_libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="site_libs/bootstrap-3.3.5/css/cosmo.min.css" rel="stylesheet" />
<script src="site_libs/bootstrap-3.3.5/js/bootstrap.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/html5shiv.min.js"></script>
<script src="site_libs/bootstrap-3.3.5/shim/respond.min.js"></script>
<style>h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }</style>
<script src="site_libs/jqueryui-1.11.4/jquery-ui.min.js"></script>
<link href="site_libs/tocify-1.9.1/jquery.tocify.css" rel="stylesheet" />
<script src="site_libs/tocify-1.9.1/jquery.tocify.js"></script>
<script src="site_libs/navigation-1.1/tabsets.js"></script>
<link href="site_libs/highlightjs-9.12.0/default.css" rel="stylesheet" />
<script src="site_libs/highlightjs-9.12.0/highlight.js"></script>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
</style>
<style type="text/css">code{white-space: pre;}</style>
<script type="text/javascript">
if (window.hljs) {
hljs.configure({languages: []});
hljs.initHighlightingOnLoad();
if (document.readyState && document.readyState === "complete") {
window.setTimeout(function() { hljs.initHighlighting(); }, 0);
}
}
</script>
<style type="text/css">
/* for pandoc --citeproc since 2.11 */
div.csl-bib-body { }
div.csl-entry {
clear: both;
}
.hanging div.csl-entry {
margin-left:2em;
text-indent:-2em;
}
div.csl-left-margin {
min-width:2em;
float:left;
}
div.csl-right-inline {
margin-left:2em;
padding-left:1em;
}
div.csl-indent {
margin-left: 2em;
}
</style>
<link rel="stylesheet" href="tutorial.css" type="text/css" />
<style type = "text/css">
.main-container {
max-width: 940px;
margin-left: auto;
margin-right: auto;
}
img {
max-width:100%;
}
.tabbed-pane {
padding-top: 12px;
}
.html-widget {
margin-bottom: 20px;
}
button.code-folding-btn:focus {
outline: none;
}
summary {
display: list-item;
}
details > summary > p:only-child {
display: inline;
}
pre code {
padding: 0;
}
</style>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #cccccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #adb5bd;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
border-radius: 6px 0 6px 6px;
}
</style>
<script type="text/javascript">
// manage active state of menu based on current page
$(document).ready(function () {
// active menu anchor
href = window.location.pathname
href = href.substr(href.lastIndexOf('/') + 1)
if (href === "")
href = "index.html";
var menuAnchor = $('a[href="' + href + '"]');
// mark the anchor link active (and if it's in a dropdown, also mark that active)
var dropdown = menuAnchor.closest('li.dropdown');
if (window.bootstrap) { // Bootstrap 4+
menuAnchor.addClass('active');
dropdown.find('> .dropdown-toggle').addClass('active');
} else { // Bootstrap 3
menuAnchor.parent().addClass('active');
dropdown.addClass('active');
}
// Navbar adjustments
var navHeight = $(".navbar").first().height() + 15;
var style = document.createElement('style');
var pt = "padding-top: " + navHeight + "px; ";
var mt = "margin-top: -" + navHeight + "px; ";
var css = "";
// offset scroll position for anchor links (for fixed navbar)
for (var i = 1; i <= 6; i++) {
css += ".section h" + i + "{ " + pt + mt + "}\n";
}
style.innerHTML = "body {" + pt + "padding-bottom: 40px; }\n" + css;
document.head.appendChild(style);
});
</script>
<!-- tabsets -->
<style type="text/css">
.tabset-dropdown > .nav-tabs {
display: inline-table;
max-height: 500px;
min-height: 44px;
overflow-y: auto;
border: 1px solid #ddd;
border-radius: 4px;
}
.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before {
content: "\e259";
font-family: 'Glyphicons Halflings';
display: inline-block;
padding: 10px;
border-right: 1px solid #ddd;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before {
content: "\e258";
font-family: 'Glyphicons Halflings';
border: none;
}
.tabset-dropdown > .nav-tabs > li.active {
display: block;
}
.tabset-dropdown > .nav-tabs > li > a,
.tabset-dropdown > .nav-tabs > li > a:focus,
.tabset-dropdown > .nav-tabs > li > a:hover {
border: none;
display: inline-block;
border-radius: 4px;
background-color: transparent;
}
.tabset-dropdown > .nav-tabs.nav-tabs-open > li {
display: block;
float: none;
}
.tabset-dropdown > .nav-tabs > li {
display: none;
}
</style>
<!-- code folding -->
<style type="text/css">
#TOC {
margin: 25px 0px 20px 0px;
}
@media (max-width: 768px) {
#TOC {
position: relative;
width: 100%;
}
}
@media print {
.toc-content {
/* see https://github.com/w3c/csswg-drafts/issues/4434 */
float: right;
}
}
.toc-content {
padding-left: 30px;
padding-right: 40px;
}
div.main-container {
max-width: 1200px;
}
div.tocify {
width: 20%;
max-width: 260px;
max-height: 85%;
}
@media (min-width: 768px) and (max-width: 991px) {
div.tocify {
width: 25%;
}
}
@media (max-width: 767px) {
div.tocify {
width: 100%;
max-width: none;
}
}
.tocify ul, .tocify li {
line-height: 20px;
}
.tocify-subheader .tocify-item {
font-size: 0.90em;
}
.tocify .list-group-item {
border-radius: 0px;
}
.tocify-subheader {
display: inline;
}
.tocify-subheader .tocify-item {
font-size: 0.95em;
}
</style>
</head>
<body>
<div class="container-fluid main-container">
<!-- setup 3col/9col grid for toc_float and main content -->
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-3">
<div id="TOC" class="tocify">
</div>
</div>
<div class="toc-content col-xs-12 col-sm-8 col-md-9">
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-bs-toggle="collapse" data-target="#navbar" data-bs-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">MarineOmics</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
<a href="contributions.html">Contributions</a>
</li>
<li>
<a href="panels.html">Panel Seminars</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Population Genomics
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="choosing-population-genetics.html">Choosing a Population Genomics Approach</a>
</li>
<li>
<a href="WGS_intro.html">Whole Genome Resequencing</a>
</li>
<li>
<a href="RADseq.html">Reduced Representation Sequencing</a>
</li>
<li>
<a href="poolseq.html">Poolseq</a>
</li>
<li>
<a href="RDAtraitPredictionTutorial.html">Redundancy Analysis (RDA) Trait Prediction</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Functional Genomics
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="DGE_comparison_v2.html">Mutifactorial RNAseq</a>
</li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Genome-Phenome
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li class="dropdown-header">coming soon!</li>
</ul>
</li>
<li>
<a href="https://github.com/MarineOmics/marineomics.github.io/discussions">Discussion Forum</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'G-53GH9PV49T', 'auto');
ga('send', 'pageview');
</script>
<div id="header">
<h1 class="title toc-ignore">Fitting Multifactorial Models of
Differential Expression</h1>
<h3 class="subtitle"><em>Samuel N. Bogan</em></h3>
</div>
<div id="intro-to-multifactorial-rna-seq-models" class="section level1">
<h1>Intro to multifactorial RNA-seq models</h1>
<p>Studies of molecular responses to environmental change increasingly
employ multifactorial experimental designs incorporating different
developmental stages, stressors, populations, or non-linear dynamics
that resolve interactions between variables that shape expression,
physiology, and performance. After an experiment during which a study
organism was exposed to abiotic variation and perhaps other variables,
researchers interested in how gene expression correlates with these
variables will often extract RNA across treatment groups, prepare cDNA
libraries for sequencing, and conduct an analysis of differential
expression (DE) across variables of interest after mapping and counting
RNA-seq reads. DE analysis is achieved by fitting RNA-seq read count
data to statistical models, often using tried-and-true DE packages. Most
packages do not have the flexibility to accommodate a number of common
experimental design components and it can be difficult to navigate their
functionality for fitting multivariate models. When these packages fall
short, determining how to fit customized multifactorial models yourself
can be an additional challenge. Many great walkthroughs exist for
conducting DE analysis across using single-variable experimental
designs, but there is a lack of guidance on multifactorial approaches
for testing for DE and modelling gene expression. Regardless of whether
you have RNA-seq data on hand or you’re in the process of planning your
experiment, this walkthrough will help you navigate what DE packages and
model fitting approaches are best suited to your experimental
design.</p>
<p><br></p>
<div id="targeted-audience" class="section level2">
<h2>Targeted audience</h2>
<p>This walkthrough is for both intermediate and expert practitioners of
RNA-seq analyses, and most of all, those new to multifactorial RNA-seq.
We have written this page with the assumption that readers have a basic
familiarity with model fitting and statistical analysis, as well as next
generation sequencing technologies, RNA-seq workflows, and the R
statistical environment.</p>
<p><br></p>
</div>
<div id="variables-we-will-cover" class="section level2">
<h2>Variables we will cover</h2>
<p>This walkthrough can be broken down into different types of predictor
variables that can be incorporated in models of gene expression. In the
order we address them, these variables include:</p>
<ul>
<li>Non-linear fixed effects</li>
<li>Continuous fixed effects</li>
<li>Interactive fixed effects</li>
<li>Random intercepts</li>
<li>Random slopes</li>
</ul>
<p><br></p>
</div>
<div id="packages-we-will-cover" class="section level2">
<h2>Packages we will cover</h2>
<ul>
<li>DESeq2 <span class="citation">(Love, Huber, and Anders 2014)</span>
<a
href="http://bioconductor.org/packages/devel/bioc/vignettes/DESeq2/inst/doc/DESeq2.html">Link</a></li>
<li>edgeR <span class="citation">(Robinson, McCarthy, and Smyth
2010)</span> <a
href="https://www.bioconductor.org/packages/devel/bioc/vignettes/edgeR/inst/doc/edgeRUsersGuide.pdf">Link</a></li>
<li>Voom (often called Limma-Voom) <span class="citation">(Law et al.
2014)</span> <a
href="https://ucdavis-bioinformatics-training.github.io/2018-June-RNA-Seq-Workshop/thursday/DE.html">Link</a></li>
</ul>
<p><br></p>
</div>
</div>
<div id="features-of-popular-dge-packages" class="section level1">
<h1>Features of popular DGE packages</h1>
<p>Two important considerations when choosing a DE package to analyze
RNA-seq data are the distribution family used by the package and the
effect types it incorporate into a model. The DE packages we will cover
assume the following read count distributions and are capable of fitting
the following effect types:</p>
<table style="width:100%;">
<colgroup>
<col width="14%" />
<col width="14%" />
<col width="14%" />
<col width="14%" />
<col width="14%" />
<col width="14%" />
<col width="14%" />
</colgroup>
<thead>
<tr class="header">
<th align="left">Program</th>
<th align="left">Distribution</th>
<th align="left">Continuous fixed eff.</th>
<th align="left">Random intercepts</th>
<th align="left">Random slopes</th>
<th align="left">Interactive eff.</th>
<th align="left">Non-linear eff.</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td align="left">edgeR</td>
<td align="left">Negative binomial generalized linear model</td>
<td align="left">✔</td>
<td align="left">✖</td>
<td align="left">✖</td>
<td align="left">✔</td>
<td align="left">✔</td>
</tr>
<tr class="even">
<td align="left">DESeq2</td>
<td align="left">Negative binomial generalized linear model</td>
<td align="left">✔</td>
<td align="left">✖</td>
<td align="left">✖</td>
<td align="left">✔</td>
<td align="left">✔</td>
</tr>
<tr class="odd">
<td align="left">Voom</td>
<td align="left">Mean-variance linear model</td>
<td align="left">✔</td>
<td align="left">✔</td>
<td align="left">✖</td>
<td align="left">✔</td>
<td align="left">✔</td>
</tr>
</tbody>
</table>
<p><br></p>
<div id="summary-of-approach" class="section level2">
<h2>Summary of approach</h2>
<p>We will walk you through (i) how to conduct essential checks of your
data such as principal components analysis and observing the
distribution of filtered read counts, (ii) evaluating each package’s
functionality for multifactorial model fitting, and (iii) how to fit
each type of predictor by performing differential expression tests using
real data. These data come from an experiment that exposed the Antarctic
pteropod (a free-swimming planktonic snail) <em>Limacina helicina
antarctica</em> to three continuous levels of ocean acidification (OA)
for either 0.5 or 7 days <span class="citation">(Bogan, Johnson, and
Hofmann 2020)</span>. These RNA-seq counts are derived from reads mapped
and counted via RSEM <span class="citation">(Li and Dewey 2011)</span>
using a <em>de novo</em> reference transcriptome that includes
transcript isoforms assembled by <span class="citation">Johnson and
Hofmann (2016)</span>.</p>
<p>Throughout this walkthrough, we will provide examples of custom
scripts for fitting linear, linear mixed models, generalized linear
models to read count data using for loops in order to provide
functionality where it cannot be met by most differential expression
packages.</p>
<p>At the end of the walkthrough, we demonstrate how to compare model
predictions by different packages for different effect types commonly
used in multifactorial RNAseq analyses.</p>
<p>Let’s start by loading our required packages…</p>
<p><br></p>
<pre class="r"><code>## Unhash and run the code below if you believe you may need to install the packages loaded below
#invisible(lapply(c( "tidyverse", "ape", "vegan", "GGally",
#"rgl", "adegenet", "MASS",
#"data.table", "plyr", "lmtest", "reshape2", "Rmisc", "lmerTest","statmod"),
#function(p){
#if(! p %in% rownames(installed.packages())) {
#install.packages(p)
#}
#library(p, character.only=TRUE)
#}))
#if (!require("BiocManager", quietly = TRUE))
#install.packages("BiocManager")
#BiocManager::install(c("DESeq2","edgeR","arrayQualityMetrics"))
# Load packages
library(DESeq2)
library(edgeR)
library(tidyverse)
library(ape)
library(vegan)
library(GGally)
library(arrayQualityMetrics)
library(rgl)
library(adegenet)
library(MASS)
library(data.table)
library(plyr)
library(lmtest)
library(reshape2)
library(Rmisc)
library(lmerTest)</code></pre>
</div>
</div>
<div id="filter-and-visualize-read-counts" class="section level1">
<h1>Filter and visualize read counts</h1>
<p>Before model fitting and testing for DE, it is important to visually
inspect read counts pre- and post-filtering. In this walk through, we
will plot the distributions of read counts and sample loading to
multidimensional scaling axes (e.g., plotting principal components or
principal coordinates analyses). Looking at these plots, we can (i)
determine whether the distribution of our data match the assumptions of
model families used by different packages and (ii) determine whether one
or multiple variables within a dataset explain a significant degree of
variation in gene expression across replicates. Depending on the
distribution of your data and the variables that appear important (or
variable you would like to incorporate into your models), we will then
demonstrate how to choose an appropriate package to test for DE.</p>
<p>Most DE packages assume that read counts possess a negative binomial
distribution. The negative binomial distribution is an extension of
distributions for binary variables such as the Poisson distribution,
allowing for estimations of “equidispersion” and “overdispersion”, equal
and greater-than-expected variation in expression attributed to
biological variability . However, RNA-seq datasets can exhibit poor fits
with the negative binomial distribution <span class="citation">(Hawinkel
et al. 2020)</span>. It is well worth visualizing and testing the
distributions of RNA-seq read counts before and after filtering. Keep in
mind that the distribution applies not to the raw data, but the
residuals of a model. Additionally, individual models are fit to the
read counts of each gene. Thus, the most accurate representation of how
appropriate a negative binomial distribution is for read counts would
come from plotting the distribution of residuals across all genes
following model fitting. Below is a visual example of negative binomial
distributions that possess different means and variances:</p>
<p><img src="DGE_comparison_v2_files/figure-html/unnamed-chunk-2-1.png" width="672" /></p>
<p>Now let’s first plot the distribution of unfiltered reads from our
dataset:</p>
<p><br></p>
<pre class="r"><code># Read in matrix of RSEM expected read counts
data <- read.delim("RNA_data/GE2_expected_counts_gene.matrix", sep = "\t", header = T, row.names = 1)
# Peak at data to check that it looks okay
head(data)</code></pre>
<pre><code>## B7a.genes.results B7b.genes.results B7c.genes.results
## TR100110|c0_g1_i1 4.00 10.00 3.00
## TR101578|c0_g1_i1 0.00 0.00 0.00
## TR1047|c0_g1_i1 14.00 19.00 11.00
## TR105096|c0_g1_i1 14.00 12.00 9.00
## TR107626|c1_g1_i1 4530.93 28139.91 14141.83
## TR11301|c0_g1_i1 0.00 0.00 0.00
## B12a.genes.results B12b.genes.results B12c.genes.results
## TR100110|c0_g1_i1 6.00 9.0 8.00
## TR101578|c0_g1_i1 0.00 0.0 0.00
## TR1047|c0_g1_i1 15.00 14.0 9.00
## TR105096|c0_g1_i1 15.00 5.0 10.00
## TR107626|c1_g1_i1 80846.09 5649.4 30756.08
## TR11301|c0_g1_i1 0.00 0.0 0.00
## R7a.genes.results R7b.genes.results R7c.genes.results
## TR100110|c0_g1_i1 18.0 15.00 6.00
## TR101578|c0_g1_i1 0.0 0.00 0.00
## TR1047|c0_g1_i1 16.0 16.00 27.00
## TR105096|c0_g1_i1 25.0 15.00 6.00
## TR107626|c1_g1_i1 137592.5 45299.57 14843.47
## TR11301|c0_g1_i1 0.0 0.00 0.00
## R12a.genes.results R12b.genes.results R12c.genes.results
## TR100110|c0_g1_i1 11.00 13.0 9
## TR101578|c0_g1_i1 0.00 0.0 0
## TR1047|c0_g1_i1 23.00 14.0 11
## TR105096|c0_g1_i1 14.00 45.0 12
## TR107626|c1_g1_i1 21210.52 230436.5 0
## TR11301|c0_g1_i1 0.00 0.0 0
## Y7a.genes.results Y7b.genes.results Y7c.genes.results
## TR100110|c0_g1_i1 6 4 12.0
## TR101578|c0_g1_i1 0 0 0.0
## TR1047|c0_g1_i1 20 3 18.0
## TR105096|c0_g1_i1 9 1 13.0
## TR107626|c1_g1_i1 0 0 112214.6
## TR11301|c0_g1_i1 0 0 0.0
## Y12a.genes.results Y12b.genes.results Y12c.genes.results
## TR100110|c0_g1_i1 21.00 12 12.00
## TR101578|c0_g1_i1 0.00 0 0.00
## TR1047|c0_g1_i1 25.00 14 9.00
## TR105096|c0_g1_i1 14.00 19 24.00
## TR107626|c1_g1_i1 86243.14 148100 74153.54
## TR11301|c0_g1_i1 0.00 0 0.00</code></pre>
<p>The table of read counts above has rows representing individual
transcripts and columns representing different replicate samples across
treatments.</p>
<p><br></p>
<pre class="r"><code># Name experimental samples: names correspond to pCO2 treatment (300, 600, 900) + days (12 h2 vs 7 days) + replicate ID
colnames(data) <- c("300.7.a", "300.7.b", "300.7.c","300.12.a", "300.12.b", "300.12.c",
"900.7.a", "900.7.b", "900.7.c", "900.12.a", "900.12.b", "900.12.c",
"600.7.a", "600.7.b", "600.7.c", "600.12.a", "600.12.b", "600.12.c")
## Create 'targets' and 'Group dataframe, expressing experimental variables for DEG analysis
pCO2 <- as.numeric(c( 255, 255, 255, 255, 255, 255,
530, 530, 530, 530, 530, 530,
918, 918, 918, 918, 918, 918))
treatment <- c("B","B", "B", "B", "B", "B",
"R", "R", "R", "R", "R", "R",
"Y", "Y", "Y", "Y", "Y", "Y")
day <- as.numeric(c(7, 7, 7, .5, .5, .5,
7, 7, 7, .5, .5, .5,
7, 7, 7, .5, .5, .5))
targets <- data.frame(pCO2, day, treatment)
targets$grouping <- paste(targets$pCO2, targets$day, sep = ".")
# The group factor represents the combined levels of an experimental replicate across all variables
Group <- factor(paste(targets$day, targets$pCO2, sep = "_"))
# Data must be rounded to nearest integer in order to be fit for negative binomial distribution
data_input <- round(data)
# Peak at rounded data
head(data_input)</code></pre>
<pre><code>## 300.7.a 300.7.b 300.7.c 300.12.a 300.12.b 300.12.c 900.7.a
## TR100110|c0_g1_i1 4 10 3 6 9 8 18
## TR101578|c0_g1_i1 0 0 0 0 0 0 0
## TR1047|c0_g1_i1 14 19 11 15 14 9 16
## TR105096|c0_g1_i1 14 12 9 15 5 10 25
## TR107626|c1_g1_i1 4531 28140 14142 80846 5649 30756 137592
## TR11301|c0_g1_i1 0 0 0 0 0 0 0
## 900.7.b 900.7.c 900.12.a 900.12.b 900.12.c 600.7.a 600.7.b
## TR100110|c0_g1_i1 15 6 11 13 9 6 4
## TR101578|c0_g1_i1 0 0 0 0 0 0 0
## TR1047|c0_g1_i1 16 27 23 14 11 20 3
## TR105096|c0_g1_i1 15 6 14 45 12 9 1
## TR107626|c1_g1_i1 45300 14843 21211 230436 0 0 0
## TR11301|c0_g1_i1 0 0 0 0 0 0 0
## 600.7.c 600.12.a 600.12.b 600.12.c
## TR100110|c0_g1_i1 12 21 12 12
## TR101578|c0_g1_i1 0 0 0 0
## TR1047|c0_g1_i1 18 25 14 9
## TR105096|c0_g1_i1 13 14 19 24
## TR107626|c1_g1_i1 112215 86243 148100 74154
## TR11301|c0_g1_i1 0 0 0 0</code></pre>
<pre class="r"><code># Plot distribution of unfiltered read counts across all samples
ggplot(data = data.frame(rowMeans(data_input)),
aes(x = rowMeans.data_input.)) +
geom_histogram(fill = "grey") +
xlim(0, 500) +
theme_classic() +
labs(title = "Distribution of unfiltered reads") +
labs(y = "Density", x = "Raw read counts",
title = "Read count distribution: untransformed, unnormalized, unfiltered")</code></pre>
<p><img src="DGE_comparison_v2_files/figure-html/unnamed-chunk-4-1.png" width="672" /></p>
<p>As you can see in the above plot, the raw distribution of all read
counts takes on a left-skewed negative binomial distribution similar to
the purple distribution in the example above. While looking at the
distribution of your raw reads is useful, these are not in fact the data
you will be inputting to tests of differential expression. Let’s plot
the distribution of filtered reads normalized by library size, expressed
as log2 counts per million reads (logCPM). These are the reads we will
use in our test, and after we plot their distribution, we will conduct
one more, slightly more robust, test of our data’s fit to the negative
binomial distribution using residuals from fitted models.</p>
<p><br></p>
<pre class="r"><code># Make a DGEList object for edgeR
y <- DGEList(counts = data_input, remove.zeros = TRUE)
#Let's remove samples with less than 0.5 cpm (this is ~10 counts in the count file) in fewer then 9/12 samples
keep <- rowSums(cpm(y) > .5) >= 9
table(keep)</code></pre>
<pre><code>## keep
## FALSE TRUE
## 18871 62579</code></pre>
<pre class="r"><code># Set keep.lib.sizes = F and recalculate library sizes after filtering
y <- y[keep, keep.lib.sizes = FALSE]
y <- calcNormFactors(y)
# Calculate logCPM
df_log <- cpm(y, log = TRUE, prior.count = 2)
# Plot distribution of filtered logCPM values
ggplot(data = data.frame(rowMeans(df_log)),
aes(x = rowMeans.df_log.) ) +
geom_histogram(fill = "grey") +
theme_classic() +
labs(y = "Density", x = "Filtered read counts (logCPM)",
title = "Distribution of normalized, filtered read counts")</code></pre>
<p><img src="DGE_comparison_v2_files/figure-html/unnamed-chunk-5-1.png" width="672" /></p>
<p>Our raw data appear to follow a strong negative binomial
distribution! Later, we will see whether this holds for residuals from
fitted negative binomial GLMs.</p>
<p><br></p>
<div id="mds-plot-visualizing-experimental-factors"
class="section level2">
<h2>MDS plot visualizing experimental factors</h2>
<p>Before analyzing our data, it is essential that we look at the
multivariate relationships between our samples based on
transcriptome-wide expression levels. Below is example code and output
for a principal coordinates analysis (PCOA) plot that visualizes
multifactorial RNA-seq replicates according to two predictor variables
across major and minor latent variables or PCOA axes. These predictor
variables, as discussed above, are <em>p</em>CO<span
class="math inline">\({_2}\)</span> and time-in-treatment.</p>
<p><br></p>
<pre class="r"><code># Export pcoa loadings
dds.pcoa = pcoa(vegdist(t(df_log <- cpm(y, log = TRUE, prior.count = 2)),
method = "euclidean") / 1000)
# Create df of MDS vector loading
scores <- dds.pcoa$vectors
## Plot pcoa loadings of each sample, groouped by time point and pCO2 treatment
# Calculate % variation explained by each eigenvector
percent <- dds.pcoa$values$Eigenvalues
cumulative_percent_variance <- (percent / sum( percent)) * 100
# Prepare information for pcoa plot, then plot
color <- c("steelblue1", "tomato1", "goldenrod1")
par(mfrow = c(1, 1))
plot(
scores[, 1],
scores[, 2],
cex = .5,
cex.axis = 1,
cex.lab = 1.25,
xlab = paste("PC1, ", round(cumulative_percent_variance[1], 2), "%"),
ylab = paste("PC2, ", round(cumulative_percent_variance[2], 2), "%")
)
# Add visual groupings to pcoa plot
ordihull(
scores,
as.factor(targets$treatment),
border = NULL,
lty = 2,
lwd = .5,
label = F,
col = color,
draw = "polygon",
alpha = 100,
cex = .5
)
ordispider(scores, as.factor(targets$grouping), label = F) # Vectors connecting samples in same pCO2 x time group
ordilabel(scores, cex = 0.5) # Label sample IDs</code></pre>
<p><img src="DGE_comparison_v2_files/figure-html/unnamed-chunk-6-1.png" width="672" /></p>
<p>In the PCOA above, blue = low <em>p</em><span
class="math inline">\(CO_{2}\)</span>, yellow = moderate <em>p</em><span
class="math inline">\(CO_{2}\)</span>, and red = high <em>p</em><span
class="math inline">\(CO_{2}\)</span>. From this plot, we can see that
treatment and time both influence multivariate gene expression across
the RNA-seq samples. By and large, samples cluster according to these
two predictors in a manner consistent with what we would expect from our
experimental design if <em>p</em><span
class="math inline">\(CO_{2}\)</span> and time were to affect gene
expression.</p>
<p><br></p>
<pre class="r"><code>logCPM.pca <- prcomp(t (df_log))
logCPM.pca.proportionvariances <-
((logCPM.pca$sdev ^ 2) / (sum(logCPM.pca$sdev ^ 2))) * 100
## Do treatment groups fully segregate? Wrap samples by pCO2 x time, not just pCO2
# Replot using logCPM.pca
plot(
logCPM.pca$x,
type = "n",
main = NA,
xlab = paste("PC1, ", round(logCPM.pca.proportionvariances[1], 2), "%"),
ylab = paste("PC2, ", round(logCPM.pca.proportionvariances[2], 2), "%")
)
points(logCPM.pca$x,
col = "black",
pch = 16,
cex = 1)
colors2 <-
c("steelblue1",
"dodgerblue2",
"tomato1",
"coral",
"goldenrod1",
"goldenrod3")
ordihull(
logCPM.pca$x,
targets$grouping,
border = NULL,
lty = 2,
lwd = .5,
col = colors2,
draw = "polygon",
alpha = 75,
cex = .5,
label = T
)</code></pre>
<p><img src="DGE_comparison_v2_files/figure-html/unnamed-chunk-7-1.png" width="672" /></p>
<p>This plot is only a slight adjustment of the first PCOA. If you’d
like to wrap each multifactorial group and get a better idea of
potential overlap between clusters, the plot and code above can be
applied to do so.</p>
<p>Now that we have conducted QC analyses and plots of the read count
data, it is time to begin model fitting and testing for differential
expression.</p>
<p><br></p>
</div>
</div>
<div id="non-linear-effects" class="section level1">
<h1>Non-linear effects</h1>
<p>Gene expression traits can exhibit non-linear performance curves
across a continuous variable much like other physiological traits.
Studies that incorporate more than two levels of a continuous predictor
provide an opportunity to test for non-linear effects on gene
expression. Similar to performance traits such as growth or metabolic
rates, gene expression can be modelled across a continuous variable by
fitting non-linear ‘performance curves’ to read count data. Rivera
<em>et al.</em> 2021 recently discussed the benefits of fitting
non-linear reaction norms to gene expression data in order to better
model acclimation by tolerant and sensitive genotypes to an
environmental stressor. In a conceptual figure of theirs, shown below,
they depict non-linear variation in expression before, during, and after
exposure to a stressor for four reaction norm phenotypes: (i) a tolerant
conspecific that frontloads (e.g., constitutively upregulates)
stress-induced transcripts, (ii) a tolerant conspecific that exhibits
reduced overall expression of stress-responsive transcripts, (iii) a
sensitive conspecific that upregulates inducible transcripts and cannot
recover post-stress, and (iv) a resilient conspecific that mounts a
transcriptional stress response followed by recovery and downregulation
<span class="citation">(Rivera et al. 2021)</span>.</p>
<p><br></p>
<p><img src="images/Rivera_etal_fig.png" width="1137" height="40%" style="display: block; margin: auto;" />
From Rivera <em>et al.</em> 2021 - “Transcriptomic resilience and
timing. (a) Gene expression reaction norms of four strategies during
recovery after a stressor. We use triangles again for patterns that may
confer tolerance and circles for patterns associated with stress
sensitivity. While all triangle paths show a return to baseline
(resilience) the pink (frontloading) and yellow (dampening) are also
depicting differences in baseline and plasticity and are therefore
labelled differently. (b) Adapted from the rolling ball analogy commonly
used for ecological resilience and depicted in Hodgson et al. (2015).
Each ball represents a gene showing a color-matched expression pattern
in (a). Landscapes represent expression possibilities during a stress
event. In the absence of stress, the ball will settle in a trough,
representing baseline expression levels. Elasticity (rate of return to
the baseline) is represented by the size of the arrow (i.e., larger
arrows have faster rates of return). Pink dotted line is the expression
landscape for the frontloaded ball. (c) Using Torres et al. (2016) loops
through disease space as an alternative framework of an organism’s path
through stress response and recovery. The color gradient represents the
resulting phenotype for a given path through stress and recovery space,
though x-and y-axis can denote any two parameters that are correlated
but with a time lag.”</p>
<p>Non-linear reaction norms can be modelled across time, such as Rivera
<em>et al.</em> have presented, or across multiple levels of an abiotic
variable such as temperature, pH, etc. in order to fit a performance
curve. Performance curves are a fundamental tool in ecological
physiology, and enable more robust hypothesis testing in RNA-seq studies
of environmental acclimation. For example, testing for variation in the
shape of gene expression performance curves between early and long-term
exposure timepoints can provide critical information about the role of
gene expression in acclimation. Below we outline how to fit and test for
non-linear gene expression performance curves in multifactorial RNA-seq
experiments using examples in edgeR, DESeq2, and custom code.</p>
<p>One of the simplest non-linear relationships that can be fitted to
the expression of a transcript across an continuous variable is a
second-order polynomial, otherwise known as a quadratic function, which
can be expressed as <span class="math inline">\(y_{i} = \mu +
\beta_{1}x^2 + \beta_{2}x\)</span> where <span
class="math inline">\(y\)</span> is the abundance of a given transcript
(<span class="math inline">\(i\)</span>), <span
class="math inline">\(\mu\)</span> is the intercept, and <span
class="math inline">\(y\)</span> is the continuous variable. For the
parabola generated by fitting a second-order polynomial, <span
class="math inline">\(\beta_{1}\)</span> > 0 opens the parabola
upwards while <span class="math inline">\(\beta_{1}\)</span> < 0
opens the parabola downwards. The vertex of the parabola is controlled
by <span class="math inline">\(\beta_{2}\)</span> such that when <span
class="math inline">\(\beta_{1}\)</span> is negative, greater <span
class="math inline">\(\beta_{2}\)</span> values result in the vertex
falling at higher values of <span class="math inline">\(x\)</span>.</p>
<p>Quadratic polynomials applied to phenotypic performance curves
commonly possess negative <span class="math inline">\(\beta_{1}\)</span>
values with positive <span class="math inline">\(\beta_{2}\)</span>
values: a downard-opening parabola with a positive vertex. However,