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 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309
|
=head1 NAME
EMBOSS::GUI::Conf - repository for EMBOSS::GUI site-specific configuration
=head1 AUTHOR
Luke McCarthy <lukem@gene.pbi.nrc.ca>
=head1 SYNOPSIS
use EMBOSS::GUI::Conf;
$conf = EMBOSS::GUI::Conf->new();
foreach $app ($conf->apps) {
($name, $doc) = @$app;
if (!$conf->is_excluded($name)) {
...
}
}
foreach $group ($conf->groups) {
$group_name = shift @$group;
if (!conf->is_excluded($group_name) {
foreach $app (@$group) {
($name, $doc) = @$app;
...
}
}
}
=head1 DESCRIPTION
EMBOSS::GUI::Conf contains site-specific configuration information for
EMBOSS::GUI. Consult the source for a description of the variables that can
be set.
Public methods are described below:
=over 4
=cut
package EMBOSS::GUI::Conf;
use warnings;
use Carp;
our $VERSION = 1.10;
open (config_file, "</etc/emboss-explorer/emboss-explorer.conf") or die "Cannot load /etc/emboss-explorer.conf!";
my @conf = <config_file>;
eval join("\n", @conf);
die $@ if $@;
=item new()
Returns a new EMBOSS::GUI::Conf object. This method stores the
EMBOSS::GUI::Conf package variables in the object hash, ensures that the
specified output path is writeable and adds the EMBOSS binaries to the path.
=cut
sub new {
my $invocant = shift;
my $class = ref $invocant || $invocant;
my $self = {
HTML_URL => $HTML_URL,
STYLE_URL => $STYLE_URL,
IMAGE_URL => $IMAGE_URL,
MANUAL_URL => $MANUAL_URL,
OUTPUT_PATH => $OUTPUT_PATH,
OUTPUT_URL => $OUTPUT_URL,
EMBOSS_ACDROOT => $ENV{EMBOSS_ACDROOT} || $EMBOSS_ACDROOT,
EMBOSS_DATA => $EMBOSS_DATA,
EMBOSS_MANUAL => $EMBOSS_MANUAL,
EXCLUDED => \@EXCLUDED,
REFRESH_DELAY => $REFRESH_DELAY,
FRAMES => $FRAMES
};
bless $self, $class;
# check to make sure the output directory is writeable...
#
-d $OUTPUT_PATH && -w $OUTPUT_PATH
or die "output directory $OUTPUT_PATH is not writeable";
# add the EMBOSS binary directory to the path...
#
$ENV{PATH} = "$EMBOSS_BIN:$ENV{PATH}";
$self->{excluded} = {};
foreach my $item (@{$self->{EXCLUDED}}) {
++$self->{excluded}->{$item};
}
return $self;
}
=item apps()
Returns a list of available EMBOSS applications. Each element of the list is
a reference to an array containing the name and description of an application.
=cut
sub apps {
my ($self) = @_;
$self->_cache_appinfo unless $self->{apps};
return @{$self->{apps}};
}
=item groups()
Returns a list of application groups. Each element of the list is a reference
to an array containing the name of the group and a list of applications
belonging to that group (each application is in turn a reference to an array
as described in apps() above.) Note that an individual application can appear
in multiple groups.
=cut
sub groups {
my ($self) = @_;
$self->_cache_appinfo unless $self->{groups};
return @{$self->{groups}};
}
=item is_excluded($subject)
Returns true if the subject is being excluded from public display, false
otherwise.
$subject is the name of an application or application group as it appears in
the output from wossname.
=cut
sub is_excluded {
my ($self, $subject) = @_;
return $self->{excluded}->{$subject};
}
=item databases()
Returns a list of available databases. Each element of the list is the name
of a database, suitable for use in a USA.
=cut
sub databases {
my ($self) = @_;
$self->_cache_databases unless $self->{databases};
return @{$self->{databases}};
}
=item matrices()
Returns a list of available alignment scoring matrices. Each element of the
list is a reference to an array containing the filename of the scoring matrix,
suitable for use as the value of a matrix or matrixf argument, and a
description of the matrix.
=cut
sub matrices {
my ($self) = @_;
$self->_cache_matrices unless $self->{matrices};
return @{$self->{matrices}};
}
=item codon_usage_tables()
Returns a list of available codon usage tables. Each element of the list is a
reference to an array containing the filename of the codon usage table,
suitable for use as the value of a codon argument, and the name of the species
from which it is derived.
=cut
sub codon_usage_tables {
my ($self) = @_;
$self->_cache_codon_usage_tables unless $self->{codon_usage_tables};
return @{$self->{codon_usage_tables}};
}
# # # # # # # # # # # # # # # PRIVATE METHODS # # # # # # # # # # # # # # #
sub _cache_appinfo {
my ($self) = @_;
# run wossname to get a list of application groups and the applications
# therein...
#
my (@groups, @current_group);
open WOSSNAME, '-|', 'wossname', '-auto', '-gui'
# comment the line above and uncomment the line below to cope with a bug
# in perl 5.6...
#open WOSSNAME, 'wossname -auto -gui |'
or $self->_fatal_error("couldn't run wossname: $!");
while (<WOSSNAME>) {
chomp;
if (/^$/) { # blank lines separate groups...
# if the current group is not empty and not in the exclude list,
# add it to the list of avaialable groups...
#
push @groups, [ @current_group ]
if @current_group && !$self->is_excluded($current_group[0]);
@current_group = ();
} elsif (@current_group) { # we've already read the group name...
my ($app, $doc) = split /\s+/, $_, 2;
push @current_group, [ $app, $doc ];
} else { # read the group name...
push @current_group, $_;
}
}
close WOSSNAME;
$self->{groups} = \@groups;
# step through the list of groups and create a master list of applications
# in alphabetical order...
#
my %apps;
foreach my $group (@groups) {
my $group_name = shift @$group;
foreach my $aref (@$group) {
my ($app, $doc) = @$aref;
$apps{$app} = $aref
unless $self->is_excluded($app);
}
unshift @$group, $group_name; # stick the group back on...
}
$self->{apps} = [ sort {$a->[0] cmp $b->[0]} values %apps ];
}
sub _cache_databases {
my ($self) = @_;
# run showb to get a list of databases...
#
my @databases;
open SHOWDB, '-|', 'showdb', '-auto', '-noheading'
# comment the line above and uncomment the line below to cope with a bug
# in perl 5.6...
#open SHOWDB, 'showdb -auto -noheading |'
or $self->_fatal_error("couldn't run showdb: $!");
while (<SHOWDB>) {
my ($name, $type, $id, $query, $all, $comment) = split;
push @databases, $name;
}
$self->{databases} = \@databases;
}
sub _cache_matrices {
my ($self) = @_;
my @matrices;
foreach my $file (glob "$self->{conf}->{EMBOSS_DATA}/Matrices.*") {
open INDEX, '<', $file
or $self->_fatal_error("couldn't open matrix index '$file': $!");
while (<INDEX>) {
chomp;
next if /^#/; # skip comments...
next unless /\S/; # skip blank lines...
my ($filename, $description) = split /\s+/, $_, 2;
push @matrices, [ $filename => $description ];
}
}
$self->{matrices} = \@matrices;
}
sub _cache_codon_usage_tables {
my ($self) = @_;
my @codon_usage_tables;
open INDEX, '<', "$self->{conf}->{EMBOSS_DATA}/CODONS/Cut.index"
or $self->_fatal_error("couldn't open codon usage table index: $!");
while (<INDEX>) {
chomp;
next if /^#/; # skip comments...
next unless /\S/; # skip blank lines...
#my ($filename, $description) = split /\s+/, $_, 2;
my ($filename, $species) = split;
push @codon_usage_tables, [ $filename => $species ];
}
$self->{codon_usage_tables} = \@codon_usage_tables;
}
1;
=back
=head1 BUGS
None that I know of.
=head1 COPYRIGHT
Copyright (c) 2004 Luke McCarthy. All rights reserved. This program is free
software. You may copy or redistribute it under the same terms as Perl itself.
|