File Coverage

blib/lib/Bio/GMOD/Admin/Update/WormBase.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Bio::GMOD::Admin::Update::WormBase;
2              
3 1     1   26759 use strict;
  1         2  
  1         47  
4 1     1   6 use vars qw/@ISA/;
  1         2  
  1         50  
5 1     1   533 use Bio::GMOD::Admin::Update;
  0            
  0            
6             #use Bio::GMOD::Admin::Monitor::httpd;
7             #use Bio::GMOD::Admin::Monitor::acedb;
8             #use Bio::GMOD::Admin::Monitor::mysqld;
9             #use Bio::GMOD::Admin::Monitor::blat;
10             use Bio::GMOD::Util::Rearrange;
11             use File::Path 'rmtree';
12              
13              
14             @ISA = qw/Bio::GMOD::Admin::Update/;
15              
16             ################################################
17             # WormBase-specific update methods
18             ################################################
19             sub update {
20             my ($self,@p) = @_;
21             my $adaptor = $self->adaptor;
22             $adaptor->parse_params(@p);
23              
24             my $version = $adaptor->version;
25             my $rsync_module = $adaptor->rsync_module;
26              
27             $self->analyze_logs(-version => $version,
28             -site => `hostname`);
29             $self->prepare_tmp_dir();
30             $self->fetch_acedb(-version => $version);
31             $self->fetch_elegans_gff(-version => $version);
32             $self->fetch_briggsae_gff(-version => $version);
33             $self->fetch_blast_blat(-version => $version);
34             $self->rsync_software(-module => $rsync_module,
35             -install_root => '/usr/local/wormbase/');
36             }
37              
38             sub fetch_acedb {
39             my ($self,@p) = @_;
40             $self->logit(-msg => 'Fetching and installing Acedb',
41             -emphasis => 1);
42              
43             my $adaptor = $self->adaptor;
44             $adaptor->parse_params(@p);
45              
46             # Version to update to
47             my $version = $adaptor->version;
48              
49             # Where to find the database tarballs.
50             my $databases = $adaptor->database_repository;
51              
52             # The acedb tarball
53             my $acedb = sprintf($adaptor->acedb_tarball,$version);
54              
55             # Local and remote paths
56             my $remote_path = "$databases/$version/$acedb";
57             my $local_path = $adaptor->tmp_path . "/$version";
58              
59             # Make sure there is enough space first
60             my $disk_space = $adaptor->acedb_disk_space;
61             $self->check_disk_space(-path => $local_path,
62             -required => $disk_space,
63             -component => 'acedb');
64              
65             $self->mirror(-remote_path => $remote_path,
66             -local_path => $local_path);
67              
68             my $acedb_path = $adaptor->acedb_path;
69              
70             unless ($adaptor->dl_only) {
71             $self->logit(-msg => "Unpacking and installing $acedb");
72             chdir($acedb_path);
73             system("gunzip -c $local_path/$acedb | tar -x --no-same-owner -f -");
74             unlink($acedb_path . '/elegans');
75             symlink("elegans_$version",'elegans');
76              
77             # Adjust permissions
78             my $command = <
79             chown -R acedb $acedb_path/elegans*
80             chgrp -R acedb $acedb_path/elegans*
81             chmod 2775 $acedb_path/elegans*
82             ##chown acedb $acedb_path/bin/*
83             ##chgrp acedb $acedb_path/bin/*
84             END
85              
86             $self->test_for_error(system($command),"Fetching and installing acedb for WormBase");
87             }
88             }
89              
90              
91             sub fetch_elegans_gff {
92             my ($self,@p) = @_;
93             $self->logit(-msg=>'Fetching and installing C. elegans GFF database',
94             -emphasis => 1);
95             my $adaptor = $self->adaptor;
96             $adaptor->parse_params(@p);
97              
98             # Version to update to
99             my $version = $adaptor->version;
100              
101             # Where to find the database tarballs.
102             my $databases = $adaptor->database_repository;
103              
104             # The gff tarball
105             my $gff = sprintf($adaptor->elegans_gff_tarball,$version);
106              
107             # Local and remote paths
108             my $remote_path = "$databases/$version/$gff";
109             my $local_path = $adaptor->tmp_path . "/$version";
110              
111             # Make sure there is enough space first
112             my $disk_space = $adaptor->elegans_gff_disk_space;
113             $self->check_disk_space(-path => $local_path,
114             -required => $disk_space,
115             -component => 'elegans_gff');
116              
117             $self->mirror(-remote_path => $remote_path,
118             -local_path => $local_path);
119              
120             my $mysql_path = $adaptor->mysql_path;
121              
122              
123             unless ($adaptor->dl_only) {
124             $self->logit(-msg => "Unpacking and installing $gff");
125             my $command = <
126             cd $mysql_path
127             mv elegans elegans.bak
128             mv elegans_pmap elegans_pmap.bak
129             gunzip -c $local_path/$gff | tar xvf -
130             rm -rf elegans.bak
131             rm -rf elegans_pmap.bak
132             chgrp -R mysql elegans_pmap
133             chgrp -R mysql elegans
134             chown -R mysql elegans_pmap
135             chown -R mysql elegans
136             END
137              
138             $self->test_for_error(system($command),"Fetching and installing C. elegans GFF database for WormBase");
139             }
140             }
141              
142             sub fetch_blast_blat {
143             my ($self,@p) = @_;
144             $self->logit(-msg=>'Fetching and installing BLAST databases',
145             -emphasis => 1);
146             my $adaptor = $self->adaptor;
147             $adaptor->parse_params(@p);
148              
149             # Version to update to
150             my $version = $adaptor->version;
151              
152             # Where to find the database tarballs.
153             my $databases = $adaptor->database_repository;
154              
155             # The gff tarball
156             my $blast = sprintf($adaptor->blast_tarball,$version);
157              
158             # Local and remote paths
159             my $remote_path = "$databases/$version/$blast";
160             my $local_path = $adaptor->tmp_path . "/$version";
161              
162             # Make sure there is enough space first
163             my $disk_space = $adaptor->blast_disk_space;
164             $self->check_disk_space(-path => $local_path,
165             -required => $disk_space,
166             -component => 'blast');
167              
168             $self->mirror(-remote_path => $remote_path,
169             -local_path => $local_path);
170              
171             unless ($adaptor->dl_only) {
172             $self->logit(-msg => "Unpacking and installing $blast");
173             my $command = <
174             cd /usr/local/wormbase
175             # Deal with blat
176             rm -rf blat.previous
177             mkdir blat.previous
178             mv blat/* blat.previous/.
179              
180             # Create the blast directory
181             mkdir blast
182             gunzip -c $local_path/$blast | tar -x --no-same-owner -f -
183             mv blast_$version blast/.
184             rm -f blast/blast
185             cd blast/
186             ln -s blast_$version blast
187              
188             # Fix permissions as necessary
189             chgrp -R wormbase /usr/local/wormbase/blat
190             chmod 2775 /usr/local/wormbase/blat
191              
192             END
193              
194             $self->test_for_error(system($command),"Fetching and installing blast databases for WormBase");
195             }
196             }
197              
198              
199             sub fetch_briggsae_gff {
200             my ($self,@p) = @_;
201             $self->logit(-msg=>'Fetching and installing C. briggsae GFF database',
202             -emphasis => 1);
203             my $adaptor = $self->adaptor;
204             $adaptor->parse_params(@p);
205              
206             # Version to update to
207             my $version = $adaptor->version;
208              
209             # Where to find the database tarballs.
210             my $databases = $adaptor->database_repository;
211              
212             # The gff tarball
213             my $gff = sprintf($adaptor->briggsae_gff_tarball,$version);
214              
215             # Local and remote paths
216             my $remote_path = "$databases/$version/$gff";
217             my $local_path = $adaptor->tmp_path . "/$version";
218              
219             my $disk_space = $adaptor->briggsae_disk_space;
220             $self->check_disk_space(-path => $local_path,
221             -required => $disk_space,
222             -component => 'briggsae_gff');
223              
224             my $result = $self->mirror(-remote_path => $remote_path,
225             -local_path => $local_path);
226              
227             # If the briggsae GFF isn't present it hasn't been updated
228             # This is not yet complete! Note that the packaging script also
229             # needs to be updated.
230             # unless ($result) {
231             # # Do we have a briggsae DB installed? If not, fetch the stable version
232             # unless (-d "$mysql_path/briggsae") {
233             # my $stable = $adaptor->database_repository_stable;
234             # my $remote_path = $stable . "/briggsae/$gff";
235             # }
236             # }
237              
238             my $mysql_path = $adaptor->mysql_path;
239             unless ($adaptor->dl_only) {
240             $self->logit(-msg => "Unpacking and installing $gff");
241             my $command = <
242             cd $mysql_path
243             mv briggsae briggsae.bak
244             gunzip -c $local_path/$gff | tar -xf -
245             rm -rf briggsae.bak
246             chgrp -R mysql briggsae
247             chown -R mysql briggsae
248             END
249              
250             $self->test_for_error(system($command),"Fetching and installing C. briggsae GFF database for WormBase");
251             }
252             }
253              
254              
255             # THe libraires are not included above
256             # This really needs to be worked in
257             # This will only be used for WormBase packages
258             #sub fetch_libraries {
259             # my $version = shift;
260             # my $ftp = "ftp://$ftp_site/$ftp_path/$version";
261             # chdir("$TMP/$version");
262             #
263             # my $ignore_libraries;
264             # if (! -e "libraries_$version.tgz") {
265             # $self->logit(-msg => "Downloading libraries_$version.ace.tgz - $version-specific libraries");
266             # my $lib_path = $ftp_site . FTP_LIBRARIES;
267             # $ignore_libraries = system("curl -O ftp://$lib_path/libraries_$version.tgz");
268             # # $ignore_libraries = system("curl -O ftp://$lib_path/libraries_current.tgz");
269             # $self->logit(-msg => "Couldn't fetch/no new libraries for $version: $!, not rebuilding");
270             # }
271             #
272             # unless ($ignore_libraries) {
273             # $self->logit(-msg => "Unpacking and installing libraries_$version.tgz");
274             # system("gunzip -c libraries_$version.tgz | tar xf -");
275             # chdir("libraries_$version");
276             # system("cp -r Library /Library");
277             # system("cp -r usr /usr");
278             # # Link the current blast databases
279             # chdir("/usr/local/blast");
280             # symlink('/usr/local/wormbase/blast/blast','databases');
281             # }
282             #}
283              
284              
285              
286             #########################################################
287             # Log analysis
288             #########################################################
289             sub analyze_logs {
290             my ($self,@p) = @_;
291             my ($site,$version) = rearrange(qw/SITE VERSION/,@p);
292             $site ||= `hostname`;
293             return unless $version;
294              
295             $self->logit(-msg => 'Analyzing server logs',
296             -emphasis => 1);
297              
298             $version =~ /WS(.*)/;
299             my $old_version = 'WS' . ($version - 1);
300             my $result = system("/usr/local/wormbase/util/log_analysis/analyze_logs $old_version $site");
301              
302             # We've already fired off the log analysis. Restart apache to intialize new logs.
303             # THIS SHOULD BE PART OF MONITOR
304             system('sudo /usr/local/apache/bin/apachectl restart');
305             }
306              
307              
308              
309             # This is rather out of date
310             # Configure MySQL and nobody for access to the current database I
311             # should make sure that the database is running. If not, start it.
312             #sub add_user_perms_to_db {
313             # my $self = shift;
314             # # This privs should be granted to the current user?
315             # # Granting of privs will be handled in the individual data modules
316             # my $command = <
317             #mysql -u root -e 'grant select on elegans.* to nobody@localhost'
318             #mysql -u root -e 'grant select on elegans_pmap.* to nobody@localhost'
319             #mysql -u root -e 'grant select on briggsae.* to nobody@localhost'
320             #END
321             #
322             # $self->test_for_error(system($command),"Adjusting permissions for MySQL databases");
323             #}
324              
325              
326             # clear the cache
327             sub clear_cache {
328             my ($self,@p) = @_;
329             my ($cache) = rearrange([qw/CACHE/],@p);
330             $self->logit(-msg => 'Clearing disk cache',
331             -emphasis => 1);
332              
333             $cache ||= '/usr/local/wormbase/cache';
334             chdir $cache;
335             my @remove;
336             opendir(D,$cache) or $self->logit(-msg => "Couldn't open $cache: $!",die=>1);
337             while (my $f = readdir(D)) {
338             next unless -d $f;
339             next if $f eq 'README';
340             next if $f eq 'CVS';
341             next if $f =~ /^\./;
342             push @remove,$f;
343             }
344             closedir D;
345             rmtree(\@remove,0,0);
346             }
347              
348              
349              
350             __END__