in reply to How to find any of many motifs?

Using a BioPerl module to parse sequences files lifts away the burden of having to manually detect what constitutes a sequence start and end for many of the available formats, also, it takes care of handling the sequence objects and IO tasks efficiently and succinctly.

While learning Perl, make sure you are learning it the right way by building on the good habits that would at the end lead you to becoming an established hacker, great emphasis is there to always

use strict; use warnings;
At the top of your programs, these stricture would enable you to save time debugging by giving you warnings about potential pitfalls and enforcing rules like "variable localization and scoping", that would really save you from a lot of errors. Also, make sure that your variables are named in a self-descriptive fashion and that your code is indented in a readable way.

Here is how you can perform the same job by using the library Bio::SeqIO from the BioPerl suite.

use strict; use warnings; use Bio::SeqIO; my $seq_file = 'D:/Motif Search/sequence.txt'; my $mot_file = 'D:/Motif Search/motif.txt'; my $in = Bio::SeqIO->new( #sequences object -format => 'fasta', -file => $seq_file, ); my $mot = Bio::SeqIO->new( #motifs object -format => 'fasta', -file => $mot_file ); my @motifs; while ( my $motif = $mot->next_seq ) { #read in motifs my $motif_string = $motif->seq; #stringify motifs push @motifs, $motif_string; } while ( my $seq = $in->next_seq ) { my $string = $seq->seq; foreach my $motif (@motifs) { if ( $string =~ /$motif([agct]+)[AGCT]/ ) { print "'$motif' ", length $1, " bases away at ", $seq->id, "\n"; } } }

Have a great Perl journey ...

Excellence is an Endeavor of Persistence. A Year-Old Monk :D .