Introduction to Bioinformatics

Introduction to Perl

Turning Your Pseudocode into Something the Computer Understands


Prep readings:

In this assignment, we wish to:


Testing Your Perl Installation

You are free to work on your Perl programming assignments from the computer laboratories in Buildings 58/58A, or from your home computer using a remote login to eDesktop. Once you are sitting at a machine with Perl, your first goal is to get comfortable with testing a simple program, such as a program which prints a message or two to the screen. Here are the steps for doing this with the test.pl file provided above:

  1. First, save the test.pl file to your computer.

  2. Now, open the file in Notepad and carefully read through it. Notice that in Notepad, you can go to a particular line number using the Edit-Go To menu. Try this option now. (This will be important later when you need to fix syntax errors that occur on a particular line number.)
  3. Next, open an MS-DOS prompt (also known as a Command Prompt) window. There are several methods for doing this. In earlier versions of Windows, you can usually locate the MS-DOS prompt application off of the Start-Programs menus. In newer versions of Windows, you might try the sequence Start-Programs-Accessories-Command Prompt. If all else fails, search your computer for files/folders with the name "MS-DOS" or "Command Prompt". (If you are a Mac user, please e-mail me with the name/location of the corresponding tool on that platform.)
  4. In the MS-DOS/Command prompt window, change into the directory where you stored the test.pl file.

  5. Once you are in the subdirectory where you stored the test.pl file, type the
    dir
    command to confirm that the test.pl file is there.
  6. Now, issue the command
    perl test.pl
    in the MS-DOS/Command prompt window to interpret/compile and run the Perl program in the file test.pl. If you are successful, you should see two messages displayed on the screen, as described in the comments of the test.pl file.
  7. Next, edit the test.pl file and remove one of the semicolons in the print statements. What happens when you now try to run the program? Note the line numbers indicated in any error messages. Use Notepad to find these line numbers and fix the indicated error. Run the program again to make sure it still works.
  8. Finally, edit the test.pl file with Notepad so that the welcome message includes your first and last names. Save the file and run the new program to make sure it still works with the modified message.

Turning Pseudocode into Perl Source Code

In class we developed pseudocode and a rough flowchart for the design of a program to count the number of vowels in a word provided by the user. Locate and review your class notes on this. Our next step is to start thinking about how to turn our pseudocode into Perl code that we can execute. Let's begin by considering the major steps of the algorithm we developed in class:

  1. Obtain input word from the user
  2. Count the number of vowels in input word
  3. Display final vowel count results
Steps 1 and 3 are the easiest to implement, so I suggest you start with a program to do just these steps. This goes along with the idea of coding around five lines of code at a time, in an Edit-Run-Revise (and Save) cycle. This helps you to make progress on an assignment, and build your confidence. So let's begin:
  1. Save the file vowels1.pl to your directory of Perl programs. Open the file in Notepad and read through it. Carefully consider these questions:
  2. Now, open an MS-DOS/Command Prompt window and run the program. What results do you get? How informative is the program in telling you what the program does, what input to enter, what output to expect, etc.?
  3. Now, try uncommenting some of the lines of code in the section of the program labeled with a NOTE comment. For example, uncomment the line:
    $vowel_count = 0;
    Rerun the program. What happens?
  4. Uncomment the remainder of the code in this section (from the start to the end of the for loop). Rerun the program. What happens now?

Think, think, think

If all goes well in the steps above, you just executed a non-trivial Perl program. Congrats! Now, think carefully:

The sequence of steps you have just followed mimics the way most good programmers develop a computer program. They typically begin with pseudocode (and possibly a flowchart), and start creating Perl code from that, one or two lines of code at a time. Some programmers polish their code up as they go along, while others get chunks of the functionality working, and then tidy it up before moving on to the next chunk. Either method works, as long as you aren't saving the clean up/tidy up to the end - that's essentially wasted energy and makes debugging your code very time-consuming. You will develop your own style of programming as you proceed through this class, but I encourage you to develop good habits now (good readability, reuse, reuse, reuse, and a great user interface) - you will reap many rewards along the way if you do!
Possible Problems and Solutions


Getting Credit for Your Progress

To get credit for this assignment, you need to complete three additional steps:

  1. Create a Perl program called nucleotide-counting1.pl which counts and displays the number of instances of the letters: A, C, G, and T in a user-provided sequence of letters. Provide output counts of each of these letters. Your program should be insensitive to case (i.e., it should be able to process uppercase and lowercase letters in the same manner). Your program should be well-written and user friendly, using the guidelines provided here and in class.
  2. Include a link to your new Perl program on your course Webpage, under a heading titled, "Lab: Counting Nucleotides."

Congratulations! You just made it through your second assignment! Feel free to check out how the other students in the class did on this assignment.
These pages are optimized for viewing under Netscape.
© Copyright 2003. Melanie A. Sutton, Ph.D. (msutton@uwf.edu) All rights reserved.