I really wanted to solve this problem as it was rather interesting, but I couldn't figure out what you were looking for in @seg_mis, so you might want to read the node that broquaint suggested. In the meantime, here's what I whipped up. It's a bit closer, but not quite what you need. If you can show sample output for both arrays, that would help.
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
my @segments = map { [split //] } qw( ATCG AAGG );
print Dumper get_mismatches(@segments);
sub get_mismatches {
my ($segment, $comp_segment) = make_base_pairs(@_);
my @seg_mismatches;
my @seg_mis;
foreach my $i ( 0 .. $#$segment ) {
my $p1 = $segment->[$i];
my $p2 = $comp_segment->[$i];
if (
bad_pair($p1->[0],$p2->[0]) or
bad_pair($p1->[1],$p2->[1])
) {
push @seg_mismatches => sprintf "%s%s/%s%s", @$p1, @$p2;
}
}
return (\@seg_mismatches, \@seg_mis);
}
sub make_base_pairs {
my @segment = @_;
# assumes length of 4. Don't know if this is correct
my @results;
foreach my $dna (@segment) {
push @results => [ [@{$dna}[0..1]], [@{$dna}[2..3]] ];
}
return @results;
}
sub bad_pair {
my ($a,$b) = @_;
my %good_pairs = (
'A'=> 'T',
'C' => 'G',
'G' => 'C',
'T' => 'A'
);
return 1 if exists $good_pairs{$a} and $good_pairs{$a} eq $b;
}
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)