/
swarmPlots_QTLs.Rmd
352 lines (249 loc) · 11.6 KB
/
swarmPlots_QTLs.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
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
---
title: "Top APA QTL in other phenotypes"
author: "Briana Mittleman"
date: "10/8/2018"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
##Upload Data:
Library
```{r}
library(workflowr)
library(reshape2)
library(tidyverse)
library(VennDiagram)
library(data.table)
library(cowplot)
```
Permuted Results from APA:
```{r}
nuclearAPA=read.table("../data/perm_QTL_trans/filtered_APApeaks_merged_allchrom_refseqGenes_pheno_Nuclear_transcript_permResBH.txt", stringsAsFactors = F, header = T)
totalAPA=read.table("../data/perm_QTL_trans/filtered_APApeaks_merged_allchrom_refseqGenes_pheno_Total_transcript_permResBH.txt", stringsAsFactors = F, header=T)
```
I want to use a buzz swarm plot to plot peak usage for some of the top QTLs. I can use the examples I gave Tony.
Nuclear:
* peak305794, sid: 7:128635754
* peak: 164036, sid: 2:3502035
Total:
* **Peak: peak228606, SID 3:150302010**
* Peak: peak152751, SID 19:4236475
I need to pull out the genotypes for each snp and the corresponding phenotype. I want to make a python script that I can give a snp and a peak and it will make a table with the genotypes and phenotypes for the necessary gene snp pair.
##Example Peak: peak228606, SID 3:150302010
```{r}
geno3_m=fread("../data/apaExamp/geno3_150302010.txt", header = T) %>% dplyr::select(starts_with("NA")) %>% t
geno3df= data.frame(geno3_m) %>% separate(geno3_m, into=c("geno", "dose", "extra"), sep=":") %>% dplyr::select(dose) %>% rownames_to_column(var="ind")
apaphen228606_m= fread("../data/apaExamp/Total.peak228606.txt", header = T) %>% dplyr::select(starts_with("NA")) %>% t
apaphen228606_df=data.frame(apaphen228606_m) %>% rownames_to_column(var="ind")
```
```{r}
toplotAPA=geno3df %>% inner_join(apaphen228606_df, by="ind")
toplotAPA$dose= as.factor(toplotAPA$dose)
colnames(toplotAPA)= c("ind", "Genotype", "APA")
EIF2A_APAex=ggplot(toplotAPA, aes(y=APA, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="APA phenotype", title="Total APA: Peak 228606, EIF2A") + scale_fill_brewer(palette="YlOrRd")
ggsave("../output/plots/EIF2a_APA.png", EIF2A_APAex)
```
This is in the gene EIF2A, I need to find this in the eQTL data. The ensg id for this gene is ENSG00000144895.
```{r}
RNAseqEIF2A_m=read.table("../data/apaExamp/RNAseq.phenoEIF2A.txt", header=T) %>% dplyr::select(starts_with("NA")) %>% t
RNAseqEIF2A_df= data.frame(RNAseqEIF2A_m) %>% rownames_to_column("ind")
plotRNA=geno3df %>% inner_join(RNAseqEIF2A_df, by="ind")
plotRNA$dose= as.factor(plotRNA$dose)
colnames(plotRNA)= c("ind", "Genotype", "Expression")
EIF2A_RNAex=ggplot(plotRNA, aes(y=Expression, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="Normalized Expression", title="Gene Expression: EIF2A") + scale_fill_brewer(palette="YlGn")
ggsave("../output/plots/EIF2a_RNA.png", EIF2A_RNAex)
```
Try this in protein:
```{r}
ProtEIF2A_m=read.table("../data/apaExamp/ProtEIF2A.txt", header=T) %>% dplyr::select(starts_with("NA")) %>% t
ProtEIF2A_df= data.frame(ProtEIF2A_m) %>% rownames_to_column("ind")
plotProt=geno3df %>% inner_join(ProtEIF2A_df, by="ind")
plotProt$dose= as.factor(plotProt$dose)
colnames(plotProt)= c("ind", "Genotype", "Prot_level")
IF2A_Protex= ggplot(plotProt, aes(y=Prot_level, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="Normalized Protein Level", title="Protein Level: EIF2A") +scale_fill_brewer(palette="PuBu")
ggsave("../output/plots/EIF2a_Prot.png", IF2A_Protex)
```
```{r}
multphenoEIF2a=plot_grid(EIF2A_APAex,IF2A_Protex,EIF2A_RNAex,nrow=1)
ggsave("../output/plots/EIF2a_multpheno.png", multphenoEIF2a, width=15, height=5)
```
Do this with 4su 60:
have to remove the #
```{r}
su60_EIF2A_m=read.table("../data/apaExamp/Foursu60EIF2A.txt", header=T) %>% dplyr::select(starts_with("NA")) %>% t
su60_EIF2A_df= data.frame(su60_EIF2A_m) %>% rownames_to_column("ind")
plot4su60=geno3df %>% inner_join(su60_EIF2A_df, by="ind")
plot4su60$dose= as.factor(plot4su60$dose)
colnames(plot4su60)= c("ind", "Genotype", "su60")
EIF2A_4su60ex=ggplot(plot4su60, aes(y=su60, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="4su60", title="4su 60min Value: EIF2A") + scale_fill_brewer(palette="RdPu") + theme_classic()
ggsave("../output/plots/EIF2a_4su60.png", EIF2A_4su60ex)
```
Geuvadis RNA
```{r}
rnaG_EIF2A_m=read.table("../data/apaExamp/RNA_GEU_EIF2A.txt", header=T) %>% dplyr::select(starts_with("NA")) %>% t
rnaG_EIF2A_df= data.frame(rnaG_EIF2A_m) %>% rownames_to_column("ind")
plotRNAg=geno3df %>% inner_join(rnaG_EIF2A_df, by="ind")
plotRNAg$dose= as.factor(plotRNAg$dose)
colnames(plotRNAg)= c("ind", "Genotype", "RNAg")
EIF2A_RNAgex=ggplot(plotRNAg, aes(y=RNAg, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="RNA expression", title="RNA Expression Geuvadis: EIF2A") + scale_fill_brewer(palette="RdPu")
ggsave("../output/plots/EIF2a_RNAg.png", EIF2A_RNAgex)
```
Ribo:
```{r}
ribo_EIF2A_m=read.table("../data/apaExamp/Ribo_EIF2A.txt", header=T) %>% dplyr::select(starts_with("NA")) %>% t
ribo_EIF2A_df= data.frame(ribo_EIF2A_m) %>% rownames_to_column("ind")
plotrib=geno3df %>% inner_join(ribo_EIF2A_df, by="ind")
plotrib$dose= as.factor(plotrib$dose)
colnames(plotrib)= c("ind", "Genotype", "Ribo")
EIF2A_riboex=ggplot(plotrib, aes(y=Ribo, x=Genotype, by=Genotype, fill=Genotype)) + geom_boxplot() + geom_jitter() + labs(y="RNA expression", title="Ribo Geuvadis: EIF2A") + scale_fill_brewer(palette="RdPu")
ggsave("../output/plots/EIF2a_Ribo.png", EIF2A_riboex)
```
##Create a script to make the relevent files
Python script that take a chromosome, snp, peak#, fraction
createQTLsnpAPAPhenTable.py
```{bash,eval=F}
def main(PhenFile, GenFile, outFile, snp, peak):
fout=open(outFile, "w")
Phen=open(PhenFile, "r")
Gen=open(GenFile, "r")
#get ind and pheno info
for num, ln in enumerate(Phen):
if num == 0:
indiv= ln.split()[4:]
else:
id=ln.split()[3].split(":")[3]
peakID=id.split("_")[2]
if peakID == peak:
pheno_list=ln.split()[4:]
pheno_data=list(zip(indiv,pheno_list))
pheno_df=pd.DataFrame(data=pheno_data,columns=["Ind", "Pheno"])
for num, lnG in enumerate(Gen):
if num == 13:
Ind_geno=lnG.split()[9:]
if num >= 14:
sid= lnG.split()[2]
if sid == snp:
gen_list=lnG.split()[9:]
allele1=[]
allele2=[]
for i in gen_list:
genotype=i.split(":")[0]
allele1.append(genotype.split("|")[0])
allele2.append(genotype.split("|")[1])
#now i have my indiv., phen, allele 1, alle 2
geno_data=list(zip(Ind_geno, allele1, allele2))
geno_df=pd.DataFrame(data=geno_data, columns=["Ind", "Allele1", "Allele2"])
full_df=pd.merge(geno_df, pheno_df, how="inner", on="Ind")
full_df.to_csv(fout, sep="\t", encoding='utf-8', index=False)
fout.close()
if __name__ == "__main__":
import sys
import pandas as pd
chrom=sys.argv[1]
snp = sys.argv[2]
peak = sys.argv[3]
fraction=sys.argv[4]
PhenFile = "/project2/gilad/briana/threeprimeseq/data/phenotypes_filtPeakTranscript/filtered_APApeaks_merged_allchrom_refseqGenes.Transcript_sm_quant.%s.pheno_fixed.txt.gz.phen_chr%s"%(fraction, chrom)
GenFile= "/project2/gilad/briana/YRI_geno_hg19/chr%s.dose.filt.vcf"%(chrom)
outFile = "/project2/gilad/briana/threeprimeseq/data/ApaQTL_examples/qtlSNP_PeakAPA%s.%s%s.txt"%(fraction, snp, peak)
main(PhenFile, GenFile, outFile, snp, peak)
```
Use the results to plot the nuclear pheno:
```{r}
EIF2a_APAnuc=read.table("../data/apaExamp/qtlSNP_PeakAPANuclear.3:150302010peak228606.txt", header=T, stringsAsFactors = F) %>% mutate(Geno=Allele1 + Allele2)
EIF2a_APAnuc$Geno= as.factor(as.character(EIF2a_APAnuc$Geno))
ggplot(EIF2a_APAnuc, aes(y=Pheno, x=Geno, by=Geno, fill=Geno)) + geom_boxplot() + geom_jitter() + labs(y="APA Nuc Usage", title="APA nuc: EIF2A") + scale_fill_brewer(palette="RdPu")
```
This does the total and nuclear fraction of APA. I will do this for a snp and gene and get all of the other phenotypes. This will be similar other than changing the names of the genes and seperating the name for all but protein.
createQTLsnpMolPhenTable.py
```{bash,eval=F}
def main(PhenFile, GenFile, outFile, snp, gene, molPhen):
genenames=open("/project2/gilad/briana/genome_anotation_data/ensemble_to_genename.txt", "r" )
for ln in genenames:
geneName=ln.split()[1]
if geneName == gene:
gene_ensg=ln.split()[0]
fout=open(outFile, "w")
Phen=open(PhenFile, "r")
Gen=open(GenFile, "r")
#get ind and pheno info
for num,ln in enumerate(Phen):
if num == 0:
indiv= ln.split()[4:]
else:
if molPhen=="Prot":
gene=ln.split()[3]
if gene == gene_ensg:
pheno_list=ln.split()[4:]
pheno_data= list(zip(indiv, pheno_list))
else:
full_gene=ln.split()[3]
gene= full_gene.split(".")[0]
if gene == gene_ensg:
pheno_list=ln.split()[4:]
pheno_data= list(zip(indiv, pheno_list))
pheno_df=pd.DataFrame(data=pheno_data,columns=["Ind", "Pheno"])
for num, lnG in enumerate(Gen):
if num == 13:
Ind_geno=lnG.split()[9:]
if num >= 14:
sid= lnG.split()[2]
if sid == snp:
gen_list=lnG.split()[9:]
allele1=[]
allele2=[]
for i in gen_list:
genotype=i.split(":")[0]
allele1.append(genotype.split("|")[0])
allele2.append(genotype.split("|")[1])
#now i have my indiv., phen, allele 1, alle 2
geno_data=list(zip(Ind_geno, allele1, allele2))
geno_df=pd.DataFrame(data=geno_data, columns=["Ind", "Allele1", "Allele2"])
full_df=pd.merge(geno_df, pheno_df, how="inner", on="Ind")
full_df.to_csv(fout, sep="\t", encoding='utf-8', index=False)
fout.close()
if __name__ == "__main__":
import sys
import pandas as pd
chrom=sys.argv[1]
snp = sys.argv[2]
gene = sys.argv[3]
molPhen=sys.argv[4]
PhenFile = "/project2/gilad/briana/threeprimeseq/data/molecular_phenos/fastqtl_qqnorm%sphase2.fixed.noChr.txt"%(molPhen)
GenFile= "/project2/gilad/briana/YRI_geno_hg19/chr%s.dose.filt.vcf"%(chrom)
outFile = "/project2/gilad/briana/threeprimeseq/data/ApaQTL_examples/qtlSNP_Peak%s%s%s.txt"%(molPhen, snp, gene)
main(PhenFile, GenFile, outFile, snp, gene,molPhen)
```
test this:
```{bash, eval=F}
python createQTLsnpMolPhenTable.py 3 3:150302010 EIF2A _RNAseq_
```
list for phenos:
* 4su_30
* 4su_60
* RNAseqGeuvadis
* RNAseq
* prot
* ribo
Create a bash script that will use a for loop to run the python script on a all of the phenotypes
run_createQTLsnpMolPhenTable.sh
```{bash,eval=F}
#!/bin/bash
#SBATCH --job-name=run_createQTLsnpMolPhenTable
#SBATCH --account=pi-yangili1
#SBATCH --time=24:00:00
#SBATCH --output=run_createQTLsnpMolPhenTable.out
#SBATCH --error=run_createQTLsnpMolPhenTable.err
#SBATCH --partition=broadwl
#SBATCH --mem=12G
#SBATCH --mail-type=END
module load python
chrom=$1
snp=$2
gene=$3
for i in "_4su_30_" "_4su_60_" "_RNAseqGeuvadis_" "_RNAseq_" "_prot." "_ribo_"
do
python createQTLsnpMolPhenTable.py ${chrom} ${snp} ${gene} ${i}
done
```