in reply to Exact string matching
use warnings; use strict; use Data::Dumper; my %word_counts = (); my $DNA = "CGTAGATCCAGTCGA"; # set for the test code, actual dna shoul +d be parsed into a single line string with no whitespace my $cur_len = 3; #set curent word length to minimum word length my $max_len = (length $DNA) -1; #set maximum word length, set here to +avoid recalculating $DNA length for every iteration for (;$cur_len <= $max_len; $cur_len++){ #for each word length my $last_pos = (length $DNA) -$cur_len; #again, set to avoid recalc +ulating for every iteration for (my $pos = 0; $pos <= $last_pos; $pos++){ $DNA =~ m/^.{$pos}(.{$cur_len})/; $word_counts{$1}++; } } print Dumper(\%word_counts); exit;
|
|---|