/
mispriming_approach.Rmd
311 lines (202 loc) · 7.8 KB
/
mispriming_approach.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
---
title: "Mispriming Approach"
author: "Briana Mittleman"
date: "1/11/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
In this analysis I am gonig to explore the ways to handle mispriming in the 3' seq data. Some people call this internal priming. This is when the polyDt primer attached to an RNA molecule that has a long stretch of A's rather than to the tail. You can identify when this is happening because polyA tails are not in the genome but mispriming As are. In my data I need to look for Ts upstream of the read. This is because our reads are on the opposite strand.
Sheppard et al. cited 2 other papers, Beaudoing et al 2000 and Tian et al 2005. Thet excluded reads with 6 consequitive upstream As or those with 7 in a 10nt window. They did this at the read level.
I started thinking about this in https://brimittleman.github.io/threeprimeseq/filter_As.html. I did not have it mapped out correctly because I was looking for A's on one strand and T's on the other.
I will assess the problem then will create a blacklist to get rid of the reads. I should do this in the snakefile before we create BW for the peak calling.
I can start by updating 6up_bed.sh. To make a new script that grabs the upstream 10 bases. I will look for7 of 10 T's in this region. I am going to do this in python because it is more straight forward to read then an awk script. I can also wrap it easier this way. I can also account for negative values and values larger than the chromosome this way.
##Retreive 10 upstream bases for each read
Upstream10Bases.py
```{bash,eval=F}
#python
def main(Fin, Fout):
outBed=open(Fout, "w")
chrom_lengths=open("/project2/gilad/briana/genome_anotation_data/chrom_lengths2.sort.bed","r")
#make a dictionary with chrom lengths
length_dic={}
for i in chrom_lengths:
chrom, start, end = i.split()
length_dic[str(chrom)]=int(end)
#write file
for ln in open(Fin):
chrom, start, end, name, score, strand = ln.split()
chrom=str(chrom)
if strand=="+":
start_new=int(start)-10
if start_new <= 1:
start_new = 0
end_new= int(start)
if end_new == 0:
end_new=1
outBed.write("%s\t%d\t%d\t%s\t%s\t%s\n"%(chrom, start_new, end_new, name, score, strand))
if strand == "-":
start_new=int(end)
end_new=int(end) + 10
if end_new >= length_dic[chrom]:
end_new = length_dic[chrom]
start_new=end_new-1
outBed.write("%s\t%d\t%d\t%s\t%s\t%s\n"%(chrom, start_new, end_new, name, score, strand))
outBed.close()
if __name__ == "__main__":
import sys
inFile = sys.argv[1]
fileNoPath=inFile.split("/")[-1]
fileshort=fileNoPath[:-4]
outFile="/project2/gilad/briana/threeprimeseq/data/bed_10up/" + fileshort + "10up.bed"
main(inFile, outFile)
```
I can wrap this for all of the files.
wrap_Upstream10Bases.sh
```{bash,eval=F}
#!/bin/bash
#SBATCH --job-name=w_Upstream10Bases
#SBATCH --account=pi-yangili1
#SBATCH --time=8:00:00
#SBATCH --output=w_Upstream10Bases.out
#SBATCH --error=w_Upstream10Bases.err
#SBATCH --partition=broadwl
#SBATCH --mem=8G
#SBATCH --mail-type=END
module load Anaconda3
source activate three-prime-env
for i in $(ls /project2/gilad/briana/threeprimeseq/data/bed_sort/*-combined-sort.bed); do
python Upstream10Bases.py $i
done
```
I need to sort the files:
Next step is running the nuc function to get the sequences of the positions I just put in the bed files.
bedtools nuc
* -fi (fasta file) /project2/gilad/briana/genome_anotation_data/genome/Homo_sapiens.GRCh37.75.dna_sm.all.fa
* -bed results from 10up stream
* -s strand specific
* -seq print exracted sequence
* > output
Nuc10BasesUp.sh
```{bash,eval=F}
#!/bin/bash
#SBATCH --job-name=Nuc10BasesUp
#SBATCH --account=pi-yangili1
#SBATCH --time=8:00:00
#SBATCH --output=Nuc10BasesUp.out
#SBATCH --error=Nuc10BasesUp.err
#SBATCH --partition=broadwl
#SBATCH --mem=36G
#SBATCH --mail-type=END
for i in $(ls /project2/gilad/briana/threeprimeseq/data/bed_10up/*);do
describer=$(echo ${i} | sed -e 's/.*YL-SP-//' | sed -e "s/-combined-sort10up.bed$//")
bedtools nuc -s -seq -fi /project2/gilad/briana/genome_anotation_data/genome/Homo_sapiens.GRCh37.75.dna_sm.all.fa -bed $i > /project2/gilad/briana/threeprimeseq/data/nuc_10up/TenBaseUP.${describer}.txt
done
```
##Evaluate problem in 1 line
```{r}
library(data.table)
require(ggseqlogo)
library(workflowr)
library(tidyverse)
```
###Nuclear
Goals for this section:
* make a seq logo plot
I made logo plot in https://brimittleman.github.io/Net-seq/explore_umi_usage.html with ggseq logo.
```{r}
res_colNames=c("chrom","start", "end", "name", "score", "strand", "pctAT", "pctGC", "A", "C", "G", "T", "N", "Other", "Length", "Seq")
```
```{r}
nuc_18486_N= fread("../data/nuc_10up/TenBaseUP.18486-N.txt", col.names = res_colNames)
```
Extract seq for seq logo plot:
```{r}
#filter for full 10 bp - removes 422 reads (too close to ends)
nuc_18486_N=nuc_18486_N %>% filter(Length==10)
seqs_18486N= nuc_18486_N$Seq
```
Scheme for logo plot:
```{r}
cs1 = make_col_scheme(chars=c('A', 'T', 'C', 'G', 'N'), groups=c('A', 'T', 'C', 'G', 'N'), cols=c('red', 'blue', 'green', 'yellow', 'pink'))
```
Create plot:
```{r}
ggseqlogo(seqs_18486N, col_scheme=cs1, method = 'prob')
```
This is not overwhelming:
* count number of non passing reads with 6 T's in a row
```{r}
SixT="TTTTTT"
nuc_18486_N_6Ts=nuc_18486_N %>% filter(grepl(SixT, Seq))
perc_Bad6T= nrow(nuc_18486_N_6Ts)/nrow(nuc_18486_N)
perc_Bad6T
```
* count number of non passing with 7 of 10 T's
```{r}
nuc_18486_N_70perc= nuc_18486_N%>% mutate(percT=T/Length) %>% filter(percT>=.7)
perc_Bad70= nrow(nuc_18486_N_70perc)/nrow(nuc_18486_N)
perc_Bad70
```
* count number of total non passing reads
For this I need to use an or statement.
```{r}
nuc_18486_N_bad= nuc_18486_N%>% mutate(percT=T/Length) %>% filter(percT>=.7 |grepl(SixT, Seq) )
perc_Bad=nrow(nuc_18486_N_bad)/nrow(nuc_18486_N)
perc_Bad
```
This shows us that 46% of reads pass these filters.
###Total
```{r}
nuc_18486_T= fread("../data/nuc_10up/TenBaseUP.18486-T.txt", col.names = res_colNames)
```
* Seqlogo plot
Filter less than 10 base pair in length for seqlogo
```{r}
nuc_18486_T=nuc_18486_T %>% filter(Length==10)
seqs_18486T= nuc_18486_T$Seq
```
Create plot:
```{r}
ggseqlogo(seqs_18486T, col_scheme=cs1, method = 'prob')
```
* count number of non passing reads with 6 T's in a row
```{r}
nuc_18486_T_6Ts=nuc_18486_T %>% filter(grepl(SixT, Seq))
perc_Bad6T_tot= nrow(nuc_18486_T_6Ts)/nrow(nuc_18486_T)
perc_Bad6T_tot
```
* count number of non passing with 7 of 10 T's
```{r}
nuc_18486_T_70perc= nuc_18486_T%>% mutate(percT=T/Length) %>% filter(percT>=.7)
perc_Bad70_tot= nrow(nuc_18486_T_70perc)/nrow(nuc_18486_T)
perc_Bad70_tot
```
* count number of total non passing reads
For this I need to use an or statement.
```{r}
nuc_18486_T_bad= nuc_18486_T%>% mutate(percT=T/Length) %>% filter(percT>=.7 |grepl(SixT, Seq) )
perc_Bad_tot=nrow(nuc_18486_T_bad)/nrow(nuc_18486_T)
perc_Bad_tot
```
This shows us that 25% of reads pass these filters
##For all
I may have to use python when i look at all beacuse this is not fast.
##Extra not using
sort_10upbedFile.sh
```{bash,eval=F}
#!/bin/bash
#SBATCH --job-name=sort_10upbedFile
#SBATCH --account=pi-yangili1
#SBATCH --time=8:00:00
#SBATCH --output=sort_10upbedFile.out
#SBATCH --error=sort_10upbedFile.err
#SBATCH --partition=broadwl
#SBATCH --mem=8G
#SBATCH --mail-type=END
for i in $( ls /project2/gilad/briana/threeprimeseq/data/bed_10up/*);do
describer=$(echo ${i} | sed -e 's/.*YL-SP-//' | sed -e "s/-combined-sort10up.bed$//")
sort -k 1,1 -k2,2n $i > /project2/gilad/briana/threeprimeseq/data/bed_10up_sort/YL-SP-${describer}-combined-sort10up.sort.bed
done
```