Warm up question:

What is a codon? Where do we find codons?

Write a program that takes the string below and prints the position and letter following for every letter in the string:

Example output given the string "ATCG":

Position 0 has the letter A 
Position 1 has the letter T
Position 2 has the letter C
Position 3 has the letter G

Hint: you will have to use range() and len()

In [3]:
sequence = 'AUGUUUUUGAUACUUU'
In [1]:
sequence = 'AUGUUUUUGAUACUUU'
# your code here
    

Coding warm up 2:

Using string indexing, print the word bioinformatics from the string below

In [3]:
my_string = 'I love Bioinformatics so much!'

Biology review about codons:

codon_table.png

There are four special codons: one start, and three stop. Can you point out the start and stop codons?

Where do codons go in an RNA molecule?

transcript_structure.png

Can we write a program to find the start codon in an RNA sequence?

What are the parts of the program we would need?

- Variable to store the RNA sequence

- A way to extract codons

- Variable to remember the position of the codon

- A way to check if the codon is a start codon

- Do we know a way to extract 3 letters from a string at once?

Try to write a program that will print the start codon position in this example sequence

hints: you'll need a for loop, len(), and range()

In [1]:
rna_sequence = 'AUGUUUUUGAUACUUUUAAUUUCCUUACCAACGGCUUUUGCUGUUAUAGGAGAUUUAAAGUGUACUACAGUUUCCAUUAAUGAUGUUGACACUGGUGUUCCUUCUAUUAGCACUGAUACUGUCGAUGUUACUAAUGGUUUAGGUACUUAUUAUGUUUUAGAUCGUGUGUAUUUAAAUACUACGUUGUUGCUUAAUGGUUAUUACCCUACUUCAGGUUCUACAUAUCGUAAUAUGGCACUGAAGGGAACUUUACUAUUGAGCACACUGUGGUUUAAACCACCUUUUCUUUCUGAUUUUACUAAUGG'

# your code here

Try to write a program that will print the stop codon position in this example sequence

In [2]:
rna_sequence = 'AUGUUUUUGAUACUUUUAAUUUCCUUACCAACGGCUUUUGCUGUUAUAGGAGAUUUAAAGUGUACUACAGUUUCCAUUAAUGAUGUUGACACUGGUGUUCCUUCUAUUAGCACUGAUACUGUCGAUGUUACUAAUGGUUUAGGUACUUAUUAUGUUUUAGAUCGUGUGUAUUUAAAUACUACGUUGUUGCUUAAUGGUUAUUACCCUACUUCAGGUUCUACAUAUCGUAAUAUGGCACUGAAGGGAACUUUACUAUUGAGCACACUGUGGUUUAAACCACCUUUUCUUUCUGAUUUUACUAAUGG'
stop_codon_list = ['UGA','UAA','UAG']
# your code here
        

Using the last few cells of code, write a program that stores the position of all start codon positions in the list start_codons, and all stop codon positions in the list stop_codons

In [3]:
rna_sequence = 'AUGUUUUUGAUACUUUUAAUUUCCUUACCAACGGCUUUUGCUGUUAUAGGAGAUUUAAAGUGUACUACAGUUUCCAUUAAUGAUGUUGACACUGGUGUUCCUUCUAUUAGCACUGAUACUGUCGAUGUUACUAAUGGUUUAGGUACUUAUUAUGUUUUAGAUCGUGUGUAUUUAAAUACUACGUUGUUGCUUAAUGGUUAUUACCCUACUUCAGGUUCUACAUAUCGUAAUAUGGCACUGAAGGGAACUUUACUAUUGAGCACACUGUGGUUUAAACCACCUUUUCUUUCUGAUUUUACUAAUGG'
stop_codon_list = ['UGA','UAA','UAG']
start_codons = []
stop_codons = []

# your code here

Our start codon finder is very similar to the stop codon finder

Python functions allow you to run code blocks define the python function

YOU define the Python function, and call it with different arguments

Defining a function in python:

The keyword def is used to define a function

def is followed by the name of your function, an open/close parentheses, and a colon

Just like in other python statements you must indent the next line

In [3]:
def my_new_function(): 
    print('this is a function') 

To use a function, you have to call it.

Call a function using its name and the parentheses

If the function takes arguments, you have to put them in the parentheses

If the function doesn't take arguments, nothing goes in the parentheses

In [4]:
my_new_function()
this is a function

Defining a function with arguments

You also define the order that the arguments go in

The arguments only exist inside of the function when the function executes

In [8]:
def a_new_function(first_argument, second_argument):
    print('the first argument is: ' + first_argument)
    print('the second argument is: ' + second_argument)
In [9]:
a_new_function('Cat','Dog')
the first argument is: Cat
the second argument is: Dog

What went wrong here?

In [10]:
def uh_oh():
print("did it work?")
  Input In [10]
    print("did it work?")
    ^
IndentationError: expected an indented block
In [13]:
def uh_oh()
    print("did it work?")
  Input In [13]
    def uh_oh()
               ^
SyntaxError: invalid syntax
In [15]:
def uh_oh('an_argument'):
    print("did it work?")
  Input In [15]
    def uh_oh('an_argument'):
              ^
SyntaxError: invalid syntax
In [21]:
def function_with_arguments(first, second):
    print(first + second)
function_with_arguments('python ','is cool')
print(first + second)
python is cool
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [21], in <cell line: 4>()
      2     print(first + second)
      3 function_with_arguments('python ','is cool')
----> 4 print(first + second)

NameError: name 'first' is not defined

Write a function that takes three numbers and prints their sum

Check the function by summing 3, 5, and 7

In [4]:
# your code here 

write a function that takes a number as an input and multiplies it by 4. Print the result

In [5]:
# your code here

Saving the output of a function call

Remember that variables created inside of a function stay in that function

To save the output of a function, you would put return <your variable> at the end of the function

In [27]:
def my_sum_function(one, two, three): 
    output_sum = int(one) + int(two) + int(three)
    return output_sum
output = my_sum_function(3,5,7)
print(output)
15

you can return any type of variable from a function

In [28]:
def make_a_list(one, two, three): 
    output_list = [one,two,three]
    return output_list
output = make_a_list(3,5,7)
print(output)
[3, 5, 7]

Write a function that takes a number and squares it

Save the output of the function in the variable squared_number

In [6]:
# your code here

You can call functions from inside other functions

In [54]:
def print_sum(statement):
    print("the sum of the numbers is: " + str(statement))
def calculate_sum(number_one, number_two): 
    my_sum = number_one + number_two
    print_sum(my_sum)
calculate_sum(6,10)
the sum of the numbers is: 16

Write a function that squares a number

Write a function that divides a number by 3

Using those two functions, write a function that takes a number, squares it, and divides the output by three

If you input the number 912, what is the output?

In [7]:
# your code here

Great! you're an expert in functions now.

Challenge: Write a function that takes a string input and prints all of the start and stop codons in the string.

(You can use a lot of the code you wrote above)

In [9]:
# your code here