-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDMR PCA Plots
146 lines (131 loc) · 9.72 KB
/
DMR PCA Plots
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
library(data.table)
library(ggfortify)
library(openxlsx)
##Function to make PCA plot from smooth methylation values over DMRs
SmoothMethPCAPlot <- function(file, sample_info, name){
x <- read.delim(file, header = TRUE, check.names = FALSE)
x <- x[,-1:-16]
t_x <- data.table::transpose(x)
colnames(t_x) <- rownames(x)
rownames(t_x) <- colnames(x)
sample_info <- read.xlsx(sample_info, rowNames = TRUE)
y <- merge(sample_info, t_x, by = 'row.names', all = FALSE)
PCA <- prcomp(y[,-1:-3], center = TRUE, scale. = TRUE)
plot <- autoplot(PCA, data = y, colour = "ASD_Diagnosis", frame = TRUE, frame.type = 'norm') +
theme_classic() +
theme(plot.background = element_rect(fill = "white"),
axis.text = element_text(color = "black", size = 12, family = "sans"),
axis.title.x = element_text(color = "black", size = 12, family = "sans"),
axis.title.y = element_text(color = "black", size = 12, family = "sans"),
axis.line = element_line(color = "black", linewidth = 0.2),
legend.position = "none")
pdf(file = name, width = 7, height = 6)
print(plot)
dev.off()
return(plot)
}
##Discovery Newborn Blood (CHDS) samples and DMRs ######################################
setwd("/Smoothed methylation/CHDS")
CHDSsamples_CHDS_DMRs_combined <- SmoothMethPCAPlot(file = "/CHDS /DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHDS_SampleInfo.xlsx",
name = "CHDS_SmoothMeth_SexCombined.pdf")
CHDSsamples_CHDS_DMRs_females <- SmoothMethPCAPlot(file = "/CHDS /DMRichR/Females/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHDS_SampleInfo.xlsx",
name = "CHDS_SmoothMeth_Females.pdf")
CHDSsamples_CHDS_DMRs_males <- SmoothMethPCAPlot(file = "/CHDS /DMRichR/Males/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHDS_SampleInfo.xlsx",
name = "CHDS_SmoothMeth_Males.pdf")
##Replication Newborn Blood (ReCHARGE/ECHO) samples and DMRs ######################################
setwd("/Smoothed methylation/CHARGE")
CHARGEsamples_CHARGE_DMRs_combined <- SmoothMethPCAPlot(file = "/ReCHARGE:ECHO/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHARGE_SampleInfo.xlsx",
name = "CHARGE_SmoothMeth_SexCombined.pdf")
CHARGEsamples_CHARGE_DMRs_females <- SmoothMethPCAPlot(file = "/ReCHARGE:ECHO/DMRichR/Females/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHARGE_SampleInfo.xlsx",
name = "CHARGE_SmoothMeth_Females.pdf")
CHARGEsamples_CHARGE_DMRs_males <- SmoothMethPCAPlot(file = "/ReCHARGE:ECHO/DMRichR/Males/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHARGE_SampleInfo.xlsx",
name = "CHARGE_SmoothMeth_Males.pdf")
### Cord Blood samples and DMRs ###########################################
setwd("/Smoothed methylation/Cord Blood")
CordSamples_CordDMRs_combined <- SmoothMethPCAPlot(file = "/CordBlood/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CordBlood_SampleInfo.xlsx",
name = "CordBlood_SmoothMeth_SexCombined.pdf")
CordSamples_CordDMRs_females <- SmoothMethPCAPlot(file = "/CordBlood/DMRichR/Females/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CordBlood_SampleInfo.xlsx",
name = "CordBlood_SmoothMeth_Females.pdf")
CordSamples_CordDMRs_males <- SmoothMethPCAPlot(file = "/CordBlood/DMRichR/Males/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CordBlood_SampleInfo.xlsx",
name = "CordBlood_SmoothMeth_Males.pdf")
### Placenta samples and DMRs #########################################
setwd("/Smoothed methylation/Placenta")
PlacentaSamples_PlacentaDMRs_combined <- SmoothMethPCAPlot(file = "/Placenta/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Placenta_SampleInfo.xlsx",
name = "Placenta_SmoothMeth_SexCombined.pdf")
PlacentaSamples_PlacentaDMRs_females <- SmoothMethPCAPlot(file = "/Placenta/DMRichR/Females/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Placenta_SampleInfo.xlsx",
name = "Placenta_SmoothMeth_Females.pdf")
PlacentaSamples_PlacentaDMRs_males <- SmoothMethPCAPlot(file = "/Placenta/DMRichR/Males/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Placenta_SampleInfo.xlsx",
name = "Placenta_SmoothMeth_Males.pdf")
### Cortex samples and DMRs ############################################
setwd("/Smoothed methylation/Cortex")
CortexSamples_CortexDMRs_combined <- SmoothMethPCAPlot(file = "/Cortex/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Cortex_SampleInfo.xlsx",
name = "Cortex_SmoothMeth_SexCombined.pdf")
CortexSamples_CortexDMRs_females <- SmoothMethPCAPlot(file = "/Cortex/DMRichR/Females/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Cortex_SampleInfo.xlsx",
name = "Cortex_SmoothMeth_Females.pdf")
CortexSamples_CortexDMRs_males <- SmoothMethPCAPlot(file = "/Cortex/DMRichR/Males/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Cortex_SampleInfo.xlsx",
name = "Cortex_SmoothMeth_Males.pdf")
# Supplemental Figure #############################################################################
##Function to separate samples by sex (from Sex Combined analyses) instead of ASD Diagnosis
SmoothMethPCAPlot2_Sex <- function(file, sample_info, name){
x <- read.delim(file, header = TRUE, check.names = FALSE)
x <- x[,-1:-16]
t_x <- data.table::transpose(x)
colnames(t_x) <- rownames(x)
rownames(t_x) <- colnames(x)
sample_info <- read.xlsx(sample_info, rowNames = TRUE)
y <- merge(sample_info, t_x, by = 'row.names', all = FALSE)
PCA <- prcomp(y[,-1:-3], center = TRUE, scale. = TRUE)
plot <- autoplot(PCA, data = y, colour = "Sex", frame = TRUE, frame.type = 'norm') +
theme_classic() +
theme(plot.background = element_rect(fill = "white"),
axis.text = element_text(color = "black", size = 12, family = "sans"),
axis.title.x = element_text(color = "black", size = 12, family = "sans"),
axis.title.y = element_text(color = "black", size = 12, family = "sans"),
axis.line = element_line(color = "black", linewidth = 0.2),
legend.position = "none") +
scale_fill_manual(values = c("#FFCF60", "#6373B7")) +
scale_color_manual(values = c("#FFCF60", "#6373B7"))
pdf(file = name, width = 7, height = 6)
print(plot)
dev.off()
return(plot)
}
##CHDS samples and CHDS DMRs ######################################
setwd("/CHDS /Smoothed methylation/CHDS")
#CHDS Sex Combined
CHDSsamples_CHDS_DMRs_combined <- SmoothMethPCAPlot2_Sex(file = "/CHDS /DMRichR/SexCombined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CHDS_SampleInfo.xlsx",
name = "CHDS_SmoothMeth_SexCombined_Sex.pdf")
### Cord Blood samples and Cord Blood DMRs ###########################################
setwd("/CHDS /Smoothed methylation/Cord Blood")
#Cord Blood Sex Combined
CordSamples_CordDMRs_combined <- SmoothMethPCAPlot2_Sex(file = "/CHDS /CordBlood/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "CordBlood_SampleInfo.xlsx",
name = "CordBlood_SmoothMeth_SexCombined_Sex.pdf")
### Placenta samples and Placenta DMRs #########################################
setwd("/CHDS /Smoothed methylation/Placenta")
#Placenta Sex Combined
PlacentaSamples_PlacentaDMRs_combined <- SmoothMethPCAPlot2_Sex(file = "/CHDS /Placenta/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Placenta_SampleInfo.xlsx",
name = "Placenta_SmoothMeth_SexCombined_Sex.pdf")
### Cortex samples and Cortex DMRs ############################################
setwd("/CHDS /Smoothed methylation/Cortex")
#Cortex Sex Combined
CortexSamples_CortexDMRs_combined <- SmoothMethPCAPlot2_Sex(file = "/CHDS /Cortex/DMRichR/Combined/DMRs/DMR_individual_smoothed_methylation.txt",
sample_info = "Cortex_SampleInfo.xlsx",
name = "Cortex_SmoothMeth_SexCombined_Sex.pdf")