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
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.use strict; use warnings;
Here is how you can perform the same job by using the library Bio::SeqIO from the BioPerl suite.
Have a great Perl journey ...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"; } } }
In reply to Re: How to find any of many motifs?
by biohisham
in thread How to find any of many motifs?
by Nikulina
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |