User Tools

Site Tools


script:ex10

Exercise 10 Code

exercise10.py
'''
10d) Write a function, nt_content(seq), that returns the
numbers of As, Cs, Gs, and Ts in a DNA sequence as a tuple.
Outside the function, your code should print the results,
for example: A: 5 C: 7 G: 6 T: 3
'''
 
def nt_content(seq):
    return seq.count('A'), seq.count('C'), seq.count('G'), seq.count('T')
 
a,c,g,t = nt_content('AAACCCGGGGT')
 
print("A: " +  str(a))
print("C: " +  str(c))
print("G: " +  str(g))
print("T: " +  str(t))
 
 
'''
10e) Using list comprehensions, reverse complement a list of
sequences such as the one below.
 
sequences = ['ATATGCTACCCCC',
	     'GGGCTAGCTGAGCAAA',
	     'CCATGCATGCATCGGG',
	     'TTTTTTTTACTTCA']
'''
 
rev_comps = [seq.translate(str.maketrans('ACTG', 'TGAC'))[::-1] for seq in sequences ]
rev_comps
 
 
'''
10f) Using list comprehensions, create a list of lists out
of a list of tuples, such as the one below.
 
tuples_list = [(1,2), (3,4), (5,6), (7,8)]
'''
 
list_list = [list(item) for item in tuples_list]
list_list
script/ex10.txt · Last modified: 2018/10/22 16:27 by dokuroot