Skip to content

Commit

Permalink
Updated trunk to 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kgalinsky committed Oct 28, 2009
1 parent a19aebe commit df6b6ec
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/JCVI/Translator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -391,7 +391,6 @@ sub add_translation {
{ regex => qr/^${nuc_match}{3}$/ },
{ regex => qr/^$aa_match$/ },
{ type => Params::Validate::HASHREF, default => {} }

);

my %p = validate(
Expand Down
45 changes: 44 additions & 1 deletion lib/JCVI/Translator/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit df6b6ec

Please sign in to comment.