http://www.perlmonks.org?node_id=970267

supriyoch_2008 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on How can I count the types of changes in 1st, 2nd and 3rd positions of all 3-letter words in comparing two separate strings of unequal length?
  • Download Code

Replies are listed 'Best First'.
Re: How can I count the types of changes in 1st, 2nd and 3rd positions of all 3-letter words in comparing two separate strings of unequal length?
by ww (Archbishop) on May 13, 2012 at 12:14 UTC
    You say a very basic Perl operation "appears very complicated" and then repeat the tactics you've used to get others to do your work -- posting a code sample that's essentially no more than a few lines of boilerplate.

    This time, what you're looking for is scarcely more than an extension or adaptation of the advice (and solutions) you've been given previously.

    You'll do better to start now to try to solve your own homework(?) or $work(?). Twenty-one posts with little evidence that you've made a serious attempt to think through your own questions is not a good reflection on your desire to learn... which is what PM is largely about.

Re: How can I count the types of changes in 1st, 2nd and 3rd positions of all 3-letter words in comparing two separate strings of unequal length?
by baxy77bax (Deacon) on May 13, 2012 at 11:06 UTC
    Ok, so if i understood you correctly you have two problems here:
    1. You need to know which codons are homologous and which are not. Is that correct ??
    2. After you figure out the first you wish to know where are the changes within the proper reading frame ???

    Are my assumptions correct ?? Or the sequences are already aligned and you just wish to count the differences ?

    In both cases, when alignment is done to count the diff you just iterate through both arrays count triplets, hash them and the for every triplet make a subhash that will record the type and the count of a specific change.

    Example:

    use strict; use Data::Dumper; my $r = 'AAATGTGATGTGAACGT'; my $t = 'AATGTGTCGT-TG-ATG'; my @a = split('',$r); my @v = split('',$t); my %hash =(); my $tt = @a>@v ? @a : @v; for(my $i = 0 ; $i<$tt;$i++){ my $z = 1+$i %3; # Update - suggested by Perlbotics, better ! unless ($a[$i] eq $v[$i]){ $hash{$z}->{"$a[$i]2$v[$i]"}++; } } print Dumper(\%hash);
    Result:
    $VAR1 = { '1' => { 'G2T' => 3, 'T2G' => 1, 'A2G' => 1 }, '3' => { 'G2T' => 1, 'C2A' => 1, 'T2G' => 2, 'A2T' => 1 }, '2' => { 'G2T' => 1, 'T2G' => 1, 'A2-' => 1, 'A2C' => 1, 'T2-' => 1 } };