view variant_effect_predictor/Bio/Graphics/Util.pm @ 0:1f6dce3d34e0

Uploaded
author mahtabm
date Thu, 11 Apr 2013 02:01:53 -0400
parents
children
line wrap: on
line source

package Bio::Graphics::Util;

# $Id: Util.pm,v 1.2.2.2 2003/07/06 21:53:55 heikki Exp $
# Non object-oriented utilities used here-and-there in Bio::Graphics modules

use strict;
require Exporter;
use vars '@ISA','@EXPORT','@EXPORT_OK';
@ISA = 'Exporter';
@EXPORT = 'frame_and_offset';


=over 4

=item ($frame,$offset) = frame_and_offset($pos,$strand,$phase)

Calculate the reading frame for a given genomic position, strand and
phase.  The offset is the offset from $pos to the first nucleotide
of the reading frame.

In a scalar context, returns the frame only.

=back

=cut

sub frame_and_offset {
  my ($pos,$strand,$phase) = @_;
  $strand ||= +1;
  $phase  ||= 0;
  my $frame = $strand >= 0 
    ? ($pos - $phase - 1) % 3
    : (1 - $pos - $phase) % 3;
  my $offset = -$phase % 3;
  $offset   *= -1 if $strand < 0;
  return wantarray ? ($frame,$offset) : $frame;
}


1;