-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTissue Specificity PCA
146 lines (119 loc) · 9.07 KB
/
Tissue Specificity PCA
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
# load DMR bed files ################################################
# Sex Combined DMRs
CHDS_Combined_DMRs <- import("/CHDS_NDBS/DMRichR/SexCombined/DMRs/DMRs.bed")
Cord_Combined_DMRs <- import("/CHDS_NDBS/Tissue_Comparisons/CordBlood_Comparison/DMRichR/Combined/DMRs/DMRs.bed")
Placenta_Combined_DMRs <- import("/CHDS_NDBS/Tissue_Comparisons/Placenta_Comparison/DMRichR/Combined/V2/DMRs/DMRs.bed")
Cortex_Combined_DMRs <- import("/CHDS_NDBS/Tissue_Comparisons/Cortex_Comparison/DMRichR/Combined/V3/DMRs/DMRs.bed")
# Female DMRs
CHDS_Females_DMRs <- import("/CHDS_NDBS/DMRichR/Females/DMRs/DMRs.bed")
Cord_Females_DMRs <- import("/CHDS_NDBS/CordBlood/DMRichR/Females/DMRs/DMRs.bed")
Placenta_Females_DMRs <- import("/CHDS_NDBS/Placenta/DMRichR/Females/DMRs/DMRs.bed")
Cortex_Females_DMRs <- import("/CHDS_NDBS/Cortex/DMRichR/Females/DMRs/DMRs.bed")
# Male DMRs
CHDS_Males_DMRs <- import("/CHDS_NDBS/DMRichR/Males/DMRs/DMRs.bed")
Cord_Males_DMRs <- import("/CHDS_NDBS/CordBlood/DMRichR/Males/DMRs/DMRs.bed")
Placenta_Males_DMRs <- import("/CHDS_NDBS/Placenta/DMRichR/Males/DMRs/DMRs.bed")
Cortex_Males_DMRs <- import("/CHDS_NDBS/Cortex/DMRichR/Males/DMRs/DMRs.bed")
# Function to input DMRs BED file and get smooth methylation levels over those DMRs in a different tissue ############################################
module load R/4.1.0
R
.libPaths("/share/lasallelab/programs/comethyl/R_4.1.0/rtest")
AnnotationHub::setAnnotationHubOption("CACHE", value = "/share/lasallelab/programs/comethyl/R_4.1.0/rtest")
BiocManager::install("bsseq")
library(bsseq)
library(openxlsx)
library(rtracklayer)
getMeth(BSseq, regions = NULL, type = c("smooth", "raw"),
what = c("perBase", "perRegion"), confint = FALSE, alpha = 0.95,
withDimnames = TRUE)
#Smoothed Methylation in discovery newborn blood samples (females and males) over DMRs identified in sex combined comparisons in other tissues ######################
setwd("/CHDS_NDBS/Tissue_Comparisons/Smooth_Methylation/SexCombined")
load("/CHDS_NDBS/DMRichR/SexCombined/RData/bsseq.RData")
Cord_combined_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cord_Combined_DMRs, type = "smooth", what = "perRegion")
Placenta_combined_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Placenta_Combined_DMRs, type = "smooth", what = "perRegion")
Cortex_combined_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cortex_Combined_DMRs, type = "smooth", what = "perRegion")
CHDS_combined_list <- list('CordBlood Sex Combined DMRs' = Cord_combined_in_CHDS, 'Placenta Sex Combined DMRs' = Placenta_combined_in_CHDS, 'Cortex Sex Combined DMRs' = Cortex_combined_in_CHDS)
write.xlsx(CHDS_combined_list, "CHDS_SexCombined_SmoothMethylation.xlsx")
#Smoothed Methylation in discovery newborn blood female samples over DMRs identfied in females only comparisons in other tissues ######################
setwd("/CHDS_NDBS/Tissue_Comparisons/Smooth_Methylation/Females")
load("/CHDS_NDBS/DMRichR/Females/RData/bsseq.RData")
Cord_Female_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cord_Females_DMRs, type = "smooth", what = "perRegion")
Placenta_Female_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Placenta_Females_DMRs, type = "smooth", what = "perRegion")
Cortex_Female_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cortex_Females_DMRs, type = "smooth", what = "perRegion")
CHDS_Female_list <- list('CordBlood Female DMRs' = Cord_Female_in_CHDS, 'Placenta Female DMRs' = Placenta_Female_in_CHDS, 'Cortex Female DMRs' = Cortex_Female_in_CHDS)
write.xlsx(CHDS_Female_list, "CHDS_Female_SmoothMethylation.xlsx")
#Smoothed Methylation in discovery newborn blood male samples over DMRs identfied in males only comparisons in other tissues ######################
setwd("/CHDS_NDBS/Tissue_Comparisons/Smooth_Methylation/Males")
load("/CHDS_NDBS/DMRichR/Males/RData/bsseq.RData")
Cord_Male_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cord_Males_DMRs, type = "smooth", what = "perRegion")
Placenta_Male_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Placenta_Males_DMRs, type = "smooth", what = "perRegion")
Cortex_Male_in_CHDS <- getMeth(BSseq = bs.filtered.bsseq, regions = Cortex_Males_DMRs, type = "smooth", what = "perRegion")
CHDS_Male_list <- list('CordBlood Male DMRs' = Cord_Male_in_CHDS, 'Placenta Male DMRs' = Placenta_Male_in_CHDS, 'Cortex Male DMRs' = Cortex_Male_in_CHDS)
write.xlsx(CHDS_Male_list, "CHDS_Male_SmoothMethylation.xlsx")
#Function to make PCA plot from smooth methylation values #######################################################
library(data.table)
library(ggfortify)
library(openxlsx)
SmoothMethPCAPlot <- function(file, sheet, name){
x <- read.xlsx(file, sheet)
t_x <- data.table::transpose(x)
colnames(t_x) <- rownames(x)
rownames(t_x) <- colnames(x)
y <- merge(CHDS_diagnosis, t_x, by = 'row.names', all = FALSE)
PCA <- prcomp(y[,-1:-2], 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)
}
## Sex Combined ##############################################################################################################
setwd("/CHDS /Smoothed methylation/Sex Combined")
CHDS_diagnosis <- read.xlsx("CHDS_diagnosis.xlsx", rowNames = TRUE)
#CHDS samples in cord blood DMRs - Sex Combined
CHDS_samples_cord_DMRs_combined <- SmoothMethPCAPlot(file = "CHDS_SexCombined_SmoothMethylation.xlsx",
sheet = "CordBlood Sex Combined DMRs",
name = "CHDS_SexCombined_SmoothMeth_Plots/CHDSsamples_CordDMRs_SexCombined.pdf")
#CHDS samples in placenta DMRs - Sex Combined
CHDS_samples_placenta_DMRs_combined <- SmoothMethPCAPlot(file = "CHDS_SexCombined_SmoothMethylation.xlsx",
sheet = "Placenta Sex Combined DMRs",
name = "CHDS_SexCombined_SmoothMeth_Plots/CHDSsamples_placentaDMRs_SexCombined.pdf")
#CHDS samples in cortex DMRs - Sex Combined
CHDS_samples_cortex_DMRs_combined <- SmoothMethPCAPlot(file = "CHDS_SexCombined_SmoothMethylation.xlsx",
sheet = "Cortex Sex Combined DMRs",
name = "CHDS_SexCombined_SmoothMeth_Plots/CHDSsamples_cortexDMRs_SexCombined.pdf")
## Females ########################################################################
setwd("/CHDS /Smoothed methylation/Females")
#CHDS samples in Cord Blood DMRs - Females Only
CHDS_samples_cord_DMRs_females <- SmoothMethPCAPlot(file = "CHDS_Female_SmoothMethylation.xlsx",
sheet = "CordBlood Female DMRs",
name = "CHDS_Females_SmoothMeth_Plots/CHDSsamples_Cord_DMRs_Females.pdf")
#CHDS samples in Placenta DMRs - Females Only
CHDS_samples_placenta_DMRs_females <- SmoothMethPCAPlot(file = "CHDS_Female_SmoothMethylation.xlsx",
sheet = "Placenta Female DMRs",
name = "CHDS_Females_SmoothMeth_Plots/CHDSsamples_Placenta_DMRs_Females.pdf")
#CHDS samples in Cortex DMRs - Females Only
CHDS_samples_cortex_DMRs_females <- SmoothMethPCAPlot(file = "CHDS_Female_SmoothMethylation.xlsx",
sheet = "Cortex Female DMRs",
name = "CHDS_Females_SmoothMeth_Plots/CHDSsamples_Cortex_DMRs_Females.pdf")
## Males #########################################################################
setwd("/CHDS /Smoothed methylation/Males")
#CHDS samples in Cord Blood DMRs - Males Only
CHDS_samples_Cord_DMRs_males <- SmoothMethPCAPlot(file = "CHDS_Male_SmoothMethylation.xlsx",
sheet = "CordBlood Male DMRs",
name = "CHDS_Males_SmoothMeth_Plots/CHDSsamples_CordBlood_DMRs_Males.pdf")
#CHDS samples in Placenta DMRs - Males Only
CHDS_samples_Placenta_DMRs_males <- SmoothMethPCAPlot(file = "CHDS_Male_SmoothMethylation.xlsx",
sheet = "Placenta Male DMRs",
name = "CHDS_Males_SmoothMeth_Plots/CHDSsamples_Placenta_DMRs_Males.pdf")
#CHDS samples in Cortex DMRs - Males Only
CHDS_samples_Cortex_DMRs_males <- SmoothMethPCAPlot(file = "CHDS_Male_SmoothMethylation.xlsx",
sheet = "Cortex Male DMRs",
name = "CHDS_Males_SmoothMeth_Plots/CHDSsamples_Cortex_DMRs_Males.pdf")