1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
#!/usr/bin/perl -w
=head1 NAME
auto_install_databases.pl - Download and install GFF data sets
=head1 SYNOPSYS
% auto_install_databases.pl --rdms pg --user scott
=head1 DESCRIPTION
This program queries a web server to determine what data sets are
available and presents the user with a list to choose from, with the
option of getting several data sets at once. The chosen data sets
are downloaded and they are used as inputs for the bulk loader of the
specified relational database management system (either MySQL or
PostgreSQL) to initialize and load the GFF and optionally fasta
data.
=head2 NOTES
This program uses the bulk loader for its database (bp_bulk_load_gff.pl
for mysql, bp_pg_bulk_load_gff.pl for postgres); read the documentation
for those programs for caveats with their use.
Like the bulk loaders, this program uses \$TMPDIR to transiently store
downloaded data, therefore, \$TMPDIR must have enough free space to store
all of the raw data and the processed files for importation to the database.
To create your own web server data source, carefully copy the syntax and
file structure of the default data source, as this program is very
inflexible with regard to the obtaining information from the web server.
Since the data is being downloaded uncompressed from web server, it may
take a very long time for the download and database load to complete.
An hour or more is not out of the question for a large data set like
wormbase.
=head1 COMMAND-LINE OPTIONS
Options can be abbreviated. For example, you can use -s for --server.
--server URL of web server to obtain datasets
Default = 'http://brie4.cshl.org:8000/'
--rdms RDMS to use (mysql or pg (Postgres))
Default = 'mysql'
--user Username to log into database server as
Default = ''
--password Password associated with username
Default = ''
=head1 SEE ALSO
L<Bio::DB::GFF>, L<bp_bulk_load_gff.pl>, L<bp_pg_bulk_load_gff.pl>
=head1 AUTHOR
Scott Cain, cain@cshl.org
Copyright (c) 2003 Cold Spring Harbor Laboratory
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. See DISCLAIMER.txt for
disclaimers of warranty.
=cut
use strict;
use LWP::UserAgent;
use Getopt::Long;
my $bWINDOWS = ($^O =~ /MSWin32/i) ? 1 : 0;
my ($USER,$PASS,$RDMS,$SERVER);
GetOptions ('server:s' => \$SERVER,
'rdms:s' => \$RDMS,
'user:s' => \$USER,
'password:s' => \$PASS) or die <<USAGE;
Usage: $0 [options]
Retrieve data sets and bulk-load multiple Bio::DB::GFF databases from GFF files.
Options:
--server URL of web server to obtain datasets
Default = 'http://brie4.cshl.org:8000/'
--rdms RDMS to use (mysql or pg (Postgres))
Default = 'mysql'
--user Username to log into database server as
Default = ''
--password Password associated with username
Default = ''
Options can be abbreviated. For example, you can use -s for --server.
This program uses the bulk loader for its database (bp_bulk_load_gff.pl
for mysql, bp_pg_bulk_load_gff.pl for postgres); read the documentation
for those programs for caveats with their use.
Like the bulk loaders, this program uses \$TMPDIR to transiently store
downloaded data, therefore, \$TMPDIR must have enough free space to store
all of the raw data and the processed files for importation to the database.
To create your own web server data source, carefully copy the syntax and
file structure of the default data source, as this program is very
inflexible with regard to the obtaining information from the web server.
Since the data is being downloaded uncompressed from web server, it may
take a very long time for the download and database load to complete.
An hour or more is not out of the question for a large data set like
wormbase.
USAGE
;
$RDMS ||= 'mysql';
$SERVER ||= 'http://brie4.cshl.org:8000/';
my $bulkloader = ($RDMS =~ /mysql/i) ? 'bp_bulk_load_gff.pl'
: 'bp_pg_bulk_load_gff.pl';
my $tmpdir = $ENV{TMP} || $ENV{TMPDIR} || '/usr/tmp';
$tmpdir =~ s!\\!\\\\!g if $bWINDOWS; #eliminates backslash mis-interpretation
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $SERVER);
my $res = $ua->request($req);
die "Failed to connect to gbrowse data source server $SERVER\n" unless ($res->is_success);
my $result = $res->content;
my @result = split /\n/, $result;
my %available_data;
# note that since I control both the page being retrieved and
# this script, I can parse the html "by hand". Were that not
# the case, I would certainly use HTML::Parser (or something
# like that).
foreach (@result) {
if (/<li>.*href=\"(.*)\">(.*)<.*<\/li>/) {
$available_data{$2} = $1;
}
}
my $i = 0;
my @keys;
$keys[0] = '';
foreach my $key (reverse sort keys %available_data) {
$i++;
push @keys, $key;
print "[$i] $key\n";
}
print "Choose data sets to install (comma delimited list) [0]:";
my $answer;
chomp($answer = <STDIN>);
die "OK, won't install anything\n" unless $answer;
my @data_sets = split /\,\s*/, $answer;
print "\nInstall these datasets?\n";
foreach my $set (@data_sets) {
print "$keys[$set]\n";
}
print "answer yes to confirm, no to quit [y]?";
chomp($answer = <STDIN>);
die "ok, nothing will be installed\n" if ($answer =~ /^n/i);
#do arg building and error checking here
my @args;
push @args, $bulkloader;
push @args, '--create';
if (defined $USER) {
push @args, "--user";
push @args, $USER;
if (defined $PASS) {
push @args, "--password";
push @args, $PASS;
}
}
#figure out which data sets, and if they include fastas
#don't allow loading fasta without gff
#this loop is really taking advantage of my control of the download site
#it assumes that for every gff file there is a fasta, and than they are named
#with the same prefix (eg, yeast_), and that the gff file comes second
#alphabetically (ie, first when reverse sorted).
warn "retrieving data (this could take a while) ...\n";
for ($i=0;$i < scalar @data_sets;$i++) {
my $set = $data_sets[$i];
if ($set % 2 == 0) {
warn "Importing of fasta without gff is not permitted from this interface\n";
unlink "$tmpdir/$keys[$set].$$";
next;
}
if (defined $data_sets[$i+1] && $set + 1 == $data_sets[$i+1]) {
# fasta is to be imported too
my $gff = "$tmpdir/$keys[$set].$$";
my $fasta = "$tmpdir/$keys[$set+1].$$";
download_data($keys[$set]);
download_data($keys[$set+1]);
$keys[$set] =~ /^(.+)_/;
my $db = $1;
push @args, "--fasta";
push @args, $fasta;
push @args, "--database";
push @args, $db;
push @args, $gff;
warn "executing @args\n";
system (@args);
unlink $gff;
unlink $fasta;
$i++;
} else { # don't import fasta
my $gff = "$tmpdir/$keys[$set].$$";
download_data($keys[$set]);
$keys[$set] =~ /^(.+)_/;
my $db = $1;
push @args, "--database";
push @args, $db;
push @args, $gff;
warn "executing @args\n";
system (@args);
unlink $gff;
}
}
sub download_data {
my $set = shift;
warn "getting $set ...\n";
$req = HTTP::Request->new(GET => $available_data{$set});
$res = $ua->request($req,"$tmpdir/$set.$$" );
}
__END__
|