Michael Robeson wrote:
Don't post MIME or HTML to the list. Plain text only.
>
> 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.
>
>
> Example of relationship:
> M F D F = amino-acid
> agt tca --- act --- tcg = dna
>
>
> I have everything else set up I just need a few suggestions on how to
> do the above. Any help will be greatly appreciated.
Here's one approach:
#!/usr/bin/perl
use strict;
while (<DATA>) {
my ($key, $mask, $src) = split;
my @mask = $mask =~ /./g;
my @src = $src =~ /.../g;
print "$key: ";
print $_ eq '-' ? '---' : shift @src for @mask;
print "\n";
}
__DATA__
cat mfgdhf agtcatgcacactgatcg
dog mfg--f agtcatgcatcg
mouse mf-d-f agtcatcactcg
Outputs:
cat: agtcatgcacactgatcg
dog: agtcatgca------tcg
mouse: agtcat---cac---tcg
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>