#!/usr/bin/env perl
package Bio::MLST::Bin::Download;

# ABSTRACT: Downloads all the MLST databases to disk. It requires access to the Internet.
# PODNAME: download_mlst_databases

BEGIN { unshift( @INC, '../lib' ) }
use lib "/software/pathogen/internal/prod/lib";
use Moose;
use Getopt::Long;
use Bio::MLST::DatabaseSettings;
use Bio::MLST::Download::Databases;

my ($config_file, $base_directory, $help);

GetOptions ('c|config=s'         => \$config_file,
            'b|base_directory=s' => \$base_directory,
            'h|help'             => \$help,
);

(! $help)or die <<USAGE;
Usage: $0 [options]
Downloads all the MLST databases to disk

# download everything with defaults
download_mlst_databases

# XML file containing details of the MLST databases (from pubmlst)
download_mlst_databases -c my_config_file.json

# destination base directory defaults to the environment variable \$MLST_DATABASES
download_mlst_databases -b /path/to/destination

USAGE
;

$base_directory ||= $ENV{MLST_DATABASES};
$base_directory ||= '/lustre/scratch108/pathogen/pathpipe/mlst';

$config_file    ||= 'http://pubmlst.org/data/dbases.xml';

my $database_settings = Bio::MLST::DatabaseSettings->new(filename => $config_file)->settings;
my $databases = Bio::MLST::Download::Databases->new(
  databases_attributes => $database_settings,
  base_directory  => $base_directory
);
$databases->update();

__END__

=pod

=head1 NAME

download_mlst_databases - Downloads all the MLST databases to disk. It requires access to the Internet.

=head1 VERSION

version 1.133090

=head1 SYNOPSIS

Downloads all the MLST databases to disk. It requires access to the Internet.

   # download everything with defaults
   download_mlst_databases
 
   # XML file containing details of the MLST databases (from pubmlst)
   download_mlst_databases -c my_config_file.json
 
   # destination base directory defaults to the environment variable \$MLST_DATABASES
   download_mlst_databases -b /path/to/destination

=head1 AUTHOR

Andrew J. Page <ap13@sanger.ac.uk>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute.

This is free software, licensed under:

  The GNU General Public License, Version 3, June 2007

=cut
