-
Notifications
You must be signed in to change notification settings - Fork 1
/
Blast the protein sequences identified by the 2 databases to each other.rmd
246 lines (229 loc) · 6.83 KB
/
Blast the protein sequences identified by the 2 databases to each other.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
---
title: "Blast the protein sequences identified by the 2 databases to each other For Fig. S5"
author: "xyz"
date: "2020/11/25"
output: html_document
---
### extract sequence
```{r}
library(Biostrings)
df <- readRDS("../temp/ncbiMasterProtein.rds")
df2 <- readRDS("../temp/metaMasterProtein.rds")
df <- df[rowSums(df[, 80:81] != "Not Found") > 0, ]
df2 <- df2[rowSums(df2[, 173:174] != "Not Found") > 0, ]
seq <- df$Sequence
names(seq) <- df$Accession
protein <- AAStringSet(seq)
writeXStringSet(protein, "../temp/public.fasta")
seq <- df2$Sequence
names(seq) <- df2$Accession
protein <- AAStringSet(seq)
writeXStringSet(protein, "../temp/meta.fasta")
```
### blast
```{bash eval=F}
cd temp
nohup blastp -query panamaMeta.fasta -subject panamaNCBI.fasta -outfmt 5 -evalue 1e-6 -out "meta2NCBI.xml" &>meta2NCBI.log &
nohup blastp -query panamaNCBI.fasta -subject panamaMeta.fasta -outfmt 5 -evalue 1e-6 -out "NCBI2meta.xml" &>NCBI2meta.log &
```
### Convert blast xml to tabular
```{r}
# https://github.com/peterjc/galaxy_blast/blob/master/tools/ncbi_blast_plus/blastxml_to_tabular.py
# blastxml_to_tabular.py -o meta2NCBI.xml.txt -c std meta2NCBI.xml
# blastxml_to_tabular.py -o NCBI2meta.xml.txt -c std NCBI2meta.xml
meta2NCBI <- data.table::fread("../temp/meta2NCBI.xml.txt")
NCBI2meta <- data.table::fread("../temp/NCBI2meta.xml.txt")
# 1 qseqid Query Seq-id (ID of your sequence)
# 2 sseqid Subject Seq-id (ID of the database hit)
# 3 pident Percentage of identical matches
# 4 length Alignment length
# 5 mismatch Number of mismatches
# 6 gapopen Number of gap openings
# 7 qstart Start of alignment in query
# 8 qend End of alignment in query
# 9 sstart Start of alignment in subject (database hit)
# 10 send End of alignment in subject (database hit)
# 11 evalue Expectation value (E-value)
# 12 bitscore Bit score
colnames(meta2NCBI) <-
c(
"qseqid",
"sseqid",
"pident",
"length",
"mismatch",
"gapopen",
"qstart",
"qend",
"sstart",
"send",
"evalue",
"bitscore"
)
colnames(NCBI2meta) <-
c(
"qseqid",
"sseqid",
"pident",
"length",
"mismatch",
"gapopen",
"qstart",
"qend",
"sstart",
"send",
"evalue",
"bitscore"
)
```
### summary
```{r }
# 16647 in meta blastd by 4256 in public
length(unique(meta2NCBI$qseqid))
length(unique(meta2NCBI$sseqid))
# 87.9% in meta blastd by 98.5% in public
length(unique(meta2NCBI$qseqid)) / nrow(df2)
length(unique(meta2NCBI$sseqid)) / nrow(df)
# 4254 in public blastd by 16574 in meta
length(unique(NCBI2meta$qseqid))
length(unique(NCBI2meta$sseqid))
# 98.5% in public blastd by 87.5% in meta
length(unique(NCBI2meta$qseqid)) / nrow(df)
length(unique(NCBI2meta$sseqid)) / nrow(df2)
```
```{r Percentage of identical matches}
library(ggplot2)
library(ggpubr)
# keep the match with highest score
meta2NCBI <- meta2NCBI[!duplicated(meta2NCBI$qseqid), ]
NCBI2meta <- NCBI2meta[!duplicated(NCBI2meta$qseqid), ]
tempDf <- data.frame(
Percentage = c(meta2NCBI$pident, NCBI2meta$pident),
group = rep(c("Meta to Public", "Public to Meta"), times =
c(nrow(meta2NCBI), nrow(NCBI2meta)))
)
ggplot(tempDf, aes(group, Percentage, fill = group)) + geom_violin(show.legend = FALSE) +
geom_boxplot(width = .1, show.legend = FALSE) +
ylab("Percentage (%)") +
theme(
text = element_text(size = 30),
axis.text = element_text(colour = "black"),
axis.title.x = element_blank()
) +
stat_compare_means(
label = "p.signif",
method = "wilcox.test",
comparisons = list(c("Meta to Public", "Public to Meta")),
size = 5
) +
ggsave(
paste0("../figure/Percentage of identical matches", ".png"),
width = 10.24,
height = 7.68,
dpi = 100
)
# W = 25026280, p-value < 2.2e-16
wilcox.test(meta2NCBI$pident, NCBI2meta$pident)
# meta2NCBI 64.95%, NCBI2meta 75.25%
median(meta2NCBI$pident)
median(NCBI2meta$pident)
```
```{r Alignment length}
tempDf <- data.frame(
length = c(meta2NCBI$length, NCBI2meta$length),
group = rep(c("Meta to Public", "Public to Meta"), times =
c(nrow(meta2NCBI), nrow(NCBI2meta)))
)
ggplot(tempDf, aes(group, length, fill = group)) + geom_violin(show.legend = FALSE) +
geom_boxplot(width = .1, show.legend = FALSE) +
ylab("Alignment length") +
theme(
text = element_text(size = 30),
axis.text = element_text(colour = "black"),
axis.title.x = element_blank()
) +
stat_compare_means(
label = "p.signif",
method = "wilcox.test",
comparisons = list(c("Meta to Public", "Public to Meta")),
size = 5
) +
ggsave(
paste0("../figure/Alignment length", ".png"),
width = 10.24,
height = 7.68,
dpi = 100
)
# W = 31437879, p-value < 2.2e-16
wilcox.test(meta2NCBI$length, NCBI2meta$length)
# meta2NCBI 316, NCBI2meta 343
median(meta2NCBI$length)
median(NCBI2meta$length)
```
```{r Expectation value (E-value)}
tempDf <- data.frame(
evalue = c(meta2NCBI$evalue, NCBI2meta$evalue),
group = rep(c("Meta to Public", "Public to Meta"), times =
c(nrow(meta2NCBI), nrow(NCBI2meta)))
)
# convert 0 to the smallest positive value
tempDf$evalue <-
-log10(tempDf$evalue + min(tempDf$evalue[tempDf$evalue > 0]))
ggplot(tempDf, aes(group, evalue, fill = group)) + geom_violin(show.legend = FALSE) +
geom_boxplot(width = .1, show.legend = FALSE) +
ylab(expression(-log[10]("E-value"))) +
theme(
text = element_text(size = 30),
axis.text = element_text(colour = "black"),
axis.title.x = element_blank()
) +
stat_compare_means(
label = "p.signif",
method = "wilcox.test",
comparisons = list(c("Meta to Public", "Public to Meta")),
size = 5
) +
ggsave(
paste0("../figure/Expectation value (E-value)", ".png"),
width = 10.24,
height = 7.68,
dpi = 100
)
# W = 45364782, p-value < 2.2e-16
wilcox.test(meta2NCBI$evalue, NCBI2meta$evalue)
# meta2NCBI 128.5229, NCBI2meta 180
median(tempDf$evalue[tempDf$group == "Meta to Public"])
median(tempDf$evalue[tempDf$group == "Public to Meta"])
```
```{r bitscore Bit score}
tempDf <- data.frame(
bitscore = c(meta2NCBI$bitscore, NCBI2meta$bitscore),
group = rep(c("Meta to Public", "Public to Meta"), times =
c(nrow(meta2NCBI), nrow(NCBI2meta)))
)
ggplot(tempDf, aes(group, bitscore, fill = group)) + geom_violin(show.legend = FALSE) +
geom_boxplot(width = .1, show.legend = FALSE) +
ylab("Bit score") +
theme(
text = element_text(size = 30),
axis.text = element_text(colour = "black"),
axis.title.x = element_blank()
) +
stat_compare_means(
label = "p.signif",
method = "wilcox.test",
comparisons = list(c("Meta to Public", "Public to Meta")),
size = 5
) +
ggsave(
paste0("../figure/Bit score", ".png"),
width = 10.24,
height = 7.68,
dpi = 100
)
# W = 25140924, p-value < 2.2e-16
wilcox.test(meta2NCBI$bitscore, NCBI2meta$bitscore)
# meta2NCBI 369, NCBI2meta 504
median(meta2NCBI$bitscore)
median(NCBI2meta$bitscore)
```