egorleg has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I have a task as part of a bioinformatics course. I need to search within a FASTA file for a motif. below is the code i have so far but it won't work. error says,
syntax error at motif_finder.pl line 18, near ") {" Execution of motif_finder.pl aborted due to compilation errors.

(that;s just where the while loop begins)

Another task is to not only find a motif but to report the title for each line in which it is found. If you could help me out here I'd appreciate it. can't figure out what's causing the error message. Here's the code
#!/usr/bin/perl use warnings; use strict; my $motif; my $fastaseq; my $filename; my $line; print "Please enter the name of the file containing the DNA sequence d +ata: "; $filename = <STDIN>; chomp $filename; open (DNAFILE, $filename) || die "Cannot open file\n" while (<DNAFILE>) { if ($line =~ m/^>/) { next; } else { $fastaseq .= $line; } } close DNAFILE; $fastaseq =~ s/\s//g; print "Enter a motif to search for; "; $motif = <STDIN>; chomp $motif; if ($fastaseq =~ /$motif/) { print "Motif found\n\n"; } else { print "Motif was not found\n\n"; } }

Replies are listed 'Best First'.
Re: How do i write code for searching motifs in a FASTA file?
by johngg (Canon) on Nov 22, 2010 at 20:54 UTC

    At first glance you are missing a semi-colon at the end of your open ... line.

    Cheers,

    JohnGG

      Hi JohnGG Thanks for the feedback. I got it to work with the changes you suggested. btw have you any idea how to return the title line of a fasta file for each line the motif is found? thanks

        Sadly, I have no idea as I'm not in the bio-informatics line. Hopefully, the links provided by Sinistral and umasuresh will provide some answers.

        Cheers,

        JohnGG

Re: How do i write code for searching motifs in a FASTA file?
by Sinistral (Monsignor) on Nov 22, 2010 at 21:35 UTC
Re: How do i write code for searching motifs in a FASTA file?
by umasuresh (Hermit) on Nov 22, 2010 at 22:30 UTC