Skip to content

Commit

Permalink
Download given database or list available databases.
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
  • Loading branch information
yeban committed Jan 2, 2016
0 parents commit 83e10d4
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source 'http://rubygems.org'

gemspec
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2016 Anurag Priyam

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Fast download BLAST databases from NCBI

Database files (volumes) are downloaded in parallel: number of threads to use
is determined automatically. MD5 checksum is verified and the database files
extracted upon download. Database volumes are not downloaded in a particular
order. Downloads are incremental, that is it will only download new data,
provided the `.tar.gz` files have not been deleted.

It is faster than NCBI's `update_blastdb.pl`. But unlike `update_blastdb.pl`,
which is a pure Perl script, it delegates download and checksum verification
to `wget` and `md5sum` and is thus not as universal.

### Installation

gem install ncbi-blast-dbs

### Usage

#### List available BLAST databases

ncbi-blast-dbs

#### Download all volumes of a BLAST database

ncbi-blast-dbs nr

NCBI expects users to submit their email address when downloading data from
their FTP server. To comply with that, download as:

email="my email address here" ncbi-blast-dbs nr
5 changes: 5 additions & 0 deletions bin/ncbi-blast-dbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby

require 'rake'
import "#{__dir__}/../lib/ncbi-blast-dbs.rake"
app = Rake.application; app.init; app.load_imports; app.top_level
28 changes: 28 additions & 0 deletions lib/ncbi-blast-dbs.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'net/ftp'

def download(url)
file = File.basename(url)
sh "wget -Nc #{url} && wget -Nc #{url}.md5 &&"\
" md5sum -c #{file}.md5 && tar xvf #{file}"
end

def databases
host, dir = 'ftp.ncbi.nlm.nih.gov', 'blast/db'
usr, pswd = 'anonymous', ENV['email']

Net::FTP.open(host, usr, pswd) do |con|
con.passive = true
con.nlst(dir).
map { |file| File.join(host, file) }.
select { |file| file.match(/\.tar\.gz$/) }.
group_by { |file| File.basename(file).split('.')[0] }
end
end

databases.each do |name, files|
multitask(name => files.map { |file| task(file) { download(file) } })
end

task :default do
puts databases.keys.join(', ')
end
19 changes: 19 additions & 0 deletions ncbi-blast-dbs.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.authors = ['Anurag Priyam']
s.email = ['anurag08priyam@gmail.com']
s.name = 'ncbi-blast-dbs'
s.version = '0.0.1'
s.summary = 'Fast download BLAST databases from NCBI.'
s.description = <<DESC
Downloads BLAST databases from NCBI. Database files (volumes) are downloaded in
parallel; number of threads to use is determined automatically. Database files
are verified and extracted upon download.
DESC
s.license = 'MIT'
s.homepage = 'http://github.com/yeban/ncbi-blast-dbs'

s.files = `git ls-files`.split
s.require_paths = ['lib']
s.add_dependency('rake', '~> 10.3', '>= 10.3.2')
s.executables = ['ncbi-blast-dbs']
end

0 comments on commit 83e10d4

Please sign in to comment.