Bio::EnsEMBL::Funcgen::Utils EFGUtils
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::EnsEMBL::Funcgen::Utils::EFGUtils
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::Utils::Exception qw ( throw )
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_cmdDescriptionCode
species_chr_num
No description
Code
species_name
No description
Code
Methods description
run_system_cmdcode    nextTop
 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
backup_filedescriptionprevnextTop
sub backup_file {
  my $file_path = shift;

  throw("Must define a file path to backup") if(! $file_path);

  if (-f $file_path) {
    #$self->log("Backing up:\t$file_path");
system ("mv ${file_path} ${file_path}.".`date '+%T'`) == 0 || return 0; } return 1; } 1;
}
get_datedescriptionprevnextTop
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();

	#print "	($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)\n";
if((! defined $format && ! defined $file) || $format eq "date"){ $time = ($year+1900)."-".$mday."-".($mon+1); } elsif($format eq "time"){#not working!
$time = "${hour}:${min}:${sec}"; } elsif($format eq "timedate"){#
$time = localtime(); } else{#add mysql formats here, datetime etc...
croak("get_date does not handle format:\t$format"); } return $time; } #migrate this data to defs file!!??
#must contain all E! species and any other species which are used in local DB extractions
#NEED TO ADD FLY!!
}
get_month_numberdescriptionprevnextTop
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)};
}
meandescriptionprevnextTop
sub mean {
  my $scores = shift;
  
  my $total = 0;

  map $total+= $_, @$scores;
  my $mean = $total/(scalar(@$scores));
return $mean;
}
mediandescriptionprevnextTop
sub median {
  my $scores = shift;

  return undef if (! @$scores);

  my ($median);
  my $count = scalar(@$scores);
  my $index = $count-1;
  #need to deal with lines with no results!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#deal with one score fastest
return $scores->[0] if ($count == 1); #taken from Statistics::Descriptive
#remeber we're dealing with size starting with 1 but indices starting at 0
if ($count % 2) { #odd number of scores
$median = $scores->[($index+1)/2];
} else { #even, get mean of flanks
$median = ($scores->[($index)/2] + $scores->[($index/2)+1] ) / 2;
} return $median;
}
open_filedescriptionprevnextTop
sub open_file {
  my ($file, $operator) = @_;
	
  $operator ||= '<';

  my $fh = new FileHandle "$operator $file";
	
  if(! defined $fh){
	croak("Failed to open $operator $file");
  }

  return $fh;
}



################################################################################
}
run_system_cmddescriptionprevnextTop
sub run_system_cmd {
  my ($command, $no_exit) = @_;

  my $redirect = '';

  #$self->debug(3, "system($command)");
# decide where the command line output should be redirected
#This should account for redirects
#if ($self->{_debug_level} >= 3){
# if (defined $self->{_debug_file}){
# $redirect = " >>".$self->{_debug_file}." 2>&1";
# }
# else{
# $redirect = "";
# }
#}
#else{
#$redirect = " > /dev/null 2>&1";
#}
# execute the passed system command
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); #get the true 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"); } } #reverse boolean logic for perl...can't do this anymore due to tab2mage successful non-zero exit codes :/
return $exit_code;
}
species_chr_numdescriptionprevnextTop
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;
}

#Sort should always be done in the caller if required
}
species_namedescriptionprevnextTop
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.