Here is what I've come up with:
use strict; use warnings; my $str1 = "LTIEAVPSNAAEGKEVLLLVHNLPQDPRGYNWYKGETVDANRRIIGYVISNQQITPGP +AYSNRETIYPNASLLMRNVTRNDTGSYTLQVIKLNLMSEEVTGQ-FSVHPETPKPSISSNNSNPVEDKD +AVAFTCEPETQNTTYLWWVNGQSLPVSP"; my $str2 = "PTISPSYTYYRPGVNLSLSCHAASNPPAQYSWLIDGNIQQHTQE-------------- +-------------LFISNITEKNSGLYTCQANNSASGHSRTTVKTITVSAELPKPSISSNNSKPVEDKD +AVAFTCEPEAQNTTYLWWVNGQSLPVSP"; my %hash; my @a = split('',$str1); my @b = split('',$str2); my $a_index = 36; #Start counting at residue number my $b_index = 206; for my $i (0 .. $#b) { #Loop through arrays if ($b[$i] eq "-") { #Check for a gap in str2, if so increment a_i +ndex and go to the next residue $a_index++; next; } if ($a[$i] eq "-") { #Check for a gap in str1, if so store the gap + in the hash without a residue #, increment b_index, and go to the ne +xt residue $hash{$b[$i].$b_index}=$a[$i]; $b_index++; next; } $hash{$b[$i].$b_index}=$a[$i].$a_index; #Else store residue pair i +n hash $b_index++; $a_index++; } print "value of N254 is $hash{'N254'}\n"; print "value of I255 is $hash{'I255'}\n"; print "value of K280 is $hash{'K280'}\n"; print "value of T281 is $hash{'T281'}\n"; print "value of I282 is $hash{'I282'}\n";
Which prints:
value of N254 is N111
value of I255 is V112
value of K280 is Q137
value of T281 is -
value of I282 is F138
It seems to be working OK, but now I need to run this on thousands of alignments for an arbitrary number of residues per alignment. If you see any room for improvement or optimization, or errors, please let me know. Thanks again for the help!

In reply to Re: Per residue sequence alignment - per character string comparison? by proteins
in thread Per residue sequence alignment - per character string comparison? by proteins

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.