use strict;
use Cwd;

my %flags=(
	"hg18"=>0,
	"mm9"=>0,
	"rn4"=>0,
);
my $PROG = $0;
my $PROG_ABS_PATH = Cwd::abs_path($PROG);
$PROG_ABS_PATH = `dirname $PROG_ABS_PATH`;
chomp($PROG_ABS_PATH);
print "\n\tPrepare to download databases from CSHL...\n";

print "\tWhich database(s) do you want to download?\n";
print "\tChoose from\t ";
foreach my $key (keys %flags)
{
	print $key,"/";
}
print "ALL \n\n\tseparated by blank...don't enter anything if you don't want to download!\n\nPlease enter:[NONE]";

my @dbnames = split(/\s+/,<>);
for (my $i=0;$i<@dbnames;$i++)
{
	if (uc($dbnames[$i]) eq "ALL" )
	{
	foreach my $key (keys %flags)
	{
		$flags{$key}=1;
	}
	last;
	}
	
	if( exists $flags{$dbnames[$i]})
	{
		$flags{$dbnames[$i]} = 1;
	}
	#system ("wget http://rulai.cshl.edu/splicetrap/db/")		
}

foreach my $key (keys %flags)
{
	if ($flags{$key} ==1)
	{
		system ("wget http://rulai.cshl.edu/splicetrap/db/".$key.".tar.gz");
		print "untar the database file for $key...please wait...";
		system ("tar -ixzf $key.tar.gz");
		system ("rm $key.tar.gz");
		mkdir "$key/parallel";
		print "creating files for parallel computing...\n";
		system("bash $PROG_ABS_PATH/splitdb.sh $key/parallel")
	}
}
