Commit 9e9cb382 authored by Tommy Marrinan's avatar Tommy Marrinan
Browse files

renaming

parent 47d5500f
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"# Code challenge: Interpret a DNA sequence into its amino acid sequence\n",
"\n",
"<img src=\"https://s-media-cache-ak0.pinimg.com/originals/70/0e/aa/700eaa15a8f4c8b0c8dee7dfb7058465.jpg\" width=\"300\" ALIGN=\"right\"/>\n",
"\n",
"Because DNA sequences are combinations of letters (strings!), we'll need a new coding concept called \"Methods\" which is python code for modifying string data.\n",
"\n",
"Then, you'll need to use your creativity and investigate some new functions to put it all together to work this complex problem!\n",
"\n",
"## DNA Sequence\n",
"\n",
"\n",
"GGTCAGAAAAAGCCCTCTCCATGTCTACTCACGATACATCCCTGAAAACCACTGAGGAAGTGGC\n",
"TTTTCAGATCATCTTGCTTTGCCAGTTTGGGGTTGGGACTTTTGCCAATGTATTTCTCTTTGTC\n",
"TATAATTTCTCTCCAATCTCGACTGGTTCTAAACAGAGGCCCAGACAAGTGATTTTAAGACACA\n",
"TGGCTGTGGCCAATGCCTTAACTCTCTTCCTCACTATATTTCCAAACAACATGATGACTTTTGC\n",
"TCCAATTATTCCTCAAACTGACCTCAAATGTAAATTAGAATTCTTCACTCGCCTCGTGGCAAGA\n",
"AGCACAAACTTGTGTTCAACTTGTGTTCTGAGTATCCATCAGTTTGTCACACTTGTCCTGTTAA\n",
"TTCAGGTAAAGGAATACTCAGAGCAAGTGTCACAAACATGGCAAGTTATTCTTGTTACAGTTGT\n",
"TGGTTCTTCAGTGTCTTAAATAACATCTACATTCCAATTAAGGTCACTGGTCCACAGTTAACAG\n",
"ACAATAACAATAACTCTAAAAGCAAGTTGTTCTGTTCCACTTCTGATTTCAGTGTAGGCATTGT\n",
"CTTCTTGAGGTTTGCCCATGATGCCACATTCATGAGCATCATGGTCTGGACCAGTGTCTCCATG\n",
"GTACTTCTCCTCCATAGACATTGTCAGAGAATGCAGTACATATTCACTCTCAATCAGGACCCCA\n",
"GGGGCCAAGCAGAGACCACAGCAACCCATACTATCCTGATGCTGGTAGTCACATTTGTTGGCTT\n",
"TTATCTTCTAAGTCTTATTTGTATCATCTTTTACACCTATTTTATATATTCTCATCATTCCCTG\n",
"AGGCATTGCAATGACATTTTGGTTTCGGGTTTCCCTACAATTTCTCCTTTACTGTTGACCTTCA\n",
"GAGACCCTAAGGGTCCTTGTTCTGTGTTCTTCAACTGTTGAAAGCCAGAGTCACTAAAAATGCC\n",
"AAACACAGAAGACAGCTTTGCTAATACCATTAAATACTTTATTCCATAAATATGTTTTTAAAAG\n",
"CTTGTATGAACAAGGTATGGTGCTCACTGCTATACTTATAAAAGAGTAAGGTTATAATCACTTG\n",
"TTGATATGAAAAGATTTCTGGTTGGAATCTGATTGAAACAGTGAGTTATTCACCACCCTCCATTC\n",
"\n",
"## Test DNA Sequence\n",
"\n",
"AGTCAATACGGT"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Define variable for DNA sequence\n",
"# Define variable for the shorter test DNA sequence"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Matching Base Pairs\n",
"\n",
"First, we'll need to do the transcription, which involves taking a DNA sequence and making the complementary mRNA strand by converting the base pairs. Example:\n",
"\n",
"DNAsequence \"AGTCAATGGTA\"\n",
"mRNAsequence \"UCAGUUACCAU\"\n",
"\n",
"- C's are replaced with G's\n",
"- G's are replaced with C's\n",
"- A's are replaced with U's ** (because there's no thymine in RNA, uracil fills in!) **\n",
"- T's are replaced with A's\n",
"\n",
"# Python String replace() Method\n",
"\n",
"What it does: replaces every instance of a substring you tell it to look for with something new.\n",
"What it outputs: the new string with all of the replacements.\n",
"\n",
"In this example, we've begun the transcription process by substituting the C's with G's in a short DNAsequence example. You can copy the code below and try it out to see what happens:\n",
"\n",
"DNAtranscribed_C = DNAsequence.replace('C', 'G') # Replace cytosine with guanine\n",
"print(DNAtranscribed_C)\n",
"\n",
"# Complete DNA Transcription\n",
"\n",
"Now, modify your code to transcribe the entire DNAsequence to the correct RNA complementary sequence, a variable you should name RNAsequence:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Substitute base pairs in DNA sequence to transcribe DNA to RNA"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Find the Start Codon\n",
"\n",
"There is a lot of \"junk\" in DNA ... extra amino acids that are unused. So where does the real information begin? Your program needs to start out by reading through the DNA sequence string data to find the important \"start\" codon (AUG), which tells where the real sequence begins.\n",
"\n",
"# Python String find() Method\n",
"\n",
"What it does: Determines if a certain substring is found within a string\n",
"What it outputs: Index (the position in the string) if found or -1 if otherwise\n",
"\n",
"**Remember that Python starts counting at zero!**\n",
"\n",
"Example:\n",
"\n",
"RNAsequence_test = \"AUCGAAUGUUUCGA\" #finding the start codon\n",
"start_codon = RNAsequence_test.find(\"AUG\") #index position of the test start codon\n",
"print (start_codon)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Find index position of the start codon in your RNA sequence"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"In the space below, you can work to come up with a function to translate your RNA sequence into the protein sequence. Here are some things you will need:\n",
"\n",
"# Dictionary with codons and corresponding amino acid abbreviations\n",
"\n",
"<img src=\"http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/imgorg/gencode.gif\" \"width=300\" align=\"right\"/>\n",
"\n",
" codon_aminoacid = {\"UUU\":\" PHE\", \"UUC\":\" PHE\", \"UUA\":\" LEU\", \"UUG\":\" LEU\", \n",
" \"UCU\":\" SER\", \"UCC\":\" SER\", \"UCA\":\" SER\", \"UCG\":\" SER\", \n",
" \"UAU\":\" TYR\", \"UAC\":\" TYR\", \"UAA\":\"_STOP_\", \"UAG\":\"_STOP_\", \n",
" \"UGU\":\" CYS\", \"UGC\":\" CYS\", \"UGA\":\"_STOP_\", \"UGG\":\" TRP\", \n",
" \"CUU\":\" LEU\", \"CUC\":\" LEU\", \"CUA\":\" LEU\", \"CUG\":\" LEU\",\n",
" \"CCU\":\" PRO\", \"CCC\":\" PRO\", \"CCA\":\" PRO\", \"CCG\":\" PRO\",\n",
" \"CAU\":\" HIS\", \"CAC\":\" HIS\", \"CAA\":\" GIN\", \"CAG\":\" GIN\",\n",
" \"CGU\":\" ARG\", \"CGC\":\" ARG\", \"CGA\":\" ARG\", \"CGG\":\" ARG\",\n",
" \"AUU\":\" ILE\", \"AUC\":\" ILE\", \"AUA\":\" ILE\", \"AUG\":\" MET\",\n",
" \"ACU\":\" THR\", \"ACC\":\" THR\", \"ACA\":\" THR\", \"ACG\":\" THR\",\n",
" \"AAU\":\" ASN\", \"AAC\":\" ASN\", \"AAA\":\" LYS\", \"AAG\":\" LYS\",\n",
" \"AGU\":\" SER\", \"AGC\":\" SER\", \"AGA\":\" ARG\", \"AGG\":\" ARG\",\n",
" \"GUU\":\" VAL\", \"GUC\":\" VAL\", \"GUA\":\" VAL\", \"GUG\":\" VAL\",\n",
" \"GCU\":\" ALA\", \"GCC\":\" ALA\", \"GCA\":\" ALA\", \"GCG\":\" ALA\",\n",
" \"GAU\":\" ASP\", \"GAC\":\" ASP\", \"GAA\":\" GLU\", \"GAG\":\" GLU\",\n",
" \"GGU\":\" GLY\", \"GGC\":\" GLY\", \"GGA\":\" GLY\", \"GGG\":\" GLY\"}\n",
" \n",
" # Some functions and resources to get you started\n",
" \n",
" Learn about these Python functions\n",
" - len() function https://www.tutorialspoint.com/python/list_len.htm\n",
" - int() function http://www.linuxnix.com/pfotd-python-int-function-examples/ \n",
" \n",
" - How to slice up strings\n",
" http://pythoncentral.io/how-to-get-a-substring-from-a-string-in-python-slicing-strings/"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
#! /usr/bin/env python
import time
red=[1.0, 0.0, 0.0]
green=[0.0, 1.0, 0.0]
blue=[0.0, 1.0, 0.0]
yellow=[1.0, 1.0, 0.0]
purple=[0.5, 0.0, 1.0]
orange=[1.0, 0.5, 0.0]
cyan=[0.0, 1.0, 1.0]
black=[0.0, 0.0, 0.0]
white=[1.0, 1.0, 1.0]
import sys, turtle
def mysquare(size, color=black, filled=True):
t.color(color)
if filled:
t.begin_fill()
for x in range(4):
t.forward(size)
t.left(90)
if filled:
t.end_fill()
def myrectangle(size1, size2, color=black, filled=True):
t.color(color)
if filled:
t.begin_fill()
for x in range(2):
t.forward(size1)
t.left(90)
t.forward(size2)
t.left(90)
if filled:
t.end_fill()
def mycircle(size, color=yellow, filled=True):
t.color(color)
if filled:
t.begin_fill()
t.circle(size)
if filled:
t.end_fill()
def mytriangle(size, color=red, filled=True):
t.color(color)
if filled:
t.begin_fill()
for x in range(3):
t.forward(size)
t.left(120)
if filled:
t.end_fill()
t=turtle.Pen()
t.up()
# Draw the face
t.right(90)
t.forward(350)
t.left(90)
t.down()
mycircle(350)
t.up()
# Draw the left eye
t.left(90)
t.forward(450)
t.left(90)
t.forward(200)
t.right(180)
t.down()
mysquare(100)
t.up()
# Draw the right eye
# Move to the correct position
# (HINT: there is one blank line for each turn/move required)
t.down()
mysquare(100)
t.up()
draw_nose=False
# Draw the nose
# Move to the correct position
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_nose):
t.down()
mytriangle(100)
t.up()
draw_mouth=False
# Draw the mouth
# Move to the correct position
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_mouth):
t.down()
myrectangle(400,75)
t.up()
# Feeling adventurous?
# Draw the teeth
# First the bottom row of 3
draw_bottom_tooth_l=False
# Left tooth
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_bottom_tooth_l):
t.down()
mytriangle(50, yellow)
t.up()
draw_bottom_tooth_c=False
# Center tooth
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_bottom_tooth_c):
t.down()
mytriangle(50, yellow)
t.up()
draw_bottom_tooth_r=False
# Right tooth
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_bottom_tooth_c):
t.down()
mytriangle(50, yellow)
t.up()
# Then the top row of 2
draw_top_tooth_r=False
# Right tooth
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_top_tooth_r):
t.down()
mytriangle(50, yellow)
t.up()
draw_top_tooth_l=False
# Left tooth
# (HINT: there is one blank line for each turn/move required)
# Dont for get to indent.
if (draw_top_tooth_l):
t.down()
mytriangle(50, yellow)
t.up()
# Now move the turtle/curser out of the way
t.forward(800)
# Save the image as a postscript file
ts=turtle.getscreen()
ts.getcanvas().postscript(file='my_name.eps')
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 'Sort' as a Function\n",
"\n",
"What can we do if we want to sort many lists? Rather than writing code to loop over each list, we can encapsulate the 'sort' algorithm in a function. Then we can call the function as often as we like!\n",
"\n",
"##### Make 'sort' into a function\n",
"\n",
"Modify the code below to populate a list with a set amount of random numbers, then to sort that list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Original: one-time sort with loops\n",
"import random\n",
"\n",
"# create a list with random numbers\n",
"myarray = []\n",
"for i in range(10):\n",
" myarray.append(random.randint(1, 100))\n",
"\n",
"print(\"orginal myarray %s\" % myarray)\n",
"\n",
"# sort the list: each iteration moves the smallest remaining number to position 'i'\n",
"for i in range(len(myarray)):\n",
" for j in range(i+1, len(myarray)):\n",
" if myarray[j] < myarray[i]:\n",
" tmp = myarray[i]\n",
" myarray[i] = myarray[j]\n",
" myarray[j] = tmp\n",
"\n",
"print(\"sorted myarray %s\" % myarray)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Now sort using functions!\n",
"\n",
"\n",
"# function to fill and array with 'num_items' elements of random numbers between 1 and 100\n",
"#def populate_random(array, num_items):\n",
" # code populating a list here\n",
"\n",
"\n",
"# function to sort a list from lowest to highest\n",
"#def sort(array):\n",
" # code sort algorithm here \n",
"\n",
"\n",
"arr1 = []\n",
"#populate_random(arr1, 10)\n",
"print(\"\")\n",
"print(\"orginal arr1 %s\" % arr1)\n",
"#sort(arr1)\n",
"print(\"sorted arr1 %s\" % arr1)\n",
"\n",
"\n",
"arr2 = []\n",
"#populate_random(arr2, 6)\n",
"print(\"\")\n",
"print(\"orginal arr2 %s\" % arr2)\n",
"#sort(arr2)\n",
"print(\"sorted arr2 %s\" % arr2)\n",
"\n",
"arr3 = []\n",
"#populate_random(arr3, 14)\n",
"print(\"\")\n",
"print(\"orginal arr3 %s\" % arr3)\n",
"#sort(arr3)\n",
"print(\"sorted arr3 %s\" % arr3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Use the 'sort' algorithm: How to tell if two strings contain the same characters?\n",
"\n",
"Given two strings (such as `\"the morse code\"` and `\"here come dots\"`), do they contain the exact same letters (and the exact same amount of each letter)?\n",
"\n",
"One way to find out would be to loop through the characters in the first string and count how often each letter occurs. Then we do the same thing with the second string and compare the frequency of each character. If all frequencies match, the two strings contain the same characters!\n",
"\n",
"However, this approach is a bit heavy handed. Can you think of a better way using 'sort'?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"string1 = \"the morse code\"\n",
"string2 = \"here come dots\"\n",
"string3 = \"a decimal this\"\n",
"\n",
"# convert the strings to a list of characters\n",
"string1_chars = list(string1)\n",
"string2_chars = list(string2)\n",
"string3_chars = list(string3)\n",
"\n",
"\n",
"# compare the characters to see if they are the same\n",
"# code here!\n",
"\n",
"\n",
"# if characters in string1 are the same as characters in string2\n",
"# print `string1` has same characters as `string2`\n",
"# else\n",
"# print `string1` has different characters from `string2`\n",
"\n",
"# if characters in string1 are the same as characters in string3\n",
"# print `string1` has same characters as `string3`\n",
"# else\n",
"# print `string1` has different characters from `string3`"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment