Hi,
I have computed one equation based on the given string.
Can anyone please review my code.
#!c:\perl\bin\perl use strict; use warnings; use Math::BigInt; use Data::Dumper; my %index_val = ( A=> 2, C => 3, D => 4, N => 2, M => 2, T => 1, G => 4); my $sequence="ACTGACN"; my $distance_index= int(rand(4)); my $window=int(rand(3)); my $arr_ref = &alpha_index({ sequence => $sequence, distance => $distance_index, aa_index => \%index_val, window_size => $window }); print STDERR Dumper($arr_ref); sub alpha_index { my $self=shift; my $sequence=$self->{sequence}; my $distance=$self->{distance}; my $aa_index=$self->{aa_index}; my ($left,$middle,$right,@carbon_index); my $window_size= $self->{window_size}; if($self->{window_size} ==1) { $window_size=1;} elsif($self->{window_size} > 1 ) { $window_size = int(($self->{window_size}-1)/2); } else { $window_size=0; } foreach (0.. (length($sequence)-1)) { my %carbon_aa=(); ($left,$middle,$right) = $sequence =~ m/(\w{$_})?(\w{1})?(\w*)/; $carbon_aa{$middle}=$aa_index->{$middle} if($middle); $left=reverse($left); my ($left_aa,$right_aa,$distance_index,$power)=0; my $initial_index=2; my $length_index= ($window_size) ? $window_size:length($left); if($self->{window_size} ==1 ) { push @carbon_index, \%carbon_aa if(%carbon_aa); next; } foreach my $increment (0..$length_index-1) { $left_aa=substr($left,$increment,1); next if not exists $aa_index->{$left_aa}; $power=Math::BigInt->new($initial_index); $distance_index=($power->bpow($distance))->numify(); $carbon_aa{$middle}+= ( $aa_index->{$left_aa} * (1/$distance_index)); $initial_index++; } $initial_index=2; $length_index= ($window_size)?$window_size:length($right); foreach my $increment (0..$length_index-1) { $right_aa=substr($right,$increment,1); next if not exists $aa_index->{$right_aa}; $power=Math::BigInt->new($initial_index); $distance_index=($power->bpow($distance))->numify(); $carbon_aa{$middle}+= ( $aa_index->{$right_aa} * ( 1/$distance_index)); $initial_index++; } push @carbon_index, \%carbon_aa if(%carbon_aa); } return \@carbon_index; }

Thanks in advance.
- kulls

In reply to Equation - code review by kulls

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.