forked from CCBR/DSP_Analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DSP_Analysis_QC_Report.qmd
831 lines (590 loc) · 23.1 KB
/
DSP_Analysis_QC_Report.qmd
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
---
title: "DSP Analysis QC Report Template"
format:
html:
code-fold: true
editor: visual
#css: "qc_report_style.css"
params:
data.folder: "$path_to_folder"
results.folder: "$path_to_folder"
run.folder: "$path_to_folder"
---
## Load Libraries
```{r Load Libraries}
#| warning: false
#| message: false
# Load all relevant libraries
library(DSPWorkflow)
library(GeomxTools)
library(dplyr)
library(limma)
library(edgeR)
library(ggplot2)
library(ggrepel)
library(ggforce)
library(shadowtext)
library(stringr)
library(PCAtools)
library(readxl)
library(gridExtra)
library(grid)
library(knitr)
library(gt)
library(tidyr)
library(openxlsx)
library(ComplexUpset)
library(reshape2)
library(cowplot)
library(preprocessCore)
source("DSP_QC_functions.R")
```
## Initialization
```{r Initialization}
# Input file parameters
pkc.file.name <- "Hs_R_NGS_WTA_v1.0.pkc"
pkc.file.path <- paste0(params$data.folder, pkc.file.name)
annotation.file.name <- "$annotation.file.xlsx"
annotation.file.path <- paste0(params$data.folder, annotation.file.name)
dcc.files <- list.files(file.path(paste0(params$data.folder, "dcc")),
pattern = ".dcc$",
full.names = TRUE,
recursive = TRUE
)
# Annotation parameters
annotation.sheet.name <- "annotation"
sample.id.field.name <- "Sample_ID"
roi.field.name <- "ROI"
panel.field.name <- "panel"
slide.field.name <- "slide name"
class.field.name <- "class"
region.field.name <- "Region"
segment.field.name <- "segment"
area.field.name <- "area"
nuclei.field.name <- "nuclei"
exclude.sankey <- FALSE
segment.id.length <- 8
# Create the GeoMxSet Object
init.object <- initialize_object(dcc.files = dcc.files,
pkc.files = pkc.file.path,
annotation.file = annotation.file.path,
annotation.sheet.name = annotation.sheet.name,
sample.id.field.name = sample.id.field.name,
roi.field.name = roi.field.name,
panel.field.name = panel.field.name,
slide.field.name = slide.field.name,
class.field.name = class.field.name,
region.field.name = region.field.name,
segment.field.name = segment.field.name,
area.field.name = area.field.name,
nuclei.field.name = nuclei.field.name,
segment.id.length = segment.id.length)
```
## Object Summary
@fig-sankey shows a summary of AOIs per annotation
```{r Object Summary, fig.width=12, fig.height=8}
#| label: fig-sankey
#| fig-cap: "Sankey Plot"
#| warning: false
sankey.output <- plot_sankey(object = init.object,
lane.1 = "slide",
lane.2 = "class",
lane.3 = "region",
lane.4 = "segment",
fill.lane = "region")
print(sankey.output$sankey.plot)
```
@fig-aoibarplot shows the total AOI counts per annotation
```{r AOI Count Bar Plot, fig.width=12, fig.height=8}
#| label: fig-aoibarplot
#| fig-cap: "AOI Count Bar Plot"
#| warning: false
print(sankey.output$AOI.bar.plot)
```
@fig-upsetr shows the size of annotation groups
```{r UpsetR Plot, fig.width=12, fig.height=8}
#| label: fig-upsetr
#| fig-cap: "UpSetR Plot"
#| warning: false
upsetr.plot <- upsetr_plot(object = init.object,
annotation.groups = c("class",
"region",
"segment"))
print(upsetr.plot)
```
## QC and Filtering
```{r QC and Filtering}
qc.output <- qcProc(object = init.object,
min.segment.reads = 1000,
percent.trimmed = 80,
percent.stitched = 80,
percent.aligned = 80,
percent.saturation = 50,
min.negative.count = 3,
max.ntc.count = 1000,
min.nuclei = 200,
min.area = 1000,
print.plots = FALSE)
```
Summary of QC for AOIs and Probes
```{r QC Summary}
qc.output$table
```
#### AOI QC
AOI distribution by parameter and annotation
```{r AOI Plots}
# Print AOI plots
qc.output$plot$trimmed
qc.output$plot$aligned
qc.output$plot$stitched
qc.output$plot$saturated
qc.output$plot$neg.plot
```
AOIs that have been flagged with the given QC parameters
```{r AOI Flags}
aoi.flag.table <- aoi_flag_table(aoi.flags = qc.output$segment.flags)
print(aoi.flag.table)
```
### Probe QC
Probes that have been flagged as either local or global outliers.
```{r Probe Flag Tables}
probe.flag.output <- probe_flag_table(probe.flags = qc.output$probe.flags,
object = qc.output$object)
print(probe.flag.summary)
print(probe.flags.table)
```
### Filtering
```{r Filtering}
# Add LOQ and calculate detection of genes per AOI
loq.detection.output <- loq_detection(object = qc.output$object,
pkc.file.names = pkc.file.name)
```
#### Overall Gene Detection per AOI
@fig-GeneDetectionbByAOI shows detection rate per AOI, colored by region.
```{r Overall AOI Detection}
#| label: fig-AOIDetection
#| tbl-cap: "AOI Detection"
#| warning: false
aoi.detection <- aoi_detection(object = loq.detection.output$object)
print(gene.detection.per.aoi$detection.bar.plot)
```
AOIs in the low detection bin of 1-5%
```{r Low Detection AOI}
#| warning: false
#| message: false
print(gene.detection.per.aoi$low.detection.table)
```
```{r Gene Detection All AOIs}
#| warning: false
#| message: false
# Store the AOI detection for export in the QC summary
aoi.detection.summary <- pData(object) %>%
select(any_of(c("segmentID", "GeneDetectionRate", "DetectionThreshold")))
```
##### Filter out AOIs with low detection
```{r Filter by AOI}
#| warning: false
#| message: false
# Filter the data using the cutoff for gene detection rate
aoi.gene.rate.cutoff <- 5
object.aoi.filtered <-
object[, pData(object)$GeneDetectionRate >= aoi.gene.rate.cutoff]
# Create a table of AOIs that are filtered out
aoi.filtered.out <- pData(object[, pData(object)$GeneDetectionRate < aoi.gene.rate.cutoff])
aoi.filtered.out.table <- aoi.filtered.out %>%
select(segmentID, GeneDetectionRate) %>%
gt() %>%
tab_header(title = "AOIs Filtered Out",
subtitle = paste0(aoi.gene.rate.cutoff, "% Cutoff"), preheader = NULL)
print(aoi.filtered.out.table)
```
#### Detection per Gene
```{r Detection per Gene}
#| warning: false
#| message: false
# Rerun LOQ to calculate new detection rate for individual genes:
loq.detection.output.aoi.filtered <- loq_detection(object = object.aoi.filtered,
pkc.file.names = pkc.file.name)
```
@fig-GeneDetection shows the gene detection as a percent of all AOIs
```{r Gene Detection Plot}
#| label: fig-GeneDetection
#| fig-cap: "Gene Detection Percent of All AOIs"
#| warning: false
gene.detection <- gene_detection(object = loq.detection.output.aoi.filtered$object,
facet.column = "region",
loq.mat = loq.detection.output.aoi.filtered$loq.matrix)
print(gene.detection$total.plot)
```
@fig-FacetGeneDetection shows the gene detection as a percent of all AOIs per annotation group
```{r Facet Gene Detection Plot}
#| label: fig-FacetGeneDetection
#| fig-cap: "Gene Detection Percent of All AOIs per Annotation Group"
#| warning: false
print(gene.detection$facet.plot)
```
Gene detection rates for specified genes of interest
```{r Genes of Interest}
#| label: tbl-GenesOfInterest
#| tbl-cap: "Gene of Interest Detection Rate"
#| warning: false
# Gene of interest detection table
goi <- c("A2M", "CD44")
goi.df <- data.frame(Gene = goi,
Number = fData(loq.detection.output.aoi.filtered$object)[goi, "DetectedSegments"],
DetectionRate = fData(loq.detection.output.aoi.filtered$object)[goi, "DetectionRate"])
# Print the GOI table
goi.table <- goi.table %>% gt()
print(goi.table)
```
@fig-DetectionPerGeneLoss shows the loss of percentage of all AOIs individual genes are detected within
```{r Gene Detection Rates Loss Plot}
#| label: fig-DetectionPerGeneLoss
#| fig-cap: "Gene Detection Loss"
#| warning: false
print(gene.detection$detect.loss.plot)
```
Summary of all gene detection rates
```{r Gene Detection Rate Summary}
#| warning: false
#| message: false
# Gather a summary of the every gene's detection percentage in all AOIs
gene.detection.summary <- fData(loq.detection.output.aoi.filtered$object) %>%
mutate(gene = rownames(fData(loq.detection.output.aoi.filtered$object))) %>%
select(any_of(c("gene", "DetectionRate", "DetectionThreshold")))
```
##### Filter out genes with low detection
```{r Filter Genes}
#| warning: false
#| message: false
# Set the cutoff for gene detection (percentage)
gene.detection.cutoff <- 5
# Manually include the negative control probe, for downstream use
negative.probe.fData <- subset(fData(loq.detection.output.aoi.filtered$object), CodeClass == "Negative")
neg.probes <- unique(negative.probe.fData$TargetName)
# Subset for genes above the study gene detection rate cutoff
object.gene.filtered <- loq.detection.output.aoi.filtered$object[fData(loq.detection.output.aoi.filtered$object)$DetectionRate >= gene.detection.cutoff |
fData(loq.detection.output.aoi.filtered$object)$TargetName %in% neg.probes, ]
# Create a summary of genes that are filtered out
genes.filtered.out <- fData(loq.detection.output.aoi.filtered$object[fData(loq.detection.output.aoi.filtered$object)$DetectionRate < gene.detection.cutoff, ])
print(paste0(nrow(genes.filtered.out), " genes were filtered out of the GeoMxSet Object. For the full list, check the QC Output File."))
```
**Write QC Output File**
```{r Write QC output}
write.qc.file <- FALSE
if(write.qc.file == TRUE){
# Start the QC output excel workbook
qc.info.output <- createWorkbook()
# Add the AOI flag info to the output file
addWorksheet(qc.info.output, "AOI QC Flags")
writeData(qc.info.output, sheet = "AOI QC Flags", qc.output$segment.flags)
# Add the probe flag QC info to the output file
addWorksheet(qc.info.output, "Probe QC Flags")
writeData(qc.info.output, sheet = "Probe QC Flags", probe.flags.table)
# Add the AOI detection QC info
addWorksheet(qc.info.output, "AOI Detection Rate")
writeData(qc.info.output, sheet = "AOI Detection Rate", segment.detection.summary)
# Add the Gene detection QC info to the output file
addWorksheet(qc.info.output, "Gene Detection Rate")
writeData(qc.info.output, sheet = "Gene Detection Rate", gene.detection.summary)
# Save the QC output file
saveWorkbook(qc.info.output, paste0(params$results.folder, params$run.folder, "QC_info.xlsx"), overwrite = TRUE)
}
```
#### Q3 versus Negative Background
```{r Visualize Density of Q3 Scores versus Negative Background, warning=FALSE, message=FALSE}
#| label: fig-densityQ3vsBackground
#| fig-cap: "Density of Q3 Normalized Counts versus Background"
#| warning: false
plot.distribution <- plot_distribution(object = object.gene.filtered,
facet.annotation = "region")
```
#### Nuclei per ROI Plot
```{r Nuclei per Annotation}
#| warning: false
#| message: false
# Plot the number of nuclei per ROI for an annotation of interest
object <- object.gene.filtered
annotation <- pData(object.gene.filtered)
nuclei.plot <- nuclei_plot(annotation = annotation,
color = "region",
facet = "class",
x.axis = "roi",
order.by.ROI.num = TRUE)
```
### Normalization
```{r Normalization, warning=FALSE, message=FALSE}
q3.normalization.output <- geomxNorm(
object = object.gene.filtered,
norm = "q3")
neg.normalization.output <- geomxNorm(
object = object.gene.filtered,
norm = "neg")
export.norm.object <- FALSE
if(export.norm.object == TRUE){
object <- q3.normalization.object
save(object, file = paste0(params$results.folder, params$run.folder, "$normalized.object.RDA"))
}
```
#### RLE Plots
```{r RLE Plots}
#| warning: false
#| message: false
# Counts
raw.counts <- q3.normalization.output$object@assayData$exprs
q3.counts <- q3.normalization.output$object@assayData$q_norm
neg.counts <- neg.normalization.output$object@assayData$neg_norm
# Annotation
annotation <- pData(q3.normalization.output$object)
raw.rle <- make_rle_plot(counts = raw.counts,
annotation = annotation,
annotation.facet = "region")
q3.rle <- make_rle_plot(counts = q3.counts,
annotation = annotation,
annotation.facet = "region")
```
#### **Example AOIs**
```{r Normalization Effects on Counts, fig.width=12, fig.height=8}
#| label: fig-NormEffects
#| fig-cap: "Normalization Effects on Counts"
#| warning: false
#| message: false
# The raw counts boxplot
transform1.raw<- exprs(q3.normalization.object[,1:30])
transform2.raw<- as.data.frame(transform1.raw)
transform3.raw<- melt(transform2.raw)
ggboxplot.raw <- ggplot(transform3.raw, aes(variable, value)) +
stat_boxplot(geom = "errorbar") +
geom_boxplot(fill="grey") +
scale_y_log10() +
xlab("Example AOIs") +
ylab("Counts, Raw") +
ggtitle("Neg Norm Counts") +
scale_x_discrete(labels=c(1:30))
# The Q3 normalized counts boxplot
transform1.norm<- assayDataElement(q3.normalization.object[,1:30], elt = "q_norm")
transform2.norm<- as.data.frame(transform1.norm)
transform3.norm<- melt(transform2.norm)
ggboxplot.q3norm <- ggplot(transform3.norm, aes(variable, value)) +
stat_boxplot(geom = "errorbar") +
geom_boxplot(fill="cadetblue2") +
scale_y_log10() +
xlab("Example AOIs") +
ylab("Counts, Q3 Normalized") +
ggtitle("Q3 Norm Counts") +
scale_x_discrete(labels=c(1:30))
# The Negative normalized counts boxplot
transform1.norm<- assayDataElement(neg.normalization.object[,1:30], elt = "neg_norm")
transform2.norm<- as.data.frame(transform1.norm)
transform3.norm<- melt(transform2.norm)
ggboxplot.negnorm <- ggplot(transform3.norm, aes(variable, value)) +
stat_boxplot(geom = "errorbar") +
geom_boxplot(fill="indianred") +
scale_y_log10() +
xlab("Example AOIs") +
ylab("Counts, Neg. Normalized") +
ggtitle("Neg Norm Counts") +
scale_x_discrete(labels=c(1:30))
print(ggboxplot.raw)
print(ggboxplot.q3norm)
print(ggboxplot.negnorm)
```
#### Principal Component Analysis (PCA)
```{r PCA, warning=FALSE, message=FALSE}
# See reference vignette: https://bioconductor.org/packages/release/bioc/vignettes/PCAtools/inst/doc/PCAtools.html#introduction
# Load the Geomx objects
object.q3 <- q3.normalization.output$object
object.neg <- neg.normalization.output$object
# Gather the the normalized counts
q3.norm.counts.df <- as.data.frame(object.q3@assayData$q_norm)
neg.norm.counts.df <- as.data.frame(object.neg@assayData$neg_norm)
# Convert counts to log2
q3.log.counts.df <- q3.norm.counts.df %>%
mutate_all(~ log2(.)) %>%
rename_all(~ gsub("\\.dcc", "", .))
neg.log.counts.df <- neg.norm.counts.df %>%
mutate_all(~ log2(.)) %>%
rename_all(~ gsub("\\.dcc", "", .))
# Remove the negative controls from the log counts
control.probes <- c("NegProbe-WTX")
q3.log.counts.df <- q3.log.counts.df[!(rownames(q3.log.counts.df) %in% control.probes), ]
neg.log.counts.df <- neg.log.counts.df[!(rownames(neg.log.counts.df) %in% control.probes), ]
# Load the annotation (same for both normalization types)
annotation <- pData(object.q3)
# Remove NTCs
cleaned.annotation.df <- as.data.frame(annotation[annotation$'slide_name' != "No Template Control", ])
# Order of rownames of annotation need to match columns of count data
cleaned.annotation.df <- cleaned.annotation.df[order(rownames(cleaned.annotation.df)), ]
q3.log.counts.df <- q3.log.counts.df[order(colnames(q3.log.counts.df))]
neg.log.counts.df <- neg.log.counts.df[order(colnames(neg.log.counts.df))]
# Remove .dcc from Sample ID row names
cleaned.annotation.df <- cleaned.annotation.df %>% `rownames<-`(sub("\\.dcc", "", rownames(.)))
# Generate a PCA table for all samples for both normalization types
q3.pca.table <- pca(q3.log.counts.df,
metadata = cleaned.annotation.df,
removeVar = 0.1)
neg.pca.table <- pca(neg.log.counts.df,
metadata = cleaned.annotation.df,
removeVar = 0.1)
```
#### PCA by Segment
```{r PCA for Q3 segment, fig.width=12, fig.height=8}
#| label: fig-PCAsegmentQ3
#| fig-cap: "PCA colored by Segment for Q3 Normalization"
#| warning: false
q3.pca.plot.segment <- biplot(q3.pca.table,
colby = "segment",
legendPosition = "right",
legendLabSize = 6,
legendIconSize = 3,
lab = NULL,
title = "Q3 Normalization",
subtitle = "NTCs removed")
print(q3.pca.plot.segment)
```
```{r PCA for Negative segment, fig.width=12, fig.height=8}
#| label: fig-PCAsegmentNeg
#| fig-cap: "PCA colored by Segment for Negative Normalization"
#| warning: false
neg.pca.plot.segment <- biplot(neg.pca.table,
colby = "segment",
legendPosition = "right",
legendLabSize = 6,
legendIconSize = 3,
lab = NULL,
title = "Negative Normalization",
subtitle = "NTCs removed")
print(neg.pca.plot.segment)
```
#### PCA by Region
```{r PCA for Q3 region, fig.width=12, fig.height=8}
#| label: fig-PCAregionQ3
#| fig-cap: "PCA colored by Region for Q3 Normalization"
#| warning: false
q3.pca.plot.region <- biplot(q3.pca.table,
colby = "region",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Q3 Normalization",
subtitle = "NTCs removed")
print(q3.pca.plot.region)
```
```{r PCA for Neg region, fig.width=12, fig.height=8}
#| label: fig-PCAregionNeg
#| fig-cap: "PCA colored by Region for Negative Normalization"
#| warning: false
neg.pca.plot.region <- biplot(neg.pca.table,
colby = "region",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Negative Normalization",
subtitle = "NTCs removed")
print(neg.pca.plot.region)
```
#### PCA by Class
```{r PCA for Q3 class, fig.width=12, fig.height=8}
#| label: fig-PCAclassQ3
#| fig-cap: "PCA colored by Class for Q3 Normalization"
#| warning: false
q3.pca.plot.class <- biplot(q3.pca.table,
colby = "class",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Q3 Normalization",
subtitle = "NTCs removed")
print(q3.pca.plot.class)
```
```{r PCA for Negative class, fig.width=12, fig.height=8}
#| label: fig-PCAclassNeg
#| fig-cap: "PCA colored by Class for Negative Normalization"
#| warning: false
neg.pca.plot.class <- biplot(neg.pca.table,
colby = "class",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Negative Normalization",
subtitle = "NTCs removed")
print(neg.pca.plot.class)
```
#### PCA by Slide
```{r PCA for Q3 slide, fig.width=12, fig.height=8}
#| label: fig-PCAslideQ3
#| fig-cap: "PCA colored by Slide for Q3 Normalization"
#| warning: false
q3.pca.plot.slide <- biplot(q3.pca.table,
colby = "slide_name",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Q3 Normalization",
subtitle = "NTCs removed")
print(q3.pca.plot.slide)
```
```{r PCA for Neg slide, fig.width=12, fig.height=8}
#| label: fig-PCAslideNeg
#| fig-cap: "PCA colored by Slide for Negative Normalization"
#| warning: false
neg.pca.plot.slide <- biplot(neg.pca.table,
colby = "slide_name",
legendPosition = "right",
legendLabSize = 10,
legendIconSize = 5,
lab = NULL,
title = "Negative Normalization",
subtitle = "NTCs removed")
print(neg.pca.plot.slide)
```
### MA Plots
```{r}
# Set up pre and post normalization counts and convert to log
pre.norm.counts <-
log(as.data.frame(q3.normalization.output$object@assayData$exprs), base = 2)
post.q3norm.counts <- log(as.data.frame(q3.normalization.output$object@assayData$q_norm), base = 2)
post.negnorm.counts <- log(as.data.frame(neg.normalization.output$object@assayData$neg_norm), base = 2)
# Setup annotation groups for the ratio "M" (log A - log B)
region.types <- c("region_A", "region_B")
# Define the name of the contrast
contrast.name <- paste0(region.types[[1]],
"_",
region.types[[2]])
# Set up the annotations and raw counts for the MA plots
contrast.field <- "region"
condition.label <- "region_A"
reference.label <- "region_B"
raw.log.counts <- pre.norm.counts
annotation.MA <- annotation
```
#### Q3 Normalization
```{r MA Plot Q3, message=FALSE, warning=FALSE, fig.width=12, fig.height=8}
# MA plots for two annotation groups to evaluate negative normalization
log.counts <- post.q3norm.counts
MA.plots.q3 <- make_MA(contrast.field = contrast.field,
condition.label = condition.label,
reference.label = reference.label,
log.counts = log.counts,
raw.log.counts = raw.log.counts,
annotation = annotation.MA)
grid.draw(MA.plots.q3)
```
#### Negative Normalization
grid.draw(MA.plots.neg)
```{r MA Plot Neg, message=FALSE, warning=FALSE, fig.width=12, fig.height=8}
# MA plots for two annotation groups to evaluate negative normalization
log.counts <- post.negnorm.counts
MA.plots.neg <- make_MA(contrast.field = contrast.field,
condition.label = condition.label,
reference.label = reference.label,
log.counts = log.counts,
raw.log.counts = raw.log.counts,
annotation = annotation.MA)
grid.draw(MA.plots.neg)
```