13 use File
::Temp qw
/tempfile/;
15 use CXGN
::Tools
::Wget qw
/wget_filter/;
19 my $message = shift || '';
20 $message = "Error: $message\n" if $message;
22 my $file_bases = join '', sort map ' '.$_->file_base."\n", CXGN
::BlastDB
->retrieve_all;
27 $FindBin::Script [ options ] -d <path>
29 Go over all the BLAST databases we keep in stock and update them if
30 needed. When run with just the -g option, goes over all the BLAST
31 dbs listed in the sgn.blast_db table and updates them if needed,
32 putting them under the top-level BLAST db path given with the -d
37 -d <path> required. path where all blast DB files are expected to go.
39 -t <path> path to put tempfiles. must be writable. Defaults to /tmp.
41 -x dry run, just print what you would update
43 -f <db name> force-update the DB with the given file base (e.g. 'genbank/nr')
45 Current list of file_bases:
51 getopts
('xt:d:f:',\
%opt) or usage
('invalid arguments');
52 $opt{t
} ||= File
::Spec
->tmpdir;
54 #if a alternate blast dbs path was given, set it in the BlastDB
56 $opt{d
} or usage
('-d option is required');
57 -d
$opt{d
} or usage
("directory $opt{d} not found");
58 CXGN
::BlastDB
->dbpath($opt{d
});
60 my @dbs = $opt{f
} ? CXGN
::BlastDB
->search( file_base
=> $opt{f
} )
61 : CXGN
::BlastDB
->retrieve_all;
63 print $opt{f
} ?
"No database found with file_base='$opt{f}'.\n"
64 : "No dbs found in database.\n";
67 foreach my $db (@dbs) {
69 #check if the blast db needs an update
70 unless($opt{f
} || $db->needs_update) {
71 print $db->file_base." is up to date.\n";
75 #skip the DB if it does not have a source url defined
76 unless($db->source_url) {
77 warn $db->file_base." needs to be updated, but has no source_url. Skipped.\n";
82 print "Would update ".$db->file_base." from source url ".$db->source_url."\n";
85 print "Updating ".$db->file_base." from source url...\n";
89 # check whether we have permissions to do the format
90 if( my $perm_error = $db->check_format_permissions() ) {
91 die "Cannot format ".$db->file_base.":\n$perm_error";
94 #download the sequences from the source url to a tempfile
95 print "Downloading source (".$db->source_url.")...\n";
96 my (undef,$sourcefile) = tempfile
('blastdb-source-XXXXXXXX',
101 my $wget_opts = { cache
=> 0 };
102 $wget_opts->{gunzip
} = 1 if $db->source_url =~ /\.gz$/i;
103 wget_filter
( $db->source_url => $sourcefile, $wget_opts );
105 #formatdb it into the correct place
106 print "Formatting database...\n";
107 $db->format_from_file($sourcefile);
109 unlink $sourcefile or warn "$! unlinking tempfile '$sourcefile'";
111 print $db->file_base." done.\n";
112 }; if( $EVAL_ERROR ) {
113 print "Update failed for ".$db->file_base.":\n$EVAL_ERROR";