Quick recap

  • Collections: Lists and String

In [ ]:
# list
my_list = [1, 4, 5, 9]
print(my_list)

In [ ]:
type(my_list)

In [ ]:
# accessing each element by index
print(my_list[2])

In [ ]:
len(my_list)

In [ ]:
# assigning new value
my_list[1] = 12
print(my_list)

In [ ]:
# append an element at the end
my_list.append(7)
print(my_list)

In [ ]:
help(list)

In [ ]:
# String
my_name = 'Anne' # it is also a tuple of characters
my_name[2]

In [ ]:
len(my_name)

In [ ]:
# sequence string separated by space
seq = 'AAA TTT CCC GGG'
print(seq.split())

In [ ]:
?str.split

In [ ]:
?str.join

In [ ]:
','.join(my_name)

Session 1.4

  • Collections Sets and dictionaries

In [ ]:
# Sets
my_set = set([1, 2, 3, 3, 3, 4])
print(my_set)

In [ ]:
len(my_set)

In [ ]:
my_set.add(3) # sets are unordered
print(my_set)

In [ ]:
my_set.remove(3)
print(my_set)

In [ ]:
# set operation using union | or intersection &
my_first_set = set([1, 2, 4, 6, 8])
my_second_set = set([8, 9, 10])
my_first_set | my_second_set

In [ ]:
my_first_set & my_second_set

Exercises 1.4.1

Given the protein sequence "MPISEPTFFEIF", find the unique amino acids in the sequence.


In [ ]:
# Dictionnaries are collections of key/value pairs
my_dict = {'A': 'Adenine', 'C': 'Cytosine', 'T': 'Thymine', 'G': 'Guanine'}
print(my_dict)

In [ ]:
my_dict['C']

In [ ]:
my_dict['N']

In [ ]:
?my_dict.get

In [ ]:
my_dict.get('N', 'unknown')

In [ ]:
print(my_dict)
len(my_dict)

In [ ]:
type(my_dict)

In [ ]:
'T' in my_dict

In [ ]:
# Assign new key/value pair
my_dict['Y'] = 'Pyrimidine'
print(my_dict)

In [ ]:
my_dict['Y'] = 'Cytosine or Thymine'
print(my_dict)

In [ ]:
del my_dict['Y']
print(my_dict)

In [ ]:
help(dict)

In [ ]:
my_dict.keys()

In [ ]:
list(my_dict.keys())

In [ ]:
my_dict.values()

In [ ]:
my_dict.items()

Exercises 1.4.2

  1. Create a codon sequence "GTT GCA CCA CAA CCG"
  2. Build a genetic code dictionary using the DNA codon table
  3. Print each codon and its correspondong amino acid

Exercise 1.4.3

Tomorrow

  • Conditional execution
  • Loops
  • Files