Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mortier:master #12

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
15 changes: 15 additions & 0 deletions hw2/compare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 2 23:52:25 2014

@author: ubuntu
"""

def comp(x,y):
if x>y:
return 1
elif x<y:
return -1
else:
return 0

21 changes: 21 additions & 0 deletions hw2/fermat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 2 23:34:37 2014

@author: ubuntu
"""

def fermatCheck(a,b,c,n):
if a**n + b**n == c**n and n>2:
print "Holy smokes, Fermat was wrong!"
else:
print "No, that doesn't work"

def fermatPrompt():
a = int(raw_input("input a"))
b = int(raw_input("input b"))
c = int(raw_input("input c"))
n = int(raw_input("input n"))
fermatCheck(a,b,c,n)

fermatPrompt()
15 changes: 15 additions & 0 deletions hw2/grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 2 23:20:02 2014

@author: ubuntu
"""

def makeGrid():
print ("+"+(4*" -"+" +")*2 + 4*("\n|"+" |"*2)+"\n")*2 +"+"+(4*" -"+" +")*2


def makeGrid4():
print ("+"+(4*" -"+" +")*3 + 4*("\n|"+" |"*3)+"\n")*3 +"+"+(4*" -"+" +")*3

makeGrid4()
119 changes: 89 additions & 30 deletions hw3/gene_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
"""
Created on Sun Feb 2 11:24:42 2014

@author: YOUR NAME HERE
@author: Josh Sapers and Paul Ruvolo
(from replacement code for code lost)
"""

from numpy import argmax
from random import shuffle

# you may find it useful to import these variables (although you are not required to use them)
from amino_acids import aa, codons

Expand All @@ -25,13 +29,29 @@ def coding_strand_to_AA(dna):
returns: a string containing the sequence of amino acids encoded by the
the input DNA fragment
"""

# YOUR IMPLEMENTATION HERE
retval = ""
for i in range(0,len(dna),3):
for j in range(len(codons)):
if dna[i:i+3] in codons[j]:
retval += aa[j]
break
return retval

def coding_strand_to_AA_unit_tests():
""" Unit tests for the coding_strand_to_AA function """

# YOUR IMPLEMENTATION HERE
print "input: ATGCGA, expected output: MR, actual output: " + coding_strand_to_AA("ATGCGA")
print "input: ATGCCCGCTTT, expected output: MPA, actual output: " + coding_strand_to_AA("ATGCCCGCTTT")

def get_complementary_base(B):
""" Returns the complementary nucleotide to the specified nucleotide. """
if B == 'A':
return 'T'
elif B == 'C':
return 'G'
elif B == 'G':
return 'C'
elif B == 'T':
return 'A'

def get_reverse_complement(dna):
""" Computes the reverse complementary sequence of DNA for the specfied DNA
Expand All @@ -40,13 +60,15 @@ def get_reverse_complement(dna):
dna: a DNA sequence represented as a string
returns: the reverse complementary DNA sequence represented as a string
"""

# YOUR IMPLEMENTATION HERE
retval = ""
for i in reversed(dna):
retval += get_complementary_base(i)
return retval

def get_reverse_complement_unit_tests():
""" Unit tests for the get_complement function """
# YOUR IMPLEMENTATION HERE
print "input: ATGCCCGCTTT, expected output: AAAGCGGGCAT, actual output: " + get_reverse_complement("ATGCCCGCTTT")
print "input: CCGCGTTCA, expected output: CCGCGTTCA, actual output: " + get_reverse_complement("CCGCGTTCA")

def rest_of_ORF(dna):
""" Takes a DNA sequence that is assumed to begin with a start codon and returns
Expand All @@ -56,13 +78,17 @@ def rest_of_ORF(dna):
dna: a DNA sequence
returns: the open reading frame represented as a string
"""

# YOUR IMPLEMENTATION HERE
retval = ""
for i in range(0,len(dna),3):
if dna[i:i+3] in ['TAG', 'TAA', 'TGA']:
break
retval += dna[i:i+3]
return retval

def rest_of_ORF_unit_tests():
""" Unit tests for the rest_of_ORF function """
# YOUR IMPLEMENTATION HERE
print "input: ATGTGAA, expected output: ATG, actual output: " + rest_of_ORF("ATGTGAA")
print "input: ATGAGATAGG, expected output: ATGAGA, actual output: " + rest_of_ORF("ATGAGATAGG")

def find_all_ORFs_oneframe(dna):
""" Finds all non-nested open reading frames in the given DNA sequence and returns
Expand All @@ -74,13 +100,18 @@ def find_all_ORFs_oneframe(dna):
dna: a DNA sequence
returns: a list of non-nested ORFs
"""

# YOUR IMPLEMENTATION HERE

retval = []
i = 0
while i < len(dna):
if dna[i:i+3] == 'ATG':
retval.append(rest_of_ORF(dna[i:]))
i += len(retval[-1])
i += 3
return retval

def find_all_ORFs_oneframe_unit_tests():
""" Unit tests for the find_all_ORFs_oneframe function """

# YOUR IMPLEMENTATION HERE
print "input: ATGCATGAATGTAGATAGATGTGCCC, expected output: ['ATGCATGAATGTAGA', 'ATGTGCCC'], actual output: " + str(find_all_ORFs_oneframe("ATGCATGAATGTAGATAGATGTGCCC"))

def find_all_ORFs(dna):
""" Finds all non-nested open reading frames in the given DNA sequence in all 3
Expand All @@ -91,13 +122,11 @@ def find_all_ORFs(dna):
dna: a DNA sequence
returns: a list of non-nested ORFs
"""

# YOUR IMPLEMENTATION HERE
return find_all_ORFs_oneframe(dna) + find_all_ORFs_oneframe(dna[1:]) + find_all_ORFs_oneframe(dna[2:])

def find_all_ORFs_unit_tests():
""" Unit tests for the find_all_ORFs function """

# YOUR IMPLEMENTATION HERE
print "input: ATGCATGAATGTAG, expected output: ['ATGCATGAATGTAG', 'ATGAATGTAG', 'ATG'], actual output: " + str(find_all_ORFs("ATGCATGAATGTAG"))

def find_all_ORFs_both_strands(dna):
""" Finds all non-nested open reading frames in the given DNA sequence on both
Expand All @@ -106,19 +135,20 @@ def find_all_ORFs_both_strands(dna):
dna: a DNA sequence
returns: a list of non-nested ORFs
"""

# YOUR IMPLEMENTATION HERE
return find_all_ORFs(dna) + find_all_ORFs(get_reverse_complement(dna))

def find_all_ORFs_both_strands_unit_tests():
""" Unit tests for the find_all_ORFs_both_strands function """

print "input: ATGCGAATGTAGCATCAAA, expected output: ['ATGCGAATG', 'ATGCTACATTCGCAT'], actual output: " + str(find_all_ORFs_both_strands("ATGCGAATGTAGCATCAAA"))
# YOUR IMPLEMENTATION HERE

def longest_ORF(dna):
""" Finds the longest ORF on both strands of the specified DNA and returns it
as a string"""
ORFs = find_all_ORFs_both_strands(dna)
ind = argmax(map(len,ORFs))
return ORFs[ind]

# YOUR IMPLEMENTATION HERE

def longest_ORF_unit_tests():
""" Unit tests for the longest_ORF function """
Expand All @@ -132,8 +162,20 @@ def longest_ORF_noncoding(dna, num_trials):
dna: a DNA sequence
num_trials: the number of random shuffles
returns: the maximum length longest ORF """

# YOUR IMPLEMENTATION HERE
#import random
ORF = ""
for i in range(num_trials):
dna_temp = []
dna_string = ""
for char in dna:
dna_temp.append(char)
shuffle(dna_temp)
for item in dna_temp:
dna_string +=item
if len(longest_ORF(dna_string))>len(ORF):
ORF = longest_ORF(dna_string)
return len(ORF)


def gene_finder(dna, threshold):
""" Returns the amino acid sequences coded by all genes that have an ORF
Expand All @@ -145,5 +187,22 @@ def gene_finder(dna, threshold):
returns: a list of all amino acid sequences whose ORFs meet the minimum
length specified.
"""

# YOUR IMPLEMENTATION HERE
protiens = []
protein = ""
ORFs = find_all_ORFs_both_strands(dna)
for item in ORFs:
if len(item)>threshold:
protiens+=coding_strand_to_AA(item)
for items in protiens:
protein += items
return protein

def search_genome_simple(DNA,aa):

names = []
for items in DNA:
if len(items)==3:
if aa in items[2]:
print items
names.append(items[1])
return names
3 changes: 1 addition & 2 deletions hw3/load.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
hw# -*- coding: utf-8 -*-
"""
Created on Sat Feb 1 22:02:04 2014

@author: pruvolo
"""

from os import path

def load_seq(fasta_file):
""" Reads a FASTA file and returns the DNA sequence as a string.

Expand Down
82 changes: 79 additions & 3 deletions hw4/random_art.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,64 @@

# you do not have to use these particular modules, but they may help
from random import randint
from math import *
import Image

current_depth = 1
def build_random_function(min_depth, max_depth):
# your doc string goes here

"""Prints an array including function strings prod, sin_pi, cos_pi, x, y with their
repsective inputs in nested arrays.
inputs:
min_depth: the minimum depth that you want your function to reach
max_depth: the maximum depth that you want your function to reach
"""
# your code goes here
global current_depth
if current_depth < min_depth:
current_depth += 1
choices = ["prod","sin_pi","cos_pi"]
i = randint(0,len(choices)-1)
s = choices[i]
if s == "prod":
return [s,build_random_function(min_depth, max_depth),build_random_function(min_depth, max_depth)]
else:
return [s,build_random_function(min_depth, max_depth)]

elif current_depth >= min_depth:

if current_depth == max_depth:
current_depth += 1
choices = ["x","y"]
i = randint(0,len(choices)-1)
s = choices[i]
else:
current_depth += 1
choices = ["prod","sin_pi","cos_pi","x","y"]
i = randint(0,len(choices)-1)
s = choices[i]

if s == "prod":
return [s,build_random_function(min_depth, max_depth),build_random_function(min_depth, max_depth)]
elif s=="sin_pi" or s=="cos_pi":
return [s,build_random_function(min_depth, max_depth)]
else:
return [s]


def evaluate_random_function(f, x, y):
# your doc string goes here

# your code goes here
if f[0] == 'prod':
return evaluate_random_function(f[1], x, y)*evaluate_random_function(f[2], x, y)
elif f[0] == 'sin_pi':
return sin(pi*evaluate_random_function(f[1], x, y))
elif f[0] == 'cos_pi':
return cos(pi*evaluate_random_function(f[1], x, y))
elif f[0] == 'y':
return y
elif f[0] == 'x':
return x

def remap_interval(val, input_interval_start, input_interval_end, output_interval_start, output_interval_end):
""" Maps the input value that is in the interval [input_interval_start, input_interval_end]
Expand All @@ -27,4 +74,33 @@ def remap_interval(val, input_interval_start, input_interval_end, output_interva
TODO: please fill out the rest of this docstring
"""
# your code goes here

ratio = (output_interval_end-output_interval_start)/(input_interval_end-input_interval_start)
offset = output_interval_start-input_interval_start*ratio
return val*ratio + offset


global current_depth
fR = build_random_function(2, 25)
current_depth = 1
fB = build_random_function(2, 25)
current_depth = 1
fG = build_random_function(2, 25)
print fR
print fG
print fB
im = Image.new("RGB",(350,350))
pixels = im.load()
for i in range(0,350):
for j in range(0,350):
x = remap_interval(i, 0, 350, -1,1.)
y = remap_interval(j, 0, 350, -1,1.)
R = remap_interval(evaluate_random_function(fR, x, y),-1,1,0,256)
B =remap_interval(evaluate_random_function(fB, x, y),-1,1,0,256)
G = remap_interval(evaluate_random_function(fG, x, y),-1,1,0,256)
RBG = (R,G,B)

pixels[i,j] = (int(R),int(G),int(B))

im.save("pic" + ".thumbnail", "JPEG")


Binary file added hw5/Reflection.pdf
Binary file not shown.
Loading