in reply to substr help
my $dna = 'accatgagctgtacgtagcatctgagcgcgcatgactgtgactgacgtaggcagca'; my $increment = 3; my @windows; for ( my $loc=0; $loc <= (length($dna)-10); $loc+=$increment ){ push @windows, substr($dna, $loc, 10); } print "$_\n" for @windows;
If you have multiple $dna sequences you'll probably want an outer loop to iterate over an array holding them. Otherwise, this code ought to do what you're looking for.
It's one of the few instances where I would actually use a C-style 'for' loop.
You could also do it with a regexp.
Update: Replaced (length($dna)-$increment) with (length($dna)-10) per duff's comment. Good catch!
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: substr help
by duff (Parson) on May 12, 2004 at 16:11 UTC | |
|
Re: Re: substr help
by ysth (Canon) on May 12, 2004 at 18:05 UTC |