Michael S. Robeson II wrote:
I have two sets of data that have been stored in hashes. The first
hash has amino-acid (protein) sequence data. The second hash has
the corresponding DNA sequence of those amino-acids:
Hash 1
key: value:
cat = mfgdhf
doq = mfg--f
mouse = mf-d-f
Hash 2
key: value:
cat = agtcatgcacactgatcg
dog = agtcatgcatcg
mouse = agtcatcactcg
And I need to insert gaps (missing or absent data) proportionally
into the DNA sequence (Hash 2) so that the output is as follows:
Hash 3
key: value:
cat = agtcatgcacactgatcg
dog = agtcatgca------tcg
mouse = agtca---tca---ctcg
It doesn't look right here, but all the lines should end up being
the same length with courier font. Basically, I am having trouble
scanning though, say... hash1{cat} and for every dash found there
being finally represented as three dashes in hash2{cat}. Also,
every amino-acid is represented by 3 DNA letters. This is why I
need to move in increments of 3 and add in increments of 3 for my
final data to appear as it does in Hash 3.
Shifting from temporary arrays is one possibility:
my %hash3;
for ( keys %hash1 ) {
my @tmp1 = split //, $hash1{$_};
my @tmp2 = $hash2{$_} =~ /.../g;
while ( my $aa = shift @tmp1 ) {
$hash3{$_} .= $aa eq '-' ? '---' : shift @tmp2;
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>