[Bioperl-l] K-mer generating script

Michael Eisen mbeisen at lbl.gov
Fri Dec 19 19:18:33 EST 2008


here's a quick one:

#!/usr/bin/perl
#

$k = shift;
@bases = ('A','C','G','T');

@words = @bases;

for ($i=1;$i<$k;$i++)
{
    undef @newwords;

    foreach $w (@words)
    {
         foreach $b (@bases)
         {
             push (@newwords,$w.$b);
         }
    }

    undef @words;

    @words = @newwords;
}

foreach $w (@words)
{
     print "$w\n";
}


On Dec 19, 2008, at 3:25 PM, Blanchette, Marco wrote:

> Dear all,
>
> Does anyone have a little function that I could use to generate all  
> possible k-mer DNA sequences? For instance all possible 3-mer (AAA,  
> AAT, AAC, AAG, etc...). I need something that I could input the  
> value of k and get all possible sequences...
>
> I know that it's a problem that need to use recursive programming  
> but I can't get my brain around the problem.
>
> Many thanks
>
> Marco
> --
> Marco Blanchette, Ph.D.
> Assistant Investigator
> Stowers Institute for Medical Research
> 1000 East 50th St.
>
> Kansas City, MO 64110
>
> Tel: 816-926-4071
> Cell: 816-726-8419
> Fax: 816-926-2018
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l



More information about the Bioperl-l mailing list