Bio-EnsEMBL

 view release on metacpan or  search on metacpan

lib/Bio/EnsEMBL/Utils/ConversionSupport.pm  view on Meta::CPAN


sub is_patch {
  my ($self,$slice) = @_;
  my @patch_attrib_types = qw(patch_fix patch_novel); #seq_region_attribs used to define a patch
  foreach my $attrib_type (@patch_attrib_types) {
    if (@{$slice->get_all_Attributes($attrib_type)}) {
      return 1;
    }
  }
  return 0;
}


=head2 log

  Arg[1]      : String $txt - the text to log
  Arg[2]      : Int $indent - indentation level for log message
  Example     : my $log = $support->log_filehandle;
                $support->log('Log foo.\n', 1);
  Description : Logs a message to the filehandle initialised by calling
                $self->log_filehandle(). You can supply an indentation level
                to get nice hierarchical log messages.
  Return type : true on success
  Exceptions  : thrown when no filehandle can be obtained
  Caller      : general

=cut

sub log {
  my ($self, $txt, $indent) = @_;
  $indent ||= 0;

  # strip off leading linebreaks so that indenting doesn't break
  $txt =~ s/^(\n*)//;

  $txt = $1."    "x$indent . $txt;
  my $fh = $self->{'_log_filehandle'};
  throw("Unable to obtain log filehandle") unless $fh;
  print $fh "$txt";
  return(1);
}

=head2 lock_log

  Description : Use flock-style locks to lock log and fastforward to end.
                Useful if log is being written to by multiple processes.
=cut

sub lock_log {
  my ($self) = @_;
  ## no critic
  my $fh = $self->{'_log_filehandle'};
  return if -t $fh or -p $fh; # Shouldn't lock such things
  flock($self->{'_log_filehandle'},LOCK_EX) || return 0;
  seek($self->{'_log_filehandle'},0,SEEK_END); # fail ok, prob not reg file
  return 1;
}

=head2 unlock_log

  Description : Unlock log previously locked by lock_log.

=cut

sub unlock_log {
  my ($self) = @_;
  ## no critic
  my $fh = $self->{'_log_filehandle'};
  return if -t $fh or -p $fh; # We don't lock such things
  # flush is implicit in flock
  flock($self->{'_log_filehandle'},LOCK_UN) || return 0;
  return 1;
}

=head2 log_warning

  Arg[1]      : String $txt - the warning text to log
  Arg[2]      : Int $indent - indentation level for log message
  Arg[3]      : Bool - add a line break before warning if true
  Example     : my $log = $support->log_filehandle;
                $support->log_warning('Log foo.\n', 1);
  Description : Logs a message via $self->log and increases the warning counter.
  Return type : true on success
  Exceptions  : none
  Caller      : general

=cut

sub log_warning {
  my ($self, $txt, $indent, $break) = @_;
  $txt = "WARNING: " . $txt;
  $txt = "\n$txt" if ($break);
  $self->log($txt, $indent);
  $self->{'_warnings'}++;
  return(1);
}

=head2 log_error

  Arg[1]      : String $txt - the error text to log
  Arg[2]      : Int $indent - indentation level for log message
  Example     : my $log = $support->log_filehandle;
                $support->log_error('Log foo.\n', 1);
  Description : Logs a message via $self->log and exits the script.
  Return type : none
  Exceptions  : none
  Caller      : general

=cut

sub log_error {
  my ($self, $txt, $indent) = @_;
  $txt = "ERROR: ".$txt;
  $self->log($txt, $indent);
  $self->log("Exiting.\n");
  exit;
}

=head2 log_verbose

  Arg[1]      : String $txt - the warning text to log



( run in 0.619 second using v1.01-cache-2.11-cpan-39bf76dae61 )