Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Finding DNA string mismatches

by Ovid (Cardinal)
on Apr 22, 2003 at 15:21 UTC ( #252283=note: print w/replies, xml ) Need Help??


in reply to Finding DNA string mismatches

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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://252283]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2023-02-08 04:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?