CS 4950 Spring 2016
Find a computer and log into the
OSX side using your CS login name and password.
Open Firefox and find the class web
Open TextWrangler - use the finder
window and go to applications.
Find the Terminal - use the finder
window and go to applications and then utilities.
Today we are going to work on the things
we learned in Chapter 10:
Let's start with the file we worked on in the last lab. Create a
file with the source code for aminoacid_table.html and call it aminoacid_table.txt
- Open a file to read or write
- Loop through each line of a file using a regular expression to
pick up data and store it
- Write a function
- Output our results to a file
- Close a file
Here is what we did to get the source code in the last lab:
We will start by writing the molecular weight program
on page 156.
The first step is to create the dictionary of molecular weights:
- find the file aminoacid_table.html in the books
examples using Finder
- drag the file to Firefox
- once it is open, use Command-u to get the source
Now we want to write a python program called aminoacid.py
Your name and the date and "Lab 6" should be included in
comments near the top of the file.
Your program should:
- Open aminoacid_table.txt
- Open aminoacid.out
- Use a for loop to go through aminoacid_table.txt one line at a
- For each line use a regular expression to get the single
letter representing the amino acid and the corresponding
- Store the letter and molecular weight in a dictionary indexed
by the letter.
- Write a function to compute the average molecular weight. Hint on passing a dictionary as a parameter
use ** in both the function definition and the call.
- Write a the dictionary to the output file. Hint: you will need to use convert it to a
- Write "the average molecular weight is:" followed by the
result of your computation to the output file.
Viewing HTML Source on
To be able to view the source code of a
webpage under Safari, you first need to enable
the Developer menu:
- Click on Safari menu > Preferences >
- Check "Show Develop menu in menu bar".
- Close the Preferences window.
- Go to the Develop menu > Show Page
For Chrome: View -> Developer -> View
For Firefox: Command-u
Turn it in:
Go to the CS Homework Submission System: https://www.cs.csustan.edu/cshomework/
Choose: instructor Martin
Upload the your aminoacid.py
and aminoacid.out files