From df6b6ecbf074e4ad98de70147fe6533d9f478279 Mon Sep 17 00:00:00 2001 From: kgalinsky Date: Wed, 28 Oct 2009 21:55:20 +0000 Subject: [PATCH] Updated trunk to 0.4.2 git-svn-id: https://jcvi-tools.svn.sourceforge.net/svnroot/jcvi-tools/JCVI-Translator/trunk@7 a16988d2-67c9-4db9-a897-0603be59747b --- Changes | 3 +++ lib/JCVI/Translator.pm | 3 +-- lib/JCVI/Translator/Utils.pm | 45 +++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 3776f57..4f981c1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for JCVI-Translator +0.4.2 Apr 1 2009 + - Added find method into utils + 0.4.1 Mar 31 2009 - Minor fixes in documentation - Use "my $self = shift->SUPER::new(@_)" in constructors diff --git a/lib/JCVI/Translator.pm b/lib/JCVI/Translator.pm index 7d3fa0b..2dfc483 100644 --- a/lib/JCVI/Translator.pm +++ b/lib/JCVI/Translator.pm @@ -67,7 +67,7 @@ use strict; use warnings; use version; -our $VERSION = qv('0.4.1'); +our $VERSION = qv('0.4.2'); use base qw(Class::Accessor::Fast); __PACKAGE__->mk_accessors(qw(id names _table _starts _reverse)); @@ -391,7 +391,6 @@ sub add_translation { { regex => qr/^${nuc_match}{3}$/ }, { regex => qr/^$aa_match$/ }, { type => Params::Validate::HASHREF, default => {} } - ); my %p = validate( diff --git a/lib/JCVI/Translator/Utils.pm b/lib/JCVI/Translator/Utils.pm index 64affe7..2a2c93b 100644 --- a/lib/JCVI/Translator/Utils.pm +++ b/lib/JCVI/Translator/Utils.pm @@ -54,7 +54,7 @@ our $DEFAULT_SANITIZED = 0; =cut sub _new { - my $self = shift->SUPER::_new(); + my $self = shift->SUPER::_new(); $self->_regexes( [] ); foreach my $rc ( 0 .. 1 ) { @@ -135,6 +135,49 @@ sub regex { return $regex; } +=head2 find + + my $locations = $translator->find( $seq_ref, $residue ); + my $locations = $translator->find( $seq_ref, $residue, \%params ); + +Find the indexes of a given residue in a sequence. Valid options for the params +hash are: + + strand: 1 or -1; default = 1 + +=cut + +sub find { + my $self = shift; + + my ( $seq_ref, $residue, @p ); + + ( $seq_ref, $residue, $p[0] ) = validate_pos( + @_, { type => Params::Validate::SCALARREF }, + 1, { default => {}, type => Params::Validate::HASHREF } + ); + + my %p = validate( + @p, + { + strand => { + default => 1, + regex => qr/^[+-]?1$/, + type => Params::Validate::SCALAR + } + } + ); + + my $regex = $self->regex( $residue, $p{strand} ); + + my @positions; + while ( $$seq_ref =~ m/(?=$regex)/ig ) { + push @positions, pos($$seq_ref); + } + + return \@positions; +} + =head2 getORF my $orf_hash = $translator->getORF( $seq_ref );