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)


In reply to Re: Finding DNA string mismatches by Ovid
in thread Finding DNA string mismatches by Anonymous Monk

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.