Exercise 6 -1

advertisement
Exercise 6 -1 The file src/files/constants.txt5 contains a table of the values and the dimensions of some
fundamental constants from physics. We want to load this table into a dictionary constants, where the
keys arethe names of the constants. For example, constants[’gravitational constant’] holds the value of
the gravitational constant (6.67259 · 10−11) in Newton’s law of gravitation. Make a function that reads
and interprets the text in the file, and finally returns the dictionary. Filename:
fundamental_constants.py.
Exercise 6-5 Based on the stars data in Exercise 3.33, make a dictionary where the keys contain the
names of the stars and the values correspond to the luminosity. Filename: stars_data_dict1.py.
Exercise 6.17: Make a function more robust Consider the function get_base_counts(dna) from Section
6.5.3, which counts how many times A, C, G, and T appears in the string dna:
Function
def get_base_counts(dna):
counts = {’A’: 0, ’T’: 0, ’G’: 0, ’C’: 0} for base in dna:
counts[base] += 1
return counts
Unfortunately, this function crashes if other letters appear in dna. Write an enhanced function
get_base_counts2 which solves this problem. Test it on a string like ’ADLSTTLLD’. Filename:
get_base_counts2.py.
Exercise 6-6 The file src/files/human_evolution.txt6 holds information about various human species and
their height, weight, and brain volume. Make a program that reads this file and stores the tabular data
in a nested dictionary humans. The keys in humans correspond to the specie name (e.g., homo erectus),
and the values are dictionaries with keys for height, weight, brain volume, and when (the latter for when
the specie lived). For example, humans[’homo neanderthalensis’][’mass’] should equal ’55-70’. Let the
program write out the humans dictionary in a nice tabular form similar to that in the file. Filename:
humans.py.
Exercise 6.18: Find proportion of bases inside/outside exons Consider the lactase gene as described in
Sections 6.5.4 and 6.5.5. What is the proportion of base A inside and outside exons of the lactase gene?
Hint. Write a function get_exons, which returns all the substrings of the exon regions concatenated. Also
write a function get_introns, which returns all the substrings between the exon regions concatenated.
The function get_base_frequencies from Section 6.5.3 can then be used to analyze the frequencies of
bases A, C, G, and T in the two strings. Filename: prop_A_exons.py.
5 http://tinyurl.com/pwyasaa/files/constants.txt
6 http://tinyurl.com/pwyasaa/files/human_evolution.txt
Langtangen, Hans Petter (2014-08-01). A Primer on Scientific Programming with Python (Texts in
Computational Science and Engineering) (Page 371). Springer Berlin Heidelberg. Kindle Edition.
-------------------------------------------------------------------Final Exercise
A secret message has been hidden in the homework page for this course. To access it, you must search
the HTML that creates the homework page for the course for lines containing the HTML comment
character “<!—“ and the string “PHY396”. The message may be found by breaking the strings that make
up these lines up into words and saving the strings that appear between successive appearances of
PHY396.
Write a program that accesses the homework page online and extracts the secret message.
Download