diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..d65e2a6 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'http://rubygems.org' + +gemspec diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..8ef8c40 --- /dev/null +++ b/LICENSE.txt @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c10dd07 --- /dev/null +++ b/README.md @@ -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 diff --git a/bin/ncbi-blast-dbs b/bin/ncbi-blast-dbs new file mode 100755 index 0000000..0d37d76 --- /dev/null +++ b/bin/ncbi-blast-dbs @@ -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 diff --git a/lib/ncbi-blast-dbs.rake b/lib/ncbi-blast-dbs.rake new file mode 100644 index 0000000..3265506 --- /dev/null +++ b/lib/ncbi-blast-dbs.rake @@ -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 diff --git a/ncbi-blast-dbs.gemspec b/ncbi-blast-dbs.gemspec new file mode 100644 index 0000000..74282cc --- /dev/null +++ b/ncbi-blast-dbs.gemspec @@ -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 = < 10.3', '>= 10.3.2') + s.executables = ['ncbi-blast-dbs'] +end