0
|
1 package Bio::Graphics::Util;
|
|
2
|
|
3 # $Id: Util.pm,v 1.2.2.2 2003/07/06 21:53:55 heikki Exp $
|
|
4 # Non object-oriented utilities used here-and-there in Bio::Graphics modules
|
|
5
|
|
6 use strict;
|
|
7 require Exporter;
|
|
8 use vars '@ISA','@EXPORT','@EXPORT_OK';
|
|
9 @ISA = 'Exporter';
|
|
10 @EXPORT = 'frame_and_offset';
|
|
11
|
|
12
|
|
13 =over 4
|
|
14
|
|
15 =item ($frame,$offset) = frame_and_offset($pos,$strand,$phase)
|
|
16
|
|
17 Calculate the reading frame for a given genomic position, strand and
|
|
18 phase. The offset is the offset from $pos to the first nucleotide
|
|
19 of the reading frame.
|
|
20
|
|
21 In a scalar context, returns the frame only.
|
|
22
|
|
23 =back
|
|
24
|
|
25 =cut
|
|
26
|
|
27 sub frame_and_offset {
|
|
28 my ($pos,$strand,$phase) = @_;
|
|
29 $strand ||= +1;
|
|
30 $phase ||= 0;
|
|
31 my $frame = $strand >= 0
|
|
32 ? ($pos - $phase - 1) % 3
|
|
33 : (1 - $pos - $phase) % 3;
|
|
34 my $offset = -$phase % 3;
|
|
35 $offset *= -1 if $strand < 0;
|
|
36 return wantarray ? ($frame,$offset) : $frame;
|
|
37 }
|
|
38
|
|
39
|
|
40 1;
|