in reply to counting the number of 16384 pattern matches in a large DNA sequence

@string = <IN1>; chomp @string; foreach my $string (@string) { foreach $key (keys %seq) { chomp $string; study $seq{$key}; my @matches = ($seq{$key} =~ /$string/ig); #print "@matches\n"; $result{$string} = scalar(@matches); } foreach my $s (keys %result) { print "$s => $result{$s}\n"; }

Your current algorithm would be more efficient as:

@string = <IN1>; chomp @string; while ( my $string = <IN1> ) { chomp $string; my ( $value ) = values %seq; my $result = () = $value =~ /$string/ig; print "$string => $result\n"; }

Replies are listed 'Best First'.
Re^2: counting the number of 16384 pattern matches in a large DNA sequence
by anonym (Acolyte) on Jun 14, 2012 at 20:47 UTC

    Hey, Thanks.I modified the code above as below to iterate over each value in the %seq hash and it works pretty fast :)

    while (my $string = <IN1>) { chomp $string; #my ($value) = values %seq; foreach $value (values %seq) { my $result = () = $value =~ /$string/g; print "$string => $result\n"; } }

      still for 16384 strings it is taking a lot of time to get the count.Hmm