-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsex_summary.Rmd
197 lines (155 loc) · 8.47 KB
/
sex_summary.Rmd
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
---
title: "Summarizing Sex in the SRA"
author: "Shannon E. Ellis"
output:
BiocStyle::html_document
vignette: >
%\VignetteIndexEntry{sex summary}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r vignetteSetup, echo=FALSE, message=FALSE, warning = FALSE}
## Track time spent on making the vignette
startTime <- Sys.time()
```
```{r load-packages, message = FALSE, warning = FALSE}
library(extrafont)
library(gridExtra)
library(dplyr)
## load colors
bright= c(red=rgb(222,45,38, maxColorValue=255), #de2d26
pink=rgb( 255, 102, 153, maxColorValue=255), #ff6699
orange=rgb(232,121,12, maxColorValue=255), #e8790c
yellow=rgb(255,222,13, maxColorValue=255), #ffde0d
green=rgb(12,189,24, maxColorValue=255), #0cbd18
teal=rgb(59,196,199, maxColorValue=255), #3bc4c7
blue=rgb(58,158,234, maxColorValue=255), #3a9eea
purple=rgb(148,12,232, maxColorValue=255)) #940ce8
```
# Load data
```{r load-data, message = FALSE, warning = FALSE}
## load predicted phenotypes
load('/dcl01/leek/data/sellis/barcoding/output/PredictedPhenotypes_v0.0.06.rda')
df = PredictedPhenotypes #70479
df$predicted_sex <- as.factor(tolower(df$predicted_sex))
## load SRA metadata
load('/dcl01/leek/data/recount-website/metadata/metadata_sra.Rdata')
metadata <- metadata[!is.na(metadata$bigwig_path), ]
sra_meta = metadata
rm(metadata)
pd = read_csv("https://raw.githubusercontent.com/nellore/runs/master/sra/v2/hg38/SraRunInfo.csv")
sra_meta = left_join(as.data.frame(sra_meta),pd,by=c("run"="Run","sample"="Sample"))
colnames(sra_meta)[4] <- "sample_id"
meta = left_join(sra_meta,df)
```
# Recount breakdown
```{r recount, message = FALSE, warning = FALSE}
## overall breakdown
(sex_recount <- df %>% dplyr::filter(!is.na(dataset)) %>% group_by(predicted_sex) %>% dplyr::summarise(n = n()) %>% mutate(freq = n / sum(n)))
b <- ggplot(data = sex_recount, aes(x=predicted_sex, y = freq,label = freq)) +
labs(y="Proportion",x="Predicted Sex",title="") +
geom_bar(stat="identity", aes(fill = predicted_sex),position="dodge") +
# geom_text(aes(fill=predicted_sex),size = 12, position = position_dodge(width = 0.9),colour="black") +
scale_fill_manual(values=c("#940CE8", "#0CBD18", "grey48"))+
theme_bw()+
theme(legend.title=element_blank(),legend.text=element_text(size=16),plot.title = element_text(hjust = 0.5),text = element_text(size=16), panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),axis.text=element_text(colour="black"))
# pdf('/dcl01/leek/data/sellis/barcoding/plots/Sex_recount.pdf',family="Roboto Condensed",width=15,height=15)
plot(b)
# dev.off()
```
# TCGA and GTEx Breakdown
```{r sra, message = FALSE, warning = FALSE}
## get breakdown across projects
(sex_recount2 <- df %>% dplyr::filter(dataset=="tcga" | dataset=="gtex") %>% group_by(dataset,predicted_sex) %>% dplyr::summarise(n = n()) %>% mutate(freq = n / sum(n)))
## Overall summary
b <- ggplot(data = sex_recount2, aes(x=dataset, y = freq,label = freq)) +
labs(y="Proportion",x="Data Set",title="Predicted Sex") +
geom_bar(stat="identity", aes(fill = predicted_sex),position="dodge") +
# geom_text(aes(fill=predicted_sex),size = 12, position = position_dodge(width = 0.9),colour="black") +
scale_fill_manual(values=c("#940CE8", "#0CBD18"))+
theme_bw()+
theme(legend.title=element_blank(),legend.text=element_text(size=16),plot.title = element_text(hjust = 0.5),text = element_text(size=16), panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),axis.text=element_text(colour="black"))
# pdf('/dcl01/leek/data/sellis/barcoding/plots/Sex_recount_summary.pdf',family="Roboto Condensed",width=15,height=15)
plot(b)
# dev.off()
```
# Analyze sex across the SRA
```{r sex-summary, message = FALSE, warning = FALSE, fig.width=9, cache=TRUE, fig.height=5}
## Sex Breakdown w/n SRA
(sex_SRA <- meta %>% group_by(predicted_sex) %>% select(predicted_sex) %>% dplyr::summarise(Count = n()))
## Overall summary
# pdf('/dcl01/leek/data/sellis/barcoding/plots/Sex_SRA_summary.pdf',family="Roboto Condensed",width=15,height=15)
# plot(ggplot(data = sex_SRA, aes(x=predicted_sex, y = Count,label = Count)) +
# labs(y="No. of Samples",x="Data Set",title="Predicted Sex") +
# geom_bar(stat="identity", aes(fill = predicted_sex),position="dodge") +
# # geom_text(aes(fill=predicted_sex),size = 12, position = position_dodge(width = 0.9),colour="black") +
# scale_fill_manual(values=c("#940CE8", "#0CBD18", "grey48"))+
# theme_bw()+
# theme(legend.title=element_blank(),legend.text=element_text(size=60),plot.title = element_text(hjust = 0.5),text = element_text(size=48), panel.border = element_blank(), panel.grid.major = element_blank(),
# panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),axis.text=element_text(colour="black")))
# dev.off()
plot(ggplot(data = sex_SRA, aes(x=predicted_sex, y = Count,label = Count)) +
labs(y="No. of Samples",x="Data Set",title="Predicted Sex") +
geom_bar(stat="identity", aes(fill = predicted_sex),position="dodge") +
geom_text(aes(fill=predicted_sex),size = 6, position = position_dodge(width = 0.9),colour="black") +
scale_fill_manual(values=c("#940CE8", "#0CBD18", "grey48"))+
theme_bw()+
theme(legend.title=element_blank(),legend.text=element_text(size=12),plot.title = element_text(hjust = 0.5),text = element_text(size=12), panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),axis.text=element_text(colour="black")))
```
# Looking at sex broken down by project
```{r sex-project, message = FALSE, warning = FALSE, fig.width=9, cache=TRUE, fig.height=5}
## Broken down by project type
## combine to look at sex across SRA
(projorder <- meta %>% group_by(ProjectID) %>% summarise(n=n()) %>% arrange(n) %>% mutate(index=1:nrow(.)))
(proj <- meta %>% group_by(ProjectID,predicted_sex) %>% summarise(n=n()) %>% mutate(prop= n/sum(n)))
test = left_join(proj,projorder, by="ProjectID") %>% arrange(index)
scale <- function(X){
(X - min(X))/diff(range(X))+0.001
}
test$widths <- scale(test$n.y)
# pdf("plots/Sex_by_proj.pdf",width=100,family="Roboto Condensed")
# ggplot(test, aes(x = index, y = prop,fill=predicted_sex)) +
# geom_bar(stat='identity',aes(width=widths))+
# scale_fill_manual(values=c("#940CE8", "#0CBD18", "grey48"))
# # dev.off()
proj_summ <- proj %>% group_by(ProjectID) %>% summarise(projtype = paste(predicted_sex, collapse=","), times=length(predicted_sex))
proj_summ$type <- proj_summ$projtype
proj_summ$type[proj_summ$times>1] <- "mixed"
proj_summ$type[proj_summ$type=="female"] <- "female only"
proj_summ$type[proj_summ$type=="male"] <- "male only"
proj_summ$type[proj_summ$type=="unassigned"] <- "unassigned only"
d <- proj_summ %>% group_by(type) %>% summarise(Count = n())
# pdf('plots/Sex_SRA_ProjectType.pdf',width=12,height=12,family="Roboto Condensed")
ggplot(data = d, aes(x=type, y = Count,label = Count)) +
labs(y="No. of Projects",x="Project Type",title="Project Type Summary")+
geom_bar(stat="identity", aes(fill = type),position="dodge") +
geom_text(aes(fill=type),size = 6, position = position_dodge(width = 0.9),colour="black") +
scale_fill_manual(values=c("#940CE8", "#0CBD18","#E8790C", "grey48"))+
theme_bw()+
theme(legend.title=element_blank(),plot.title = element_text(hjust = 0.5),text = element_text(size=16), panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),axis.text=element_text(colour="black"))
# dev.off()
# embed_fonts('plots/Sex_SRA_ProjectType.pdf',outfile='plots/Sex_SRA_ProjectType.pdf')
```
# Vignette information
```{r reproducibility}
## Time spent creating this report:
diff(c(startTime, Sys.time()))
## Date this report was generated
message(Sys.time())
## Reproducibility info
options(width = 120)
devtools::session_info()
```
# Code for creating the vignette
```{r createVignette, eval=FALSE}
## Create the vignette
library('rmarkdown')
system.time(render('/dcl01/leek/data/sellis/barcoding/phenopredict_usecase/sex_summary.Rmd', 'BiocStyle::html_document'))
## Extract the R code
library('knitr')
knit('/dcl01/leek/data/sellis/barcoding/phenopredict_usecase/sex_summary.Rmd', tangle = TRUE)
```