Skip to content

Commit

Permalink
all passed
Browse files Browse the repository at this point in the history
  • Loading branch information
vahtras committed Nov 30, 2015
1 parent c46f666 commit 527fce8
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def transcribe_dna_to_rna(s):
Return string s with each letter T replaced by U.
Result is always uppercase.
"""
return None
return "".join('U' if c.upper() == 'T' else c.upper() for c in s)


def test_transcribe_dna_to_rna():
Expand All @@ -190,7 +190,8 @@ def get_complement(s):
Return the DNA complement in uppercase
(A -> T, T-> A, C -> G, G-> C).
"""
return None
pairs = {'A': 'T', 'T': 'A', 'C': 'G', 'G': 'C'}
return "".join(pairs[k.upper()] for k in s)


def test_get_complement():
Expand All @@ -205,7 +206,7 @@ def get_reverse_complement(s):
Return the reverse complement of string s
(complement reversed in order).
"""
return None
return get_complement(s)[::-1]


def test_get_reverse_complement():
Expand All @@ -219,7 +220,7 @@ def remove_substring(substring, string):
"""
Returns string with all occurrences of substring removed.
"""
return None
return string.replace(substring,'')


def test_remove_substring():
Expand All @@ -237,7 +238,12 @@ def get_position_indices(triplet, dna):
in a DNA sequence. We start counting from 0
and jump by 3 characters from one position to the next.
"""
return None
li = []
for i in range(len(dna)):
if dna[i:i+3] == triplet:
li.append(i//3)

return li


def test_get_position_indices():
Expand All @@ -256,9 +262,20 @@ def get_3mer_usage_chart(s):
The list is alphabetically sorted by the name
of the 3-mer.
"""
return None
chart = {}
for i in range(len(s)-2):
triplet = s[i:i+3]
if triplet in chart.keys():
chart[triplet] += 1
else:
chart[triplet] = 1


sorted_keys = chart.keys()
sorted_keys.sort()
return [(k, chart[k]) for k in sorted_keys]


def test_get_3mer_usage_chart():
s = 'CCGGAAGAGCTTACTTAGGAAGAA'
result = []
Expand Down Expand Up @@ -287,7 +304,9 @@ def read_column(file_name, column_number):
Reads column column_number from file file_name
and returns the values as floats in a list.
"""
return None
import numpy
data = numpy.loadtxt(file_name)
return list(data[:, column_number-1])


def test_read_column():
Expand Down Expand Up @@ -326,7 +345,14 @@ def character_statistics(file_name):
Use the isalpha() method to figure out
whether the character is in the alphabet.
"""
return None
filestring = open(file_name).read().lower()
stat = {}
for c in filestring:
if c.isalpha():
stat[c] = stat.get(c, 0) + 1
kmax = max(stat, key=stat.get)
kmin = min(stat, key=stat.get)
return (kmax, kmin)


def test_character_statistics():
Expand Down

0 comments on commit 527fce8

Please sign in to comment.