Dear Fellow Monks,
Suppose I have a string ($str) and also the number
of maximum mismatch position is given ($d).
$str = 'TTTCGG'; # (length 6)
$d = 2;
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].
I already have a brute-force way to do it. That
is to pre-generate as many as 4^l, all the strings of length $l, and then find the neighbours from there.
But this way is way too time consuming to do it.
Since there are many many strings to test. And also
the length of the string is around 12-20 characters.
Can anybody advice what's the best way to go about it?
The script that does brute-force way is this:
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 ] );
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|