python test
class DNAAnalyser:
REPORT_MAPPING_FILENAME = 'codon.tsv'
def __init__(self):
pass
@staticmethod
def clean_strands(filename):
"""
TODO(Part 1): Complete this method
"""
cleaned_list = []
offset_list = ["A", "T", "G", "C"]
with open(filename, "r") as readtsv:
lines = readtsv.readlines()
for line in lines:
if 10 < len(line) < 100 and line:
flag = 0
for letter in line:
if letter not in offset_list:
flag = 1
if flag == 1:
cleaned_list.append(line)
if len(cleaned_list) < 3:
return []
else:
return cleaned_list
def create_strands(self, cleaned_list):
"""
TODO(Part 2): Complete this method
"""
result = ''
if not cleaned_list:
return result
ptr = 0
first_str = cleaned_list[ptr]
second_str = ""
while cleaned_list:
for curr_str in cleaned_list:
if curr_str == first_str:
continue
elif first_str[-3: ] == curr_str[0: 4]:
second_str = curr_str
if second_str != "":
if result == '':
result += first_str + second_str[3:]
cleaned_list.remove(first_str)
cleaned_list.remove(second_str)
first_str = second_str
second_str = ""
else:
result += second_str[3:]
cleaned_list.remove(first_str)
cleaned_list.remove(second_str)
first_str = second_str
second_str = ""
else:
ptr += 1
first_str = cleaned_list[ptr]
return result
def get_amino_acids_report(self, dna_sequence):
"""
TODO(Part 3): Complete this method
"""
import csv
report = {}
file_contents = {}
with open("codon.tsv", "rb") as tsv_file:
tsvin = csv.reader(tsv_file, delimiter='\t')
for row in tsvin:
file_contents[row[0]] = row[1]
if not dna_sequence:
return report
itr = 0
while itr <= len(dna_sequence) - 4:
amin_key = dna_sequence[ itr : itr + 4 ]
report_key = file_contents[amin_key]
val_count = report.get(report_key, 0)
report[report_key] = val_count + 1
itr = itr + 4
return report