Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 193495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:30:55+00:00 2026-05-11T16:30:55+00:00

I have written the following script to search for a motif(substring) in a protein

  • 0

I have written the following script to search for a motif(substring) in a protein sequences(strings). I am beginner and writing this has been tough for me. I have two questions regarding the same:
1. Errors: The following script has few errors. I have been at it for quite sometime now but have not figured out what and why?
2. The following script has been written to search for one motif(substring) in protein sequences(strings). My next task involves searching for multiple motifs in a specific order (ex: motif1 motif2 motif 3 motif4 this order cannot be changed) in the same protein sequences(strings)

        use strict;
        use warnings;

        my @file_data=();
        my $motif ='';
        my $protein_seq='';
        my $h= '[VLIM]';   
        my $s= '[AG]';
        my $x= '[ARNDCEQGHILKMFPSTWYV]';
        my $regexp = "($h){4}D($x){4}D"; #motif to be searched is hhhhDxxxxD
        my @locations=();

        @file_data= get_file_data("seq.txt");

        $protein_seq= extract_sequence(@file_data); 

    #searching for a motif hhhhDxxxxD in each protein sequence in the give file

        foreach my $line(@file_data){
        if ($motif=~ /$regexp/){
        print "found motif \n\n";
        }
        else {
        print "not found \n\n";
        }
        }
#recording the location/position of motif to be outputed

        @locations= match_position($regexp,$seq);
        if (@locations){ 
        print "Searching for motifs $regexp \n";
        print "Catalytic site is at location:\n";
        }
        else{
        print "motif not found \n\n";
        }
        exit;

        sub get_file_data{
        my ($filename)=@_;
        use strict;
        use warnings;
        my $sequence='';

        foreach my $line(@file_data){

        if ($line=~ /^\s*$/){
        next;
                }
        elsif ($line=~ /^\s*#/){
        next;
        }
        elsif ($line=~ /^>/){
        next;
        }
        else {
        $sequence.=$line;
        }
        }
        $sequence=~ s/\s//g;
        return $sequence;
        }

        sub(match_positions) {
        my ($regexp, $sequence)=@_;
        use strict;
        my @position=();
        while ($sequence=~ /$regexp/ig){
        push (@position, $-[0]);
        }
        return @position;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:30:55+00:00Added an answer on May 11, 2026 at 4:30 pm
    1. First of all, the keyword is elsif, second of all you don’t need it. You can compress the code in the get_file_data loop to:

      next if $line =~ /^\s*$|^>/; 
      $sequence .= $line;
      

      As long as you’re going to use regular expressions — unless too unwieldy — you might as well search for all the cases that you want to ignore. If you find that actual second case, you can add it as an another alternation. Say you wanted to exclude lines that begin with #-. Then you would just add it in like so: /^\s*$|^>|^#-/

    2. Another thing is that my position=(); needs to have the @ sigil, before position, or otherwise, perl thinks you’re trying to something tricky with a call to position().

    3. You need the following changes:

       my $h= '[VLIM]';   
       my $s= '[AG]';
       my $x= '[ARNDCEQGHILKMFPSTWYV]';
      

      Otherwise, you’re just assigning to $h to an array reference with a single slot populated by whatever would be returned from the sub VLIM.

    4. Third, don’t use $&. Replace pos($sequence)-length($&)+1

      push @positions, $-[0];
      

      or better yet, use English:

      use English qw<-no_match_vars>;
      ...
      push @positions, $LAST_MATCH_START[0];
      
    5. I would suggest the following for the file reading:

      use IO::File;
      ...
      # Use real file handles
      my $fh = IO::File->new( "<seq.txt" );
      get_file_data( $fh ); # They can be passed
      ...
      sub get_file_data{
          my $file_handle = shift; 
          ...
          # while loop conserves resources
          while ( my $line = <$file_handle> ) { 
              next if $line =~ /^\s*$|^>/;
              $sequence .= $line;
          } 
      
    6. A suggestion for going forward — it helps me immensely:

      A. Install Smart::Comments

      B. Put this at the top of your script:

       use Smart::Comments;
      

      C. Every time you’re not sure what you’ve got so far, like if you wanted to see the current contents of $sequence, place the following in the code:

      ### $sequence
      exit 0;
      

      just show it and exit. When you get too many printouts, delete them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am an absolute beginner in this field. I have written the following code
I have written a Perl script for the following bioinformatics question, but unfortunately there
related (sort of) to this question. I have written a script that will loop
I have written the following Perl script- use HTML::TreeBuilder; my $html = HTML::TreeBuilder->new_from_content(<<END_HTML); <span
I have the following situation: There is a windows folder that has been mounted
I have written the following script. It opens a file, reads each line from
I have found the following script which is apparently written using the javascript framework
I have written following script in python which works fine: from sys import argv
I have written the following script to get the value of hidden field to
I'm running Cygwin on WinXP. I have written the following shell script to copy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.