[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] All possible DNA sequences that are 5-7 bases long
Enjoy, :)
j
#!/usr/bin/perl
# http://www.perl.com/pub/a/2005/06/16/iterators.html
# {slightly modified by jhannah 20081124)
my @DNA = qw/A C T G/;
my $seq = gen_permutate(5, 7, @DNA);
while ( my $strand = $seq->() ) {
print "$strand\n";
}
sub gen_permutate {
my ($min, $max, @list) = @_;
my @curr = (0) x $min;
return sub {
if ( (join '', map { $list[ $_ ] } @curr) eq $list[ -1 ] x @curr )
{
@curr = (0) x (@curr + 1);
}
else {
my $pos = @curr;
while ( --$pos > -1 ) {
++$curr[ $pos ], last if $curr[ $pos ] < $#list;
$curr[ $pos ] = 0;
}
}
return undef if @curr > $max;
return join '', map { $list[ $_ ] } @curr;
};
}