/
mapapaQTL.Rmd
199 lines (123 loc) · 5.24 KB
/
mapapaQTL.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
---
title: "apaQTLs"
author: "Briana Mittleman"
date: "4/18/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(reshape2)
library(workflowr)
library(cowplot)
```
In this analysis I will call apaQTls in both fractions. I will start with the phenotype files and normalized the counts using the leafcutter package in order to run the fastq QTL mapper.
##Prepare phenotypes for QTL- phenotype dir
It is best to run this analysis in the data/phenotype_5perc directory. I have copied the leafcutter prepare_phenotype_table.py to the code directroy to use here.
```{bash,eval=F}
#!/bin/bash
module load python
gzip APApeak_Phenotype_GeneLocAnno.Total.5perc.fc
gzip APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc
python ../../code/prepare_phenotype_table.py APApeak_Phenotype_GeneLocAnno.Total.5perc.fc.gz
python ../../code/prepare_phenotype_table.py APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc.gz
```
This will output bash scripts to run.
```{bash,eval=F}
module load Anaconda3
source activate three-prime-env
sh APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc.gz_prepare.sh
sh APApeak_Phenotype_GeneLocAnno.Total.5perc.fc.gz_prepare.sh
```
Subset the PCs to use the first 2 in the qtl calling:
```{bash,eval=F}
module load Anaconda3
source activate three-prime-env
head -n 3 APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc.gz.PCs > APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc.gz.2PCs
head -n 3 APApeak_Phenotype_GeneLocAnno.Total.5perc.fc.gz.PCs > APApeak_Phenotype_GeneLocAnno.Total.5perc.fc.gz.2PCs
```
##Call QTLs- code dir
Next I will need to make a sample list. From the code directory:
```{bash,eval=F}
python makeSampleList.py
```
*remove 19092 and 19193*
Prepare directroy
```{bash,eval=F}
mkdir ../data/apaQTLNominal
mkdir ../data/apaQTLPermuted
```
Run the code to call QTLs within 1mb of each PAS peak. I run both a nominal pass and a permuted pas. The permulted pas chosses the best snp for each peak gene pair.
```{bash,eval=F}
sbatch apaQTL_Nominal.sh
sbatch apaQTL_permuted.sh
```
Concatinate all of the results in the permuted set. I do this so I can account for multiple testing with the benjamini hochberg test.
Concatinate results in permuted directory:
```{bash,eval=F}
cat APApeak_Phenotype_GeneLocAnno.Total.5perc.fc.gz.qqnorm_chr* > APApeak_Phenotype_GeneLocAnno.Total_permRes.txt
cat APApeak_Phenotype_GeneLocAnno.Nuclear.5perc.fc.gz.qqnorm_chr* > APApeak_Phenotype_GeneLocAnno.Nuclear_permRes.txt
```
Run correction script
```{bash,eval=F}
Rscripts apaQTLCorrectPvalMakeQQ.R
```
##Evaluation results
```{r}
totRes=read.table("../data/apaQTLPermuted/APApeak_Phenotype_GeneLocAnno.Total_permResBH.txt", stringsAsFactors = F, header = T) %>% separate(pid, into=c("Chr", "Start", "End", "PeakID"), sep=":") %>% separate(PeakID, into=c("Gene", "Loc", "Strand","Peak"), sep="_")
```
Total Apa QTLs
```{r}
TotQTLs= totRes %>% filter(-log10(bh)>=1)
nrow(TotQTLs)
```
apaQTL genes:
```{r}
TotQTLs_gene=TotQTLs %>% group_by(Gene) %>% summarise(nQTL=n())
summary(TotQTLs_gene$nQTL)
hist(TotQTLs_gene$nQTL)
```
Location distribution for peaks:
```{r}
TotQTLs_loc= TotQTLs %>% group_by(Loc) %>% summarise(nLoc=n()) %>% mutate(PropLoc=nLoc/nrow(TotQTLs))
totQTLloc=ggplot(TotQTLs_loc, aes(x=Loc, y=PropLoc, fill=Loc)) + geom_bar(stat = "Identity") + labs(x="Location of Significant Peak", y="Proportion of QTLs", title="Total QTL peak distribution")+ theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
nucRes=read.table("../data/apaQTLPermuted/APApeak_Phenotype_GeneLocAnno.Nuclear_permResBH.txt", stringsAsFactors = F, header = T) %>% separate(pid, into=c("Chr", "Start", "End", "PeakID"), sep=":") %>% separate(PeakID, into=c("Gene", "Loc", "Strand","Peak"), sep="_")
```
Nuclear Apa QTLs
```{r}
NucQTLs= nucRes %>% filter(-log10(bh)>=1)
nrow(NucQTLs)
```
apaQTL genes:
```{r}
NucQTLs_gene= NucQTLs %>% group_by(Gene) %>% summarise(nQTL=n())
summary(NucQTLs_gene$nQTL)
hist(NucQTLs_gene$nQTL)
```
Location distribution for peaks:
```{r}
NucQTLs_loc= NucQTLs %>% group_by(Loc) %>% summarise(nLoc=n()) %>% mutate(PropLoc=nLoc/nrow(NucQTLs))
nucQTLloc=ggplot(NucQTLs_loc, aes(x=Loc, y=PropLoc, fill=Loc)) + geom_bar(stat = "Identity") + labs(x="Location of Significant Peak", y="Proportion of QTLs", title="Nuclear QTL peak distribution")+theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
plot_grid(totQTLloc, nucQTLloc)
```
##Distance to PAS
The distance to PAS is the location of the snp to the end of the peak for the
Strand in this file is the peak strand (opposite of gene). This means for + strand I want the start of the Peak and for the - strand i will use the end of the peak.
```{r}
TotQTLs_dist=TotQTLs %>% separate(sid, into=c("SnpCHR", "SNPpos"), sep=":") %>% mutate(Dist2PAS=ifelse(Strand=="+", as.integer(SNPpos)-as.integer(Start), as.integer(SNPpos)-as.integer(End)))
summary(abs(TotQTLs_dist$Dist2PAS))
```
Plot:
```{r}
ggplot(TotQTLs_dist, aes(x=Dist2PAS)) + geom_histogram(bins=100) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
```
```{r}
ggplot(TotQTLs_dist, aes(x=Dist2PAS)) + geom_histogram(bins=100) + theme(axis.text.x = element_text(angle = 90, hjust = 1)) + facet_grid(~Loc)
```
```