-
Notifications
You must be signed in to change notification settings - Fork 29
/
Database_Retrieval.Rmd
334 lines (267 loc) · 14.4 KB
/
Database_Retrieval.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
---
title: "NCBI Database Retrieval"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{NCBI Database Retrieval}
%\VignetteEngine{knitr::rmarkdown}
%\usepackage[utf8]{inputenc}
---
```{r, echo = FALSE, message = FALSE}
options(width = 750)
knitr::opts_chunk$set(
comment = "#>",
error = FALSE,
tidy = FALSE)
```
# Retrieve Sequence Databases from NCBI
> **_NOTE:_** To make sure that you have a sufficiently stable (internet) connection between R and the respective databases, please set the default `timeout` setting __on your local machine__ from 60sec to at least 300000sec before running any retrieval functions via:
```r
options(timeout = 300000)
```
## Getting Started
NCBI stores a variety of specialized database such as [Genbank, RefSeq, Taxonomy, SNP, etc.](https://www.ncbi.nlm.nih.gov/guide/data-software/) on their servers.
The `download.database()` and `download.database.all()` functions implemented in `biomartr` allows users to download these databases from NCBI.
This process might be very useful for downstream analyses such as sequence searches with e.g. BLAST. For this purpose see the R package [metablastr](https://github.com/drostlab/metablastr) which aims to seamlessly integrate `biomartr` based genomic data retrieval with downstream large-scale BLAST searches.
* [1. List available NCBI databases with `listNCBIDatabases()`](#ist-available-databases)
* [2. Download NCBI databases with `download.database.all()`](#download-ncbi-databases)
- [2.1 Example NCBI nr retrieval](#example-ncbi-nr)
- [2.2 Example NCBI nt retrieval](#example-ncbi-nt)
- [2.3 Example NCBI RefSeq retrieval](#example-ncbi-refseq)
- [2.4 Example Protein Database (PDB) retrieval](#example-pdb)
- [2.5 Example NCBI Taxonomy retrieval](#example-ncbi-taxonomy)
- [2.6 Example NCBI Swissprot retrieval](#example-ncbi-swissprot)
- [2.7 Example NCBI CDD Delta retrieval](#example-ncbi-cdd-delta)
## List available databases
Before downloading specific databases from NCBI users might want to list available databases. Using the `listNCBIDatabases()` function users can retrieve a list of available databases stored on NCBI.
```{r, eval=FALSE}
# retrieve a list of available sequence databases at NCBI
biomartr::listNCBIDatabases(db = "all")
```
```
[1] "16S_ribosomal_RNA" "16S_ribosomal_RNA-nucl-metadata"
[3] "18S_fungal_sequences" "18S_fungal_sequences-nucl-metadata"
[5] "28S_fungal_sequences" "28S_fungal_sequences-nucl-metadata"
[7] "Betacoronavirus" "Betacoronavirus-nucl-metadata"
[9] "blastdb-manifest" "blastdb-metadata-1-1"
[11] "blastdbv5" "cdd_delta"
[13] "cloud" "env_nr"
[15] "env_nr-prot-metadata" "env_nt"
[17] "env_nt-nucl-metadata" "FASTA"
[19] "human_genome" "human_genome-nucl-metadata"
[21] "ITS_eukaryote_sequences" "ITS_eukaryote_sequences-nucl-metadata"
[23] "ITS_RefSeq_Fungi" "ITS_RefSeq_Fungi-nucl-metadata"
[25] "landmark" "landmark-prot-metadata"
[27] "LSU_eukaryote_rRNA" "LSU_eukaryote_rRNA-nucl-metadata"
[29] "LSU_prokaryote_rRNA" "LSU_prokaryote_rRNA-nucl-metadata"
[31] "mito" "mito-nucl-metadata"
[33] "mouse_genome" "mouse_genome-nucl-metadata"
[35] "nr" "nr-prot-metadata"
[37] "nt" "nt-nucl-metadata"
[39] "pataa" "pataa-prot-metadata"
[41] "patnt" "patnt-nucl-metadata"
[43] "pdbaa" "pdbaa-prot-metadata"
[45] "pdbnt" "pdbnt-nucl-metadata"
[47] "ref_euk_rep_genomes" "ref_euk_rep_genomes-nucl-metadata"
[49] "ref_prok_rep_genomes" "ref_prok_rep_genomes-nucl-metadata"
[51] "ref_viroids_rep_genomes" "ref_viroids_rep_genomes-nucl-metadata"
[53] "ref_viruses_rep_genomes" "ref_viruses_rep_genomes-nucl-metadata"
[55] "refseq_protein" "refseq_protein-prot-metadata"
[57] "refseq_rna" "refseq_rna-nucl-metadata"
[59] "refseq_select_prot" "refseq_select_prot-prot-metadata"
[61] "refseq_select_rna" "refseq_select_rna-nucl-metadata"
[63] "SSU_eukaryote_rRNA" "SSU_eukaryote_rRNA-nucl-metadata"
[65] "swissprot" "swissprot-prot-metadata"
[67] "taxdb" "taxdb-metadata"
[69] "tsa_nr" "tsa_nr-prot-metadata"
[71] "tsa_nt" "tsa_nt-nucl-metadata"
[73] "v4" "v5"
```
However, in case users already know which database they would like to retrieve
they can filter for the exact files by specifying the NCBI database name. In the following example all sequence files that are part of the `NCBI nr` database shall be retrieved.
First, the `listNCBIDatabases(db = "nr")` allows to list all files corresponding to the `nr` database.
```{r, eval=FALSE}
# show all NCBI nr files
biomartr::listNCBIDatabases(db = "nr")
```
```
[1] "nr.00.tar.gz" "nr.01.tar.gz"
[3] "nr.02.tar.gz" "nr.03.tar.gz"
[5] "nr.04.tar.gz" "nr.05.tar.gz"
[7] "nr.06.tar.gz" "nr.07.tar.gz"
[9] "nr.08.tar.gz" "nr.09.tar.gz"
[11] "nr.10.tar.gz" "nr.11.tar.gz"
[13] "nr.12.tar.gz" "nr.13.tar.gz"
[15] "nr.14.tar.gz" "nr.15.tar.gz"
[17] "nr.16.tar.gz" "nr.17.tar.gz"
[19] "nr.18.tar.gz" "nr.19.tar.gz"
[21] "nr.20.tar.gz" "nr.21.tar.gz"
[23] "nr.22.tar.gz" "nr.23.tar.gz"
[25] "nr.24.tar.gz" "nr.25.tar.gz"
[27] "nr.26.tar.gz" "nr.27.tar.gz"
[29] "nr.28.tar.gz" "nr.29.tar.gz"
[31] "nr.30.tar.gz" "nr.31.tar.gz"
[33] "nr.32.tar.gz" "nr.33.tar.gz"
[35] "nr.34.tar.gz" "nr.35.tar.gz"
[37] "nr.36.tar.gz" "nr.37.tar.gz"
[39] "nr.38.tar.gz" "nr.39.tar.gz"
[41] "nr.40.tar.gz" "nr.41.tar.gz"
[43] "nr.42.tar.gz" "nr.43.tar.gz"
[45] "nr.44.tar.gz" "nr.45.tar.gz"
[47] "nr.46.tar.gz" "nr-prot-metadata.json"
[49] "nr.47.tar.gz" "nr.48.tar.gz"
[51] "nr.49.tar.gz" "nr.50.tar.gz"
[53] "nr.51.tar.gz" "nr.52.tar.gz"
[55] "nr.53.tar.gz" "nr.54.tar.gz"
[57] "nr.55.tar.gz"
```
The output illustrates that the `NCBI nr` database has been separated into several sub-data-packages.
Further examples are:
```{r, eval=FALSE}
# show all NCBI nt files
biomartr::listNCBIDatabases(db = "nt")
```
```
[1] "nt.00.tar.gz" "nt.01.tar.gz"
[3] "nt.02.tar.gz" "nt.03.tar.gz"
[5] "nt.04.tar.gz" "nt.05.tar.gz"
[7] "nt.06.tar.gz" "nt.07.tar.gz"
[9] "nt.08.tar.gz" "nt.09.tar.gz"
[11] "nt.10.tar.gz" "nt.11.tar.gz"
[13] "nt.12.tar.gz" "nt.13.tar.gz"
[15] "nt.14.tar.gz" "nt.15.tar.gz"
[17] "nt.16.tar.gz" "nt.17.tar.gz"
[19] "nt.18.tar.gz" "nt.19.tar.gz"
[21] "nt.20.tar.gz" "nt.21.tar.gz"
[23] "nt.22.tar.gz" "nt.23.tar.gz"
[25] "nt.24.tar.gz" "nt.25.tar.gz"
[27] "nt.26.tar.gz" "nt.27.tar.gz"
[29] "nt.28.tar.gz" "nt.29.tar.gz"
[31] "nt.30.tar.gz" "nt.31.tar.gz"
[33] "nt.32.tar.gz" "nt.33.tar.gz"
[35] "nt.34.tar.gz" "nt.35.tar.gz"
[37] "nt.36.tar.gz" "nt.37.tar.gz"
[39] "nt-nucl-metadata.json" "nt.38.tar.gz"
[41] "nt.39.tar.gz" "nt.40.tar.gz"
[43] "nt.41.tar.gz" "nt.42.tar.gz"
[45] "nt.43.tar.gz" "nt.44.tar.gz"
[47] "nt.45.tar.gz" "nt.46.tar.gz"
[49] "nt.47.tar.gz" "nt.48.tar.gz"
```
```{r, eval=FALSE}
# show all NCBI RefSeq (only proteomes)
head(biomartr::listNCBIDatabases(db = "refseq_protein"), 20)
```
```
[1] "refseq_protein.00.tar.gz" "refseq_protein.01.tar.gz"
[3] "refseq_protein.02.tar.gz" "refseq_protein.03.tar.gz"
[5] "refseq_protein.04.tar.gz" "refseq_protein.05.tar.gz"
[7] "refseq_protein.06.tar.gz" "refseq_protein.07.tar.gz"
[9] "refseq_protein.08.tar.gz" "refseq_protein.09.tar.gz"
[11] "refseq_protein.10.tar.gz" "refseq_protein.11.tar.gz"
[13] "refseq_protein.12.tar.gz" "refseq_protein.13.tar.gz"
[15] "refseq_protein.14.tar.gz" "refseq_protein.15.tar.gz"
[17] "refseq_protein.16.tar.gz" "refseq_protein.17.tar.gz"
[19] "refseq_protein.18.tar.gz" "refseq_protein.19.tar.gz"
```
```{r, eval=FALSE}
# show all NCBI RefSeq (only RNA)
biomartr::listNCBIDatabases(db = "refseq_rna")
```
```
[1] "refseq_rna.00.tar.gz" "refseq_rna.01.tar.gz"
[3] "refseq_rna.02.tar.gz" "refseq_rna.03.tar.gz"
[5] "refseq_rna.04.tar.gz" "refseq_rna.05.tar.gz"
[7] "refseq_rna.06.tar.gz" "refseq_rna.07.tar.gz"
[9] "refseq_rna.08.tar.gz" "refseq_rna-nucl-metadata.json"
[11] "refseq_rna.09.tar.gz"
```
```{r, eval=FALSE}
# show NCBI swissprot
biomartr::listNCBIDatabases(db = "swissprot")
```
```
[1] "swissprot.tar.gz" "swissprot-prot-metadata.json"
```
```{r, eval=FALSE}
# show NCBI PDB
biomartr::listNCBIDatabases(db = "pdb")
```
```
[1] "pdbaa.tar.gz" "pdbnt.tar.gz"
[3] "pdbaa-prot-metadata.json" "pdbnt-nucl-metadata.json"
```
```{r, eval=FALSE}
# show NCBI Human database
biomartr::listNCBIDatabases(db = "human")
```
```
1] "human_genome.00.tar.gz" "human_genome.01.tar.gz"
[3] "human_genome-nucl-metadata.json"
```
__Please not that all lookup and retrieval function will only work properly when a sufficient internet connection is provided.__
In a next step users can use the `listNCBIDatabases()` and `download.database.all()` functions to retrieve
all files corresponding to a specific NCBI database.
## Download NCBI databases
Using the same search strategy by specifying the database name as described above, users can now download these databases using the `download.database.all()` function.
For downloading only single files users can type:
### Example NCBI nr
```{r, eval=FALSE}
# download the entire NCBI nr database
biomartr::download.database.all(db = "nr", path = "nr")
```
This command will download the pre-formatted (by makeblastdb formatted) database version is retrieved.
Using this command, all `NCBI nr` files are loaded into the `nr` folder (`path = "nr"`). For each data package, `biomartr` checks the `md5checksum` of the downloaded file and the file stored online to make sure that internet connection losses didn't currupt the file. In case you see a warning message notifying you about not-matching `md5checksum` values, please re-download the corresponding data package by re-running the `download.database.all()` command. From my own experience this can happen when server connections or internet connections are not very stable during the download process of large data chunks.
### Example NCBI nt
The same approach can be applied to all other databases mentioned above, e.g.:
```{r, eval=FALSE}
# download the entire NCBI nt database
biomartr::download.database.all(db = "nt", path = "nt")
```
### Example NCBI RefSeq
```{r, eval=FALSE}
# download the entire NCBI refseq (protein) database
biomartr::download.database.all(db = "refseq_protein", path = "refseq_protein")
```
### Example PDB
```{r, eval=FALSE}
# download the entire NCBI PDB database
biomartr::download.database.all(db = "pdb", path = "pdb")
```
### Example NCBI Taxonomy
Download NCBI Taxonomy via:
```{r, eval=FALSE}
# download the entire NCBI taxonomy database
biomartr::download.database.all(db = "taxdb", path = "taxdb")
```
```
Starting download of the files: taxdb.tar.gz, taxdb.btd, taxdb.bti ...
This download process may take a while due to the large size of the individual data chunks ...
Starting download process of file: taxdb.tar.gz ...
Checking md5 hash of file: taxdb.tar.gz ...
The md5 hash of file 'taxdb.tar.gz' matches!
File 'taxdb/taxdb.tar.gz has successfully been retrieved.
Starting download process of file: taxdb.btd ...
Checking md5 hash of file: taxdb.btd ...
The md5 hash of file 'taxdb.btd' matches!
File 'taxdb/taxdb.btd has successfully been retrieved.
Starting download process of file: taxdb.bti ...
Checking md5 hash of file: taxdb.bti ...
The md5 hash of file 'taxdb.bti' matches!
File 'taxdb/taxdb.bti has successfully been retrieved.
Download process is finished and files are stored in 'taxdb'.
```
### Example NCBI Swissprot
Download NCBI Swissprot via:
```{r, eval=FALSE}
# download the entire NCBI swissprot database
biomartr::download.database.all(db = "swissprot", path = "swissprot")
```
### Example NCBI CDD Delta
Download NCBI CDD Delta via:
```{r, eval=FALSE}
# download the entire NCBI CDD Delta database
biomartr::download.database.all(db = "cdd_delta", path = "cdd_delta")
```
For each data package, `biomartr` checks the `md5checksum` of the downloaded file and the file stored online to make sure that internet connection losses didn't currupt the file. In case you see a warning message notifying you about not-matching `md5checksum` values, please re-download the corresponding data package. From my own experience this can happen when server connections or internet connections are not very stable during the download process of large data chunks.
__Please notice that most of these databases are very large, so users should take of of providing a stable internet connection throughout the download process.__