Bio::EnsEMBL::Funcgen::Utils
EFGUtils
Toolbar
Summary
Bio::EnsEMBL::Funcgen::Utils::EFGUtils
Package variables
No package variables defined.
Included modules
Carp
FileHandle
Time::Local
strict
Inherit
Exporter
Synopsis
BEGIN
{
unshift(@INC,"/path/of/local/src/modules");
}
use Utils;
&Utils::send_mail($to_address, $title, $message);
Nathan Johnson
njohnson@ebi.ac.uk
Description
This module collates a variety of miscellaneous methods.
Methods
backup_file | No description | Code |
get_date | No description | Code |
get_month_number | No description | Code |
mean | No description | Code |
median | No description | Code |
open_file | No description | Code |
run_system_cmd | Description | Code |
species_chr_num | No description | Code |
species_name | No description | Code |
Methods description
Description : Method to control the execution of the standard system() command
ReturnType : none
Example : $Helper->debug(2,"dir=$dir file=$file");
Exceptions : throws exception if system command returns none zero |
Methods code
sub backup_file
{ my $file_path = shift;
throw("Must define a file path to backup") if(! $file_path);
if (-f $file_path) {
system ("mv ${file_path} ${file_path}.".`date '+%T'`) == 0 || return 0;
}
return 1;
}
1; } |
sub get_date
{ my ($format, $file) = @_;
my ($time, $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
throw("File does not exist or is not a regular file:\t$file") if $file && ! -f $file;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = (defined $file) ?
localtime((stat($file))[9]) : localtime();
if((! defined $format && ! defined $file) || $format eq "date"){
$time = ($year+1900)."-".$mday."-".($mon+1);
}
elsif($format eq "time"){ $time = "${hour}:${min}:${sec}";
}
elsif($format eq "timedate"){ $time = localtime();
}
else{ croak("get_date does not handle format:\t$format");
}
return $time;
}
} |
sub get_month_number
{ my($mon) = @_;
my %month_nos =(
"jan", "01",
"feb", "02",
"mar", "03",
"apr", "04",
"may", "05",
"jun", "06",
"jul", "07",
"aug", "08",
"sep", "09",
"oct", "10",
"nov", "11",
"dec", "12",
);
return $month_nos{lc($mon)}; } |
sub mean
{ my $scores = shift;
my $total = 0;
map $total+= $_, @$scores;
my $mean = $total/(scalar(@$scores));
return $mean; } |
sub median
{ my $scores = shift;
return undef if (! @$scores);
my ($median);
my $count = scalar(@$scores);
my $index = $count-1;
return $scores->[0] if ($count == 1);
if ($count % 2) { $median = $scores->[($index+1)/2]; }
else { $median = ($scores->[($index)/2] + $scores->[($index/2)+1] ) / 2; }
return $median; } |
sub open_file
{ my ($file, $operator) = @_;
$operator ||= '<';
my $fh = new FileHandle "$operator $file";
if(! defined $fh){
croak("Failed to open $operator $file");
}
return $fh;
}
} |
sub run_system_cmd
{ my ($command, $no_exit) = @_;
my $redirect = '';
my $status = system("$command $redirect");
my $exit_code = $status >> 8;
if ($status == -1) {
warn "Failed to execute: $!\n";
}
elsif ($status & 127) {
warn sprintf("Child died with signal %d, %s coredump\nError:\t$!",($status & 127),($status & 128) ? 'with' : 'without');
}
elsif($status != 0) {
warn sprintf("Child exited with value %d\nError:\t$!\n", $exit_code); }
if ($exit_code != 0){
if (! $no_exit){
throw("System command failed:\t$command\n");
}
else{
warn("System command returned non-zero exit code:\t$command\n");
}
}
return $exit_code; } |
sub species_chr_num
{ my ($species, $val) = @_;
($species = lc($species)) =~ s/ /_/;
my %species_chrs = (
homo_sapiens => {(
'x' => 23,
'y' => 24,
'mt' => 25,
)},
mus_musculus => {(
'x' => 20,
'y' => 21,
'mt' => 22,
)},
rattus_norvegicus => {(
'x' => 21,
'y' => 22,
'mt' => 23,
)},
);
die("species not defined in chromosome hash") if(! exists $species_chrs{$species});
return (exists $species_chrs{$species}{lc($val)}) ? $species_chrs{$species}{lc($val)} : $val;
}
} |
sub species_name
{ my($species) = @_;
my %species_names = (
"HOMO_SAPIENS", "human",
"MUS_MUSCULUS", "mouse",
"RATTUS_NORVEGICUS", "rat",
"CANIS_FAMILIARIS", "dog",
"PAN_TROGOLODYTES", "chimp",
"GALLUS_GALLUS", "chicken",
"SACCHAROMYCES_CEREVISIAE", "yeast",
"HUMAN", "HOMO_SAPIENS",
"MOUSE", "MUS_MUSCULUS",
"RAT","RATTUS_NORVEGICUS",
"DOG", "CANIS_FAMILIARIS",
"CHIMP", "PAN_TROGOLODYTES",
"CHICKEN", "GALLUS_GALLUS",
"YEAST", "SACCHAROMYCES_CEREVISIAE",
);
return $species_names{uc($species)}; } |
General documentation
No general documentation available.