Skip to content

Commit 83e10d4

Browse files
committed
Download given database or list available databases.
Signed-off-by: Anurag Priyam <[email protected]>
0 parents  commit 83e10d4

6 files changed

+92
-0
lines changed

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'http://rubygems.org'
2+
3+
gemspec

LICENSE.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2016 Anurag Priyam
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Fast download BLAST databases from NCBI
2+
3+
Database files (volumes) are downloaded in parallel: number of threads to use
4+
is determined automatically. MD5 checksum is verified and the database files
5+
extracted upon download. Database volumes are not downloaded in a particular
6+
order. Downloads are incremental, that is it will only download new data,
7+
provided the `.tar.gz` files have not been deleted.
8+
9+
It is faster than NCBI's `update_blastdb.pl`. But unlike `update_blastdb.pl`,
10+
which is a pure Perl script, it delegates download and checksum verification
11+
to `wget` and `md5sum` and is thus not as universal.
12+
13+
### Installation
14+
15+
gem install ncbi-blast-dbs
16+
17+
### Usage
18+
19+
#### List available BLAST databases
20+
21+
ncbi-blast-dbs
22+
23+
#### Download all volumes of a BLAST database
24+
25+
ncbi-blast-dbs nr
26+
27+
NCBI expects users to submit their email address when downloading data from
28+
their FTP server. To comply with that, download as:
29+
30+
email="my email address here" ncbi-blast-dbs nr

bin/ncbi-blast-dbs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'rake'
4+
import "#{__dir__}/../lib/ncbi-blast-dbs.rake"
5+
app = Rake.application; app.init; app.load_imports; app.top_level

lib/ncbi-blast-dbs.rake

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'net/ftp'
2+
3+
def download(url)
4+
file = File.basename(url)
5+
sh "wget -Nc #{url} && wget -Nc #{url}.md5 &&"\
6+
" md5sum -c #{file}.md5 && tar xvf #{file}"
7+
end
8+
9+
def databases
10+
host, dir = 'ftp.ncbi.nlm.nih.gov', 'blast/db'
11+
usr, pswd = 'anonymous', ENV['email']
12+
13+
Net::FTP.open(host, usr, pswd) do |con|
14+
con.passive = true
15+
con.nlst(dir).
16+
map { |file| File.join(host, file) }.
17+
select { |file| file.match(/\.tar\.gz$/) }.
18+
group_by { |file| File.basename(file).split('.')[0] }
19+
end
20+
end
21+
22+
databases.each do |name, files|
23+
multitask(name => files.map { |file| task(file) { download(file) } })
24+
end
25+
26+
task :default do
27+
puts databases.keys.join(', ')
28+
end

ncbi-blast-dbs.gemspec

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Gem::Specification.new do |s|
2+
s.authors = ['Anurag Priyam']
3+
s.email = ['[email protected]']
4+
s.name = 'ncbi-blast-dbs'
5+
s.version = '0.0.1'
6+
s.summary = 'Fast download BLAST databases from NCBI.'
7+
s.description = <<DESC
8+
Downloads BLAST databases from NCBI. Database files (volumes) are downloaded in
9+
parallel; number of threads to use is determined automatically. Database files
10+
are verified and extracted upon download.
11+
DESC
12+
s.license = 'MIT'
13+
s.homepage = 'http://github.com/yeban/ncbi-blast-dbs'
14+
15+
s.files = `git ls-files`.split
16+
s.require_paths = ['lib']
17+
s.add_dependency('rake', '~> 10.3', '>= 10.3.2')
18+
s.executables = ['ncbi-blast-dbs']
19+
end

0 commit comments

Comments
 (0)