#!/usr/bin/perl -w use strict; # This script will download the nr databases from NCBI to $DATA_DIR use File::stat; use Time::localtime; use Net::FTP; my($NCBI_URL) = "ftp.ncbi.nlm.nih.gov"; my($DB_DIR) = "/blast/db"; my(@DB_FILES) = ("nr.tar.gz", "nt.00.tar.gz", "nt.01.tar.gz", "nt.02.tar.gz", "nt.03.tar.gz"); my($USER); my($DATA_DIR); my(@NEWFILES) = (); my($WGET); my($WGET_PARMS) = "-Nq"; my($GZIP); my($TAR); main(); exit; sub main { getarguments(); download(); } sub getarguments { my($parm); # determine arguments if (scalar(@ARGV) > 0) { foreach $parm(@ARGV) { if ($parm eq "-h") { print "Usage: $0 \n"; print " -v Verbose\n"; print " -h This help message\n"; die "\n"; } if ($parm eq "-v") { $WGET_PARMS = "-N"; } } } } sub download { my($ncbi); my($dbfile); # set some parameters $USER = "root"; $DATA_DIR = "/usr/local/ncbi/db"; $WGET = "/usr/bin/wget"; $GZIP = "/bin/gzip"; $TAR = "/bin/tar"; # determine which files to download by date $ncbi = Net::FTP->new("$NCBI_URL"); $ncbi->login("anonymous", "seqadmin\@umdnj.edu"); my($remote_filedate, $local_filedate); chdir "$DATA_DIR"; foreach $dbfile(@DB_FILES) { $remote_filedate = 0; $local_filedate = 0; $remote_filedate = $ncbi->mdtm("$DB_DIR/$dbfile"); if (-e $dbfile) { $local_filedate = stat("$dbfile")->mtime; } if ($remote_filedate > $local_filedate) { push @NEWFILES, $dbfile; } } # download and uncompress the newer files foreach $dbfile(@NEWFILES) { `$WGET $WGET_PARMS ftp://$NCBI_URL$DB_DIR/$dbfile`; `$GZIP -dc $dbfile | $TAR xvf -`; `chown root:root *`; } }