CS 4950 Spring 2017
Lab 7
Find a computer and log into the
OSX side using your CS login name and password.
Open Firefox and find the class web
page.
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:
- 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
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
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
code
Now we want to write a python program called aminoacid.py
Your name and the date and "Lab 7" should be included in
comments near the top of the file.
Your program should:
- Open aminoacid_table.txt
for reading.
- Open aminoacid.out
for writing.
- Use a for loop to go through aminoacid_table.txt one line at a
time.
- For each line use a regular expression to get the single
letter representing the amino acid and the corresponding
molecular weight.
- 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.
Eg. **AminoDict
- Write a the dictionary to the output file. Hint: you will need to use convert it to a
string: str(AminoDict)
- Write "the average molecular weight is:" followed by the
result of your computation to the output file.
Note that you will want to develop this
program incrementally, for example:
- Make sure files are opening, reading
and writing.
- Make sure your regular expression is
working.
- Make sure your dictionary is
populating properly.
We will discuss this in class and have
more lab time to work on this.
Viewing HTML Source on
different browsers
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 >
Advanced.
- Check "Show Develop menu in menu bar".
- Close the Preferences window.
- Go to the Develop menu > Show Page
Source.
ccm.net/faq/33026-safari-view-the-source-code-of-a-webpage
For Chrome: View -> Developer -> View
Source
For Firefox: Command-u
Turn it in:
Go to the CS Homework Submission System: https://www.cs.csustan.edu/cshomework/
Choose: instructor Martin
Spring 2017
CS4950
Lab7
Upload the your aminoacid.py
and aminoacid.out files
as prompted.