monkfan has asked for the wisdom of the Perl Monks concerning the following question:
What I intend to do is to find all the string of of length 6 that has maximum Hamming Distance (number of mismatches) is less or equal to $d. These strings are constructed with bases [ATCG].$str = 'TTTCGG'; # (length 6) $d = 2;
use strict; use warnings; use Data::Dumper; my $l = 6; #Motif Length my $d = 2; my $str = 'TTTCGG'; my @nucs = qw/A T C G/; my @enum = enum( $l, \@nucs ); foreach my $oligo ( @enum ) { if ( hd ($oligo,$str) <= $d ) { print "$oligo\n"; } } sub hd { return ( $_[0] ^ $_[1] ) =~ tr/\001-\255//; } sub enum { return @{ $_[1] } unless --$_[0]; map { my $nuc = $_; map { $nuc . $_ } @{ $_[1] } } enum( $_[0], $_[ 1 ] ); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding Neighbours of a String
by Aristotle (Chancellor) on Mar 01, 2006 at 10:04 UTC | |
by monkfan (Curate) on Mar 01, 2006 at 11:25 UTC | |
by Aristotle (Chancellor) on Mar 01, 2006 at 11:57 UTC | |
by monkfan (Curate) on Mar 02, 2006 at 09:25 UTC | |
by Aristotle (Chancellor) on Mar 03, 2006 at 20:15 UTC | |
by Aristotle (Chancellor) on Mar 01, 2006 at 11:35 UTC | |
by monkfan (Curate) on Mar 01, 2006 at 11:41 UTC | |
Re: Finding Neighbours of a String
by inman (Curate) on Mar 01, 2006 at 11:35 UTC | |
by Aristotle (Chancellor) on Mar 01, 2006 at 11:44 UTC | |
by inman (Curate) on Mar 01, 2006 at 12:31 UTC | |
by Aristotle (Chancellor) on Mar 01, 2006 at 14:57 UTC |