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 ] );
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.