cool
nkuipers
nkuipers at uvic.ca
Mon Feb 3 14:58:04 CST 2003
I played around in recursion a bit, wanting to get the practice but also to do
something useful. So I framed it to myself as an exercise. This was my first
idea:
#!/usr/bin/perl
use strict;
use warnings;
=pod
write a recursive function that generates a random DNA sequence of length N
=cut
sub makeDNA {
my $n = shift;
my @alphabet = qw( A C G T);
if ($lengthRemaining == 0)
{
return;
}
print $alphabet[int(rand(4))];
makeDNA($n - 1);
}
makeDNA(10);
print "\n";
This could develop into a small host of other recursive, random
functionalities useful for bioinformatics, such as taking a sequence and
randomly mutating n residues. I will be incorporating above subroutine and
possibly others in my BIO::Basic module.
Cheers,
Nathanael Kuipers
More information about the Victoria-pm
mailing list