File: Util.pm

package info (click to toggle)
libbio-graphics-perl 2.40-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,276 kB
  • sloc: perl: 21,801; makefile: 14
file content (45 lines) | stat: -rwxr-xr-x 989 bytes parent folder | download | duplicates (6)
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
package Bio::Graphics::Util;

# Non object-oriented utilities used here-and-there in Bio::Graphics modules

=head1 NAME

Bio::Graphics::Util - non-object-oriented utilities used in Bio::Graphics modules

=cut

use strict;
require Exporter;
use base qw(Exporter);
use vars '@EXPORT','@EXPORT_OK';
@EXPORT = 'frame_and_offset';
use Bio::Root::Version;

=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 $codon_start =  $strand >= 0
                   ? $pos + $phase
	           : $pos - $phase;  # probably wrong
  my $frame  = ($codon_start-1) % 3;
  my $offset = $strand >= 0 ? $phase : -$phase;
  return wantarray ? ($frame,$offset) : $frame;
}


1;