Practice with Subroutines and Regular Expressions in Perl

Prep readings:
- Text: Chapter 5 (all); Chapter 6 (pp. 87-99, 104-105); Appendix B
- Files:

In this assignment, we wish to:
- practice with additional Perl code for DNA/protein sequence processing
- learn how to use and write subroutines in Perl
- learn how to recognize, use, and write regular expressions
Getting More Practice
- First, begin reading the pages of Chapters 5-6 indicated above. As you encounter example code,
execute
the Perl programs provided.
- Next, download and review the two new versions of the vowel counting program
provided above. Run the programs and observe what happens.
Carefully review the files and all the commenting within them.
The program vowels5.pl provides your first example of using simple subroutines,
where there is at most one variable passed to/from a subroutine.
The program vowels6.pl provides an additional example of using subroutines,
where multiple variables are passed to/from a subroutine.
- Compare the code in both vowels5.pl and vowels6.pl to vowels4.pl from
the previous assignment.
What code in the new files adds the functionality of looping the
menu until the user chooses to exit? What code corresponds to an example of
a "subroutine call"? Similarly, what code corresponds to an example of a
"subroutine body"?
- Note that these
files show you the type of formatting and modularity that is expected
in future code you submit for this class. Consider how
modularity could clean up the code
you have already developed in your nucleotide-counting2.pl program.
What code do you tend to repeat across options that might make sense
to put into a subroutine?
Getting Credit for Your Progress
To get credit for this assignment, your program must meet several additional specifications
in a new program called nucleotide-counting3.pl, as follows:
- Your program must redisplay the menu after each menu option is acted upon, until
the user enters the option to exit the program. Test this version of your program
before you add any additional functionality.
- Your program must contain and call a subroutine to count nucleotides in the
provided sequence, and indicate the count of any errors encountered.
Again, test this version before you move on.
- Your program must contain and call a subroutine to write results to an output
file, with the name of the file provided by the user. Test your new code before
continuing to the next step.
- As you are modifying your code, make sure you make it readable.
Again, a good way to get a handle
on the overall readability of your program is to print out multiple pages on
a sheet of paper. In Notepad you can do this by selecting Print-Preferences
and then selecting 2 or 4 under "Pages Per Sheet". Click "OK", then "Print." Study
the overall structure of your program and specifically double-check that you have been
consistent with indentation.
- Next, your program must include a new menu option to search for a motif provided by the
user. This will be the new "Option 3" in your code, and a new "Option 4" will be used for exiting.
Before adding this functionality, complete these additional steps:
- Re-examine the code from Chapter 5 of your book to see what examples more
closely match your new requirement (hint: start with Example 5-3).
- Include a definition for regular expressions on your course Webpage, under the heading
"Lab: Practice with Subroutines and Regular Expressions."
- Search the Web for pages describing Perl regular expressions. Include a link to your
favorite page under this same heading.
- After reading about regular expressions, provide and explain three examples of regular
expressions under this same heading.
- Begin by adding Perl code directly into the main body of your program.
After you have the code working from within the main body, modify your code
to contain and call a subroutine to do motif searching.
- Include a link to your new Perl program on your course Webpage, under a
heading titled, "Lab: Practice with Subroutines and Regular Expressions (includes motif searching)."
- Finally, visit the opening page of PROSITE and then click
on the words "MotifScan." Review the documentation and
directions on these pages and then perform several
scans. How does the output provided by their program compare to your program?
Does this Website provide any ideas for how your program could be improved?
To get credit for this portion of the assignment,
on your course Webpage, provide a brief paragraph summarizing your experience with this site and answer these questions.
Feel free to work with other students
in the class if you struggle with any parts of the assignments. Also, bring questions to class next week, and if
we need to cover material in class and work through items together, we can!
These pages are optimized for viewing
under Netscape.
© Copyright 2003.
Melanie A. Sutton, Ph.D.
(msutton@uwf.edu)
All rights reserved.