Mercurial > repos > mahtabm > ensembl
diff 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 diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/variant_effect_predictor/Bio/Graphics/Util.pm Thu Apr 11 02:01:53 2013 -0400 @@ -0,0 +1,40 @@ +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;