Join for Free!
122499 members

table of contents table of contents

Home » Biology Articles » Bioinformatics » Introductory Workbook on Perl for Biology Students » 11. Retrieving protein sequences and locating motifs

11. Retrieving protein sequences and locating motifs
- Introductory Workbook on Perl for Biology Students

This program demonstrates of how to find motifs within a protein sequence. We first give the protein file name in line 3. We then check if the file exists by using the “Unless” command. The command does a particular operation unless the condition provided is true. That is if the condition is true it does not do the operation (in this case the print statement in line 5 will not be executed). If the condition is false it does the operation.


Once the file is ready, the contents of the file is read and stored in the array variable @protein. We then use chomp to remove the enter characters and use join to create one complete string. Now we have one big string of protein. We ask the user to enter a motif, so that we can search if the particular motif is present in the string or not. We chomp the user’s input and then use the “if” condition to see if the user’s motif is present in $protein. If it is present it print “I found it” else it prints “I couldn’t find it”. All this is put in a “do until” loop, which is from line 14 to 24. We have put it in a loop because the program keeps requesting the user to enter inputs after having finished with the previous one. When the user enters a space or simply hits the enter button, the condition in the “until” statement becomes true and hence the loop breaks.



  1. #retrieving protein seq
  2. #print"please type the filename of the protein sequence data:";
  3. $proteinfilename="prot.prot";
  4. unless (open(FILE,$proteinfilename)){
  5. print"cannot open file $proteinfilename\n";
  6. exit;
  7. }
  8. @protein=<FILE>;
  9. closeFILE;
  10. chomp(@protein);
  11. $protein=join('',@protein);
  12. print"protein:$protein\n";
  13. #location of motifs
  14. do{
  15. print"enter a motif to search for:\n";
  16. $motif=<STDIN>;
  17. chomp($motif);
  18. #Look for the motif
  19. if($protein=~/$motif/){
  20. print"I found it!\n\n";
  21. }else {
  22. print"I couldn\'t find it:\n\n";
  23. }
  24. }until ($motif=~/^\s*$/);
  25. exit;





enter a motif to search for:


I couldn't find it:


enter a motif to search for:


I found it!


enter a motif to search for:

rating: 3.70 from 116 votes | updated on: 30 Jan 2009 | views: 127220 |

Rate article: