In [1]:
%matplotlib inline
1. (25 points) A Caesar cipher is a very simple method of encoding and decoding data. The cipher simply replaces characters with the character offset by $k$ places. For example, if the offset is 3, we replace a
with d
, b
with e
etc. The cipher wraps around so we replace y
with b
, z
with c
and so on. Punctuation, spaces and numbers are left unchanged. Note that we don't need a decode function - we can just use a negative offset to reverse the encoding.
encode(s, k)
where s
is the string to be enoded and k
is the offset. Check that you can encode If you think Python is hell, try writing this function in R!
with offset 10 as
Sp iye drsxu Zidryx sc rovv, dbi gbsdsxq drsc pexmdsyx sx B!
and make sure you can recover the original string with offset -10.
Hint: Use the following
chr
ord
string.ascii_uppercase
string.ascii_lowercase
str.maketrans
str.translate
dictionaries
In [2]:
# Your solution here
2. (50 points)
ecoli.fas
into a string variable containing only the sequence data with no header information or line breaks. The string should start with agcttttca
and be 4639675 characters long. (5 points)
In [6]:
# Your solution here
3. (25 points) Read in the text of Ulysses by James Joyce from the file 'Ulysses.txt
.
Find the 10 most frequently used words that begin with the letter 'u' in the full text using a generator to read in only one line at a time (this is essential when dealing with huge text files that may otherwise run out of memory).
Note: punctuation is any character in string.punctuation from the string
package
In [12]:
# Your solution here