Hi Perlmonks,
I am a beginner in perl programming. I have two strings of unequal sizes (15 & 12 letters)
i.e. $a="AGAGATATTCAAATT"; and $b="TCGAACGTCGAG"; In comparing the two given strings $a and $b,
I am interested to count the types of changes (A to T i.e. A2T, G2A, A2G etc.) for 1st, 2nd and 3rd positions
of all 3-letter words between two strings. Use of hash and dumper together appears very complicated to me.
I donot know which perl code I should use
in such counting. Since the two strings are small, one can do it manually. I wish if perl code could
do the same task then it can be used in comparing two strings as long as 100 letters (which is difficult
to do manually). May I expect to get help from Perlmonks in counting the types of changes between two
strings?
#!/usr/bin/perl-w
use strict;
use Data::Dump qw[ pp ];
my $a="AGAGATATTCAAATT";
my $b="TCGAACGTCGAG";
my (%first,%second,%third);
my @trilet1 = $a =~ /.../g;
my @trilet2 = $b =~ /.../g;
use Data::Dump qw[ pp ];
Code?????
for my $p ( 0 .. length( $seq1 ) - 1 ) {
my $c1 = substr $seq1, $p, 1;
my $c2 = substr $seq2, $p, 1;
next if $c1 eq $c2;
++$subs{ $c1 . '2' . $c2 };
}
pp \%first,%second, %third;
exit;
<p>The result should look like:</p>
<code>Counting Results:
{ For 1st position of all 3-letter words:
A2T=> 1,
G2A=> 1,
A2G=> 1,
C2G=> 1,
For 2nd position of all 3-letter words:
G2C=> 1,
For 3rd position of all 3-letter words:
A2G=> 2,
T2C=> 2,
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.