Page 1

Student ID: 269, P-Value: 0.00e+00

Nearest Neighbor ID: 364

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2plt.style.use('bmh')  2plt.style.use('bmh')  
3plt.plot(3plt.plot(
4    [0, 1, 2],  4    [0, 1, 2],  
5    [0, 1, 0]   5    [0, 1, 0]   
6)6)
7plt.xlabel('x')7plt.xlabel('x')
8plt.ylabel('y');8plt.ylabel('y');
9def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
10    if bare_plot:10    if bare_plot:
11        plt.axis('off')11        plt.axis('off')
12    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
13    X, Y = zip(*coords)13    X, Y = zip(*coords)
14    plt.plot(X, Y);14    plt.plot(X, Y);
15plot_coords([15plot_coords([
16    (0, 0),16    (0, 0),
17    (1, 0),17    (1, 0),
18    (2, 1),18    (2, 1),
19    (3, 1),19    (3, 1),
20    (2, 0)20    (2, 0)
21])21])
22nan = float('nan')22nan = float('nan')
23plot_coords([23plot_coords([
24    (0, 0),24    (0, 0),
25    (1, 1),25    (1, 1),
26    (nan, nan),26    (nan, nan),
27    (1, 0),27    (1, 0),
28    (2, 1)28    (2, 1)
29])29])
30from math import pi, sin, cos30from math import pi, sin, cos
31DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
32def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
33    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
34    yield (0.0, 0.0)34    yield (0.0, 0.0)
35    for command in turtle_program:35    for command in turtle_program:
36        x, y, angle = state36        x, y, angle = state
37        if command in 'Ff':      37        if command in 'Ff':      
38            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
39                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)40                     angle)
41            if command == 'f':41            if command == 'f':
42                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
43            yield (state[0], state[1])43            yield (state[0], state[1])
44        elif command == '+':     44        elif command == '+':     
45            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
46        elif command == '-':     46        elif command == '-':     
47            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
50from math import isnan50from math import isnan
51def print_coords(coords):51def print_coords(coords):
52    for (x, y) in coords:52    for (x, y) in coords:
53        if isnan(x):53        if isnan(x):
54            print('<gap>')54            print('<gap>')
55        else:55        else:
56            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
59def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
60    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
63def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
64    for _ in range(iterations):64    for _ in range(iterations):
65        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
66    return sequence66    return sequence
67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
71plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
72    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
74}, 5), 90))74}, 5), 90))
75def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
76    saved_states = list()76    saved_states = list()
77    state = (0, 0, 90)77    state = (0, 0, 90)
78    yield (0, 0)78    yield (0, 0)
79    for command in turtle_program:79    for command in turtle_program:
80        x, y, angle = state80        x, y, angle = state
81        if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
82            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
83                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)84                     angle)
85            if command.islower():                  85            if command.islower():                  
86                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
87            yield (state[0], state[1])87            yield (state[0], state[1])
88        elif command == '+':                       88        elif command == '+':                       
89            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
90        elif command == '-':                       90        elif command == '-':                       
91            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
92        elif command == '[':                       92        elif command == '[':                       
93            saved_states.append(state)93            saved_states.append(state)
94        elif command == ']':                       94        elif command == ']':                       
95            state = saved_states.pop()95            state = saved_states.pop()
96            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
97            x, y, _ = state97            x, y, _ = state
98            yield (x, y)98            yield (x, y)
99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
100def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
101    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
102    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
103    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
106for i in range(5):106for i in range(5):
107    print('{}: '.format(i),107    print('{}: '.format(i),
108          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
109for i in range(5):109for i in range(5):
110    print('{}: '.format(i),110    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
113    def __init__(self):113    def __init__(self):
n114        self.instances = [] n114        self.instances = []
115        self.consensus=[] 115        self.consensus=[]
116        self.counts= {'A': [], 'C': [], "G":[],'T': []}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
117    def __str__ (self):117    def __str__ (self):
118        string = ""118        string = ""
119        for i in self.instances:119        for i in self.instances:
n120            string = string + str(i) + "\n"n120            string += i + "\n"
121        return string[:-2]121        return string[:0]
122    def __len__(self):122    def __len__(self):
n123        return (len(self.instances)-4)n123        return len (self.consensus)
124    def count(self):124    def count(self):
125        for i in self.instances:125        for i in self.instances:
126            temp = i.upper()126            temp = i.upper()
n127            self.counts["A"].append(temp.count("A"))n127        self.counts["A"].append(temp.count("A"))
128            self.counts["C"].append(temp.count("C"))128        self.counts["C"].append(temp.count("C"))
129            self.counts["G"].append(temp.count("G"))129        self.counts["G"].append(temp.count("G"))
130            self.counts["T"].append(temp.count("T"))130        self.counts["T"].append(temp.count("T"))
131    def compute_consensus(self):131    def compute_consensus(self):
132        A = self.counts["A"]132        A = self.counts["A"]
133        C = self.counts["C"]133        C = self.counts["C"]
134        G = self.counts["G"]134        G = self.counts["G"]
n135        T = self.counts["T"]n135        T = self.counts["T"]   
136        for i in range(len(A)):136        for i in range (len(A)):
137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
138                self.consensus.append("A")138                self.consensus.append("A")
139            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
140                self.consensus.append("C")140                self.consensus.append("C")
141            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
142                self.consensus.append("G")142                self.consensus.append("G")
143            else:143            else:
144                self.consensus.append("T")144                self.consensus.append("T")
n145        for x in self.consensus:n
146            print(x,end='')
147    def parse(self, filename):145    def parse(self, filename):
148        with open(filename,'r') as f:146        with open(filename,'r') as f:
149            for i in f:147            for i in f:
150                if ">" in i:148                if ">" in i:
t151                   continuet149                    continue
152                else:150                else:
153                    self.instances.append(i)151                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 2

Student ID: 364, P-Value: 0.00e+00

Nearest Neighbor ID: 269

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2plt.style.use('bmh')  2plt.style.use('bmh')  
3plt.plot(3plt.plot(
4    [0, 1, 2],  4    [0, 1, 2],  
5    [0, 1, 0]   5    [0, 1, 0]   
6)6)
7plt.xlabel('x')7plt.xlabel('x')
8plt.ylabel('y');8plt.ylabel('y');
9def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
10    if bare_plot:10    if bare_plot:
11        plt.axis('off')11        plt.axis('off')
12    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
13    X, Y = zip(*coords)13    X, Y = zip(*coords)
14    plt.plot(X, Y);14    plt.plot(X, Y);
15plot_coords([15plot_coords([
16    (0, 0),16    (0, 0),
17    (1, 0),17    (1, 0),
18    (2, 1),18    (2, 1),
19    (3, 1),19    (3, 1),
20    (2, 0)20    (2, 0)
21])21])
22nan = float('nan')22nan = float('nan')
23plot_coords([23plot_coords([
24    (0, 0),24    (0, 0),
25    (1, 1),25    (1, 1),
26    (nan, nan),26    (nan, nan),
27    (1, 0),27    (1, 0),
28    (2, 1)28    (2, 1)
29])29])
30from math import pi, sin, cos30from math import pi, sin, cos
31DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
32def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
33    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
34    yield (0.0, 0.0)34    yield (0.0, 0.0)
35    for command in turtle_program:35    for command in turtle_program:
36        x, y, angle = state36        x, y, angle = state
37        if command in 'Ff':      37        if command in 'Ff':      
38            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
39                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)40                     angle)
41            if command == 'f':41            if command == 'f':
42                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
43            yield (state[0], state[1])43            yield (state[0], state[1])
44        elif command == '+':     44        elif command == '+':     
45            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
46        elif command == '-':     46        elif command == '-':     
47            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
50from math import isnan50from math import isnan
51def print_coords(coords):51def print_coords(coords):
52    for (x, y) in coords:52    for (x, y) in coords:
53        if isnan(x):53        if isnan(x):
54            print('<gap>')54            print('<gap>')
55        else:55        else:
56            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
59def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
60    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
63def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
64    for _ in range(iterations):64    for _ in range(iterations):
65        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
66    return sequence66    return sequence
67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
71plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
72    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
74}, 5), 90))74}, 5), 90))
75def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
76    saved_states = list()76    saved_states = list()
77    state = (0, 0, 90)77    state = (0, 0, 90)
78    yield (0, 0)78    yield (0, 0)
79    for command in turtle_program:79    for command in turtle_program:
80        x, y, angle = state80        x, y, angle = state
81        if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
82            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
83                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)84                     angle)
85            if command.islower():                  85            if command.islower():                  
86                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
87            yield (state[0], state[1])87            yield (state[0], state[1])
88        elif command == '+':                       88        elif command == '+':                       
89            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
90        elif command == '-':                       90        elif command == '-':                       
91            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
92        elif command == '[':                       92        elif command == '[':                       
93            saved_states.append(state)93            saved_states.append(state)
94        elif command == ']':                       94        elif command == ']':                       
95            state = saved_states.pop()95            state = saved_states.pop()
96            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
97            x, y, _ = state97            x, y, _ = state
98            yield (x, y)98            yield (x, y)
99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
100def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
101    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
102    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
103    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
106for i in range(5):106for i in range(5):
107    print('{}: '.format(i),107    print('{}: '.format(i),
108          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
109for i in range(5):109for i in range(5):
110    print('{}: '.format(i),110    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
113    def __init__(self):113    def __init__(self):
n114        self.instances = []n114        self.instances = [] 
115        self.consensus=[]115        self.consensus=[] 
116        self.counts= {'A': [], 'C': [], "G":[],'T': []}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
117    def __str__ (self):117    def __str__ (self):
118        string = ""118        string = ""
119        for i in self.instances:119        for i in self.instances:
n120            string +i + "\n"n120            string = string + str(i) + "\n"
121        return string[:0]121        return string[:-2]
122    def __len__(self):122    def __len__(self):
n123        return len (self.consensus)n123        return (len(self.instances)-4)
124    def count(self):124    def count(self):
125        for i in self.instances:125        for i in self.instances:
126            temp = i.upper()126            temp = i.upper()
n127        self.counts["A"].append(temp.count("A"))n127            self.counts["A"].append(temp.count("A"))
128        self.counts["C"].append(temp.count("C"))128            self.counts["C"].append(temp.count("C"))
129        self.counts["G"].append(temp.count("G"))129            self.counts["G"].append(temp.count("G"))
130        self.counts["T"].append(temp.count("T"))130            self.counts["T"].append(temp.count("T"))
131    def compute_consensus(self):131    def compute_consensus(self):
132        A = self.counts["A"]132        A = self.counts["A"]
133        C = self.counts["C"]133        C = self.counts["C"]
134        G = self.counts["G"]134        G = self.counts["G"]
n135        T = self.counts["T"]   n135        T = self.counts["T"]
136        for i in range (len(A)):136        for i in range(len(A)):
137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
138                self.consensus.append("A")138                self.consensus.append("A")
139            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
140                self.consensus.append("C")140                self.consensus.append("C")
141            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
142                self.consensus.append("G")142                self.consensus.append("G")
143            else:143            else:
144                self.consensus.append("T")144                self.consensus.append("T")
nn145        for x in self.consensus:
146            print(x,end='')
145    def parse(self, filename):147    def parse(self, filename):
146        with open(filename,'r') as f:148        with open(filename,'r') as f:
147            for i in f:149            for i in f:
148                if ">" in i:150                if ">" in i:
t149                    continuet151                   continue
150                else:152                else:
151                    self.instances.append(i)153                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 3

Student ID: 113, P-Value: 1.11e-16

Nearest Neighbor ID: 269

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2plt.style.use('bmh')  2plt.style.use('bmh')  
3plt.plot(3plt.plot(
4    [0, 1, 2],  4    [0, 1, 2],  
5    [0, 1, 0]   5    [0, 1, 0]   
6)6)
7plt.xlabel('x')7plt.xlabel('x')
8plt.ylabel('y');8plt.ylabel('y');
9def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
10    if bare_plot:10    if bare_plot:
11        plt.axis('off')11        plt.axis('off')
12    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
13    X, Y = zip(*coords)13    X, Y = zip(*coords)
14    plt.plot(X, Y);14    plt.plot(X, Y);
15plot_coords([15plot_coords([
16    (0, 0),16    (0, 0),
17    (1, 0),17    (1, 0),
18    (2, 1),18    (2, 1),
19    (3, 1),19    (3, 1),
20    (2, 0)20    (2, 0)
21])21])
22nan = float('nan')22nan = float('nan')
23plot_coords([23plot_coords([
24    (0, 0),24    (0, 0),
25    (1, 1),25    (1, 1),
26    (nan, nan),26    (nan, nan),
27    (1, 0),27    (1, 0),
28    (2, 1)28    (2, 1)
29])29])
30from math import pi, sin, cos30from math import pi, sin, cos
31DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
32def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
33    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
34    yield (0.0, 0.0)34    yield (0.0, 0.0)
35    for command in turtle_program:35    for command in turtle_program:
36        x, y, angle = state36        x, y, angle = state
37        if command in 'Ff':      37        if command in 'Ff':      
38            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
39                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)40                     angle)
41            if command == 'f':41            if command == 'f':
42                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
43            yield (state[0], state[1])43            yield (state[0], state[1])
44        elif command == '+':     44        elif command == '+':     
45            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
46        elif command == '-':     46        elif command == '-':     
47            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
50from math import isnan50from math import isnan
51def print_coords(coords):51def print_coords(coords):
52    for (x, y) in coords:52    for (x, y) in coords:
53        if isnan(x):53        if isnan(x):
54            print('<gap>')54            print('<gap>')
55        else:55        else:
56            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
59def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
60    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
63def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
64    for _ in range(iterations):64    for _ in range(iterations):
65        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
66    return sequence66    return sequence
67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
71plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
72    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
74}, 5), 90))74}, 5), 90))
75def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
76    saved_states = list()76    saved_states = list()
77    state = (0, 0, 90)77    state = (0, 0, 90)
78    yield (0, 0)78    yield (0, 0)
79    for command in turtle_program:79    for command in turtle_program:
80        x, y, angle = state80        x, y, angle = state
81        if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
82            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
83                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)84                     angle)
85            if command.islower():                  85            if command.islower():                  
86                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
87            yield (state[0], state[1])87            yield (state[0], state[1])
88        elif command == '+':                       88        elif command == '+':                       
89            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
90        elif command == '-':                       90        elif command == '-':                       
91            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
92        elif command == '[':                       92        elif command == '[':                       
93            saved_states.append(state)93            saved_states.append(state)
94        elif command == ']':                       94        elif command == ']':                       
95            state = saved_states.pop()95            state = saved_states.pop()
96            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
97            x, y, _ = state97            x, y, _ = state
98            yield (x, y)98            yield (x, y)
99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
100def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
101    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
102    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
103    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
106for i in range(5):106for i in range(5):
107    print('{}: '.format(i),107    print('{}: '.format(i),
108          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
109for i in range(5):109for i in range(5):
110    print('{}: '.format(i),110    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
113    def __init__(self):113    def __init__(self):
114        self.instances = [] 114        self.instances = [] 
115        self.consensus=[] 115        self.consensus=[] 
116        self.counts= {'A': [], 'C': [], "G":[],'T': []}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
117    def __str__ (self):117    def __str__ (self):
118        string = ""118        string = ""
119        for i in self.instances:119        for i in self.instances:
n120            string +i + "\n"n120            string = string + str(i) + "\n"
121        return string[:-2]121        return string[:-2]
122    def __len__(self):122    def __len__(self):
n123        return len(self.instances)n123        return (len(self.instances)-4)
124    def count(self):124    def count(self):
125        for i in self.instances:125        for i in self.instances:
126            temp = i.upper()126            temp = i.upper()
127            self.counts["A"].append(temp.count("A"))127            self.counts["A"].append(temp.count("A"))
128            self.counts["C"].append(temp.count("C"))128            self.counts["C"].append(temp.count("C"))
129            self.counts["G"].append(temp.count("G"))129            self.counts["G"].append(temp.count("G"))
130            self.counts["T"].append(temp.count("T"))130            self.counts["T"].append(temp.count("T"))
131    def compute_consensus(self):131    def compute_consensus(self):
132        A = self.counts["A"]132        A = self.counts["A"]
133        C = self.counts["C"]133        C = self.counts["C"]
134        G = self.counts["G"]134        G = self.counts["G"]
135        T = self.counts["T"]135        T = self.counts["T"]
136        for i in range(len(A)):136        for i in range(len(A)):
137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
138                self.consensus.append("A")138                self.consensus.append("A")
139            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
140                self.consensus.append("C")140                self.consensus.append("C")
141            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
142                self.consensus.append("G")142                self.consensus.append("G")
143            else:143            else:
144                self.consensus.append("T")144                self.consensus.append("T")
nn145        for x in self.consensus:
146            print(x,end='')
145    def parse(self, filename):147    def parse(self, filename):
146        with open(filename,'r') as f:148        with open(filename,'r') as f:
147            for i in f:149            for i in f:
148                if ">" in i:150                if ">" in i:
149                   continue151                   continue
150                else:152                else:
151                    self.instances.append(i)153                    self.instances.append(i)
t152if __name__=='__main__':t
153    lex=DNAMOTIF()
154    lex.parse('lexA.fasta')
155    print("length",len(lex))
156    print(lex)
157    print("consensus",lex.consensus)
158    print('seq',lex.counts)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 4

Student ID: 423, P-Value: 1.05e-14

Nearest Neighbor ID: 370

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
nn2import matplotlib.pyplot as plt
2class PLANT:3class PLANT:
n3    def __init__(self, initial , gen = {}, p = 0, deltaTheta = 0):n4    def __init__ (self, initial , gen = {}, n = 0, deltaTheta = 0):
4        self.initial = initial5        self.initial=initial
5        self.gen = gen6        self.gen=gen
6        self.= p7        self.n=n
7        self.deltaTheta = deltaTheta8        self.deltaTheta=deltaTheta
8        self.str = initial9        self.str=initial
9        while p>0:10        while n>0:
10            p -= 111            n -= 1
11            y = ''12            y = ""
12            for i in self.str:13            for i in self.str:
13                if i in gen:14                if i in gen:
14                    y += gen[i]15                    y += gen[i]
15                else:16                else:
16                    y += i17                    y += i
17            self.str = y18            self.str = y
18    def drawPlant(self):19    def drawPlant(self):
19        x = []20        x = []
20        for i in self.str:21        for i in self.str:
n21            if i == '[':n22            if i == "[":
22                x.append([currentPt,theta])23                x.append([initialPt,theta])
23            elif i == ']':24            elif i == "]":
24                currentPt = x[-1][0]25                initiaPt = x[-1][0]
25                theta = x[-1][1]26                theta = x[-1][1]
n26            elif i == '+':n27            elif i == "+":
27                theta += self.deltaTheta28                theta += self.deltaTheta
n28            elif i == '-':n29            elif i == "-":
29                theta -= self.deltaTheta30                theta -= self.deltaTheta
30        currentPt=(200,0)31        currentPt=(200,0)
31        theta = 9032        theta = 90
n32        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)n33        nextPt = (initialPt[0] + math.cos(theta), initialPt[1] + math.sin(theta)
>)>)
33        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'34        plt.plot([initialPt[0],nextPt[0]],[initialPt[1],nextPt[1]],color='black'
>)>)
34        currentPt=nextPt35        currentPt=nextPt
35        x = []36        x = []
36        for i in self.str:37        for i in self.str:
n37            if i == '[':n38            if i == "[":
38                x.append([currentPt,theta])39                x.append([initialPt,theta])
39            elif i == ']':40            elif i == "]":
40                currentPt = x[-1][0]41                initialPt = x[-1][0]
41                theta = x[-1][1]42                theta = x[-1][1]
n42            elif i == '+':n43            elif i == "+":
43                theta += self.deltaTheta44                theta += self.deltaTheta
t44            elif i == '-':t45            elif i == "-":
45                theta -= self.deltaTheta46                theta -= self.deltaTheta
46class DNAMOTIF:47class DNAMOTIF:
47    def __init__(self):48    def __init__(self):
48        self.instances=[]49        self.instances=[]
49        self.consensus=[]50        self.consensus=[]
50        self.counts= {"A": [], "C": [], "G":[],"T":[]}51        self.counts= {"A": [], "C": [], "G":[],"T":[]}
51    def __str__(self):52    def __str__(self):
52        string = ""53        string = ""
53        for i in self.instances:54        for i in self.instances:
54            string += i + ""55            string += i + ""
55        return string[:-2]56        return string[:-2]
56    def __len__(self):57    def __len__(self):
57        return len(self.instances[0])-158        return len(self.instances[0])-1
58    def count(self):59    def count(self):
59        i = 060        i = 0
60        count = 061        count = 0
61        up = []62        up = []
62        do_again = []63        do_again = []
63        A = 064        A = 0
64        C = 065        C = 0
65        T = 066        T = 0
66        G = 067        G = 0
67        while i < len(self.instances[0])-1:68        while i < len(self.instances[0])-1:
68            while count < len(self.instances):69            while count < len(self.instances):
69                for amino in self.instances:70                for amino in self.instances:
70                    amino = amino.upper()71                    amino = amino.upper()
71                    up.append(amino[i])72                    up.append(amino[i])
72                    count += 173                    count += 1
73            count = 074            count = 0
74            do_again.append(up)75            do_again.append(up)
75            up = []76            up = []
76            i += 177            i += 1
77        for DNA in do_again:78        for DNA in do_again:
78            for an in DNA:79            for an in DNA:
79                if an == 'A':80                if an == 'A':
80                    A += 181                    A += 1
81                if an == 'C':82                if an == 'C':
82                    C += 183                    C += 1
83                if an == 'T':84                if an == 'T':
84                    T += 185                    T += 1
85                if an == 'G':86                if an == 'G':
86                    G += 1 87                    G += 1 
87            self.counts.setdefault('A',[]).append(A)88            self.counts.setdefault('A',[]).append(A)
88            self.counts.setdefault('C',[]).append(C)89            self.counts.setdefault('C',[]).append(C)
89            self.counts.setdefault('T',[]).append(T)90            self.counts.setdefault('T',[]).append(T)
90            self.counts.setdefault('G',[]).append(G)91            self.counts.setdefault('G',[]).append(G)
91            A = 092            A = 0
92            C = 093            C = 0
93            T = 094            T = 0
94            G = 095            G = 0
95    def compute_consensus(self):96    def compute_consensus(self):
96        self.count()97        self.count()
97        A = self.counts["A"]98        A = self.counts["A"]
98        C = self.counts["C"]99        C = self.counts["C"]
99        G = self.counts["G"]100        G = self.counts["G"]
100        T = self.counts["T"]101        T = self.counts["T"]
101        for amino in range(len(A)):102        for amino in range(len(A)):
102            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a103            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a
>mino]):>mino]):
103                self.consensus.append("A")104                self.consensus.append("A")
104            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):105            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):
105                self.consensus.append("C")106                self.consensus.append("C")
106            elif (G[amino] >= T[amino]):107            elif (G[amino] >= T[amino]):
107                self.consensus.append("G")108                self.consensus.append("G")
108            else:109            else:
109                self.consensus.append("T")110                self.consensus.append("T")
110        self.consensus = "".join(self.consensus)111        self.consensus = "".join(self.consensus)
111    def parse(self, filename):112    def parse(self, filename):
112        with open(filename,'r') as f:113        with open(filename,'r') as f:
113            for i in f:114            for i in f:
114                if ">" in i:115                if ">" in i:
115                    continue116                    continue
116                else:117                else:
117                    self.instances.append(i)118                    self.instances.append(i)
118lexA=DNAMOTIF()119lexA=DNAMOTIF()
119lexA.parse("lexA.fasta")120lexA.parse("lexA.fasta")
120lexA.count()121lexA.count()
121print(lexA.counts)122print(lexA.counts)
122lexA.compute_consensus()123lexA.compute_consensus()
123print(lexA.consensus)124print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 5

Student ID: 370, P-Value: 1.05e-14

Nearest Neighbor ID: 423

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2import matplotlib.pyplot as pltn
3class PLANT:2class PLANT:
n4    def __init__ (self, initial , gen = {}, n = 0, deltaTheta = 0):n3    def __init__(self, initial , gen = {}, p = 0, deltaTheta = 0):
5        self.initial=initial4        self.initial = initial
6        self.gen=gen5        self.gen = gen
7        self.n=n6        self.= p
8        self.deltaTheta=deltaTheta7        self.deltaTheta = deltaTheta
9        self.str=initial8        self.str = initial
10        while n>0:9        while p>0:
11            n -= 110            p -= 1
12            y = ""11            y = ''
13            for i in self.str:12            for i in self.str:
14                if i in gen:13                if i in gen:
15                    y += gen[i]14                    y += gen[i]
16                else:15                else:
17                    y += i16                    y += i
18            self.str = y17            self.str = y
19    def drawPlant(self):18    def drawPlant(self):
20        x = []19        x = []
21        for i in self.str:20        for i in self.str:
n22            if i == "[":n21            if i == '[':
23                x.append([initialPt,theta])22                x.append([currentPt,theta])
24            elif i == "]":23            elif i == ']':
25                initiaPt = x[-1][0]24                currentPt = x[-1][0]
26                theta = x[-1][1]25                theta = x[-1][1]
n27            elif i == "+":n26            elif i == '+':
28                theta += self.deltaTheta27                theta += self.deltaTheta
n29            elif i == "-":n28            elif i == '-':
30                theta -= self.deltaTheta29                theta -= self.deltaTheta
31        currentPt=(200,0)30        currentPt=(200,0)
32        theta = 9031        theta = 90
n33        nextPt = (initialPt[0] + math.cos(theta), initialPt[1] + math.sin(theta)n32        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)
>)>)
34        plt.plot([initialPt[0],nextPt[0]],[initialPt[1],nextPt[1]],color='black'33        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'
>)>)
35        currentPt=nextPt34        currentPt=nextPt
36        x = []35        x = []
37        for i in self.str:36        for i in self.str:
n38            if i == "[":n37            if i == '[':
39                x.append([initialPt,theta])38                x.append([currentPt,theta])
40            elif i == "]":39            elif i == ']':
41                initialPt = x[-1][0]40                currentPt = x[-1][0]
42                theta = x[-1][1]41                theta = x[-1][1]
n43            elif i == "+":n42            elif i == '+':
44                theta += self.deltaTheta43                theta += self.deltaTheta
t45            elif i == "-":t44            elif i == '-':
46                theta -= self.deltaTheta45                theta -= self.deltaTheta
47class DNAMOTIF:46class DNAMOTIF:
48    def __init__(self):47    def __init__(self):
49        self.instances=[]48        self.instances=[]
50        self.consensus=[]49        self.consensus=[]
51        self.counts= {"A": [], "C": [], "G":[],"T":[]}50        self.counts= {"A": [], "C": [], "G":[],"T":[]}
52    def __str__(self):51    def __str__(self):
53        string = ""52        string = ""
54        for i in self.instances:53        for i in self.instances:
55            string += i + ""54            string += i + ""
56        return string[:-2]55        return string[:-2]
57    def __len__(self):56    def __len__(self):
58        return len(self.instances[0])-157        return len(self.instances[0])-1
59    def count(self):58    def count(self):
60        i = 059        i = 0
61        count = 060        count = 0
62        up = []61        up = []
63        do_again = []62        do_again = []
64        A = 063        A = 0
65        C = 064        C = 0
66        T = 065        T = 0
67        G = 066        G = 0
68        while i < len(self.instances[0])-1:67        while i < len(self.instances[0])-1:
69            while count < len(self.instances):68            while count < len(self.instances):
70                for amino in self.instances:69                for amino in self.instances:
71                    amino = amino.upper()70                    amino = amino.upper()
72                    up.append(amino[i])71                    up.append(amino[i])
73                    count += 172                    count += 1
74            count = 073            count = 0
75            do_again.append(up)74            do_again.append(up)
76            up = []75            up = []
77            i += 176            i += 1
78        for DNA in do_again:77        for DNA in do_again:
79            for an in DNA:78            for an in DNA:
80                if an == 'A':79                if an == 'A':
81                    A += 180                    A += 1
82                if an == 'C':81                if an == 'C':
83                    C += 182                    C += 1
84                if an == 'T':83                if an == 'T':
85                    T += 184                    T += 1
86                if an == 'G':85                if an == 'G':
87                    G += 1 86                    G += 1 
88            self.counts.setdefault('A',[]).append(A)87            self.counts.setdefault('A',[]).append(A)
89            self.counts.setdefault('C',[]).append(C)88            self.counts.setdefault('C',[]).append(C)
90            self.counts.setdefault('T',[]).append(T)89            self.counts.setdefault('T',[]).append(T)
91            self.counts.setdefault('G',[]).append(G)90            self.counts.setdefault('G',[]).append(G)
92            A = 091            A = 0
93            C = 092            C = 0
94            T = 093            T = 0
95            G = 094            G = 0
96    def compute_consensus(self):95    def compute_consensus(self):
97        self.count()96        self.count()
98        A = self.counts["A"]97        A = self.counts["A"]
99        C = self.counts["C"]98        C = self.counts["C"]
100        G = self.counts["G"]99        G = self.counts["G"]
101        T = self.counts["T"]100        T = self.counts["T"]
102        for amino in range(len(A)):101        for amino in range(len(A)):
103            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a102            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a
>mino]):>mino]):
104                self.consensus.append("A")103                self.consensus.append("A")
105            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):104            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):
106                self.consensus.append("C")105                self.consensus.append("C")
107            elif (G[amino] >= T[amino]):106            elif (G[amino] >= T[amino]):
108                self.consensus.append("G")107                self.consensus.append("G")
109            else:108            else:
110                self.consensus.append("T")109                self.consensus.append("T")
111        self.consensus = "".join(self.consensus)110        self.consensus = "".join(self.consensus)
112    def parse(self, filename):111    def parse(self, filename):
113        with open(filename,'r') as f:112        with open(filename,'r') as f:
114            for i in f:113            for i in f:
115                if ">" in i:114                if ">" in i:
116                    continue115                    continue
117                else:116                else:
118                    self.instances.append(i)117                    self.instances.append(i)
119lexA=DNAMOTIF()118lexA=DNAMOTIF()
120lexA.parse("lexA.fasta")119lexA.parse("lexA.fasta")
121lexA.count()120lexA.count()
122print(lexA.counts)121print(lexA.counts)
123lexA.compute_consensus()122lexA.compute_consensus()
124print(lexA.consensus)123print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 6

Student ID: 290, P-Value: 3.12e-13

Nearest Neighbor ID: 113

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2plt.style.use('bmh')n2plt.style.use('bmh')  
3plt.plot(3plt.plot(
n4    [0, 1, 2],n4    [0, 1, 2],  
5    [0, 1, 0]5    [0, 1, 0]   
6)6)
7plt.xlabel('x')7plt.xlabel('x')
8plt.ylabel('y');8plt.ylabel('y');
9def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
10    if bare_plot:10    if bare_plot:
11        plt.axis('off')11        plt.axis('off')
n12    plt.axes().set_aspect('equal', 'datalim').n12    plt.axes().set_aspect('equal', 'datalim')
13    X, Y = zip(*coords)13    X, Y = zip(*coords)
14    plt.plot(X, Y);14    plt.plot(X, Y);
n15    plot_coords([n15plot_coords([
16        (0, 0),16    (0, 0),
17        (1, 0),17    (1, 0),
18        (2, 1),18    (2, 1),
19        (3, 1),19    (3, 1),
20        (2, 0)20    (2, 0)
21    ])21])
22    nan = float('nan')22nan = float('nan')
23    plot_coords([23plot_coords([
24        (0, 0),24    (0, 0),
25        (1, 1),25    (1, 1),
26        (nan, nan),26    (nan, nan),
27        (1, 0),27    (1, 0),
28        (2, 1)28    (2, 1)
29    ])29])
30from math import pi, sin, cos30from math import pi, sin, cos
31DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
32def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
33    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
34    yield (0.0, 0.0)34    yield (0.0, 0.0)
35    for command in turtle_program:35    for command in turtle_program:
36        x, y, angle = state36        x, y, angle = state
n37        if command in 'Ff':n37        if command in 'Ff':      
38            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
39                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)40                     angle)
41            if command == 'f':41            if command == 'f':
42                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
43            yield (state[0], state[1])43            yield (state[0], state[1])
n44        elif command == '+':  n44        elif command == '+':     
45            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
n46        elif command == '-':  n46        elif command == '-':     
47            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
50from math import isnan50from math import isnan
51def print_coords(coords):51def print_coords(coords):
52    for (x, y) in coords:52    for (x, y) in coords:
53        if isnan(x):53        if isnan(x):
54            print('<gap>')54            print('<gap>')
55        else:55        else:
56            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
59def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
60    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
63def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
64    for _ in range(iterations):64    for _ in range(iterations):
65        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
66    return sequence66    return sequence
67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
71plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
72    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
74}, 5), 90))74}, 5), 90))
75def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
76    saved_states = list()76    saved_states = list()
77    state = (0, 0, 90)77    state = (0, 0, 90)
78    yield (0, 0)78    yield (0, 0)
79    for command in turtle_program:79    for command in turtle_program:
80        x, y, angle = state80        x, y, angle = state
n81        if command.lower() in 'abcdefghij':       n81        if command.lower() in 'abcdefghij':        
82            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
83                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)84                     angle)
85            if command.islower():                  85            if command.islower():                  
86                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
87            yield (state[0], state[1])87            yield (state[0], state[1])
n88        elif command == '+':                      n88        elif command == '+':                       
89            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
n90        elif command == '-':                      n90        elif command == '-':                       
91            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
n92        elif command == '[':                      n92        elif command == '[':                       
93            saved_states.append(state)93            saved_states.append(state)
94        elif command == ']':                       94        elif command == ']':                       
95            state = saved_states.pop()95            state = saved_states.pop()
96            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
97            x, y, _ = state97            x, y, _ = state
98            yield (x, y)98            yield (x, y)
99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
100def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
101    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
102    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
103    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
106for i in range(5):106for i in range(5):
107    print('{}: '.format(i),107    print('{}: '.format(i),
108          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
109for i in range(5):109for i in range(5):
110    print('{}: '.format(i),110    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
n112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF:n112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
113    def __init__(self):113    def __init__(self):
n114        self.instances=[]n114        self.instances = [] 
115        self.consensus=[]115        self.consensus=[] 
116        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
117    def __str__(self):117    def __str__ (self):
118        string = ""118        string = ""
119        for i in self.instances:119        for i in self.instances:
n120            string += in120            string += i + "\n"
121        return string[:-2]
121    def __len__(self):122    def __len__(self):
n122        return len(self.instances) - len(self.counts)n123        return len(self.instances)
123    def count(self):124    def count(self):
124        for i in self.instances:125        for i in self.instances:
125            temp = i.upper()126            temp = i.upper()
126            self.counts["A"].append(temp.count("A"))127            self.counts["A"].append(temp.count("A"))
127            self.counts["C"].append(temp.count("C"))128            self.counts["C"].append(temp.count("C"))
128            self.counts["G"].append(temp.count("G"))129            self.counts["G"].append(temp.count("G"))
n129            self.counts["T"].append(temp.count("T"))  n130            self.counts["T"].append(temp.count("T"))
130    def compute_consensus(self):131    def compute_consensus(self):
131        A = self.counts["A"]132        A = self.counts["A"]
132        C = self.counts["C"]133        C = self.counts["C"]
133        G = self.counts["G"]134        G = self.counts["G"]
134        T = self.counts["T"]135        T = self.counts["T"]
135        for i in range(len(A)):136        for i in range(len(A)):
136            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
137                self.consensus.append("A")138                self.consensus.append("A")
138            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
139                self.consensus.append("C")140                self.consensus.append("C")
140            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
141                self.consensus.append("G")142                self.consensus.append("G")
142            else:143            else:
143                self.consensus.append("T")144                self.consensus.append("T")
144    def parse(self, filename):145    def parse(self, filename):
n145        with open(filename,'r') as fasta:n146        with open(filename,'r') as f:
146            for i in fasta:147            for i in f:
147                if ">" in i:148                if ">" in i:
n148                    passn149                   continue
149                else:150                else:
150                    self.instances.append(i)151                    self.instances.append(i)
t151if __name__=="__main__":t152if __name__=='__main__':
152    lex= DNAMOTIF()153    lex=DNAMOTIF()
153    lexA.parse("lexA.fasta")154    lex.parse('lexA.fasta')
154    print(len(lexA))155    print("length",len(lex))
155    lexA = DNAMOTIF()
156    lexA.parse("lexA.fasta")
157    print(lexA)156    print(lex)
158    lexA = DNAMOTIF()157    print("consensus",lex.consensus)
159    lexA.count()
160    print(lexA.counts)158    print('seq',lex.counts)
161    lexA = DNAMOTIF()
162    lexA.compute_consensus()
163    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 7

Student ID: 318, P-Value: 4.72e-13

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string,dictionary, n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string, dictionary, n):10    def generator(string, dictionary, n):
11        def character_v(string):11        def character_v(string):
12            if string in dictionary:12            if string in dictionary:
13                return dictionary.get(string)13                return dictionary.get(string)
14            return string14            return string
15        substrings_list = [string]15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
17            substring = substrings_list[-1]17            substring = substrings_list[-1]
18            new_statement = [character_v(char) for char in substring]18            new_statement = [character_v(char) for char in substring]
19            substrings_list.append(''.join(new_statement))19            substrings_list.append(''.join(new_statement))
20        newstring = substrings_list[n]20        newstring = substrings_list[n]
21        return newstring21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [currentPt, theta]27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
29            if command.upper() in upper_letters:29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>ta)))>ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
n32                currentPt = nextPtn32                currentPt = nextPt 
33            else:33            else:
34                if command == '[':34                if command == '[':
35                    stack.append(currentPt)35                    stack.append(currentPt)
36                    stack.append(theta)36                    stack.append(theta)
37                elif command == ']':37                elif command == ']':
38                    theta = stack.pop()38                    theta = stack.pop()
39                    currentPt = stack.pop()  39                    currentPt = stack.pop()  
40                elif command == '-':40                elif command == '-':
41                    theta -= deltaTheta41                    theta -= deltaTheta
42                elif command == '+':42                elif command == '+':
43                    theta += deltaTheta43                    theta += deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
52    plt.show()class DNAMOTIF:52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
n54        self.instances = []n54        self.instances=[]
55        self.consensus = []55        self.consensus=[]
56        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
n58        output = ''n58        output = ""
59        for instance in self.instances:59        for instance in self.instances:
60            output += instance60            output += instance
61        return output61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
65        for position in range(len(self)):65        for position in range(len(self)):
66            sequenceA = 066            sequenceA = 0
67            sequenceT = 067            sequenceT = 0
68            sequenceC = 068            sequenceC = 0
69            sequenceG = 069            sequenceG = 0
70            for instance in self.instances:70            for instance in self.instances:
71                sequence = instance.rstrip()71                sequence = instance.rstrip()
n72                if (sequence[position]).upper() == 'A':n72                if (sequence[position]).upper() == "A":
73                    sequenceA += 173                    sequenceA += 1
n74                elif (sequence[position]).upper() == 'T':n74                elif (sequence[position]).upper() == "T":
75                    sequenceT += 175                    sequenceT += 1
n76                elif (sequence[position]).upper() == 'C':n76                elif (sequence[position]).upper() == "C":
77                    sequenceC += 177                    sequenceC += 1
n78                elif (sequence[position]).upper() == 'G':n78                elif (sequence[position]).upper() == "G":
79                    sequenceG += 179                    sequenceG += 1
n80            self.counts.get('A').append(sequenceA)n80            self.counts.get("A").append(sequenceA)
81            self.counts.get('T').append(sequenceT)81            self.counts.get("T").append(sequenceT)
82            self.counts.get('C').append(sequenceC)82            self.counts.get("C").append(sequenceC)
83            self.counts.get('G').append(sequenceG)83            self.counts.get("G").append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
n86        A = self.counts.get('A')n86        A = self.counts.get("A")
87        T = self.counts.get('T')87        T = self.counts.get("T")
88        C = self.counts.get('C')88        C = self.counts.get("C")
89        G = self.counts.get('G')89        G = self.counts.get("G")
90        output = ""90        output = ""
91        for row in range(len(A)):91        for row in range(len(A)):
n92            maxes = max(A[row],T[row],C[row],G[row])n92            maxs = max(A[row],T[row],C[row],G[row])
93            if maxes == A[row]:93            if maxs == A[row]:
94                output += 'A'94                output += "A"
95            elif maxes == T[row]:95            elif maxs == T[row]:
96                output += 'T'96                output += "T"
97            elif maxes == C[row]:97            elif maxs == C[row]:
98                output += 'C'98                output += "C"
99            elif maxes == G[row]:99            elif maxs == G[row]:
100                output += 'G'100                output += "G"
101        self.consensus = output101        self.consensus = output
102    def parse(self, filename):102    def parse(self, filename):
103        myFile = open(filename, 'r')103        myFile = open(filename, 'r')
104        contents = [line for line in myFile.readlines()]104        contents = [line for line in myFile.readlines()]
105        myFile.close()105        myFile.close()
106        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
107            if index % 2 != 0:107            if index % 2 != 0:
108                self.instances.append(line)108                self.instances.append(line)
109if __name__ == '__main__':109if __name__ == '__main__':
110    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t111    filename = r'FinalProject\lexA.fasta't111    filename = r'FinalProject\lexA.fasta' 
112    lexA.parse(filename)112    lexA.parse(filename)
113    lexA.compute_consensus()113    lexA.compute_consensus()
114    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 8

Student ID: 203, P-Value: 4.72e-13

Nearest Neighbor ID: 318

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string,dictionary, n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string, dictionary, n):10    def generator(string, dictionary, n):
11        def character_v(string):11        def character_v(string):
12            if string in dictionary:12            if string in dictionary:
13                return dictionary.get(string)13                return dictionary.get(string)
14            return string14            return string
15        substrings_list = [string]15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
17            substring = substrings_list[-1]17            substring = substrings_list[-1]
18            new_statement = [character_v(char) for char in substring]18            new_statement = [character_v(char) for char in substring]
19            substrings_list.append(''.join(new_statement))19            substrings_list.append(''.join(new_statement))
20        newstring = substrings_list[n]20        newstring = substrings_list[n]
21        return newstring21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [currentPt, theta]27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
29            if command.upper() in upper_letters:29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>ta)))>ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
n32                currentPt = nextPt n32                currentPt = nextPt
33            else:33            else:
34                if command == '[':34                if command == '[':
35                    stack.append(currentPt)35                    stack.append(currentPt)
36                    stack.append(theta)36                    stack.append(theta)
37                elif command == ']':37                elif command == ']':
38                    theta = stack.pop()38                    theta = stack.pop()
39                    currentPt = stack.pop()  39                    currentPt = stack.pop()  
40                elif command == '-':40                elif command == '-':
41                    theta -= deltaTheta41                    theta -= deltaTheta
42                elif command == '+':42                elif command == '+':
43                    theta += deltaTheta43                    theta += deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
52    plt.show()class DNAMOTIF:52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
n54        self.instances=[]n54        self.instances = []
55        self.consensus=[]55        self.consensus = []
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
n58        output = ""n58        output = ''
59        for instance in self.instances:59        for instance in self.instances:
60            output += instance60            output += instance
61        return output61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
65        for position in range(len(self)):65        for position in range(len(self)):
66            sequenceA = 066            sequenceA = 0
67            sequenceT = 067            sequenceT = 0
68            sequenceC = 068            sequenceC = 0
69            sequenceG = 069            sequenceG = 0
70            for instance in self.instances:70            for instance in self.instances:
71                sequence = instance.rstrip()71                sequence = instance.rstrip()
n72                if (sequence[position]).upper() == "A":n72                if (sequence[position]).upper() == 'A':
73                    sequenceA += 173                    sequenceA += 1
n74                elif (sequence[position]).upper() == "T":n74                elif (sequence[position]).upper() == 'T':
75                    sequenceT += 175                    sequenceT += 1
n76                elif (sequence[position]).upper() == "C":n76                elif (sequence[position]).upper() == 'C':
77                    sequenceC += 177                    sequenceC += 1
n78                elif (sequence[position]).upper() == "G":n78                elif (sequence[position]).upper() == 'G':
79                    sequenceG += 179                    sequenceG += 1
n80            self.counts.get("A").append(sequenceA)n80            self.counts.get('A').append(sequenceA)
81            self.counts.get("T").append(sequenceT)81            self.counts.get('T').append(sequenceT)
82            self.counts.get("C").append(sequenceC)82            self.counts.get('C').append(sequenceC)
83            self.counts.get("G").append(sequenceG)83            self.counts.get('G').append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
n86        A = self.counts.get("A")n86        A = self.counts.get('A')
87        T = self.counts.get("T")87        T = self.counts.get('T')
88        C = self.counts.get("C")88        C = self.counts.get('C')
89        G = self.counts.get("G")89        G = self.counts.get('G')
90        output = ""90        output = ""
91        for row in range(len(A)):91        for row in range(len(A)):
n92            maxs = max(A[row],T[row],C[row],G[row])n92            maxes = max(A[row],T[row],C[row],G[row])
93            if maxs == A[row]:93            if maxes == A[row]:
94                output += "A"94                output += 'A'
95            elif maxs == T[row]:95            elif maxes == T[row]:
96                output += "T"96                output += 'T'
97            elif maxs == C[row]:97            elif maxes == C[row]:
98                output += "C"98                output += 'C'
99            elif maxs == G[row]:99            elif maxes == G[row]:
100                output += "G"100                output += 'G'
101        self.consensus = output101        self.consensus = output
102    def parse(self, filename):102    def parse(self, filename):
103        myFile = open(filename, 'r')103        myFile = open(filename, 'r')
104        contents = [line for line in myFile.readlines()]104        contents = [line for line in myFile.readlines()]
105        myFile.close()105        myFile.close()
106        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
107            if index % 2 != 0:107            if index % 2 != 0:
108                self.instances.append(line)108                self.instances.append(line)
109if __name__ == '__main__':109if __name__ == '__main__':
110    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t111    filename = r'FinalProject\lexA.fasta' t111    filename = r'FinalProject\lexA.fasta'
112    lexA.parse(filename)112    lexA.parse(filename)
113    lexA.compute_consensus()113    lexA.compute_consensus()
114    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 9

Student ID: 252, P-Value: 6.20e-13

Nearest Neighbor ID: 423

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2import matplotlib.pyplot as pltn
3class PLANT:2class PLANT:
n4    def __init__(self, initial , gen = {}, n = 0, deltaTheta = 0):n3    def __init__(self, initial , gen = {}, p = 0, deltaTheta = 0):
5        self.initial = initial4        self.initial = initial
6        self.gen = gen5        self.gen = gen
n7        self.n = nn6        self.p = p
8        self.deltaTheta = deltaTheta7        self.deltaTheta = deltaTheta
9        self.str = initial8        self.str = initial
n10        while n>0:n9        while p>0:
11            n -= 110            p -= 1
12            y = ''11            y = ''
13            for i in self.str:12            for i in self.str:
14                if i in gen:13                if i in gen:
15                    y += gen[i]14                    y += gen[i]
16                else:15                else:
17                    y += i16                    y += i
18            self.str = y17            self.str = y
19    def drawPlant(self):18    def drawPlant(self):
20        x = []19        x = []
n21        for let in self.str:n20        for i in self.str:
22            if let == '[':21            if i == '[':
23                x.append([currentPt,theta])22                x.append([currentPt,theta])
n24            elif let == ']':n23            elif i == ']':
25                currentPt = x[-1][0]24                currentPt = x[-1][0]
26                theta = x[-1][1]25                theta = x[-1][1]
n27            elif let == '+':n26            elif i == '+':
28                theta += self.deltaTheta27                theta += self.deltaTheta
n29            elif let == '-':n28            elif i == '-':
30                theta -= self.deltaTheta29                theta -= self.deltaTheta
31        currentPt=(200,0)30        currentPt=(200,0)
32        theta = 9031        theta = 90
33        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)32        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)
>)>)
34        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'33        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'
>)>)
35        currentPt=nextPt34        currentPt=nextPt
36        x = []35        x = []
n37        for let in self.str:n36        for i in self.str:
38            if let == '[':37            if i == '[':
39                x.append([currentPt,theta])38                x.append([currentPt,theta])
n40            elif let == ']':n39            elif i == ']':
41                currentPt = x[-1][0]40                currentPt = x[-1][0]
42                theta = x[-1][1]41                theta = x[-1][1]
n43            elif let == '+':n42            elif i == '+':
44                theta += self.deltaTheta43                theta += self.deltaTheta
n45            elif let == '-':n44            elif i == '-':
46                theta -= self.deltaTheta45                theta -= self.deltaTheta
47class DNAMOTIF:46class DNAMOTIF:
48    def __init__(self):47    def __init__(self):
49        self.instances=[]48        self.instances=[]
50        self.consensus=[]49        self.consensus=[]
51        self.counts= {"A": [], "C": [], "G":[],"T":[]}50        self.counts= {"A": [], "C": [], "G":[],"T":[]}
52    def __str__(self):51    def __str__(self):
53        string = ""52        string = ""
54        for i in self.instances:53        for i in self.instances:
55            string += i + ""54            string += i + ""
56        return string[:-2]55        return string[:-2]
57    def __len__(self):56    def __len__(self):
58        return len(self.instances[0])-157        return len(self.instances[0])-1
59    def count(self):58    def count(self):
60        i = 059        i = 0
61        count = 060        count = 0
62        up = []61        up = []
n63        up1 = []n62        do_again = []
64        A = 063        A = 0
65        C = 064        C = 0
66        T = 065        T = 0
67        G = 066        G = 0
68        while i < len(self.instances[0])-1:67        while i < len(self.instances[0])-1:
69            while count < len(self.instances):68            while count < len(self.instances):
70                for amino in self.instances:69                for amino in self.instances:
71                    amino = amino.upper()70                    amino = amino.upper()
72                    up.append(amino[i])71                    up.append(amino[i])
73                    count += 172                    count += 1
74            count = 073            count = 0
n75            up1.append(up)n74            do_again.append(up)
76            up = []75            up = []
77            i += 176            i += 1
n78        for strand in up1:n77        for DNA in do_again:
79            for i in strand:78            for an in DNA:
80                if i == 'A':79                if an == 'A':
81                    A += 180                    A += 1
n82                if i == 'C':n81                if an == 'C':
83                    C += 182                    C += 1
n84                if i == 'T':n83                if an == 'T':
85                    T += 184                    T += 1
n86                if i == 'G':n85                if an == 'G':
87                    G += 1 86                    G += 1 
88            self.counts.setdefault('A',[]).append(A)87            self.counts.setdefault('A',[]).append(A)
89            self.counts.setdefault('C',[]).append(C)88            self.counts.setdefault('C',[]).append(C)
90            self.counts.setdefault('T',[]).append(T)89            self.counts.setdefault('T',[]).append(T)
91            self.counts.setdefault('G',[]).append(G)90            self.counts.setdefault('G',[]).append(G)
92            A = 091            A = 0
93            C = 092            C = 0
94            T = 093            T = 0
95            G = 094            G = 0
96    def compute_consensus(self):95    def compute_consensus(self):
97        self.count()96        self.count()
98        A = self.counts["A"]97        A = self.counts["A"]
99        C = self.counts["C"]98        C = self.counts["C"]
100        G = self.counts["G"]99        G = self.counts["G"]
101        T = self.counts["T"]100        T = self.counts["T"]
n102        for let in range(len(A)):n101        for amino in range(len(A)):
103            if(A[let]>= C[let] and A[let] >= G[let]  and A[let] >= T[let]):102            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a
 >mino]):
104                self.consensus.append("A")103                self.consensus.append("A")
n105            elif (C[let] >= G[let] and C[let] >= T[let]):n104            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):
106                self.consensus.append("C")105                self.consensus.append("C")
t107            elif (G[let] >= T[let]):t106            elif (G[amino] >= T[amino]):
108                self.consensus.append("G")107                self.consensus.append("G")
109            else:108            else:
110                self.consensus.append("T")109                self.consensus.append("T")
111        self.consensus = "".join(self.consensus)110        self.consensus = "".join(self.consensus)
112    def parse(self, filename):111    def parse(self, filename):
113        with open(filename,'r') as f:112        with open(filename,'r') as f:
114            for i in f:113            for i in f:
115                if ">" in i:114                if ">" in i:
116                    continue115                    continue
117                else:116                else:
118                    self.instances.append(i)117                    self.instances.append(i)
119lexA=DNAMOTIF()118lexA=DNAMOTIF()
120lexA.parse("lexA.fasta")119lexA.parse("lexA.fasta")
121lexA.count()120lexA.count()
122print(lexA.counts)121print(lexA.counts)
123lexA.compute_consensus()122lexA.compute_consensus()
124print(lexA.consensus)123print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 10

Student ID: 4, P-Value: 1.54e-11

Nearest Neighbor ID: 83

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.str = string5        self.str = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        for x in range(n):n9        for i in range(n):
10            new_string = ""10            new_string = ""
11            for letter in self.str:11            for letter in self.str:
12                if letter in self.dictionary:12                if letter in self.dictionary:
13                    new_string += self.dictionary[letter]13                    new_string += self.dictionary[letter]
14                else:14                else:
15                    new_string += letter15                    new_string += letter
16            self.str = new_string16            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
18        currentPt = (200,0)18        currentPt = (200,0)
19        stack = []19        stack = []
20        theta = 9020        theta = 90
21        for letter in self.str:21        for letter in self.str:
22            if letter == "[":22            if letter == "[":
23                stack.append([currentPt,theta])23                stack.append([currentPt,theta])
24            elif letter == "]":24            elif letter == "]":
n25                latest = stack[-1]n25                current_save = stack.pop()
26                theta = current_save[1]
26                currentPt = latest[0]27                currentPt = current_save[0]
27                theta = latest[1]
28            elif letter == "+":28            elif letter == "+":
29                theta += self.deltaTheta29                theta += self.deltaTheta
30            elif letter == "-":30            elif letter == "-":
31                theta -= self.deltaTheta31                theta -= self.deltaTheta
32            else:32            else:
n33                nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin33                nextPt = (currentPt[0] + math.cos(math.radians(theta)), currentP
>n(theta))>t[1] + math.sin(math.radians(theta)))
34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor='black')>olor='black')
35                currentPt = nextPtclass DNAMOTIF:35                currentPt = nextPtclass DNAMOTIF:
n36    def __init__(self):n36    def __init_(self):
37        self.instances = []37        self.instances = []
38        self.consensus = []38        self.consensus = []
39        self.counts = {"A": [], "C": [], "G": [], "T": []}39        self.counts = {"A": [], "C": [], "G": [], "T": []}
40    def __str__(self):40    def __str__(self):
41        return "\n".join(self.instances)41        return "\n".join(self.instances)
42    def __len__(self):42    def __len__(self):
43        return len(self.instances[0])-143        return len(self.instances[0])-1
44    def parse(self, filename):44    def parse(self, filename):
45        with open(filename, 'r') as reader:45        with open(filename, 'r') as reader:
n46            self.instances = [x[0].lower() + x[1:].upper() for x in reader.readln46            self.instances = [i[0].lower()+i[1:].upper() for i in reader.readlin
>ines() if x[0] != ">"]>es() if i[0] != ">"]
47    def count(self):47    def count(self):
n48        count = 0n
49        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang48        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
>lf))]}>lf))]}
50        for instance in self.instances:49        for instance in self.instances:
n51            for x, letter in enumerate(instance):n50            for i, letter in enumerate(instance):
52                if letter != "\n":51                if letter != "\n":
n53                    self.counts[letter.upper()][x] += 1n52                    self.counts[letter.upper()][i] += 1
54    def compute_consensus(self):53    def compute_consensus(self):
55        self.count()54        self.count()
56        consensus = ""55        consensus = ""
n57        for x in range(len(self)):n56        for i in range(len(self)):
58            current_consensus = ("",0)57            current_consensus = ("",0)
59            for letter in self.counts:58            for letter in self.counts:
n60                if self.counts[letter][x] > current_consensus[1]:n59                if self.counts[letter][i] > current_consensus[1]:
61                    current_consensus = (letter, self.counts[letter][x])60                    current_consensus = (letter, self.counts[letter][i])
62            consensus += current_consensus[0]61            consensus += current_consensus[0]
63        self.consensus = consensus62        self.consensus = consensus
t64def count(self):t
65        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se 
>lf))]} 
66        for instance in self.instances:
67            for x, letter in enumerate(instance):
68                if letter != "\n":
69                    self.counts[letter.upper()][x] += 1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 11

Student ID: 83, P-Value: 1.54e-11

Nearest Neighbor ID: 4

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.str = string5        self.str = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        for i in range(n):n9        for x in range(n):
10            new_string = ""10            new_string = ""
11            for letter in self.str:11            for letter in self.str:
12                if letter in self.dictionary:12                if letter in self.dictionary:
13                    new_string += self.dictionary[letter]13                    new_string += self.dictionary[letter]
14                else:14                else:
15                    new_string += letter15                    new_string += letter
16            self.str = new_string16            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
18        currentPt = (200,0)18        currentPt = (200,0)
19        stack = []19        stack = []
20        theta = 9020        theta = 90
21        for letter in self.str:21        for letter in self.str:
22            if letter == "[":22            if letter == "[":
23                stack.append([currentPt,theta])23                stack.append([currentPt,theta])
24            elif letter == "]":24            elif letter == "]":
n25                current_save = stack.pop()n25                latest = stack[-1]
26                theta = current_save[1]
27                currentPt = current_save[0]26                currentPt = latest[0]
27                theta = latest[1]
28            elif letter == "+":28            elif letter == "+":
29                theta += self.deltaTheta29                theta += self.deltaTheta
30            elif letter == "-":30            elif letter == "-":
31                theta -= self.deltaTheta31                theta -= self.deltaTheta
32            else:32            else:
n33                nextPt = (currentPt[0] + math.cos(math.radians(theta)), currentPn33                nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.si
>t[1] + math.sin(math.radians(theta)))>n(theta))
34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor='black')>olor='black')
35                currentPt = nextPtclass DNAMOTIF:35                currentPt = nextPtclass DNAMOTIF:
n36    def __init_(self):n36    def __init__(self):
37        self.instances = []37        self.instances = []
38        self.consensus = []38        self.consensus = []
39        self.counts = {"A": [], "C": [], "G": [], "T": []}39        self.counts = {"A": [], "C": [], "G": [], "T": []}
40    def __str__(self):40    def __str__(self):
41        return "\n".join(self.instances)41        return "\n".join(self.instances)
42    def __len__(self):42    def __len__(self):
43        return len(self.instances[0])-143        return len(self.instances[0])-1
44    def parse(self, filename):44    def parse(self, filename):
45        with open(filename, 'r') as reader:45        with open(filename, 'r') as reader:
n46            self.instances = [i[0].lower()+i[1:].upper() for i in reader.readlinn46            self.instances = [x[0].lower() + x[1:].upper() for x in reader.readl
>es() if i[0] != ">"]>ines() if x[0] != ">"]
47    def count(self):47    def count(self):
nn48        count = 0
48        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang49        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
>lf))]}>lf))]}
49        for instance in self.instances:50        for instance in self.instances:
n50            for i, letter in enumerate(instance):n51            for x, letter in enumerate(instance):
51                if letter != "\n":52                if letter != "\n":
n52                    self.counts[letter.upper()][i] += 1n53                    self.counts[letter.upper()][x] += 1
53    def compute_consensus(self):54    def compute_consensus(self):
54        self.count()55        self.count()
55        consensus = ""56        consensus = ""
n56        for i in range(len(self)):n57        for x in range(len(self)):
57            current_consensus = ("",0)58            current_consensus = ("",0)
58            for letter in self.counts:59            for letter in self.counts:
n59                if self.counts[letter][i] > current_consensus[1]:n60                if self.counts[letter][x] > current_consensus[1]:
60                    current_consensus = (letter, self.counts[letter][i])61                    current_consensus = (letter, self.counts[letter][x])
61            consensus += current_consensus[0]62            consensus += current_consensus[0]
62        self.consensus = consensus63        self.consensus = consensus
tt64def count(self):
65        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
 >e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
 >lf))]}
66        for instance in self.instances:
67            for x, letter in enumerate(instance):
68                if letter != "\n":
69                    self.counts[letter.upper()][x] += 1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 12

Student ID: 345, P-Value: 2.48e-11

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string,dictionary, n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string, dictionary, n):10    def generator(string, dictionary, n):
n11        def production_rule(string):n11        def character_v(string):
12            if string in dictionary:12            if string in dictionary:
13                return dictionary.get(string)13                return dictionary.get(string)
14            return string14            return string
n15        list_of_substrings = [string]n15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
n17            current_substring = list_of_substrings[-1]n17            substring = substrings_list[-1]
18            new_axiom = [production_rule(char) for char in current_substring]18            new_statement = [character_v(char) for char in substring]
19            list_of_substrings.append(''.join(new_axiom))19            substrings_list.append(''.join(new_statement))
20        newstring = list_of_substrings[n]20        newstring = substrings_list[n]
21        return newstring21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
n23        uppera = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'Mn23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
>', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [currentPt, theta]27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
n29            if command.upper() in uppera:n29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>ta)))>ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
n32                currentPt = nextPtn32                currentPt = nextPt 
33            else:33            else:
34                if command == '[':34                if command == '[':
35                    stack.append(currentPt)35                    stack.append(currentPt)
36                    stack.append(theta)36                    stack.append(theta)
37                elif command == ']':37                elif command == ']':
38                    theta = stack.pop()38                    theta = stack.pop()
n39                    currentPt = stack.pop()n39                    currentPt = stack.pop()  
40                elif command == '-':
41                    theta -= deltaTheta
40                elif command == '+':42                elif command == '+':
41                    theta += deltaTheta43                    theta += deltaTheta
n42                elif command == '-':n
43                    theta -= deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
n52    plt.show()class DNAMOTIF: n52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
54        self.instances=[]54        self.instances=[]
55        self.consensus=[]55        self.consensus=[]
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
58        output = ""58        output = ""
59        for instance in self.instances:59        for instance in self.instances:
60            output += instance60            output += instance
61        return output61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
65        for position in range(len(self)):65        for position in range(len(self)):
66            sequenceA = 066            sequenceA = 0
67            sequenceT = 067            sequenceT = 0
68            sequenceC = 068            sequenceC = 0
69            sequenceG = 069            sequenceG = 0
70            for instance in self.instances:70            for instance in self.instances:
71                sequence = instance.rstrip()71                sequence = instance.rstrip()
72                if (sequence[position]).upper() == "A":72                if (sequence[position]).upper() == "A":
73                    sequenceA += 173                    sequenceA += 1
74                elif (sequence[position]).upper() == "T":74                elif (sequence[position]).upper() == "T":
75                    sequenceT += 175                    sequenceT += 1
76                elif (sequence[position]).upper() == "C":76                elif (sequence[position]).upper() == "C":
77                    sequenceC += 177                    sequenceC += 1
78                elif (sequence[position]).upper() == "G":78                elif (sequence[position]).upper() == "G":
79                    sequenceG += 179                    sequenceG += 1
80            self.counts.get("A").append(sequenceA)80            self.counts.get("A").append(sequenceA)
81            self.counts.get("T").append(sequenceT)81            self.counts.get("T").append(sequenceT)
82            self.counts.get("C").append(sequenceC)82            self.counts.get("C").append(sequenceC)
83            self.counts.get("G").append(sequenceG)83            self.counts.get("G").append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
86        A = self.counts.get("A")86        A = self.counts.get("A")
87        T = self.counts.get("T")87        T = self.counts.get("T")
88        C = self.counts.get("C")88        C = self.counts.get("C")
89        G = self.counts.get("G")89        G = self.counts.get("G")
90        output = ""90        output = ""
91        for row in range(len(A)):91        for row in range(len(A)):
n92            maximum = max(A[row],T[row],C[row],G[row])n92            maxs = max(A[row],T[row],C[row],G[row])
93            if maximum == A[row]:93            if maxs == A[row]:
94                output += "A"94                output += "A"
n95            elif maximum == T[row]:n95            elif maxs == T[row]:
96                output += "T"96                output += "T"
n97            elif maximum == C[row]:n97            elif maxs == C[row]:
98                output += "C"98                output += "C"
n99            elif maximum == G[row]:n99            elif maxs == G[row]:
100                output += "G"100                output += "G"
101        self.consensus = output101        self.consensus = output
102    def parse(self, filename):102    def parse(self, filename):
n103        myFile = open(filename, 'r') n103        myFile = open(filename, 'r')
104        contents = [line for line in myFile.readlines()] 104        contents = [line for line in myFile.readlines()]
105        myFile.close() 105        myFile.close()
106        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
107            if index % 2 != 0:107            if index % 2 != 0:
108                self.instances.append(line)108                self.instances.append(line)
109if __name__ == '__main__':109if __name__ == '__main__':
n110    lexA=DNAMOTIF() n110    lexA=DNAMOTIF()
111    filename = r'FinalProject\lexA.fasta' 111    filename = r'FinalProject\lexA.fasta' 
t112    lexA.parse(filename) t112    lexA.parse(filename)
113    lexA.compute_consensus() 113    lexA.compute_consensus()
114    print(lexA.consensus) 114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 13

Student ID: 443, P-Value: 7.08e-11

Nearest Neighbor ID: 113

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2plt.style.use('bmh') n2plt.style.use('bmh')  
3class PLANT:
4    def __initializer__(p):
5        p.start=[]
6plt.plot(3plt.plot(
7    [0, 1, 2],  4    [0, 1, 2],  
8    [0, 1, 0]   5    [0, 1, 0]   
9)6)
10plt.xlabel('x')7plt.xlabel('x')
11plt.ylabel('y');8plt.ylabel('y');
12def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
13    if bare_plot:10    if bare_plot:
14        plt.axis('off')11        plt.axis('off')
15    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
16    X, Y = zip(*coords)13    X, Y = zip(*coords)
17    plt.plot(X, Y);14    plt.plot(X, Y);
18plot_coords([15plot_coords([
19    (0, 0),16    (0, 0),
20    (1, 0),17    (1, 0),
21    (2, 1),18    (2, 1),
22    (3, 1),19    (3, 1),
23    (2, 0)20    (2, 0)
24])21])
25nan = float('nan')22nan = float('nan')
26plot_coords([23plot_coords([
27    (0, 0),24    (0, 0),
28    (1, 1),25    (1, 1),
29    (nan, nan),26    (nan, nan),
30    (1, 0),27    (1, 0),
31    (2, 1)28    (2, 1)
32])29])
33from math import pi, sin, cos30from math import pi, sin, cos
34DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
35def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
36    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
37    yield (0.0, 0.0)34    yield (0.0, 0.0)
38    for command in turtle_program:35    for command in turtle_program:
39        x, y, angle = state36        x, y, angle = state
40        if command in 'Ff':      37        if command in 'Ff':      
41            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
42                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
43                     angle)40                     angle)
44            if command == 'f':41            if command == 'f':
45                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
46            yield (state[0], state[1])43            yield (state[0], state[1])
47        elif command == '+':     44        elif command == '+':     
48            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
49        elif command == '-':     46        elif command == '-':     
50            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
51plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
52plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
53from math import isnan50from math import isnan
54def print_coords(coords):51def print_coords(coords):
55    for (x, y) in coords:52    for (x, y) in coords:
56        if isnan(x):53        if isnan(x):
57            print('<gap>')54            print('<gap>')
58        else:55        else:
59            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
60print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
61plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
62def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
63    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
64transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
65plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
66def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
67    for _ in range(iterations):64    for _ in range(iterations):
68        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
69    return sequence66    return sequence
70print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
71print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
72print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
73plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
74plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
75    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
76    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
77}, 5), 90))74}, 5), 90))
78def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
79    saved_states = list()76    saved_states = list()
80    state = (0, 0, 90)77    state = (0, 0, 90)
81    yield (0, 0)78    yield (0, 0)
82    for command in turtle_program:79    for command in turtle_program:
83        x, y, angle = state80        x, y, angle = state
84        if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
85            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
86                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
87                     angle)84                     angle)
88            if command.islower():                  85            if command.islower():                  
89                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
90            yield (state[0], state[1])87            yield (state[0], state[1])
91        elif command == '+':                       88        elif command == '+':                       
92            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
93        elif command == '-':                       90        elif command == '-':                       
94            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
95        elif command == '[':                       92        elif command == '[':                       
96            saved_states.append(state)93            saved_states.append(state)
97        elif command == ']':                       94        elif command == ']':                       
98            state = saved_states.pop()95            state = saved_states.pop()
99            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
100            x, y, _ = state97            x, y, _ = state
101            yield (x, y)98            yield (x, y)
102plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
103def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
104    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
105    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
106    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
107l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
108l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
109for i in range(5):106for i in range(5):
110    print('{}: '.format(i),107    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
112for i in range(5):109for i in range(5):
113    print('{}: '.format(i),110    print('{}: '.format(i),
114          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
n115l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF:n112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
116    def __init__(self):113    def __init__(self):
n117        self.instances=[]n114        self.instances = [] 
118        self.consensus=[]115        self.consensus=[] 
119        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
120    def __str__(self):117    def __str__ (self):
118        string = ""
121        for i in self.instances:119        for i in self.instances:
n122            string+=i+"\n"n120            string += i + "\n"
123        return string[:-2]121        return string[:-2]
124    def __len__(self):122    def __len__(self):
n125        return len(self.instances) + 1n123        return len(self.instances)
126    def count(self):124    def count(self):
127        for i in self.instances:125        for i in self.instances:
n128            temp=i.upper()n126            temp = i.upper()
129            self.counts["A"].append(temp.count("A"))127            self.counts["A"].append(temp.count("A"))
130            self.counts["C"].append(temp.count("C"))128            self.counts["C"].append(temp.count("C"))
131            self.counts["G"].append(temp.count("G"))129            self.counts["G"].append(temp.count("G"))
132            self.counts["T"].append(temp.count("T"))130            self.counts["T"].append(temp.count("T"))
n133        return  self.countsn
134    def compute_consensus(self):131    def compute_consensus(self):
n135        passn
136        A=self.counts["A"]132        A = self.counts["A"]
137        C=self.counts["C"]133        C = self.counts["C"]
138        G=self.counts["G"]134        G = self.counts["G"]
139        T=self.counts["T"]135        T = self.counts["T"]
140        for i in range(len(A)):136        for i in range(len(A)):
n141            if(A[i]>=C[i] and A[i] >= G[i] and A[i]>= T[i]):n137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
142                G=self.counts["G"]
143                T=self.counts["T"]
144        for i in range(len(A)):
145            if(A[i]>=C[i] and A[i]>=G[i] and A[i]>=T[i]):
146                self.consensus.append("A")138                self.consensus.append("A")
n147            elif(C[i]>=G[i] and C[i]>=T[i]):n139            elif (C[i] >= G[i] and C[i] >= T[i]):
148                self.consensus.append("C")140                self.consensus.append("C")
n149            elif(G[i]>=T[i]):n141            elif (G[i] >= T[i]):
150                self.consensus.append("G")142                self.consensus.append("G")
151            else:143            else:
152                self.consensus.append("T")144                self.consensus.append("T")
n153        return  self.consensusn
154    def parse(self, filename):145    def parse(self, filename):
155        with open(filename,'r') as f:146        with open(filename,'r') as f:
156            for i in f:147            for i in f:
n157                if">"in i:n148                if ">" in i:
158                    continue149                   continue
159                else:150                else:
160                    self.instances.append(i)151                    self.instances.append(i)
t161        return self.instancest152if __name__=='__main__':
162lexA=DNAMOTIF()153    lex=DNAMOTIF()
163lexA.parse("lexA.fasta")154    lex.parse('lexA.fasta')
164print(len(lexA))155    print("length",len(lex))
165lexA.count()156    print(lex)
166print(lexA.count())157    print("consensus",lex.consensus)
167lexA.compute_consensus()158    print('seq',lex.counts)
168print(lexA.compute_consensus())
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 14

Student ID: 224, P-Value: 1.82e-08

Nearest Neighbor ID: 373

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2from math import pi, sin, cos n2from math import sin, cos, radians
3class PLANT:3class PLANT:
n4    def __init__(self, init, gen, n, theta_delta):n4    def __init__(self, init, gen, n, delta_theta):
5        self.init_state = init5        self.init_state = init
6        self.generator = gen6        self.generator = gen
7        self.n = n7        self.n = n
n8        self.theta_delta = theta_deltan8        self.delta_theta = delta_theta
9        self.str = self.generate()9        self.str = self.generate()
10    def generate(self):10    def generate(self):
11        result = self.init_state11        result = self.init_state
12        for i in range(self.n):12        for i in range(self.n):
n13            new_result = ""n13            new_res = ""
14            for char in result:14            for char in result:
15                if char in self.generator:15                if char in self.generator:
n16                    new_result += self.generator[char]n16                    new_res += self.generator[char]
17                else:17                else:
n18                    new_result += charn18                    new_res += char
19            result = new_result19            result = new_res
20        return result20        return result
21    def drawPlant(self):21    def drawPlant(self):
22        currentPt = (200, 0)22        currentPt = (200, 0)
23        theta = 9023        theta = 90
24        stack = []24        stack = []
25        for char in self.str:25        for char in self.str:
26            if char.isalpha():26            if char.isalpha():
n27                nextPt = (currentPt[0] + cos(theta), currentPt[1] + sin(theta))n27                nextPt = (currentPt[0] + cos(radians(theta)), currentPt[1] + sin
 >(radians(theta)))
28                plt.plot(28                plt.plot(
29                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=29                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=
>"black">"black"
30                )30                )
31                currentPt = nextPt31                currentPt = nextPt
32            elif char == "[":32            elif char == "[":
33                stack.append([currentPt, theta])33                stack.append([currentPt, theta])
34            elif char == "]":34            elif char == "]":
35                [currentPt, theta] = stack[-1]35                [currentPt, theta] = stack[-1]
36            elif char == "+":36            elif char == "+":
n37                theta += self.theta_deltan37                theta += self.delta_theta
38            elif char == "-":38            elif char == "-":
n39                theta -= self.theta_deltan39                theta -= self.delta_theta
40            myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)
41            myPlant.str=='FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X'
42        plt.axis("image")40        plt.axis("image")class DNAMOTIF:
43class DNAMOTIF:
44    def __init__(self):41    def __init__(self):
45        self.instances = []42        self.instances = []
46        self.consensus = []43        self.consensus = []
47        self.counts = {"A": [], "C": [], "G": [], "T": []}44        self.counts = {"A": [], "C": [], "G": [], "T": []}
48    def __str__(self):45    def __str__(self):
49        return "".join([str(item) for item in self.instances])46        return "".join([str(item) for item in self.instances])
50    def __len__(self):47    def __len__(self):
51        return len(self.instances[0].strip("\n"))48        return len(self.instances[0].strip("\n"))
52    def count(self):49    def count(self):
53        for key in self.counts:50        for key in self.counts:
54            self.counts[key] = [0] * len(self)51            self.counts[key] = [0] * len(self)
n55        for minstances in self.instances:n52        for instance in self.instances:
56            minstances = minstances.strip("\n")53            instance = instance.strip("\n")
57            for i in range(len(self)):54            for i in range(len(self)):
n58                if minstances[i].upper() in self.counts:n55                if instance[i].upper() in self.counts:
59                    self.counts[minstances[i].upper()][i] += 156                    self.counts[instance[i].upper()][i] += 1
60    def compute_consensus(self):57    def compute_consensus(self):
61        self.count()58        self.count()
62        self.consensus = [0] * len(self.counts['A'])59        self.consensus = [0] * len(self.counts['A'])
63        for i in range(len(self.counts['A'])):60        for i in range(len(self.counts['A'])):
t64            maximumkey = max(self.counts, key=lambda x: self.counts[x][i])t61            keymax = max(self.counts, key=lambda x: self.counts[x][i])
65            self.consensus[i] = maximumkey62            self.consensus[i] = keymax
66        self.consensus = "".join([str(item) for item in self.consensus])63        self.consensus = "".join([str(item) for item in self.consensus])
67    def parse(self, filename):64    def parse(self, filename):
68        with open(filename) as fp:65        with open(filename) as fp:
69            for line in fp:66            for line in fp:
70                if line[0] != ">":67                if line[0] != ">":
71                    self.instances.append("{}\n".format(line.strip()))68                    self.instances.append("{}\n".format(line.strip()))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 15

Student ID: 373, P-Value: 1.82e-08

Nearest Neighbor ID: 224

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2from math import sin, cos, radiansn2from math import pi, sin, cos 
3class PLANT:3class PLANT:
n4    def __init__(self, init, gen, n, delta_theta):n4    def __init__(self, init, gen, n, theta_delta):
5        self.init_state = init5        self.init_state = init
6        self.generator = gen6        self.generator = gen
7        self.n = n7        self.n = n
n8        self.delta_theta = delta_thetan8        self.theta_delta = theta_delta
9        self.str = self.generate()9        self.str = self.generate()
10    def generate(self):10    def generate(self):
11        result = self.init_state11        result = self.init_state
12        for i in range(self.n):12        for i in range(self.n):
n13            new_res = ""n13            new_result = ""
14            for char in result:14            for char in result:
15                if char in self.generator:15                if char in self.generator:
n16                    new_res += self.generator[char]n16                    new_result += self.generator[char]
17                else:17                else:
n18                    new_res += charn18                    new_result += char
19            result = new_res19            result = new_result
20        return result20        return result
21    def drawPlant(self):21    def drawPlant(self):
22        currentPt = (200, 0)22        currentPt = (200, 0)
23        theta = 9023        theta = 90
24        stack = []24        stack = []
25        for char in self.str:25        for char in self.str:
26            if char.isalpha():26            if char.isalpha():
n27                nextPt = (currentPt[0] + cos(radians(theta)), currentPt[1] + sinn27                nextPt = (currentPt[0] + cos(theta), currentPt[1] + sin(theta))
>(radians(theta))) 
28                plt.plot(28                plt.plot(
29                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=29                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=
>"black">"black"
30                )30                )
31                currentPt = nextPt31                currentPt = nextPt
32            elif char == "[":32            elif char == "[":
33                stack.append([currentPt, theta])33                stack.append([currentPt, theta])
34            elif char == "]":34            elif char == "]":
35                [currentPt, theta] = stack[-1]35                [currentPt, theta] = stack[-1]
36            elif char == "+":36            elif char == "+":
n37                theta += self.delta_thetan37                theta += self.theta_delta
38            elif char == "-":38            elif char == "-":
n39                theta -= self.delta_thetan39                theta -= self.theta_delta
40            myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)
41            myPlant.str=='FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X'
40        plt.axis("image")class DNAMOTIF:42        plt.axis("image")
43class DNAMOTIF:
41    def __init__(self):44    def __init__(self):
42        self.instances = []45        self.instances = []
43        self.consensus = []46        self.consensus = []
44        self.counts = {"A": [], "C": [], "G": [], "T": []}47        self.counts = {"A": [], "C": [], "G": [], "T": []}
45    def __str__(self):48    def __str__(self):
46        return "".join([str(item) for item in self.instances])49        return "".join([str(item) for item in self.instances])
47    def __len__(self):50    def __len__(self):
48        return len(self.instances[0].strip("\n"))51        return len(self.instances[0].strip("\n"))
49    def count(self):52    def count(self):
50        for key in self.counts:53        for key in self.counts:
51            self.counts[key] = [0] * len(self)54            self.counts[key] = [0] * len(self)
n52        for instance in self.instances:n55        for minstances in self.instances:
53            instance = instance.strip("\n")56            minstances = minstances.strip("\n")
54            for i in range(len(self)):57            for i in range(len(self)):
n55                if instance[i].upper() in self.counts:n58                if minstances[i].upper() in self.counts:
56                    self.counts[instance[i].upper()][i] += 159                    self.counts[minstances[i].upper()][i] += 1
57    def compute_consensus(self):60    def compute_consensus(self):
58        self.count()61        self.count()
59        self.consensus = [0] * len(self.counts['A'])62        self.consensus = [0] * len(self.counts['A'])
60        for i in range(len(self.counts['A'])):63        for i in range(len(self.counts['A'])):
t61            keymax = max(self.counts, key=lambda x: self.counts[x][i])t64            maximumkey = max(self.counts, key=lambda x: self.counts[x][i])
62            self.consensus[i] = keymax65            self.consensus[i] = maximumkey
63        self.consensus = "".join([str(item) for item in self.consensus])66        self.consensus = "".join([str(item) for item in self.consensus])
64    def parse(self, filename):67    def parse(self, filename):
65        with open(filename) as fp:68        with open(filename) as fp:
66            for line in fp:69            for line in fp:
67                if line[0] != ">":70                if line[0] != ">":
68                    self.instances.append("{}\n".format(line.strip()))71                    self.instances.append("{}\n".format(line.strip()))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 16

Student ID: 422, P-Value: 7.81e-08

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as plt n1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
n3import stringn
4class PLANT:3class PLANT:
n5    def __init__(self, init_state = '', dictionary = {}, n = 0, deltaTheta = 0):n4    def __init__(self, string, dictionary, n, deltaTheta):
6        self.init_state = init_state5        self.string = string
7        self.dictionary = dictionary6        self.dictionary = dictionary
8        self.n = n7        self.n = n
9        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n10        self.str = PLANT.generator(init_state, dictionary, n)n9        self.str = PLANT.generator(string,dictionary, n)
11    def generator(init_state, dictionary, n):10    def generator(string, dictionary, n):
12        def character_v(init_state):11        def character_v(string):
13            if init_state in dictionary:12            if string in dictionary:
14                return dictionary[init_state]13                return dictionary.get(string)
15            return init_state14            return string
16        substrings_list = [init_state]15        substrings_list = [string]
17        for i in range(n):16        for i in range(n):
18            substring = substrings_list[-1]17            substring = substrings_list[-1]
19            new_statement = [character_v(char) for char in substring]18            new_statement = [character_v(char) for char in substring]
20            substrings_list.append(''.join(new_statement))19            substrings_list.append(''.join(new_statement))
n21        new_state = substrings_list[n]n20        newstring = substrings_list[n]
22        return new_state21        return newstring
23    def drawPlant(self):22    def drawPlant(self):
n24        upper_letters = list(string.ascii_uppercase)n23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
 >'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
25        currentPt=(200,0)24        currentPt=(200,0)
26        theta = np.radians(90)25        theta = np.radians(90)
27        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
28        stack = [currentPt, theta]27        stack = [currentPt, theta]
29        for command in self.str:28        for command in self.str:
30            if command.upper() in upper_letters:29            if command.upper() in upper_letters:
31                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>ta)))>ta)))
32                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
33                currentPt = nextPt 32                currentPt = nextPt 
34            else:33            else:
35                if command == '[':34                if command == '[':
36                    stack.append(currentPt)35                    stack.append(currentPt)
37                    stack.append(theta)36                    stack.append(theta)
38                elif command == ']':37                elif command == ']':
39                    theta = stack.pop()38                    theta = stack.pop()
40                    currentPt = stack.pop()  39                    currentPt = stack.pop()  
41                elif command == '-':40                elif command == '-':
42                    theta -= deltaTheta41                    theta -= deltaTheta
43                elif command == '+':42                elif command == '+':
44                    theta += deltaTheta43                    theta += deltaTheta
45        return plt.plot44        return plt.plot
46if __name__ == "__main__":45if __name__ == "__main__":
47    string = input()46    string = input()
48    dictionary = input()47    dictionary = input()
49    n = int(input())48    n = int(input())
50    deltaTheta = float(input())49    deltaTheta = float(input())
51    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
52    p.drawPlant()51    p.drawPlant()
n53    plt.show()class DNAMOTIF: n52    plt.show()class DNAMOTIF:
54    def __init__(self):53    def __init__(self):
55        self.instances=[]54        self.instances=[]
56        self.consensus=[]55        self.consensus=[]
57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
58    def __str__(self):57    def __str__(self):
n59        outStr = ""n58        output = ""
60        for instance in self.instances:59        for instance in self.instances:
n61            outStr += instancen60            output += instance
62        return outStr61        return output
63    def __len__(self):62    def __len__(self):
64        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
65    def count(self):64    def count(self):
n66        for index in range(len(self)):n65        for position in range(len(self)):
67            sequenceA = 066            sequenceA = 0
68            sequenceT = 067            sequenceT = 0
69            sequenceC = 068            sequenceC = 0
70            sequenceG = 069            sequenceG = 0
71            for instance in self.instances:70            for instance in self.instances:
72                sequence = instance.rstrip()71                sequence = instance.rstrip()
n73                if (sequence[index]).upper() == "A":n72                if (sequence[position]).upper() == "A":
74                    sequenceA += 173                    sequenceA += 1
n75                elif (sequence[index]).upper() == "T":n74                elif (sequence[position]).upper() == "T":
76                    sequenceT += 175                    sequenceT += 1
n77                elif (sequence[index]).upper() == "C":n76                elif (sequence[position]).upper() == "C":
78                    sequenceC += 177                    sequenceC += 1
n79                elif (sequence[index]).upper() == "G":n78                elif (sequence[position]).upper() == "G":
80                    sequenceG += 179                    sequenceG += 1
81            self.counts.get("A").append(sequenceA)80            self.counts.get("A").append(sequenceA)
82            self.counts.get("T").append(sequenceT)81            self.counts.get("T").append(sequenceT)
83            self.counts.get("C").append(sequenceC)82            self.counts.get("C").append(sequenceC)
84            self.counts.get("G").append(sequenceG)83            self.counts.get("G").append(sequenceG)
85    def compute_consensus(self):84    def compute_consensus(self):
86        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
87        A = self.counts.get("A")86        A = self.counts.get("A")
88        T = self.counts.get("T")87        T = self.counts.get("T")
89        C = self.counts.get("C")88        C = self.counts.get("C")
90        G = self.counts.get("G")89        G = self.counts.get("G")
91        output = ""90        output = ""
92        for row in range(len(A)):91        for row in range(len(A)):
93            maxs = max(A[row],T[row],C[row],G[row])92            maxs = max(A[row],T[row],C[row],G[row])
94            if maxs == A[row]:93            if maxs == A[row]:
95                output += "A"94                output += "A"
96            elif maxs == T[row]:95            elif maxs == T[row]:
97                output += "T"96                output += "T"
98            elif maxs == C[row]:97            elif maxs == C[row]:
99                output += "C"98                output += "C"
100            elif maxs == G[row]:99            elif maxs == G[row]:
101                output += "G"100                output += "G"
102        self.consensus = output101        self.consensus = output
103    def parse(self, filename):102    def parse(self, filename):
104        myFile = open(filename, 'r')103        myFile = open(filename, 'r')
105        contents = [line for line in myFile.readlines()]104        contents = [line for line in myFile.readlines()]
106        myFile.close()105        myFile.close()
107        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
108            if index % 2 != 0:107            if index % 2 != 0:
109                self.instances.append(line)108                self.instances.append(line)
110if __name__ == '__main__':109if __name__ == '__main__':
111    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t112    filename = r'C:\\Users\\aboub\\OneDrive\\ENGR 131\\IN CLASS ASSIGNMENT\\lexAt111    filename = r'FinalProject\lexA.fasta' 
>.fasta'  
113    lexA.parse(filename)112    lexA.parse(filename)
114    lexA.compute_consensus()113    lexA.compute_consensus()
115    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 17

Student ID: 278, P-Value: 7.81e-08

Nearest Neighbor ID: 492

Student (left) and Nearest Neighbor (right).


nn1import matplotlib.pyplot as plt
2from math import pi, sin, cos
1class PLANT:3class PLANT:
2    def __init__(self, init_state = "", generator = {}, iters = 0, delta_theta =4    def __init__(self, init_state = "", generator = {}, iters = 0, delta_theta =
> 0):> 0):
3        self.__start = init_state5        self.__start = init_state
4        self.__generator = generator6        self.__generator = generator
5        self.__iters = iters7        self.__iters = iters
6        self.__delta = delta_theta8        self.__delta = delta_theta
7        self.str = self.generator()9        self.str = self.generator()
8    def generator(self):10    def generator(self):
n9        passclass DNAMOTIF:n11        myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)class DNAMOTIF:
10    def file(self):12    def file(self):
n11        file = open('lexA.fasta', 'r')n13        file = open('lexA.fasta')
12        for line in file:14        for line in file:
13            if line[0] != '>':15            if line[0] != '>':
14                self.instances.append(line)16                self.instances.append(line)
15    def __init__(self):17    def __init__(self):
16        self.instances=[]18        self.instances=[]
17        self.consensus=[]19        self.consensus=[]
18        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}20        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
19    def __str__(self):21    def __str__(self):
20        dna_str = ""22        dna_str = ""
21        for string in self.instances:23        for string in self.instances:
22            dna_str += (string + "\n")24            dna_str += (string + "\n")
23        return dna_str25        return dna_str
24    def __len__(self):26    def __len__(self):
25        return len(self.instances) - 427        return len(self.instances) - 4
26    def count(self):28    def count(self):
27        for i in self.instances:29        for i in self.instances:
28            temp = i.upper()30            temp = i.upper()
29            self.counts['A'].append(temp.count('A'))31            self.counts['A'].append(temp.count('A'))
30            self.counts['C'].append(temp.count('C'))32            self.counts['C'].append(temp.count('C'))
31            self.counts['G'].append(temp.count('G'))33            self.counts['G'].append(temp.count('G'))
32            self.counts['T'].append(temp.count('T'))34            self.counts['T'].append(temp.count('T'))
33    def compute_consensus(self):35    def compute_consensus(self):
n34        dna_str = str("")n36        dna_str = ""
35        for i in range(len(self.instances[0])):37        for i in range(len(self.instances[0])):
36            a_count = 038            a_count = 0
37            c_count = 039            c_count = 0
38            g_count = 040            g_count = 0
39            t_count = 041            t_count = 0
40            for j in range(len(self.instances[0])):42            for j in range(len(self.instances[0])):
n41                curr = str(self.instances[j])n43                ocurrence = self.instances[j]
42                if curr[i].upper() == 'A':44                if ocurrence[i].upper() == 'A':
43                    a_count += 145                    a_count += 1
n44                elif curr[i].upper() == 'C':n46                elif ocurrence[i].upper() == 'C':
45                    c_count += 147                    c_count += 1
n46                elif curr[i].upper() == 'G':n48                elif ocurrence[i].upper() == 'G':
47                    g_count += 149                    g_count += 1
n48                elif curr[i].upper() == 'T':n50                elif ocurrence[i].upper() == 'T':
49                    t_count += 151                    t_count += 1
50                if a_count > c_count and a_count > g_count and a_count > t_count52                if a_count > c_count and a_count > g_count and a_count > t_count
>:>:
51                    dna_str += "A"53                    dna_str += "A"
52                elif c_count > a_count and c_count > g_count and c_count > t_cou54                elif c_count > a_count and c_count > g_count and c_count > t_cou
>nt:>nt:
53                    dna_str += "C"55                    dna_str += "C"
54                elif g_count > a_count and g_count > t_count and g_count > c_cou56                elif g_count > a_count and g_count > t_count and g_count > c_cou
>nt:>nt:
55                    dna_str += "G"57                    dna_str += "G"
56                elif t_count > a_count and t_count > g_count and t_count > c_cou58                elif t_count > a_count and t_count > g_count and t_count > c_cou
>nt:>nt:
57                    dna_str += "T"59                    dna_str += "T"
58        return dna_str60        return dna_str
59    def parse(self, filename):61    def parse(self, filename):
t60        with open(filename,'r') as file:t62        with open(filename,'r') as f:
61            for i in file:63            for i in f:
62                if '>' in i:64                if '>' in i:
63                    continue65                    continue
64                else:66                else:
65                    self.instances.append(i)67                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 18

Student ID: 492, P-Value: 7.81e-08

Nearest Neighbor ID: 278

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as pltn
2from math import pi, sin, cos
3class PLANT:1class PLANT:
4    def __init__(self, init_state = "", generator = {}, iters = 0, delta_theta =2    def __init__(self, init_state = "", generator = {}, iters = 0, delta_theta =
> 0):> 0):
5        self.__start = init_state3        self.__start = init_state
6        self.__generator = generator4        self.__generator = generator
7        self.__iters = iters5        self.__iters = iters
8        self.__delta = delta_theta6        self.__delta = delta_theta
9        self.str = self.generator()7        self.str = self.generator()
10    def generator(self):8    def generator(self):
n11        myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)class DNAMOTIF:n9        passclass DNAMOTIF:
12    def file(self):10    def file(self):
n13        file = open('lexA.fasta')n11        file = open('lexA.fasta', 'r')
14        for line in file:12        for line in file:
15            if line[0] != '>':13            if line[0] != '>':
16                self.instances.append(line)14                self.instances.append(line)
17    def __init__(self):15    def __init__(self):
18        self.instances=[]16        self.instances=[]
19        self.consensus=[]17        self.consensus=[]
20        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}18        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
21    def __str__(self):19    def __str__(self):
22        dna_str = ""20        dna_str = ""
23        for string in self.instances:21        for string in self.instances:
24            dna_str += (string + "\n")22            dna_str += (string + "\n")
25        return dna_str23        return dna_str
26    def __len__(self):24    def __len__(self):
27        return len(self.instances) - 425        return len(self.instances) - 4
28    def count(self):26    def count(self):
29        for i in self.instances:27        for i in self.instances:
30            temp = i.upper()28            temp = i.upper()
31            self.counts['A'].append(temp.count('A'))29            self.counts['A'].append(temp.count('A'))
32            self.counts['C'].append(temp.count('C'))30            self.counts['C'].append(temp.count('C'))
33            self.counts['G'].append(temp.count('G'))31            self.counts['G'].append(temp.count('G'))
34            self.counts['T'].append(temp.count('T'))32            self.counts['T'].append(temp.count('T'))
35    def compute_consensus(self):33    def compute_consensus(self):
n36        dna_str = ""n34        dna_str = str("")
37        for i in range(len(self.instances[0])):35        for i in range(len(self.instances[0])):
38            a_count = 036            a_count = 0
39            c_count = 037            c_count = 0
40            g_count = 038            g_count = 0
41            t_count = 039            t_count = 0
42            for j in range(len(self.instances[0])):40            for j in range(len(self.instances[0])):
n43                ocurrence = self.instances[j]n41                curr = str(self.instances[j])
44                if ocurrence[i].upper() == 'A':42                if curr[i].upper() == 'A':
45                    a_count += 143                    a_count += 1
n46                elif ocurrence[i].upper() == 'C':n44                elif curr[i].upper() == 'C':
47                    c_count += 145                    c_count += 1
n48                elif ocurrence[i].upper() == 'G':n46                elif curr[i].upper() == 'G':
49                    g_count += 147                    g_count += 1
n50                elif ocurrence[i].upper() == 'T':n48                elif curr[i].upper() == 'T':
51                    t_count += 149                    t_count += 1
52                if a_count > c_count and a_count > g_count and a_count > t_count50                if a_count > c_count and a_count > g_count and a_count > t_count
>:>:
53                    dna_str += "A"51                    dna_str += "A"
54                elif c_count > a_count and c_count > g_count and c_count > t_cou52                elif c_count > a_count and c_count > g_count and c_count > t_cou
>nt:>nt:
55                    dna_str += "C"53                    dna_str += "C"
56                elif g_count > a_count and g_count > t_count and g_count > c_cou54                elif g_count > a_count and g_count > t_count and g_count > c_cou
>nt:>nt:
57                    dna_str += "G"55                    dna_str += "G"
58                elif t_count > a_count and t_count > g_count and t_count > c_cou56                elif t_count > a_count and t_count > g_count and t_count > c_cou
>nt:>nt:
59                    dna_str += "T"57                    dna_str += "T"
60        return dna_str58        return dna_str
61    def parse(self, filename):59    def parse(self, filename):
t62        with open(filename,'r') as f:t60        with open(filename,'r') as file:
63            for i in f:61            for i in file:
64                if '>' in i:62                if '>' in i:
65                    continue63                    continue
66                else:64                else:
67                    self.instances.append(i)65                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 19

Student ID: 405, P-Value: 1.08e-07

Nearest Neighbor ID: 232

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n3class PLANT: n3class PLANT:
4   def __init__(self, str, generator, iterations, delta):  4    def __init__(self, str, generator, iterations, gamma):
5       self.str = str  5       self.str = str
6       self.generator = generator 6       self.generator = generator
7       self.iterations = iterations 7       self.iterations = iterations
8       self.delta = delta   8       self.gamma = gamma
9       self.stack = []  9       self.stack = []
10       for l in range(self.iterations):  10       for l in range(self.iterations):
11           lst_str = list(self.str)  11           list_str = list(self.str)
12           for i, v in enumerate(lst_str): 12           for i, w in enumerate(list_str):
13               if v in self.generator:  13               if w in self.generator:
14                   lst_str[i] = self.generator[v] 14                   list_str[i] = self.generator[w]
15           self.str = ''.join(lst_str)  15           self.str = "".join(list_str)
16   def drawPlant(self):  16    def drawPlant(self):
17       currentPt = (200.0, 0.0)  17       currentPt = (200.0, 0.0)
18       tree_angle = 90 18       treejawn = 90.0
19       self.add([currentPt, tree_angle]) 19       self.add([currentPt, treejawn])
20       list_str = list(self.str)   20       list_str = list(self.str)
21       for i, v in enumerate(list_str): 21       for i, w in enumerate(list_str):
22           if v == '[': 22           if w == '[':
23               self.add([currentPt, tree_angle])  23               self.add([currentPt, treejawn])
24           elif v == ']': 24           elif w == ']':
25               [currentPt, tree_angle] = self.peek() 25               [currentPt, treejawn] = self.peek()
26           elif v == '+': 26           elif w == '+':
27               tree_angle += self.delta  27               treejawn += self.gamma
28           elif v == '-': 28           elif w == '-':
29               tree_angle -= self.delta  29               treejawn -= self.gamma
30           elif v.isalpha(): 30           elif w.isalpha():
31               nextPt = (currentPt[0] + math.cos(math.radians(tree_angle)), curr31               nextPt = (currentPt[0] + math.cos(math.radians(treejawn)), curren
>entPt[1] + math.sin(math.radians(tree_angle))) >tPt[1] + math.sin(math.radians(treejawn)))
32               plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], co32               plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], co
>lor='green')  >lor='green')
33               currentPt = nextPt  33               currentPt = nextPt
34   def add(self, data):  34    def add(self, data):
35       self.stack.append(data)   35       self.stack.append(data)
36   def peek(self):   36    def peek(self):
37       return self.stack[-1]    37       return self.stack[-1]
38if __name__ == '__main__':   38if __name__ == '__main__':
39   np = PLANT('X', {'X': 'F[+X]F[-X]+X', 'F': 'FF'}, 2, 20) 39   np = PLANT('X', {'X': 'F[+X]F[-X]+X', 'F': 'FF'}, 2, 20)
40   np.drawPlant()  40   np.drawPlant()class DNAMOTIF:
41class DNAMOTIF:
42    def __init__(self):41    def __init__(self):
43        self.instances=[]42        self.instances=[]
44        self.consensus=[]43        self.consensus=[]
45        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}44        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
46    def __str__(self):45    def __str__(self):
47        str = ''   46        str = ''   
48        for i in self.instances:   47        for i in self.instances:   
49            str += i + '\n'   48            str += i + '\n'   
50        return str[:-2]49        return str[:-2]
51    def __len__(self):50    def __len__(self):
52        return (len(self.instances[0])-1)51        return (len(self.instances[0])-1)
53    def count(self):52    def count(self):
54        for i in self.instances:      53        for i in self.instances:      
n55            t = i.upper()     n54            jawn = i.upper()     
56            self.counts['A'].append(t.count('A'))     55            self.counts['A'].__add__(jawn.count('A'))     
57            self.counts['C'].append(t.count('C'))   56            self.counts['C'].__add__(jawn.count('C'))   
58            self.counts['G'].append(t.count('G'))     57            self.counts['G'].__add__(jawn.count('G'))     
59            self.counts['T'].append(t.count('T'))      58            self.counts['T'].__add__(jawn.count('T'))      
60    def compute_consensus(self):59    def compute_consensus(self):
61        A = self.counts['A']     60        A = self.counts['A']     
62        C = self.counts['C']   61        C = self.counts['C']   
63        G = self.counts['G']   62        G = self.counts['G']   
64        T = self.counts['T']   63        T = self.counts['T']   
65        for i in range(list(A)):64        for i in range(list(A)):
66            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):   65            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):   
67                self.consensus.append(A)   66                self.consensus.append(A)   
68            elif (C[i] >= G[i] and C[i] >= T[i]):   67            elif (C[i] >= G[i] and C[i] >= T[i]):   
69                self.consensus.append(C)   68                self.consensus.append(C)   
70            elif (G[i] >= T[i]):   69            elif (G[i] >= T[i]):   
71                self.consensus.append(G)  70                self.consensus.append(G)  
72        else:   71        else:   
73            self.consensus.append(T)    72            self.consensus.append(T)    
74    def parse(self, filename):73    def parse(self, filename):
75        with open(filename,'r') as f:   74        with open(filename,'r') as f:   
76            for i in f:   75            for i in f:   
77                if '>' in i:     76                if '>' in i:     
78                    continue   77                    continue   
79                else:     78                else:     
80                    self.instances.append(i)         79                    self.instances.append(i)         
81if __name__=='__main__':   80if __name__=='__main__':   
82  lex=DNAMOTIF()   81  lex=DNAMOTIF()   
83  lex.parse('lexA.fasta')  82  lex.parse('lexA.fasta')  
84  print('length of each sequence:',len(lex))    83  print('length of each sequence:',len(lex))    
85  print(lex)   84  print(lex)   
86  print('\nconsensus:',lex.consensus, '\n')   85  print('\nconsensus:',lex.consensus, '\n')   
t87  print('sequence counts:',lex.counts)     t86  print('sequence counts:',lex.counts)      
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 20

Student ID: 488, P-Value: 1.08e-07

Nearest Neighbor ID: 345

Student (left) and Nearest Neighbor (right).


nn1import matplotlib.pyplot as plt
1import numpy as np2import numpy as np
n2import matplotlib.pyplot as pltn
3class PLANT:3class PLANT:
n4    def __init__(self, string, dictionary, n, delta_Theta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
n8        self.delta_Theta = delta_Thetan8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string,dictionary, n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string, dictionary, n):10    def generator(string, dictionary, n):
n11        def variable(string):n11        def production_rule(string):
12            if string in dictionary:12            if string in dictionary:
13                return dictionary.get(string)13                return dictionary.get(string)
14            return string14            return string
n15        listsubstrings = [string]n15        list_of_substrings = [string]
16        for i in range(n):16        for i in range(n):
n17            current_substring = listsubstrings[-1]n17            current_substring = list_of_substrings[-1]
18            new_axiom = [variable(char) for char in current_substring]18            new_axiom = [production_rule(char) for char in current_substring]
19            listsubstrings.append(''.join(new_axiom))19            list_of_substrings.append(''.join(new_axiom))
20        new_string = listsubstrings[n]20        newstring = list_of_substrings[n]
21        return new_string21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
n23        upper_alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'Ln23        uppera = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M
>', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        current_Plant=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
n26        delta_Theta = np.radians(self.delta_Theta)n26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [current_Plant, theta]27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
n29            if command.upper() in upper_alpha:n29            if command.upper() in uppera:
30                next_Plant = (current_Plant[0]+(np.cos(theta)), current_Plant[1]30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>+(np.sin(theta)))>ta)))
31                plt.plot([current_Plant[0],next_Plant[0]],[current_Plant[1],next31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>_Plant[1]],color='black')>='black')
32                current_Plant = next_Plant 32                currentPt = nextPt
33            else:33            else:
34                if command == '[':34                if command == '[':
n35                    stack.append(current_Plant)n35                    stack.append(currentPt)
36                    stack.append(theta)36                    stack.append(theta)
37                elif command == ']':37                elif command == ']':
38                    theta = stack.pop()38                    theta = stack.pop()
n39                    current_Plant = stack.pop()  n39                    currentPt = stack.pop()
40                elif command == '+':40                elif command == '+':
n41                    theta += delta_Thetan41                    theta += deltaTheta
42                elif command == '-':42                elif command == '-':
n43                    theta -= delta_Thetan43                    theta -= deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
n49    delta_Theta = float(input())n49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
n52    plt.show()class DNAMOTIF:n52    plt.show()class DNAMOTIF: 
53    def __init__(self):53    def __init__(self):
54        self.instances=[]54        self.instances=[]
55        self.consensus=[]55        self.consensus=[]
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
58        output = ""58        output = ""
59        for instance in self.instances:59        for instance in self.instances:
60            output += instance60            output += instance
61        return output61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
65        for position in range(len(self)):65        for position in range(len(self)):
n66            seq_T = 0n
67            seq_A = 066            sequenceA = 0
68            seq_G = 067            sequenceT = 0
69            seq_C = 068            sequenceC = 0
69            sequenceG = 0
70            for instance in self.instances:70            for instance in self.instances:
71                sequence = instance.rstrip()71                sequence = instance.rstrip()
n72                if (sequence[position]).upper() == "G":n72                if (sequence[position]).upper() == "A":
73                    seq_G = seq_G + 173                    sequenceA += 1
74                elif (sequence[position]).upper() == "T":
75                    sequenceT += 1
74                elif (sequence[position]).upper() == "C":76                elif (sequence[position]).upper() == "C":
n75                    seq_C = seq_C + 1n77                    sequence+= 1
76                elif (sequence[position]).upper() == "T":78                elif (sequence[position]).upper() == "G":
77                    seq_T = seq_T + 179                    sequenceG += 1
78                elif (sequence[position]).upper() == "A":
79                    seq_A = seq_A + 1
80            self.counts.get("A").append(seq_A)80            self.counts.get("A").append(sequenceA)
81            self.counts.get("T").append(seq_T)81            self.counts.get("T").append(sequenceT)
82            self.counts.get("C").append(seq_C)82            self.counts.get("C").append(sequenceC)
83            self.counts.get("G").append(seq_G)83            self.counts.get("G").append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
86        A = self.counts.get("A")86        A = self.counts.get("A")
nn87        T = self.counts.get("T")
88        C = self.counts.get("C")
87        G = self.counts.get("G")89        G = self.counts.get("G")
n88        C = self.counts.get("C")n
89        T = self.counts.get("T")
90        output = ""90        output = ""
91        for row in range(len(A)):91        for row in range(len(A)):
92            maximum = max(A[row],T[row],C[row],G[row])92            maximum = max(A[row],T[row],C[row],G[row])
93            if maximum == A[row]:93            if maximum == A[row]:
n94                output = output + "A"n94                output += "A"
95            elif maximum == T[row]:
96                output += "T"
97            elif maximum == C[row]:
98                output += "C"
95            elif maximum == G[row]:99            elif maximum == G[row]:
n96                output = output +"G"n100                output += "G"
97            elif maximum == C[row]:
98                output = output + "C"
99            elif maximum == T[row]:
100                output = output + "T"
101        self.consensus = output101        self.consensus = output
102    def parse(self, filename):102    def parse(self, filename):
n103        my_File = open(filename, 'r')n103        myFile = open(filename, 'r') 
104        contents = [line for line in my_File.readlines()]104        contents = [line for line in myFile.readlines()] 
105        my_File.close()105        myFile.close() 
106        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
107            if index % 2 != 0:107            if index % 2 != 0:
108                self.instances.append(line)108                self.instances.append(line)
109if __name__ == '__main__':109if __name__ == '__main__':
n110    lexA=DNAMOTIF()n110    lexA=DNAMOTIF() 
111    filename = r'FinalProject\lexA.fasta' 111    filename = r'FinalProject\lexA.fasta' 
t112    lexA.parse(filename)t112    lexA.parse(filename) 
113    lexA.compute_consensus()113    lexA.compute_consensus() 
114    print(lexA.consensus)114    print(lexA.consensus) 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 21

Student ID: 232, P-Value: 1.08e-07

Nearest Neighbor ID: 405

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n3class PLANT:n3class PLANT: 
4    def __init__(self, str, generator, iterations, gamma):4   def __init__(self, str, generator, iterations, delta):  
5       self.str = str5       self.str = str  
6       self.generator = generator6       self.generator = generator 
7       self.iterations = iterations7       self.iterations = iterations 
8       self.gamma = gamma8       self.delta = delta   
9       self.stack = []9       self.stack = []  
10       for l in range(self.iterations):10       for l in range(self.iterations):  
11           list_str = list(self.str)11           lst_str = list(self.str)  
12           for i, w in enumerate(list_str):12           for i, v in enumerate(lst_str): 
13               if w in self.generator:13               if v in self.generator:  
14                   list_str[i] = self.generator[w]14                   lst_str[i] = self.generator[v] 
15           self.str = "".join(list_str)15           self.str = ''.join(lst_str)  
16    def drawPlant(self):16   def drawPlant(self):  
17       currentPt = (200.0, 0.0)17       currentPt = (200.0, 0.0)  
18       treejawn = 90.018       tree_angle = 90 
19       self.add([currentPt, treejawn])19       self.add([currentPt, tree_angle]) 
20       list_str = list(self.str)20       list_str = list(self.str)   
21       for i, w in enumerate(list_str):21       for i, v in enumerate(list_str): 
22           if w == '[':22           if v == '[': 
23               self.add([currentPt, treejawn])23               self.add([currentPt, tree_angle])  
24           elif w == ']':24           elif v == ']': 
25               [currentPt, treejawn] = self.peek()25               [currentPt, tree_angle] = self.peek() 
26           elif w == '+':26           elif v == '+': 
27               treejawn += self.gamma27               tree_angle += self.delta  
28           elif w == '-':28           elif v == '-': 
29               treejawn -= self.gamma29               tree_angle -= self.delta  
30           elif w.isalpha():30           elif v.isalpha(): 
31               nextPt = (currentPt[0] + math.cos(math.radians(treejawn)), curren31               nextPt = (currentPt[0] + math.cos(math.radians(tree_angle)), curr
>tPt[1] + math.sin(math.radians(treejawn)))>entPt[1] + math.sin(math.radians(tree_angle))) 
32               plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], co32               plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], co
>lor='green')>lor='green')  
33               currentPt = nextPt33               currentPt = nextPt  
34    def add(self, data):34   def add(self, data):  
35       self.stack.append(data)35       self.stack.append(data)   
36    def peek(self):36   def peek(self):   
37       return self.stack[-1]37       return self.stack[-1]    
38if __name__ == '__main__':38if __name__ == '__main__':   
39   np = PLANT('X', {'X': 'F[+X]F[-X]+X', 'F': 'FF'}, 2, 20)39   np = PLANT('X', {'X': 'F[+X]F[-X]+X', 'F': 'FF'}, 2, 20) 
40   np.drawPlant()class DNAMOTIF:40   np.drawPlant()  
41class DNAMOTIF:
41    def __init__(self):42    def __init__(self):
42        self.instances=[]43        self.instances=[]
43        self.consensus=[]44        self.consensus=[]
44        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}45        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
45    def __str__(self):46    def __str__(self):
46        str = ''   47        str = ''   
47        for i in self.instances:   48        for i in self.instances:   
48            str += i + '\n'   49            str += i + '\n'   
49        return str[:-2]50        return str[:-2]
50    def __len__(self):51    def __len__(self):
51        return (len(self.instances[0])-1)52        return (len(self.instances[0])-1)
52    def count(self):53    def count(self):
53        for i in self.instances:      54        for i in self.instances:      
n54            jawn = i.upper()     n55            t = i.upper()     
55            self.counts['A'].__add__(jawn.count('A'))     56            self.counts['A'].append(t.count('A'))     
56            self.counts['C'].__add__(jawn.count('C'))   57            self.counts['C'].append(t.count('C'))   
57            self.counts['G'].__add__(jawn.count('G'))     58            self.counts['G'].append(t.count('G'))     
58            self.counts['T'].__add__(jawn.count('T'))      59            self.counts['T'].append(t.count('T'))      
59    def compute_consensus(self):60    def compute_consensus(self):
60        A = self.counts['A']     61        A = self.counts['A']     
61        C = self.counts['C']   62        C = self.counts['C']   
62        G = self.counts['G']   63        G = self.counts['G']   
63        T = self.counts['T']   64        T = self.counts['T']   
64        for i in range(list(A)):65        for i in range(list(A)):
65            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):   66            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):   
66                self.consensus.append(A)   67                self.consensus.append(A)   
67            elif (C[i] >= G[i] and C[i] >= T[i]):   68            elif (C[i] >= G[i] and C[i] >= T[i]):   
68                self.consensus.append(C)   69                self.consensus.append(C)   
69            elif (G[i] >= T[i]):   70            elif (G[i] >= T[i]):   
70                self.consensus.append(G)  71                self.consensus.append(G)  
71        else:   72        else:   
72            self.consensus.append(T)    73            self.consensus.append(T)    
73    def parse(self, filename):74    def parse(self, filename):
74        with open(filename,'r') as f:   75        with open(filename,'r') as f:   
75            for i in f:   76            for i in f:   
76                if '>' in i:     77                if '>' in i:     
77                    continue   78                    continue   
78                else:     79                else:     
79                    self.instances.append(i)         80                    self.instances.append(i)         
80if __name__=='__main__':   81if __name__=='__main__':   
81  lex=DNAMOTIF()   82  lex=DNAMOTIF()   
82  lex.parse('lexA.fasta')  83  lex.parse('lexA.fasta')  
83  print('length of each sequence:',len(lex))    84  print('length of each sequence:',len(lex))    
84  print(lex)   85  print(lex)   
85  print('\nconsensus:',lex.consensus, '\n')   86  print('\nconsensus:',lex.consensus, '\n')   
t86  print('sequence counts:',lex.counts)      t87  print('sequence counts:',lex.counts)     
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 22

Student ID: 414, P-Value: 1.49e-07

Nearest Neighbor ID: 279

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
3class PLANT:3class PLANT:
n4    def __init__(self,initialStr,generator,numIters,deltaTheta):n4    def __init__(self,initialStr,randomizer,numInts,deltaTheta):
5        self.str = initialStr5        self.str=initialStr
6        self.generator= generator6        self.randomizer= randomizer
7        self.numIters = numIters7        self.numInts = numInts
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        for i in range(numIters):n9        for i in range(numInts):
10            new_string = ""10            string_1 = ""
11            for letter in self.str:11            for letter in self.str:
n12                if letter in self.generator:n12                if letter in self.randomizer:
13                    new_string =new_string+self.generator[letter]13                    string_1 = string_1+self.randomizer[letter]
14                else:14                else:
n15                    new_string =new_string+lettern15                    string_1 = string_1 + letter
16            self.str = new_string16            self.str = string_1
17    def drawPlant(self):17    def drawPlant(self):
n18        currentPt =(200,0)n18        currentPt = (200,0)
19        stack = []19        stack = []
n20        theta =90n20        theta = 90
21        for letter in self.str:21        for letter in self.str:
nn22            if letter == "]":
23                recent_save = stack.pop()
24                theta = recent_save[1]
25                currentPt = recent_save[0]
22            if letter == "[":26            elif letter == "[":
23                stack.append([currentPt,theta])27                stack.append([currentPt,theta])
n24            elif letter == "]":n
25                current_save = stack.pop()
26                theta = current_save[1]
27                currentPt = current_save[0]
28            elif letter =="+":
29                theta = theta+self.deltaTheta
30            elif letter =="-":28            elif letter == "-":
31                theta -= self.deltaTheta29                theta -= self.deltaTheta
nn30            elif letter == "+":
31                theta = theta + self.deltaTheta
32            else:32            else:
33                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[133                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[1
>] + math.sin(math.radians(theta)))>] + math.sin(math.radians(theta)))
n34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], cn34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor="black")>olor = "black")
35                currentPt = nextPt35                currentPt = nextPt
36class DNAMOTIF:36class DNAMOTIF:
37    def __init__(self):37    def __init__(self):
38        self.instances=[]38        self.instances=[]
39        self.consensus=[]39        self.consensus=[]
40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
41    def __str__(self):41    def __str__(self):
42        file = ''42        file = ''
n43        for line in self.instances:n43        for row in self.instances:
44            file += line44            file += row
45        return file45        return file
46    def __len__(self):46    def __len__(self):
47        return len(self.instances[0])-147        return len(self.instances[0])-1
48    def count(self):48    def count(self):
n49        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n49        self.counts= {'A':[], 'C':[], 'G':[], 'T':[]}
50        for i in range(len(self.instances[0])-1):50        for n in range(len(self.instances[0])-1):
51            for key in self.counts.keys():51            for key in self.counts.keys():
52                self.counts[key].append(0)52                self.counts[key].append(0)
n53                for line in self.instances:n53                for row in self.instances:
54                    if line[i].upper()==key:54                    if row[n].upper()==key:
55                        self.counts[key][i]+=155                        self.counts[key][n]+=1
56        return self.counts56        return self.counts
57    def compute_consensus(self):57    def compute_consensus(self):
n58        self.consensus = []n58        self.consunsus = []
59        self.counts = self.count()59        self.counts = self.count()
n60        for charPos in range(len(self.instances[0])-1):n60        for charP in range (len(self.instances[0])-1):
61            self.consensus.append(max(self.counts, key=lambda x: self.counts[x][61            self.consensus.append(max(self.counts, key=lambda y: self.counts[y][
>charPos]).upper())>charP]).upper())
62        self.consensus = str(''.join(self.consensus))62        self.consensus = str(''.join(self.consensus))
63    def parse(self, filename):63    def parse(self, filename):
t64        file1 = open(filename, 'r')t64        fileA = open(filename, 'r')
65        Lines = file1.readlines()65        Rows = fileA.readlines()
66        for line in Lines:66        for row in Rows:
67            if not line.startswith('>'):67            if not row.startswith('>'):
68                self.instances.append(line)68                self.instances.append(row)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 23

Student ID: 279, P-Value: 1.49e-07

Nearest Neighbor ID: 414

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
3class PLANT:3class PLANT:
n4    def __init__(self,initialStr,randomizer,numInts,deltaTheta):n4    def __init__(self,initialStr,generator,numIters,deltaTheta):
5        self.str=initialStr5        self.str = initialStr
6        self.randomizer= randomizer6        self.generator= generator
7        self.numInts = numInts7        self.numIters = numIters
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        for i in range(numInts):n9        for i in range(numIters):
10            string_1 = ""10            new_string = ""
11            for letter in self.str:11            for letter in self.str:
n12                if letter in self.randomizer:n12                if letter in self.generator:
13                    string_1 = string_1+self.randomizer[letter]13                    new_string =new_string+self.generator[letter]
14                else:14                else:
n15                    string_1 = string_1 + lettern15                    new_string =new_string+letter
16            self.str = string_116            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
n18        currentPt = (200,0)n18        currentPt =(200,0)
19        stack = []19        stack = []
n20        theta = 90n20        theta =90
21        for letter in self.str:21        for letter in self.str:
n22            if letter == "]":n
23                recent_save = stack.pop()
24                theta = recent_save[1]
25                currentPt = recent_save[0]
26            elif letter == "[":22            if letter == "[":
27                stack.append([currentPt,theta])23                stack.append([currentPt,theta])
nn24            elif letter == "]":
25                current_save = stack.pop()
26                theta = current_save[1]
27                currentPt = current_save[0]
28            elif letter =="+":
29                theta = theta+self.deltaTheta
28            elif letter == "-":30            elif letter =="-":
29                theta -= self.deltaTheta31                theta -= self.deltaTheta
n30            elif letter == "+":n
31                theta = theta + self.deltaTheta
32            else:32            else:
33                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[133                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[1
>] + math.sin(math.radians(theta)))>] + math.sin(math.radians(theta)))
n34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], cn34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = "black")>olor="black")
35                currentPt = nextPt35                currentPt = nextPt
36class DNAMOTIF:36class DNAMOTIF:
37    def __init__(self):37    def __init__(self):
38        self.instances=[]38        self.instances=[]
39        self.consensus=[]39        self.consensus=[]
40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
41    def __str__(self):41    def __str__(self):
42        file = ''42        file = ''
n43        for row in self.instances:n43        for line in self.instances:
44            file += row44            file += line
45        return file45        return file
46    def __len__(self):46    def __len__(self):
47        return len(self.instances[0])-147        return len(self.instances[0])-1
48    def count(self):48    def count(self):
n49        self.counts= {'A':[], 'C':[], 'G':[], 'T':[]}n49        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
50        for n in range(len(self.instances[0])-1):50        for i in range(len(self.instances[0])-1):
51            for key in self.counts.keys():51            for key in self.counts.keys():
52                self.counts[key].append(0)52                self.counts[key].append(0)
n53                for row in self.instances:n53                for line in self.instances:
54                    if row[n].upper()==key:54                    if line[i].upper()==key:
55                        self.counts[key][n]+=155                        self.counts[key][i]+=1
56        return self.counts56        return self.counts
57    def compute_consensus(self):57    def compute_consensus(self):
n58        self.consunsus = []n58        self.consensus = []
59        self.counts = self.count()59        self.counts = self.count()
n60        for charP in range (len(self.instances[0])-1):n60        for charPos in range(len(self.instances[0])-1):
61            self.consensus.append(max(self.counts, key=lambda y: self.counts[y][61            self.consensus.append(max(self.counts, key=lambda x: self.counts[x][
>charP]).upper())>charPos]).upper())
62        self.consensus = str(''.join(self.consensus))62        self.consensus = str(''.join(self.consensus))
63    def parse(self, filename):63    def parse(self, filename):
t64        fileA = open(filename, 'r')t64        file1 = open(filename, 'r')
65        Rows = fileA.readlines()65        Lines = file1.readlines()
66        for row in Rows:66        for line in Lines:
67            if not row.startswith('>'):67            if not line.startswith('>'):
68                self.instances.append(row)68                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 24

Student ID: 73, P-Value: 3.51e-07

Nearest Neighbor ID: 123

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
n4    def __init__ (self, initState, generator, n, delta_theta):n4    def __init__ (self, initResult, generator, n, delta_Theta):
5        self.init_state = initState5        self.init_result = initResult
6        self.gen = generator6        self.gen = generator
7        self.num = n7        self.num = n
n8        self.deltatheta = delta_thetan8        self.deltaTheta = delta_Theta 
9        self.str = self.init_state9        self.str = self.init_result
10        self.str2 = ''10        self.str2 = "" 
11        for i in range(self.num):11        for i in range(self.num):
n12            self.str2 = ''n12            self.str2 = ""
13            for char in self.str:13            for char in self.str:
14                if char in self.gen:14                if char in self.gen:
15                    self.str2 += self.gen[char]15                    self.str2 += self.gen[char]
16                else:16                else:
17                    self.str2 += char17                    self.str2 += char
n18            self.str = self.str2n18            self.str = self.str2 
19    def drawPlant(self):19    def drawPlant(self): 
20        currentpt = (200,0)20        currentPt = (200,0) 
21        theta = pi/221        theta = pi/2
n22        nextpt = ()n22        nextPt = ()
23        stack = []23        stack = [] 
24        for CHR in self.str:24        for character in self.str:
25            if CHR.isalpha():25            if character.isalpha():
26                nextpt = (currentpt[0]+cos(theta), currentpt[1]+sin(theta))26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta)) 
27                plt.plot([currentpt[0],nextpt[0]],[currentpt[1],nextpt[1]],color27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black') >='black') 
28                currentpt = nextpt28                currentPt = nextPt 
29            elif CHR == '[':29            elif character == "[":
30                stack.append([currentpt, theta]) 30                stack.append([currentPt, theta])
31            elif CHR == ']':31            elif character == "]":
32                currentpt, theta = stack.pop() 32                currentPt, theta = stack.pop()
33            elif CHR == '+':33            elif character == "+":
34                theta += (self.deltatheta * (pi/180)) 34                theta += (self.deltaTheta * (pi/180)) 
35            elif CHR == '-':35            elif character == "-":
36                theta -= (self.deltatheta * (pi/180))36                theta -= (self.deltaTheta * (pi/180))
37        plt.show() 
37class DNAMOTIF:38class DNAMOTIF:
38    def __init__(self):39    def __init__(self):
39        self.instances=[]40        self.instances=[]
40        self.consensus=[]41        self.consensus=[]
41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):43    def __str__(self):
n43        mystring = ''n44        pystr = ''
44        for item in self.instances:45        for item in self.instances:
n45            mystring += itemn46            pystr += item
46        return mystring47        return pystr
47    def __len__(self):48    def __len__(self):
48        return len(self.instances[0].rstrip('\n'))49        return len(self.instances[0].rstrip('\n'))
49    def count(self):50    def count(self):
50        for index in range(self.__len__()):51        for index in range(self.__len__()):
51            countA = 052            countA = 0
52            countC = 053            countC = 0
53            countG = 054            countG = 0
54            countT = 055            countT = 0
55            for item in self.instances:56            for item in self.instances:
56                if item[index].upper() == 'A':57                if item[index].upper() == 'A':
57                    countA += 158                    countA += 1
58                elif item[index].upper() == 'C':59                elif item[index].upper() == 'C':
59                    countC += 160                    countC += 1
60                elif item[index].upper() == 'G':61                elif item[index].upper() == 'G':
61                    countG += 162                    countG += 1
62                elif item[index].upper() == 'T':63                elif item[index].upper() == 'T':
63                    countT += 164                    countT += 1
64            self.counts['A'].append(countA)65            self.counts['A'].append(countA)
65            self.counts['C'].append(countC)66            self.counts['C'].append(countC)
66            self.counts['G'].append(countG)67            self.counts['G'].append(countG)
67            self.counts['T'].append(countT)68            self.counts['T'].append(countT)
68    def compute_consensus(self):69    def compute_consensus(self):
69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
70        self.count()71        self.count()
71        self.consensus = ''72        self.consensus = ''
72        for i in range(self.__len__()):73        for i in range(self.__len__()):
n73            cap = max([self.counts['A'][i], self.counts['C'][i], self.counts['G'n74            maximum = max([self.counts['A'][i], self.counts['C'][i], self.counts
>][i], self.counts['T'][i]])>['G'][i], self.counts['T'][i]])
74            if cap == self.counts['A'][i]:75            if maximum == self.counts['A'][i]:
75                self.consensus += 'A'76                self.consensus += 'A'
n76            elif cap == self.counts['C'][i]:n77            elif maximum == self.counts['C'][i]:
77                self.consensus += 'C'78                self.consensus += 'C'
n78            elif cap == self.counts['G'][i]:n79            elif maximum == self.counts['G'][i]:
79                self.consensus += 'G'80                self.consensus += 'G'
n80            elif cap == self.counts['T'][i]:n81            elif maximum == self.counts['T'][i]:
81                self.consensus += 'T'82                self.consensus += 'T'
82        return self.consensus83        return self.consensus
83    def parse(self, filename):84    def parse(self, filename):
t84        myfile = open(filename)t85        pyfile = open(filename)
85        lines = myfile.readlines()86        lines = pyfile.readlines()
86        myfile.close()87        pyfile.close()
87        for line in lines:88        for line in lines:
88            if line[0] != '>':89            if line[0] != '>':
89                self.instances.append(line)90                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 25

Student ID: 123, P-Value: 3.51e-07

Nearest Neighbor ID: 73

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
n4    def __init__ (self, initResult, generator, n, delta_Theta):n4    def __init__ (self, initState, generator, n, delta_theta):
5        self.init_result = initResult5        self.init_state = initState
6        self.gen = generator6        self.gen = generator
7        self.num = n7        self.num = n
n8        self.deltaTheta = delta_Theta n8        self.deltatheta = delta_theta
9        self.str = self.init_result9        self.str = self.init_state
10        self.str2 = "" 10        self.str2 = ''
11        for i in range(self.num):11        for i in range(self.num):
n12            self.str2 = ""n12            self.str2 = ''
13            for char in self.str:13            for char in self.str:
14                if char in self.gen:14                if char in self.gen:
15                    self.str2 += self.gen[char]15                    self.str2 += self.gen[char]
16                else:16                else:
17                    self.str2 += char17                    self.str2 += char
n18            self.str = self.str2 n18            self.str = self.str2
19    def drawPlant(self): 19    def drawPlant(self):
20        currentPt = (200,0) 20        currentpt = (200,0)
21        theta = pi/221        theta = pi/2
n22        nextPt = ()n22        nextpt = ()
23        stack = [] 23        stack = []
24        for character in self.str:24        for CHR in self.str:
25            if character.isalpha():25            if CHR.isalpha():
26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta)) 26                nextpt = (currentpt[0]+cos(theta), currentpt[1]+sin(theta))
27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27                plt.plot([currentpt[0],nextpt[0]],[currentpt[1],nextpt[1]],color
>='black') >='black') 
28                currentPt = nextPt 28                currentpt = nextpt
29            elif character == "[":29            elif CHR == '[':
30                stack.append([currentPt, theta])30                stack.append([currentpt, theta]) 
31            elif character == "]":31            elif CHR == ']':
32                currentPt, theta = stack.pop()32                currentpt, theta = stack.pop() 
33            elif character == "+":33            elif CHR == '+':
34                theta += (self.deltaTheta * (pi/180)) 34                theta += (self.deltatheta * (pi/180)) 
35            elif character == "-":35            elif CHR == '-':
36                theta -= (self.deltaTheta * (pi/180))36                theta -= (self.deltatheta * (pi/180))
37        plt.show() 
38class DNAMOTIF:37class DNAMOTIF:
39    def __init__(self):38    def __init__(self):
40        self.instances=[]39        self.instances=[]
41        self.consensus=[]40        self.consensus=[]
42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
43    def __str__(self):42    def __str__(self):
n44        pystr = ''n43        mystring = ''
45        for item in self.instances:44        for item in self.instances:
n46            pystr += itemn45            mystring += item
47        return pystr46        return mystring
48    def __len__(self):47    def __len__(self):
49        return len(self.instances[0].rstrip('\n'))48        return len(self.instances[0].rstrip('\n'))
50    def count(self):49    def count(self):
51        for index in range(self.__len__()):50        for index in range(self.__len__()):
52            countA = 051            countA = 0
53            countC = 052            countC = 0
54            countG = 053            countG = 0
55            countT = 054            countT = 0
56            for item in self.instances:55            for item in self.instances:
57                if item[index].upper() == 'A':56                if item[index].upper() == 'A':
58                    countA += 157                    countA += 1
59                elif item[index].upper() == 'C':58                elif item[index].upper() == 'C':
60                    countC += 159                    countC += 1
61                elif item[index].upper() == 'G':60                elif item[index].upper() == 'G':
62                    countG += 161                    countG += 1
63                elif item[index].upper() == 'T':62                elif item[index].upper() == 'T':
64                    countT += 163                    countT += 1
65            self.counts['A'].append(countA)64            self.counts['A'].append(countA)
66            self.counts['C'].append(countC)65            self.counts['C'].append(countC)
67            self.counts['G'].append(countG)66            self.counts['G'].append(countG)
68            self.counts['T'].append(countT)67            self.counts['T'].append(countT)
69    def compute_consensus(self):68    def compute_consensus(self):
70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
71        self.count()70        self.count()
72        self.consensus = ''71        self.consensus = ''
73        for i in range(self.__len__()):72        for i in range(self.__len__()):
n74            maximum = max([self.counts['A'][i], self.counts['C'][i], self.countsn73            cap = max([self.counts['A'][i], self.counts['C'][i], self.counts['G'
>['G'][i], self.counts['T'][i]])>][i], self.counts['T'][i]])
75            if maximum == self.counts['A'][i]:74            if cap == self.counts['A'][i]:
76                self.consensus += 'A'75                self.consensus += 'A'
n77            elif maximum == self.counts['C'][i]:n76            elif cap == self.counts['C'][i]:
78                self.consensus += 'C'77                self.consensus += 'C'
n79            elif maximum == self.counts['G'][i]:n78            elif cap == self.counts['G'][i]:
80                self.consensus += 'G'79                self.consensus += 'G'
n81            elif maximum == self.counts['T'][i]:n80            elif cap == self.counts['T'][i]:
82                self.consensus += 'T'81                self.consensus += 'T'
83        return self.consensus82        return self.consensus
84    def parse(self, filename):83    def parse(self, filename):
t85        pyfile = open(filename)t84        myfile = open(filename)
86        lines = pyfile.readlines()85        lines = myfile.readlines()
87        pyfile.close()86        myfile.close()
88        for line in lines:87        for line in lines:
89            if line[0] != '>':88            if line[0] != '>':
90                self.instances.append(line)89                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 26

Student ID: 316, P-Value: 3.78e-07

Nearest Neighbor ID: 73

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as plotn1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
n4    def __init__(self, initState, generator, n, delta_Theta):n4    def __init__ (self, initState, generator, n, delta_theta):
5        self.init_state = initState5        self.init_state = initState
n6        self.generator = generatorn6        self.gen = generator
7        self.num = n7        self.num = n
n8        self.delta_theta = delta_Thetan8        self.deltatheta = delta_theta
9        self.str = self.init_state9        self.str = self.init_state
n10        self.str1 = ""n10        self.str2 = ''
11        for i in range(self.num):11        for i in range(self.num):
n12            self.str1=''n12            self.str= ''
13            for char in self.str:13            for char in self.str:
n14                if char in self.generator:n14                if char in self.gen:
15                    self.str1 += self.generator[char]15                    self.str2 += self.gen[char]
16                else:16                else:
n17                    self.str1 += charn17                    self.str2 += char
18            self.str=self.str118            self.str = self.str2
19    def drawPlant(self):19    def drawPlant(self):
n20        currentPt = (200,0)n20        currentpt = (200,0)
21        theta = pi/221        theta = pi/2
n22        nextPt = ()n22        nextpt = ()
23        stack = []23        stack = []
24        for CHR in self.str:24        for CHR in self.str:
25            if CHR.isalpha():25            if CHR.isalpha():
n26                nextPt=(currentPt(0)+cos(theta), sin(theta)+currentPt(1))n26                nextpt = (currentpt[0]+cos(theta), currentpt[1]+sin(theta))
27                plot.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],colo27                plt.plot([currentpt[0],nextpt[0]],[currentpt[1],nextpt[1]],color
>r='black')>='black') 
28                currentPt=nextPt28                currentpt = nextpt
29            elif CHR=='[':29            elif CHR == '[':
30                stack.append[(currentPt, theta)]30                stack.append([currentpt, theta]) 
31            elif CHR==']':31            elif CHR == ']':
32                currentPt, theta=stack.pop()32                currentpt, theta = stack.pop() 
33            elif CHR=='+':33            elif CHR == '+':
34                theta += (self.delta_theta*[pi/180])34                theta += (self.deltatheta * (pi/180)
35            elif CHR=='-':35            elif CHR == '-':
36                theta -= (self.delta_theta*[pi/180])36                theta -= (self.deltatheta * (pi/180))
37        plot.show()
38class DNAMOTIF:37class DNAMOTIF:
39    def __init__(self):38    def __init__(self):
40        self.instances=[]39        self.instances=[]
41        self.consensus=[]40        self.consensus=[]
42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
43    def __str__(self):42    def __str__(self):
n44        thestr = ''n43        mystring = ''
45        for item in self.instances:44        for item in self.instances:
n46            thestr += itemn45            mystring += item
47        return thestr46        return mystring
48    def __len__(self):47    def __len__(self):
n49        return len(self.instances[0].rstrip("\n"))n48        return len(self.instances[0].rstrip('\n'))
50    def count(self):49    def count(self):
51        for index in range(self.__len__()):50        for index in range(self.__len__()):
52            countA = 051            countA = 0
53            countC = 052            countC = 0
54            countG = 053            countG = 0
55            countT = 054            countT = 0
56            for item in self.instances:55            for item in self.instances:
57                if item[index].upper() == 'A':56                if item[index].upper() == 'A':
58                    countA += 157                    countA += 1
59                elif item[index].upper() == 'C':58                elif item[index].upper() == 'C':
60                    countC += 159                    countC += 1
61                elif item[index].upper() == 'G':60                elif item[index].upper() == 'G':
62                    countG += 161                    countG += 1
63                elif item[index].upper() == 'T':62                elif item[index].upper() == 'T':
64                    countT += 163                    countT += 1
65            self.counts['A'].append(countA)64            self.counts['A'].append(countA)
66            self.counts['C'].append(countC)65            self.counts['C'].append(countC)
67            self.counts['G'].append(countG)66            self.counts['G'].append(countG)
n68            self.counts['T'].append(countT)       n67            self.counts['T'].append(countT)
69    def compute_consensus(self):68    def compute_consensus(self):
70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
71        self.count()70        self.count()
n72        self.consensus = ""n71        self.consensus = ''
73        for i in range(self.__len__()):72        for i in range(self.__len__()):
n74            maximum = max([self.counts['A'][i], self.counts['C'][i], self.countsn73            cap = max([self.counts['A'][i], self.counts['C'][i], self.counts['G'
>['G'][i], self.counts['T'][i]])>][i], self.counts['T'][i]])
75            if maximum == self.counts['A'][i]:74            if cap == self.counts['A'][i]:
76                self.consensus += 'A'75                self.consensus += 'A'
n77            elif maximum == self.counts['C'][i]:n76            elif cap == self.counts['C'][i]:
78                self.consensus += 'C'77                self.consensus += 'C'
n79            elif maximum == self.counts['G'][i]:n78            elif cap == self.counts['G'][i]:
80                self.consensus += 'G'79                self.consensus += 'G'
t81            elif maximum == self.counts['T'][i]:t80            elif cap == self.counts['T'][i]:
82                self.consensus += 'T'81                self.consensus += 'T'
83        return self.consensus82        return self.consensus
84    def parse(self, filename):83    def parse(self, filename):
85        myfile = open(filename)84        myfile = open(filename)
86        lines = myfile.readlines()85        lines = myfile.readlines()
87        myfile.close()86        myfile.close()
88        for line in lines:87        for line in lines:
89            if line[0] != '>':88            if line[0] != '>':
90                self.instances.append(line)89                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 27

Student ID: 442, P-Value: 3.58e-06

Nearest Neighbor ID: 269

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
nn2plt.style.use('bmh')  
2plt.plot(3plt.plot(
3    [0, 1, 2],  4    [0, 1, 2],  
4    [0, 1, 0]   5    [0, 1, 0]   
n5    )n6)
6plt.xlabel('x')7plt.xlabel('x')
n7plt.ylabel('y')n8plt.ylabel('y');
8def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
9    if bare_plot:10    if bare_plot:
10        plt.axis('off')11        plt.axis('off')
n11        plt.axes().set_aspect('equal', 'datalim')n12    plt.axes().set_aspect('equal', 'datalim')
12        X, Y = zip(*coords)13    X, Y = zip(*coords)
13        plt.plot(X, Y);14    plt.plot(X, Y);
14        plot_coords([15plot_coords([
15            (0, 0),16    (0, 0),
16            (1, 0),17    (1, 0),
17            (2, 1),18    (2, 1),
18            (3, 1),19    (3, 1),
19            (2, 0)20    (2, 0)
20            ])21])
21        nan = float('nan')22nan = float('nan')
22        plot_coords([23plot_coords([
23            (0, 0),24    (0, 0),
24            (1, 1),25    (1, 1),
25            (nan, nan),26    (nan, nan),
26            (1, 0),27    (1, 0),
27            (2, 1)28    (2, 1)
28            ])29])
29from math import pi, sin, cos30from math import pi, sin, cos
30DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
n31def drawPlant(turtle_program, turn_amount=45):n32def turtle_to_coords(turtle_program, turn_amount=45):
32    currentPt = (200.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
33    yield (0.0, 0.0)34    yield (0.0, 0.0)
34    for command in turtle_program:35    for command in turtle_program:
n35        x, y, angle = currentPtn36        x, y, angle = state
36        if command in 'Ff':      37        if command in 'Ff':      
n37            currentPt = (x - cos(angle * DEGREES_TO_RADIANS),n38            state = (x - cos(angle * DEGREES_TO_RADIANS),
38            y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
39            angle)40                     angle)
40        if command == 'f':41            if command == 'f':
41            yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
42            yield (currentPt[0], currentPt[1])43            yield (state[0], state[1])
43        elif command == '+':     44        elif command == '+':     
n44            currentPt = (x, y, angle + turn_amount)n45            state = (x, y, angle + turn_amount)
45        elif command == '-':     46        elif command == '-':     
n46            currentPt = (x, y, angle - turn_amount)n47            state = (x, y, angle - turn_amount)
47plot_coords(drawPlant('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
48plot_coords(drawPlant('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
49from math import isnan50from math import isnan
50def print_coords(coords):51def print_coords(coords):
51    for (x, y) in coords:52    for (x, y) in coords:
52        if isnan(x):53        if isnan(x):
53            print('<gap>')54            print('<gap>')
54        else:55        else:
55            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
n56            print_coords(drawPlant('F-F+F+F+f+F+F+F-F'))n57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
57            plot_coords(drawPlant('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
58def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
59    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
60transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
n61plot_coords(drawPlant(transform_sequence('FFFF', {'F': 'FfF++'})))n62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
62def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
63    for _ in range(iterations):64    for _ in range(iterations):
64        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
65    return sequence66    return sequence
66print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
67print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
68print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
n69plot_coords(drawPlant(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))n70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
70plot_coords(drawPlant(transform_multiple('L', {'L': '-RF+LFL+FR-','R': '+LF-RFR-71plot_coords(turtle_to_coords(transform_multiple('L', {
>FL+'}, 5), 90)) 
72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'
74}, 5), 90))
71def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
n72    nextPt = list()n76    saved_states = list()
73    currentPt = (200, 0, 90)77    state = (0, 0, 90)
74    yield (0, 0)78    yield (0, 0)
75    for command in turtle_program:79    for command in turtle_program:
n76        x, y, angle = currentPtn80        x, y, angle = state
77    if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
78            currentPt = (y + sin(angle * DEGREES_TO_RADIANS), x - cos(angle * DE82            state = (x - cos(angle * DEGREES_TO_RADIANS),
>GREES_TO_RADIANS),angle) 
83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)
79    if command.islower():                  85            if command.islower():                  
80        yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
81        yield (currentPt[0], currentPt[1])87            yield (state[0], state[1])
82    elif command == '+':                       88        elif command == '+':                       
83        state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
84    elif command == '-':                       90        elif command == '-':                       
85        currentPt = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
86    elif command == '[':                       92        elif command == '[':                       
87        nextPt.append(currentPt)93            saved_states.append(state)
88    elif command == ']':                       94        elif command == ']':                       
89        currentPt = nextPt.pop()95            state = saved_states.pop()
90        yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
91        x, y, _ = state97            x, y, _ = state
92        yield (x, y)98            yield (x, y)
93plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
94def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
95    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
96    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
97    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
n98    l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)n104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
99    l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
100    for i in range(5):106for i in range(5):
101        print('{}: '.format(i),107    print('{}: '.format(i),
102        transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
103    for i in range(5):109for i in range(5):
104        print('{}: '.format(i),110    print('{}: '.format(i),
105        transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
106        l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)import sys112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
107sys.setrecursionlimit(3000)
108class DNAMOTIF:
109    def __init__(self):113    def __init__(self):
n110        self.instances=[]n114        self.instances = [] 
111        self.consensus=[]115        self.consensus=[] 
112        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
113    def __str__(self):117    def __str__ (self):
114        new_str = ""118        string = ""
115        for i in self.instances:119        for i in self.instances:
n116            new_str += i + "\n"n120            string = string + str(i) + "\n"
121        return string[:-2]
117    def __len__(self):122    def __len__(self):
n118        lexA = DNAMOTIF()n123        return (len(self.instances)-4)
119        lexA.parse("lexA.fasta")
120        return len(lexA)
121    def count(self):124    def count(self):
122        for i in self.instances:125        for i in self.instances:
123            temp = i.upper()126            temp = i.upper()
124            self.counts["A"].append(temp.count("A"))127            self.counts["A"].append(temp.count("A"))
125            self.counts["C"].append(temp.count("C"))128            self.counts["C"].append(temp.count("C"))
126            self.counts["G"].append(temp.count("G"))129            self.counts["G"].append(temp.count("G"))
127            self.counts["T"].append(temp.count("T"))130            self.counts["T"].append(temp.count("T"))
128    def compute_consensus(self):131    def compute_consensus(self):
129        A = self.counts["A"]132        A = self.counts["A"]
130        C = self.counts["C"]133        C = self.counts["C"]
131        G = self.counts["G"]134        G = self.counts["G"]
132        T = self.counts["T"]135        T = self.counts["T"]
133        for i in range(len(A)):136        for i in range(len(A)):
134            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
135                self.consensus.append("A")138                self.consensus.append("A")
136            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
137                self.consensus.append("C")140                self.consensus.append("C")
138            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
139                self.consensus.append("G")142                self.consensus.append("G")
140            else:143            else:
141                self.consensus.append("T")144                self.consensus.append("T")
nn145        for x in self.consensus:
146            print(x,end='')
142    def parse(self, filename):147    def parse(self, filename):
t143        with open(filename,'r') as file:t148        with open(filename,'r') as f:
144            for i in file:149            for i in f:
145                if ">" in i:150                if ">" in i:
146                   continue151                   continue
147                else:152                else:
148                    self.instances.append(i)153                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 28

Student ID: 87, P-Value: 3.83e-06

Nearest Neighbor ID: 233

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
4    def __init__(self, initState, generator, n, delta_Theta):4    def __init__(self, initState, generator, n, delta_Theta):
5        self.init_state = initState5        self.init_state = initState
6        self.gen = generator6        self.gen = generator
7        self.num = n7        self.num = n
8        self.deltaTheta = delta_Theta8        self.deltaTheta = delta_Theta
9        self.str = self.init_state9        self.str = self.init_state
10        self.str2 = ""10        self.str2 = ""
11        for i in range(self.num):11        for i in range(self.num):
12            self.str2 = ""12            self.str2 = ""
13            for char in self.str:13            for char in self.str:
14                if char in self.gen:14                if char in self.gen:
15                    self.str2 += self.gen[char]15                    self.str2 += self.gen[char]
16                else:16                else:
17                    self.str2 += char17                    self.str2 += char
18            self.str = self.str218            self.str = self.str2
19    def drawPlant(self):19    def drawPlant(self):
20        currentPt = (200,0)20        currentPt = (200,0)
21        theta = pi/221        theta = pi/2
22        nextPt = ()22        nextPt = ()
23        stack = []23        stack = []
24        for CHR in self.str:24        for CHR in self.str:
25            if CHR.isalpha():25            if CHR.isalpha():
26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))
27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
28                currentPt = nextPt28                currentPt = nextPt
29            elif CHR == "[":29            elif CHR == "[":
30                stack.append([currentPt, theta])30                stack.append([currentPt, theta])
31            elif CHR == "]":31            elif CHR == "]":
32                currentPt, theta = stack.pop()32                currentPt, theta = stack.pop()
33            elif CHR == "+":33            elif CHR == "+":
34                theta += (self.deltaTheta * (pi/180))34                theta += (self.deltaTheta * (pi/180))
35            elif CHR == "-":35            elif CHR == "-":
n36                theta -= (self.deltaTheta * (pi/180))n36                theta -= (self.deltaTheta * (pi/180))class DNAMOTIF:
37        plt.show()
38class DNAMOTIF:
39    def __init__(self):37    def __init__(self):
40        self.instances=[]38        self.instances=[]
n41        self.consensus=[]n39        self.consensus=""
42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
43    def __str__(self):41    def __str__(self):
n44        string = ""n42        mystr = ""
45        for thing in self.instances:43        for item in self.instances:
46            string = string + item44            mystr += item
47        return string45        return mystr
48    def __len__(self):46    def __len__(self):
n49        return len(self.instances[0].rstrip('\n'))n47        return len(self.instances[0].rstrip("\n"))
50    def count(self):48    def count(self):
51        for index in range(self.__len__()):49        for index in range(self.__len__()):
n52            numA = 0n50            countA = 0
53            numC = 051            countC = 0
54            numG = 052            countG = 0
55            numT = 053            countT = 0
56            for thing in self.instances:54            for item in self.instances:
57                if thing[index].upper() == "A":55                if item[index].upper() == "A":
58                    numA += 156                    countA += 1
59                elif thing[index].upper() == "C":57                elif item[index].upper() == "C":
60                    numC += 158                    countC += 1
61                elif thing[index].upper() == "G":59                elif item[index].upper() == "G":
62                    numG += 160                    countG += 1
63                elif thing[index].upper() == "T":61                elif item[index].upper() == "T":
64                    numT += 162                    countT += 1
65            self.counts["A"].append(numA)63            self.counts["A"].append(countA)
66            self.counts["C"].append(numC)64            self.counts["C"].append(countC)
67            self.counts["G"].append(numG)65            self.counts["G"].append(countG)
68            self.counts["T"].append(numT)66            self.counts["T"].append(countT)
69    def compute_consensus(self):67    def compute_consensus(self):
70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}68        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
71        self.count()69        self.count()
n72        self.consensus = ""n
73        for letter in range(self.__len__()):70        for i in range(self.__len__()):
74            maximum = max([self.counts["A"][letter], self.counts["C"][letter], s71            maximum = max([self.counts["A"][i], self.counts["C"][i], self.counts
>elf.counts["G"][letter], self.counts["T"][letter]])>["G"][i], self.counts["T"][i]])
75            if maximum == self.counts["A"][letter]:72            if maximum == self.counts["A"][i]:
76                self.consensus += "A"73                self.consensus += "A"
n77            elif maximum == self.counts["C"][letter]:n74            elif maximum == self.counts["C"][i]:
78                self.consensus += "C"75                self.consensus += "C"
n79            elif maximum == self.counts["G"][letter]:n76            elif maximum == self.counts["G"][i]:
80                self.consensus += "G"77                self.consensus += "G"
n81            elif maximum == self.counts["T"][letter]:n78            elif maximum == self.counts["T"][i]:
82                self.consensus += "T"79                self.consensus += "T"
83        return self.consensus80        return self.consensus
84    def parse(self, filename):81    def parse(self, filename):
n85        thefile = open(filename)n82        myfile = open(filename)
86        lines = thefile.readlines()83        lines = myfile.readlines()
87        thefile.close()84        myfile.close()
88        for line in lines:85        for line in lines:
89            if line[0] != ">":86            if line[0] != ">":
90                self.instances.append(line)87                self.instances.append(line)
tt88if __name__ == "__main__":
89    lexA = DNAMOTIF()
90    lexA.parse("lexA.fasta")
91    print(lexA)
92    lexA.count()
93    print(lexA.counts)
94    lexA.compute_consensus()
95    print(lexA.consensus)
96    print(lexA.consensus == "TACTGTATATATATACAGTA")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 29

Student ID: 233, P-Value: 3.83e-06

Nearest Neighbor ID: 87

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
4    def __init__(self, initState, generator, n, delta_Theta):4    def __init__(self, initState, generator, n, delta_Theta):
5        self.init_state = initState5        self.init_state = initState
6        self.gen = generator6        self.gen = generator
7        self.num = n7        self.num = n
8        self.deltaTheta = delta_Theta8        self.deltaTheta = delta_Theta
9        self.str = self.init_state9        self.str = self.init_state
10        self.str2 = ""10        self.str2 = ""
11        for i in range(self.num):11        for i in range(self.num):
12            self.str2 = ""12            self.str2 = ""
13            for char in self.str:13            for char in self.str:
14                if char in self.gen:14                if char in self.gen:
15                    self.str2 += self.gen[char]15                    self.str2 += self.gen[char]
16                else:16                else:
17                    self.str2 += char17                    self.str2 += char
18            self.str = self.str218            self.str = self.str2
19    def drawPlant(self):19    def drawPlant(self):
20        currentPt = (200,0)20        currentPt = (200,0)
21        theta = pi/221        theta = pi/2
22        nextPt = ()22        nextPt = ()
23        stack = []23        stack = []
24        for CHR in self.str:24        for CHR in self.str:
25            if CHR.isalpha():25            if CHR.isalpha():
26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))
27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
28                currentPt = nextPt28                currentPt = nextPt
29            elif CHR == "[":29            elif CHR == "[":
30                stack.append([currentPt, theta])30                stack.append([currentPt, theta])
31            elif CHR == "]":31            elif CHR == "]":
32                currentPt, theta = stack.pop()32                currentPt, theta = stack.pop()
33            elif CHR == "+":33            elif CHR == "+":
34                theta += (self.deltaTheta * (pi/180))34                theta += (self.deltaTheta * (pi/180))
35            elif CHR == "-":35            elif CHR == "-":
n36                theta -= (self.deltaTheta * (pi/180))class DNAMOTIF:n36                theta -= (self.deltaTheta * (pi/180))
37        plt.show()
38class DNAMOTIF:
37    def __init__(self):39    def __init__(self):
38        self.instances=[]40        self.instances=[]
n39        self.consensus=""n41        self.consensus=[]
40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
41    def __str__(self):43    def __str__(self):
n42        mystr = ""n44        string = ""
43        for item in self.instances:45        for thing in self.instances:
44            mystr += item46            string = string + item
45        return mystr47        return string
46    def __len__(self):48    def __len__(self):
n47        return len(self.instances[0].rstrip("\n"))n49        return len(self.instances[0].rstrip('\n'))
48    def count(self):50    def count(self):
49        for index in range(self.__len__()):51        for index in range(self.__len__()):
n50            countA = 0n52            numA = 0
51            countC = 053            numC = 0
52            countG = 054            numG = 0
53            countT = 055            numT = 0
54            for item in self.instances:56            for thing in self.instances:
55                if item[index].upper() == "A":57                if thing[index].upper() == "A":
56                    countA += 158                    numA += 1
57                elif item[index].upper() == "C":59                elif thing[index].upper() == "C":
58                    countC += 160                    numC += 1
59                elif item[index].upper() == "G":61                elif thing[index].upper() == "G":
60                    countG += 162                    numG += 1
61                elif item[index].upper() == "T":63                elif thing[index].upper() == "T":
62                    countT += 164                    numT += 1
63            self.counts["A"].append(countA)65            self.counts["A"].append(numA)
64            self.counts["C"].append(countC)66            self.counts["C"].append(numC)
65            self.counts["G"].append(countG)67            self.counts["G"].append(numG)
66            self.counts["T"].append(countT)68            self.counts["T"].append(numT)
67    def compute_consensus(self):69    def compute_consensus(self):
68        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
69        self.count()71        self.count()
nn72        self.consensus = ""
70        for i in range(self.__len__()):73        for letter in range(self.__len__()):
71            maximum = max([self.counts["A"][i], self.counts["C"][i], self.counts74            maximum = max([self.counts["A"][letter], self.counts["C"][letter], s
>["G"][i], self.counts["T"][i]])>elf.counts["G"][letter], self.counts["T"][letter]])
72            if maximum == self.counts["A"][i]:75            if maximum == self.counts["A"][letter]:
73                self.consensus += "A"76                self.consensus += "A"
n74            elif maximum == self.counts["C"][i]:n77            elif maximum == self.counts["C"][letter]:
75                self.consensus += "C"78                self.consensus += "C"
n76            elif maximum == self.counts["G"][i]:n79            elif maximum == self.counts["G"][letter]:
77                self.consensus += "G"80                self.consensus += "G"
n78            elif maximum == self.counts["T"][i]:n81            elif maximum == self.counts["T"][letter]:
79                self.consensus += "T"82                self.consensus += "T"
80        return self.consensus83        return self.consensus
81    def parse(self, filename):84    def parse(self, filename):
n82        myfile = open(filename)n85        thefile = open(filename)
83        lines = myfile.readlines()86        lines = thefile.readlines()
84        myfile.close()87        thefile.close()
85        for line in lines:88        for line in lines:
86            if line[0] != ">":89            if line[0] != ">":
87                self.instances.append(line)90                self.instances.append(line)
t88if __name__ == "__main__":t
89    lexA = DNAMOTIF()
90    lexA.parse("lexA.fasta")
91    print(lexA)
92    lexA.count()
93    print(lexA.counts)
94    lexA.compute_consensus()
95    print(lexA.consensus)
96    print(lexA.consensus == "TACTGTATATATATACAGTA")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 30

Student ID: 266, P-Value: 1.33e-05

Nearest Neighbor ID: 4

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.str = string5        self.str = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        for x in range(n):9        for x in range(n):
10            new_string = ""10            new_string = ""
n11            for letr in self.str:n11            for letter in self.str:
12                if letr in self.dictionary:12                if letter in self.dictionary:
13                    new_string += self.dictionary[letr]13                    new_string += self.dictionary[letter]
14                else:14                else:
n15                    new_string += letrn15                    new_string += letter
16            self.str = new_string16            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
18        currentPt = (200,0)18        currentPt = (200,0)
n19        lastpt = (0,200)n
20        stack = []19        stack = []
n21        turn = 90n
22        theta = 9020        theta = 90
n23        for letr in self.str:n21        for letter in self.str:
24            if letr == "[":22            if letter == "[":
25                stack.append([currentPt,theta])23                stack.append([currentPt,theta])
n26                turn += 1n
27            elif letr == "]":24            elif letter == "]":
28                latest = stack[-1]25                latest = stack[-1]
29                currentPt = latest[0]26                currentPt = latest[0]
30                theta = latest[1]27                theta = latest[1]
n31            elif letr == "+":n28            elif letter == "+":
32                theta += self.deltaTheta29                theta += self.deltaTheta
n33                turn += 1n
34            elif letr == "-":30            elif letter == "-":
35                theta -= self.deltaTheta31                theta -= self.deltaTheta
n36                turn = lastptn
37            else:32            else:
38                nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.si33                nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.si
>n(theta))>n(theta))
39                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor='black')>olor='black')
40                currentPt = nextPtclass DNAMOTIF:35                currentPt = nextPtclass DNAMOTIF:
n41    cons = []n
42    A = 0 
43    C = 0 
44    G = 0
45    T = 0
46    def __init__(self):36    def __init__(self):
47        self.instances = []37        self.instances = []
48        self.consensus = []38        self.consensus = []
49        self.counts = {"A": [], "C": [], "G": [], "T": []}39        self.counts = {"A": [], "C": [], "G": [], "T": []}
50    def __str__(self):40    def __str__(self):
n51        alp = '\n'.join(self.instances)n41        return "\n".join(self.instances)
52        return alp
53    def __len__(self):42    def __len__(self):
n54        DNAlen = len(self.instances[0])-1n43        return len(self.instances[0])-1
55        return DNAlen
56    def parse(self, filename):44    def parse(self, filename):
57        with open(filename, 'r') as reader:45        with open(filename, 'r') as reader:
n58            self.instances = [x[0].lower() + x[1:].upper() for x in reader.readln46            self.instances = [x[0].lower() + x[1:].upper() for x in reader.readl
>ines() if x[0] != '>']>ines() if x[0] != ">"]
59    def count(self):47    def count(self):
n60        cnt = 0n48        count = 0
61        self.counts = {'A': [0 for _ in range(len(self))], 'C': [0 for _ in rang49        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
>e(len(self))], 'G': [0 for _ in range(len(self))], 'T': [0 for _ in range(len(se>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
>lf))]}>lf))]}
62        for instance in self.instances:50        for instance in self.instances:
n63            for x, gene in enumerate(instance):n51            for x, letter in enumerate(instance):
64                if gene != '\n':52                if letter != "\n":
65                    self.counts[gene.upper()][x] += 153                    self.counts[letter.upper()][x] += 1
66    def compute_consensus(self):54    def compute_consensus(self):
67        self.count()55        self.count()
n68        dnalist = 2n
69        consensus = ''56        consensus = ""
70        for x in range(len(self)):57        for x in range(len(self)):
n71            current_consensus = ('',0)n58            current_consensus = ("",0)
72            for gene in self.counts:59            for letter in self.counts:
73                if  current_consensus[1] < self.counts[gene][x]:60                if self.counts[letter][x] > current_consensus[1]:
74                    current_consensus = (gene, self.counts[gene][x])61                    current_consensus = (letter, self.counts[letter][x])
75            consensus += current_consensus[0]62            consensus += current_consensus[0]
76        self.consensus = consensus63        self.consensus = consensus
t77        cons = consensust64def count(self):
78        cons = dnalist65        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
 >e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
 >lf))]}
66        for instance in self.instances:
67            for x, letter in enumerate(instance):
68                if letter != "\n":
69                    self.counts[letter.upper()][x] += 1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 31

Student ID: 114, P-Value: 1.59e-05

Nearest Neighbor ID: 252

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, initial , gen = {}, x= 0, angle= 0):n4    def __init__(self, initial , gen = {}, = 0, deltaTheta = 0):
5        self.init = initial5        self.initial = initial
6        self.general = gen6        self.gen = gen
7        self.variable = x7        self.n = n
8        self.deltaTheta = angle8        self.deltaTheta = deltaTheta
9        self.str = initial9        self.str = initial
n10        while x>0:n10        while n>0:
11            x -= 111            n -= 1
12            y = ''12            y = ''
13            for i in self.str:13            for i in self.str:
14                if i in gen:14                if i in gen:
15                    y += gen[i]15                    y += gen[i]
16                else:16                else:
17                    y += i17                    y += i
18            self.str = y18            self.str = y
19    def drawPlant(self):19    def drawPlant(self):
n20        z = []n20        x = []
21        current_point=(200,0)
22        theta = 90*(math.pi/180)
23        next_point = (current_point[0] + math.cos(theta), current_point[1] + mat
>h.sin(theta)) 
24        current_point=next_point
25        plt.plot([current_point[0],next_point[0]],[current_point[1],next_point[1
>]],color='black') 
26        for i in self.str:21        for let in self.str:
27            if i == '[':22            if let == '[':
28                z.append([current_point,theta])23                x.append([currentPt,theta])
29            elif i == ']':24            elif let == ']':
30                current_point = z[-1][0]25                currentPt = x[-1][0]
31                theta = z[-1][1]26                theta = x[-1][1]
32            elif i == '+':27            elif let == '+':
33                theta += self.deltaTheta28                theta += self.deltaTheta
n34            elif i == '-':n29            elif let == '-':
35                theta -= self.deltaTheta30                theta -= self.deltaTheta
nn31        currentPt=(200,0)
32        theta = 90
33        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)
 >)
34        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'
 >)
35        currentPt=nextPt
36        z = []36        x = []
37        for i in self.str:37        for let in self.str:
38            if i == '[':38            if let == '[':
39                z.append([current_point,theta])39                x.append([currentPt,theta])
40            elif i == ']':40            elif let == ']':
41                current_point = z[-1][0]41                currentPt = x[-1][0]
42                theta = z[-1][1]42                theta = x[-1][1]
43            elif i == '+':43            elif let == '+':
44                theta += self.deltaTheta44                theta += self.deltaTheta
n45            elif i == '-':n45            elif let == '-':
46                theta -= self.deltaTheta46                theta -= self.deltaTheta
47class DNAMOTIF:47class DNAMOTIF:
48    def __init__(self):48    def __init__(self):
49        self.instances=[]49        self.instances=[]
50        self.consensus=[]50        self.consensus=[]
51        self.counts= {"A": [], "C": [], "G":[],"T":[]}51        self.counts= {"A": [], "C": [], "G":[],"T":[]}
52    def __str__(self):52    def __str__(self):
53        string = ""53        string = ""
54        for i in self.instances:54        for i in self.instances:
55            string += i + ""55            string += i + ""
56        return string[:-2]56        return string[:-2]
57    def __len__(self):57    def __len__(self):
58        return len(self.instances[0])-158        return len(self.instances[0])-1
59    def count(self):59    def count(self):
60        i = 060        i = 0
61        count = 061        count = 0
n62        vertical = []n
63        repeat = []62        up = []
63        up1 = []
64        A = 064        A = 0
65        C = 065        C = 0
66        T = 066        T = 0
67        G = 067        G = 0
68        while i < len(self.instances[0])-1:68        while i < len(self.instances[0])-1:
69            while count < len(self.instances):69            while count < len(self.instances):
n70                for stuff in self.instances:n70                for amino in self.instances:
71                    stuff = stuff.upper()71                    amino = amino.upper()
72                    vertical.append(stuff[i])72                    up.append(amino[i])
73                    count += 173                    count += 1
74            count = 074            count = 0
n75            repeat.append(vertical)n75            up1.append(up)
76            vertical = []76            up = []
77            i += 177            i += 1
n78        for dna in repeat:n78        for strand in up1:
79            for an in dna:79            for i in strand:
80                if an == 'A':80                if i == 'A':
81                    A += 181                    A += 1
n82                if an == 'C':n82                if i == 'C':
83                    C += 183                    C += 1
n84                if an == 'T':n84                if i == 'T':
85                    T += 185                    T += 1
n86                if an == 'G':n86                if i == 'G':
87                    G += 1 87                    G += 1 
88            self.counts.setdefault('A',[]).append(A)88            self.counts.setdefault('A',[]).append(A)
89            self.counts.setdefault('C',[]).append(C)89            self.counts.setdefault('C',[]).append(C)
90            self.counts.setdefault('T',[]).append(T)90            self.counts.setdefault('T',[]).append(T)
91            self.counts.setdefault('G',[]).append(G)91            self.counts.setdefault('G',[]).append(G)
92            A = 092            A = 0
93            C = 093            C = 0
94            T = 094            T = 0
95            G = 095            G = 0
96    def compute_consensus(self):96    def compute_consensus(self):
97        self.count()97        self.count()
98        A = self.counts["A"]98        A = self.counts["A"]
99        C = self.counts["C"]99        C = self.counts["C"]
100        G = self.counts["G"]100        G = self.counts["G"]
101        T = self.counts["T"]101        T = self.counts["T"]
n102        for stuff in range(len(A)):n102        for let in range(len(A)):
103            if(A[stuff]>= C[stuff] and A[stuff] >= G[stuff]  and A[stuff] >= T[s103            if(A[let]>= C[let] and A[let] >= G[let]  and A[let] >= T[let]):
>tuff]): 
104                self.consensus.append("A")104                self.consensus.append("A")
n105            elif (C[stuff] >= G[stuff] and C[stuff] >= T[stuff]):n105            elif (C[let] >= G[let] and C[let] >= T[let]):
106                self.consensus.append("C")106                self.consensus.append("C")
t107            elif (G[stuff] >= T[stuff]):t107            elif (G[let] >= T[let]):
108                self.consensus.append("G")108                self.consensus.append("G")
109            else:109            else:
110                self.consensus.append("T")110                self.consensus.append("T")
111        self.consensus = "".join(self.consensus)111        self.consensus = "".join(self.consensus)
112    def parse(self, filename):112    def parse(self, filename):
113        with open(filename,'r') as f:113        with open(filename,'r') as f:
114            for i in f:114            for i in f:
115                if ">" in i:115                if ">" in i:
116                    continue116                    continue
117                else:117                else:
118                    self.instances.append(i)118                    self.instances.append(i)
119lexA=DNAMOTIF()119lexA=DNAMOTIF()
120lexA.parse("lexA.fasta")120lexA.parse("lexA.fasta")
121lexA.count()121lexA.count()
122print(lexA.counts)122print(lexA.counts)
123lexA.compute_consensus()123lexA.compute_consensus()
124print(lexA.consensus)124print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 32

Student ID: 497, P-Value: 2.12e-05

Nearest Neighbor ID: 87

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2from numpy import cos, sin, pi2from numpy import cos, sin, pi
3class PLANT:3class PLANT:
n4    def __init__(self, initState, gen, n, deltaTheta):n4    def __init__(self, initState, generator, n, delta_Theta):
5        self.init_state = initState5        self.init_state = initState
n6        self.gen = genn6        self.gen = generator
7        self.num = n7        self.num = n
n8        self.deltaTheta = deltaThetan8        self.deltaTheta = delta_Theta
9        self.str = self.init_state9        self.str = self.init_state
n10        self.s2 = ""n10        self.str2 = ""
11        for i in range(self.num):11        for i in range(self.num):
n12            self.s2 = ""n12            self.str2 = ""
13            for char in self.str:13            for char in self.str:
14                if char in self.gen:14                if char in self.gen:
n15                    self.s2 += self.gen[char]n15                    self.str2 += self.gen[char]
16                else:16                else:
n17                    self.s2 += charn17                    self.str2 += char
18            self.str = self.s218            self.str = self.str2
19    def drawPlant(self):19    def drawPlant(self):
n20        currPt = (200,0)n20        currentPt = (200,0)
21        t = pi/221        theta = pi/2
22        nextPt = ()22        nextPt = ()
23        stack = []23        stack = []
24        for CHR in self.str:24        for CHR in self.str:
25            if CHR.isalpha():25            if CHR.isalpha():
n26                nextPt = (currPt[0]+cos(t), currPt[1]+sin(t))n26                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))
27                plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='blac27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>k')>='black')
28                currPt = nextPt28                currentPt = nextPt
29            elif CHR == "[":29            elif CHR == "[":
n30                stack.append([currPt, t])n30                stack.append([currentPt, theta])
31            elif CHR == "]":31            elif CHR == "]":
n32                currPt, t = stack.pop()n32                currentPt, theta = stack.pop()
33            elif CHR == "+":33            elif CHR == "+":
n34                t += (self.deltaTheta * (pi/180))n34                theta += (self.deltaTheta * (pi/180))
35            elif CHR == "-":35            elif CHR == "-":
n36                t -= (self.deltaTheta * (pi/180))n36                theta -= (self.deltaTheta * (pi/180))
37        plt.show()class DNAMOTIF:37        plt.show()
38class DNAMOTIF:
38    def __init__(self):39    def __init__(self):
39        self.instances=[]40        self.instances=[]
40        self.consensus=[]41        self.consensus=[]
41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):43    def __str__(self):
n43        ms = ""n44        string = ""
44        for item in self.instances:45        for thing in self.instances:
45            ms += item46            string = string + item
46        return ms47        return string
47    def __len__(self):48    def __len__(self):
n48        return len(self.instances[0].rstrip("\n"))n49        return len(self.instances[0].rstrip('\n'))
49    def count(self):50    def count(self):
50        for index in range(self.__len__()):51        for index in range(self.__len__()):
n51            cA = 0n52            numA = 0
52            cC = 053            numC = 0
53            cG = 054            numG = 0
54            cT = 055            numT = 0
55            for item in self.instances:56            for thing in self.instances:
56                if item[index].upper() == "A":57                if thing[index].upper() == "A":
57                    cA += 158                    numA += 1
58                elif item[index].upper() == "C":59                elif thing[index].upper() == "C":
59                    cC += 160                    numC += 1
60                elif item[index].upper() == "G":61                elif thing[index].upper() == "G":
61                    cG += 162                    numG += 1
62                elif item[index].upper() == "T":63                elif thing[index].upper() == "T":
63                    cT += 164                    numT += 1
64            self.counts["A"].append(cA)65            self.counts["A"].append(numA)
65            self.counts["C"].append(cC)66            self.counts["C"].append(numC)
66            self.counts["G"].append(cG)67            self.counts["G"].append(numG)
67            self.counts["T"].append(cT)68            self.counts["T"].append(numT)
68    def compute_consensus(self):69    def compute_consensus(self):
69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}70        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
70        self.count()71        self.count()
71        self.consensus = ""72        self.consensus = ""
n72        for i in range(self.__len__()):n73        for letter in range(self.__len__()):
73            mx = max([self.counts["A"][i], self.counts["C"][i], self.counts["G"]74            maximum = max([self.counts["A"][letter], self.counts["C"][letter], s
>[i], self.counts["T"][i]])>elf.counts["G"][letter], self.counts["T"][letter]])
74            if mx == self.counts["A"][i]:75            if maximum == self.counts["A"][letter]:
75                self.consensus += "A"76                self.consensus += "A"
n76            elif mx == self.counts["C"][i]:n77            elif maximum == self.counts["C"][letter]:
77                self.consensus += "C"78                self.consensus += "C"
n78            elif mx == self.counts["G"][i]:n79            elif maximum == self.counts["G"][letter]:
79                self.consensus += "G"80                self.consensus += "G"
n80            elif mx == self.counts["T"][i]:n81            elif maximum == self.counts["T"][letter]:
81                self.consensus += "T"82                self.consensus += "T"
82        return self.consensus83        return self.consensus
t83    def parse(self, fn):t84    def parse(self, filename):
84        mf = open(fn)85        thefile = open(filename)
85        l = mf.readlines()86        lines = thefile.readlines()
86        mf.close()87        thefile.close()
87        for line in l:88        for line in lines:
88            if line[0] != ">":89            if line[0] != ">":
89                self.instances.append(line)90                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 33

Student ID: 495, P-Value: 7.45e-05

Nearest Neighbor ID: 113

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2import mathn
3import numpy as np
4class Plant:
5    plt.style.use('bmh')  2plt.style.use('bmh')  
6plt.plot(3plt.plot(
7    [0, 1, 2],  4    [0, 1, 2],  
8    [0, 1, 0]   5    [0, 1, 0]   
9)6)
10plt.xlabel('x')7plt.xlabel('x')
11plt.ylabel('y');8plt.ylabel('y');
12def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
13    if bare_plot:10    if bare_plot:
14        plt.axis('off')11        plt.axis('off')
15    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
16    X, Y = zip(*coords)13    X, Y = zip(*coords)
17    plt.plot(X, Y);14    plt.plot(X, Y);
18plot_coords([15plot_coords([
19    (0, 0),16    (0, 0),
20    (1, 0),17    (1, 0),
21    (2, 1),18    (2, 1),
22    (3, 1),19    (3, 1),
23    (2, 0)20    (2, 0)
24])21])
25nan = float('nan')22nan = float('nan')
26plot_coords([23plot_coords([
27    (0, 0),24    (0, 0),
28    (1, 1),25    (1, 1),
29    (nan, nan),26    (nan, nan),
30    (1, 0),27    (1, 0),
31    (2, 1)28    (2, 1)
32])29])
33from math import pi, sin, cos30from math import pi, sin, cos
34DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
35def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
36    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
37    yield (0.0, 0.0)34    yield (0.0, 0.0)
38    for command in turtle_program:35    for command in turtle_program:
39        x, y, angle = state36        x, y, angle = state
40        if command in 'Ff':      37        if command in 'Ff':      
41            state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
42                     y + sin(angle * DEGREES_TO_RADIANS),39                     y + sin(angle * DEGREES_TO_RADIANS),
43                     angle)40                     angle)
44            if command == 'f':41            if command == 'f':
45                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
46            yield (state[0], state[1])43            yield (state[0], state[1])
47        elif command == '+':     44        elif command == '+':     
48            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
49        elif command == '-':     46        elif command == '-':     
50            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
51plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
52plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
53from math import isnan50from math import isnan
54def print_coords(coords):51def print_coords(coords):
55    for (x, y) in coords:52    for (x, y) in coords:
56        if isnan(x):53        if isnan(x):
57            print('<gap>')54            print('<gap>')
58        else:55        else:
59            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
60print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
61plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
62def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
63    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
64transform_sequence('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
65plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
66def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
67    for _ in range(iterations):64    for _ in range(iterations):
68        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
69    return sequence66    return sequence
70print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
71print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
72print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
73plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
74plot_coords(turtle_to_coords(transform_multiple('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
75    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
76    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
77}, 5), 90))74}, 5), 90))
78def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
79    saved_states = list()76    saved_states = list()
80    state = (0, 0, 90)77    state = (0, 0, 90)
81    yield (0, 0)78    yield (0, 0)
82    for command in turtle_program:79    for command in turtle_program:
83        x, y, angle = state80        x, y, angle = state
84        if command.lower() in 'abcdefghij':        81        if command.lower() in 'abcdefghij':        
85            state = (x - cos(angle * DEGREES_TO_RADIANS),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
86                     y + sin(angle * DEGREES_TO_RADIANS),83                     y + sin(angle * DEGREES_TO_RADIANS),
87                     angle)84                     angle)
88            if command.islower():                  85            if command.islower():                  
89                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
90            yield (state[0], state[1])87            yield (state[0], state[1])
91        elif command == '+':                       88        elif command == '+':                       
92            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
93        elif command == '-':                       90        elif command == '-':                       
94            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
95        elif command == '[':                       92        elif command == '[':                       
96            saved_states.append(state)93            saved_states.append(state)
97        elif command == ']':                       94        elif command == ']':                       
98            state = saved_states.pop()95            state = saved_states.pop()
99            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
100            x, y, _ = state97            x, y, _ = state
101            yield (x, y)98            yield (x, y)
102plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
103def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
104    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
105    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
106    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
107l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
108l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
109for i in range(5):106for i in range(5):
110    print('{}: '.format(i),107    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
112for i in range(5):109for i in range(5):
113    print('{}: '.format(i),110    print('{}: '.format(i),
114          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
115l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
116    def __init__(self):113    def __init__(self):
n117        self.instances=[]n114        self.instances = [] 
118        self.consensus=[]115        self.consensus=[] 
119        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
120    def __str__(self):117    def __str__ (self):
121        result = ""118        string = ""
122        for instance in self.instances:119        for in self.instances:
123            result += instance120            string += i + "\n"
124        return result       121        return string[:-2]
125    def __len__(self):122    def __len__(self):
n126        return len(self.instances[0].rstrip())n123        return len(self.instances)
127    def count(self):124    def count(self):
n128        for position in range(len(self)):n
129            TypeA = 0
130            TypeT = 0
131            TypeC = 0
132            TypeG = 0
133            for instance in self.instances:125        for in self.instances:
134                order = instance.rstrip()126            temp = i.upper()
135                if (order[position]).upper() == "A":
136                    TypeA += 1
137                elif (order[position]).upper() == "T":
138                    TypeT += 1
139                elif (order[position]).upper() == "C":
140                    TypeC += 1
141                elif (order[position]).upper() == "G":
142                    TypeG += 1
143            self.counts.get("A").append(TypeA)127            self.counts["A"].append(temp.count("A"))
144            self.counts.get("T").append(TypeT)
145            self.counts.get("C").append(TypeC)128            self.counts["C"].append(temp.count("C"))
146            self.counts.get("G").append(TypeG)129            self.counts["G"].append(temp.count("G"))
130            self.counts["T"].append(temp.count("T"))
147    def compute_consensus(self):131    def compute_consensus(self):
n148        DNAMOTIF.count(self)n
149        A = self.counts.get("A")132        A = self.counts["A"]
150        T = self.counts.get("T")
151        C = self.counts.get("C")133        C = self.counts["C"]
152        G = self.counts.get("G")134        G = self.counts["G"]
153        output = ""135        T = self.counts["T"]
154        for row in range(len(A)):136        for i in range(len(A)):
155            maxs = max(A[row],T[row],C[row],G[row])137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
156            if maxs == A[row]:138                self.consensus.append("A")
157                output += "A"139            elif (C[i] >= G[i] and C[i] >= T[i]):
158            elif maxs == T[row]:140                self.consensus.append("C")
159                output += "T"141            elif (G[i] >= T[i]):
160            elif maxs == C[row]:142                self.consensus.append("G")
161                output += "C"143            else:
162            elif maxs == G[row]:144                self.consensus.append("T")
163                output += "G"
164        self.consensus = output
165    def parse(self, filename):145    def parse(self, filename):
t166        myFile = open(filename, 'r')t146        with open(filename,'r') as f:
167        contents = [line for line in myFile.readlines()]147            for i in f:
168        myFile.close()148                if ">" in i:
169        for index, line in enumerate(contents):149                   continue
170            if index % 2 != 0:150                else:
171                self.instances.append(line)151                    self.instances.append(i)
172if __name__ == '__main__':152if __name__=='__main__':
173    lexA=DNAMOTIF()153    lex=DNAMOTIF()
174    filename = r'FinalProject\lexA.fasta'154    lex.parse('lexA.fasta')
175    lexA.parse(filename)155    print("length",len(lex))
176    lexA.compute_consensus()156    print(lex)
177    print(lexA.consensus)157    print("consensus",lex.consensus)
158    print('seq',lex.counts)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 34

Student ID: 105, P-Value: 3.19e-04

Nearest Neighbor ID: 364

Student (left) and Nearest Neighbor (right).


nn1import matplotlib.pyplot as plt
1plt.style.use('bmh')2plt.style.use('bmh')  
2plt.plot(3plt.plot(
n3    [0,1,2]n4    [0, 1, 2],  
4    [0,1,0]5    [0, 1, 0]   
5)6)
6plt.xlabel('x')7plt.xlabel('x')
7plt.ylabel('y');8plt.ylabel('y');
n8def plot_coords(coords,bare_plot=False):n9def plot_coords(coords, bare_plot=False):
9    if bae_plot:10    if bare_plot:
10        plt.axis('off')11        plt.axis('off')
n11    plt.axes().set_apsect('equal','datalim')n12    plt.axes().set_aspect('equal', 'datalim')
12    X,Y = zip(coords)13    X, Y = zip(*coords)
13    plt.plot(X,Y);14    plt.plot(X, Y);
14plot_coords([15plot_coords([
n15    (0,0),n16    (0, 0),
16    (1,0),17    (1, 0),
17    (2,1),18    (2, 1),
18    (3,1),19    (3, 1),
19    (2,0)20    (2, 0)
20])21])
21nan = float('nan')22nan = float('nan')
22plot_coords([23plot_coords([
n23    (0,0),n24    (0, 0),
24    (1,1),25    (1, 1),
25    (nan,nan),26    (nan, nan),
26    (1,0),27    (1, 0),
27    (2,1)28    (2, 1)
28])29])
29from math import pi, sin, cos30from math import pi, sin, cos
n30deg_to_rad = pi / 180n31DEGREES_TO_RADIANS = pi / 180
31def turtle_to_coords(turtle_program,turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
32    state = (0.0,0.0,90.0)33    state = (0.0, 0.0, 90.0)
33    yield (0.0,0.0)34    yield (0.0, 0.0)
34    for command in turtle_program:35    for command in turtle_program:
n35        x,y, angle = staten36        x, y, angle = state
36        if command in 'Ff':37        if command in 'Ff':      
37            state = (x - cos(angle * deg_to_rad),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
38                y + sin(angle * deg_to_rad),39                     y + sin(angle * DEGREES_TO_RADIANS),
39                angle)40                     angle)
40            if command == 'f':41            if command == 'f':
n41                yield(float('nan'),float('nan'))n42                yield (float('nan'), float('nan'))
42            yield(state[0],state[1])43            yield (state[0], state[1])
43        elif command =='+':44        elif command == '+':     
44            state = (x,y,angle + turn_amount)45            state = (x, y, angle + turn_amount)
45        elif command == '-':46        elif command == '-':     
46            state = (x,y,angle - turn_amount)47            state = (x, y, angle - turn_amount)
47plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
n48plot_coords(turtle_to_coords('F-F+F+F+F+f+F+F+F-F'))n49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
49from math import isnan50from math import isnan
50def print_coords(coords):51def print_coords(coords):
n51    for (x,y) in coords:n52    for (x, y) in coords:
52        if isnan(x):53        if isnan(x):
53            print('<gap>')54            print('<gap>')
54        else:55        else:
n55            print('({:.2f},{:.2f}'.format(x,y))n56            print('({:.2f}, {:.2f})'.format(x, y))
56print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
n57plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F',65))n58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
58def transform_sequence(sequence,transformations):59def transform_sequence(sequence, transformations):
59    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
n60transform_sequence('acab',{'a':'aba','c':'bb'})n61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
61plot_coords(turtle_to_coords(transform_sequece('FFFF',{'F':'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
62def transfomr_multiple(sequence,transformations,iterations):63def transform_multiple(sequence, transformations, iterations):
63    for _ in range(iterations):64    for _ in range(iterations):
n64        sequence = transform_seqence(sequence,transformations)n65        sequence = transform_sequence(sequence, transformations)
65    return sequence66    return sequence
n66print('0:',transform_multiple('abba',{'b':'bab'},0))n67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
67print('1:',transform_multiple('abba',{'b':'bab'},1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
68print('2:',transform_multiple('abba',{'b':'bab'},2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
69plot_coords(turtle_to_coords(transform_multiple('F',{'F':'+F+F--F+F'},5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
70plot_coords(turtle_to_coords(transform_multiple('L',{71plot_coords(turtle_to_coords(transform_multiple('L', {
71    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
72    'R': '+LF-RFR-FL+'73    'R': '+LF-RFR-FL+'
n73},5),90))n74}, 5), 90))
74def branching_turtle_to_coords(turtle_program,turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
75    saved_states = list()76    saved_states = list()
n76    state = (0,0,90)n77    state = (0, 0, 90)
77    yield(0,0)78    yield (0, 0)
78    for command in turtle_program:79    for command in turtle_program:
n79        x,y,angle = staten80        x, y, angle = state
80        if command.lower() in 'abcdefghuj':81        if command.lower() in 'abcdefghij':        
81            state = (c-cose(angle * deg_to_rad),82            state = (x - cos(angle * DEGREES_TO_RADIANS),
82                y + sin(angle * deg_to_rad),83                     y + sin(angle * DEGREES_TO_RADIANS),
83                angle)84                     angle)
84            if command.islower():85            if command.islower():                  
85                yield(float('nan'),float('nan'))86                yield (float('nan'), float('nan'))
86            yield(state[0],state[1])87            yield (state[0], state[1])
87        elif command == '+':88        elif command == '+':                       
88            state = (x,y,angle + turn_amount)89            state = (x, y, angle + turn_amount)
89        elif command =='-':90        elif command == '-':                       
90            state = (x,y,angle - turn_amount)91            state = (x, y, angle - turn_amount)
91        elif command == '[':92        elif command == '[':                       
92            saved_states.append(state)93            saved_states.append(state)
n93        elif command == ']':n94        elif command == ']':                       
94            state = saved_states.pop()95            state = saved_states.pop()
n95            yield(float('nan'),float('nan'))n96            yield (float('nan'), float('nan'))
96            x,y,_ = state97            x, y, _ = state
98            yield (x, y)
97plot_coords(branching_turtle_to_coords('F[-F]+F',45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
98def l_plot(axiom,transformations,iterations=0,angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
99    turtle_program = transform_multiple(axiom,transformations,iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
100    coords = branching_turtle_to_coords(turtle_program,angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
101    plot_coords(coords,bare_plot=True)103    plot_coords(coords, bare_plot=True) 
102l_plot('F',{'F[-F][+F]'},4,30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
103l_plot('F',{'F':'FF[++F][-FF]'},5,22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
104for i in range(5):106for i in range(5):
n105    print('{}:'.format(i),n107    print('{}: '.format(i),
106        transform_multiple('A',{'A':'F+A'},i))108          transform_multiple('A', {'A': 'F+A'}, i))
107for i in range(5):109for i in range(5):
n108    print('{}:'.format(i),n110    print('{}: '.format(i),
109        transform_multiple('A',{'A':'F+A','F':'FF'},i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
110l_plot('A',{'F':'FF','A':'F[+AF-[A]--A][---A]'},5,22.5)class DNAMOTIF:112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
111    def __init__(self):113    def __init__(self):
n112        self.instances=[]n114        self.instances = []
113        self.consensus=[]115        self.consensus=[]
n114        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
115    def __str__(self):117    def __str__ (self):
116        string = ""118        string = ""
117        for i in self.instances:119        for i in self.instances:
n118            string += i + ""n120            string += i + "\n"
119            return string[:-2]121        return string[:0]
120    def __len__(self):122    def __len__(self):
n121        return len(self.instances)n123        return len (self.consensus)
122    def count(self):124    def count(self):
123        for i in self.instances:125        for i in self.instances:
124            temp = i.upper()126            temp = i.upper()
125        self.counts["A"].append(temp.count("A"))127        self.counts["A"].append(temp.count("A"))
126        self.counts["C"].append(temp.count("C"))128        self.counts["C"].append(temp.count("C"))
127        self.counts["G"].append(temp.count("G"))129        self.counts["G"].append(temp.count("G"))
128        self.counts["T"].append(temp.count("T"))130        self.counts["T"].append(temp.count("T"))
129    def compute_consensus(self):131    def compute_consensus(self):
130        A = self.counts["A"]132        A = self.counts["A"]
131        C = self.counts["C"]133        C = self.counts["C"]
132        G = self.counts["G"]134        G = self.counts["G"]
n133        T = self.counts["T"]n135        T = self.counts["T"]   
134        for i in range(len(A)):136        for i in range (len(A)):
135            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
136                self.consensus.append("A")138                self.consensus.append("A")
137            elif (C[i] >= G[i] and C[i] >= T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
138                self.consensus.append("C")140                self.consensus.append("C")
139            elif (G[i] >= T[i]):141            elif (G[i] >= T[i]):
140                self.consensus.append("G")142                self.consensus.append("G")
141            else:143            else:
142                self.consensus.append("T")144                self.consensus.append("T")
143    def parse(self, filename):145    def parse(self, filename):
144        with open(filename,'r') as f:146        with open(filename,'r') as f:
145            for i in f:147            for i in f:
146                if ">" in i:148                if ">" in i:
147                    continue149                    continue
148                else:150                else:
149                    self.instances.append(i)151                    self.instances.append(i)
t150lexA = DNAMOTIF()t
151lexA.parse("lexA.fasta")
152print(len(lexA))
15319
154lexA = DNAMOTIF()
155lexA.parse("lexA.fasta")
156print(lexA)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 35

Student ID: 215, P-Value: 5.89e-04

Nearest Neighbor ID: 261

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2plt.style.use('bmh')  n2plt.style.use('bmh') 
3class PLANT:
3plt.plot(4    plt.plot(
4[0, 1, 2],  5    [0, 1, 2], 
5[0, 1, 0]   6    [0, 1, 0] 
6)7    )
7plt.xlabel('x')8plt.xlabel('x')
8plt.ylabel('y');9plt.ylabel('y');
9def plot_coords(coords, bare_plot=False):10def plot_coords(coords, bare_plot=False):
10    if bare_plot:11    if bare_plot:
11        plt.axis('off')12        plt.axis('off')
12        plt.axes().set_aspect('equal', 'datalim')13        plt.axes().set_aspect('equal', 'datalim')
n13        X, Y = zip(*coords)n14    X, Y = zip(*coords)
14        plt.plot(X, Y);15    plt.plot(X, Y);
15        plot_coords([(0, 0), (1, 0), (2, 1), (3, 1), (2, 0)])16plot_coords([
17(0, 0),
18(1, 0),
19(2, 1),
20(3, 1),
21(2, 0)
22])
16        nan = float('nan')23nan = float('nan')
17        plot_coords([(0, 0),(1, 1),(nan, nan),(1, 0),(2, 1)])24plot_coords([
25(0, 0),
26(1, 1),
27(nan, nan),
28(1, 0),
29(2, 1)
30])
18    from math import pi, sin, cos31from math import pi, sin, cos
19    DEGREES_TO_RADIANS = pi / 18032DEGREES_TO_RADIANS = pi / 180
20def turtle_to_coords(turtle_program, turn_amount=45):33def turtle_to_coords(turtle_program, turn_amount=45):
21    state = (0.0, 0.0, 90.0)34    state = (0.0, 0.0, 90.0)
22    yield (0.0, 0.0)35    yield (0.0, 0.0)
23    for command in turtle_program:36    for command in turtle_program:
24        x, y, angle = state37        x, y, angle = state
n25    if command in 'Ff':      n38    if command in 'Ff': 
26        state = (x - cos(angle * DEGREES_TO_RADIANS), y + sin(angle * DEGREES_TO39        state = (x - cos(angle * DEGREES_TO_RADIANS),
>_RADIANS),angle) 
40y + sin(angle * DEGREES_TO_RADIANS),
41angle)
27    if command == 'f':42    if command == 'f':
28        yield (float('nan'), float('nan'))43        yield (float('nan'), float('nan'))
29        yield (state[0], state[1])44        yield (state[0], state[1])
n30    elif command == '+':     n45    elif command == '+': 
31                        state = (x, y, angle + turn_amount)46        state = (x, y, angle + turn_amount)
32    elif command == '-':     47    elif command == '-': 
33                    state = (x, y, angle - turn_amount)48            state = (x, y, angle - turn_amount)
34plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))49plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
35plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))50plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
36from math import isnan51from math import isnan
37def print_coords(coords):52def print_coords(coords):
38    for (x, y) in coords:53    for (x, y) in coords:
39        if isnan(x):54        if isnan(x):
40            print('<gap>')55            print('<gap>')
n41    else:n56        else:
42        print('({:.2f}, {:.2f})'.format(x, y))57            print('({:.2f}, {:.2f})'.format(x, y))
43        print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))58print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
44        plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))59plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
45def transform_sequence(sequence, transformations):60def transform_sequence(sequence, transformations):
46    return ''.join(transformations.get(c, c) for c in sequence)61    return ''.join(transformations.get(c, c) for c in sequence)
n47    transform_sequence('acab', {'a': 'aba', 'c': 'bb'})n62transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
48    plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))63plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
49def transform_multiple(sequence, transformations, iterations):64def transform_multiple(sequence, transformations, iterations):
50    for _ in range(iterations):65    for _ in range(iterations):
51        sequence = transform_sequence(sequence, transformations)66        sequence = transform_sequence(sequence, transformations)
52        return sequence67        return sequence
n53        print('0:', transform_multiple('abba', {'b': 'bab'}, 0))n68print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
54        print('1:', transform_multiple('abba', {'b': 'bab'}, 1))69print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
55        print('2:', transform_multiple('abba', {'b': 'bab'}, 2))70print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
56        plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'},71plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
> 5))) 
57        plot_coords(turtle_to_coords(transform_multiple('L', {'L': '-RF+LFL+FR-'72plot_coords(turtle_to_coords(transform_multiple('L', {
>,'R': '+LF-RFR-FL+'}, 5), 90)) 
73'L': '-RF+LFL+FR-',
74'R': '+LF-RFR-FL+'
75}, 5), 90))
58def branching_turtle_to_coords(turtle_program, turn_amount=45):76def branching_turtle_to_coords(turtle_program, turn_amount=45):
59    saved_states = list()77    saved_states = list()
60    state = (0, 0, 90)78    state = (0, 0, 90)
61    yield (0, 0)79    yield (0, 0)
62    for command in turtle_program:80    for command in turtle_program:
63        x, y, angle = state81        x, y, angle = state
n64        if command.lower() in 'abcdefghij':        n82    if command.lower() in 'abcdefghij': 
65            state = (x - cos(angle * DEGREES_TO_RADIANS), y + sin(angle * DEGREE83        state = (x - cos(angle * DEGREES_TO_RADIANS),
>S_TO_RADIANS), angle) 
66        if command.islower():                  84y + sin(angle * DEGREES_TO_RADIANS),
85angle)
86    if command.islower(): 
67            yield (float('nan'), float('nan'))87        yield (float('nan'), float('nan'))
68            yield (state[0], state[1])88        yield (state[0], state[1])
69        elif command == '+':                       89    elif command == '+': 
70            state = (x, y, angle + turn_amount)90        state = (x, y, angle + turn_amount)
71        elif command == '-':                       91    elif command == '-': 
72            state = (x, y, angle - turn_amount)92        state = (x, y, angle - turn_amount)
73        elif command == '[':                       93    elif command == '[': 
74            saved_states.append(state)94        saved_states.append(state)
75        elif command == ']':                       95    elif command == ']': 
76            state = saved_states.pop()96        state = saved_states.pop()
77            yield (float('nan'), float('nan'))97    yield (float('nan'), float('nan'))
78            x, y, _ = state98    x, y, _ = state
79            yield (x, y)99    yield (x, y)
80            plot_coords(branching_turtle_to_coords('F[-F]+F', 45))100plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
81def l_plot(axiom, transformations, iterations=0, angle=45):101def l_plot(axiom, transformations, iterations=0, angle=45):
82    turtle_program = transform_multiple(axiom, transformations, iterations)102    turtle_program = transform_multiple(axiom, transformations, iterations)
83    coords = branching_turtle_to_coords(turtle_program, angle)103    coords = branching_turtle_to_coords(turtle_program, angle)
84    plot_coords(coords, bare_plot=True) 104    plot_coords(coords, bare_plot=True) 
n85    l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)n105l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
86    l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)106l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
87    for i in range(5):107for i in range(5):
88        print('{}: '.format(i), transform_multiple('A', {'A': 'F+A'}, i))108    print('{}: '.format(i),
109transform_multiple('A', {'A': 'F+A'}, i))
89    for i in range(5):110for i in range(5):
111    print('{}: '.format(i),
90        print('{}: '.format(i),transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, 112transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
>i)) 
91        l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMO113l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)from re import X
>TIF: 
114class DNAMOTIF:
92    def __init__(self):115    def __init__(self):
93        self.instances=[]116        self.instances=[]
94        self.consensus=[]117        self.consensus=[]
95        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}118        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
96    def __str__(self):119    def __str__(self):
n97        print(instances)n120        x=len(self.instances)
98        return121        return x
99        pass 
100    def __len__(self):122    def __len__(self):
n101        print(len(str(dna_str)))n123        x=len(self.instances)
102        return124        return x
103    def count(self):125    def count(self):
n104        for x in self.counts:n
105            if dna_str == A:
106                print('A')
107            elif dna_str == G:
108                print('G')
109            elif dna_str == C:
110                print('C')
111            elif dna_str == T:
112                print('T')       
113        pass 126        pass 
114    def compute_consensus(self):127    def compute_consensus(self):
n115        print(filename.consensus)n
116        pass 128        pass 
117    def parse(self, filename):129    def parse(self, filename):
t118        p = filename.parse(filename.FASTA)t130        pass
119        print(p)
120self.instances = instances
121self.consensus = consensus
122self.counts = counts
123instances = str(filename)
124A = str(seq).count('A')
125T = str(seq).count('T')
126C = str(seq).count('C')
127G = str(seq).count('G')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 36

Student ID: 261, P-Value: 5.89e-04

Nearest Neighbor ID: 215

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2plt.style.use('bmh') n2plt.style.use('bmh')  
3class PLANT:
4    plt.plot(3plt.plot(
5    [0, 1, 2], 4[0, 1, 2],  
6    [0, 1, 0] 5[0, 1, 0]   
7    )6)
8plt.xlabel('x')7plt.xlabel('x')
9plt.ylabel('y');8plt.ylabel('y');
10def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
11    if bare_plot:10    if bare_plot:
12        plt.axis('off')11        plt.axis('off')
13        plt.axes().set_aspect('equal', 'datalim')12        plt.axes().set_aspect('equal', 'datalim')
n14    X, Y = zip(*coords)n13        X, Y = zip(*coords)
15    plt.plot(X, Y);14        plt.plot(X, Y);
16plot_coords([15        plot_coords([(0, 0), (1, 0), (2, 1), (3, 1), (2, 0)])
17(0, 0),
18(1, 0),
19(2, 1),
20(3, 1),
21(2, 0)
22])
23nan = float('nan')16        nan = float('nan')
24plot_coords([17        plot_coords([(0, 0),(1, 1),(nan, nan),(1, 0),(2, 1)])
25(0, 0),
26(1, 1),
27(nan, nan),
28(1, 0),
29(2, 1)
30])
31from math import pi, sin, cos18    from math import pi, sin, cos
32DEGREES_TO_RADIANS = pi / 18019    DEGREES_TO_RADIANS = pi / 180
33def turtle_to_coords(turtle_program, turn_amount=45):20def turtle_to_coords(turtle_program, turn_amount=45):
34    state = (0.0, 0.0, 90.0)21    state = (0.0, 0.0, 90.0)
35    yield (0.0, 0.0)22    yield (0.0, 0.0)
36    for command in turtle_program:23    for command in turtle_program:
37        x, y, angle = state24        x, y, angle = state
n38    if command in 'Ff': n25    if command in 'Ff':      
39        state = (x - cos(angle * DEGREES_TO_RADIANS),26        state = (x - cos(angle * DEGREES_TO_RADIANS), y + sin(angle * DEGREES_TO
 >_RADIANS),angle)
40y + sin(angle * DEGREES_TO_RADIANS),
41angle)
42    if command == 'f':27    if command == 'f':
43        yield (float('nan'), float('nan'))28        yield (float('nan'), float('nan'))
44        yield (state[0], state[1])29        yield (state[0], state[1])
n45    elif command == '+': n30    elif command == '+':     
46        state = (x, y, angle + turn_amount)31                        state = (x, y, angle + turn_amount)
47    elif command == '-': 32    elif command == '-':     
48            state = (x, y, angle - turn_amount)33                    state = (x, y, angle - turn_amount)
49plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))34plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
50plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))35plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
51from math import isnan36from math import isnan
52def print_coords(coords):37def print_coords(coords):
53    for (x, y) in coords:38    for (x, y) in coords:
54        if isnan(x):39        if isnan(x):
55            print('<gap>')40            print('<gap>')
n56        else:n41    else:
57            print('({:.2f}, {:.2f})'.format(x, y))42        print('({:.2f}, {:.2f})'.format(x, y))
58print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))43        print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
59plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))44        plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
60def transform_sequence(sequence, transformations):45def transform_sequence(sequence, transformations):
61    return ''.join(transformations.get(c, c) for c in sequence)46    return ''.join(transformations.get(c, c) for c in sequence)
n62transform_sequence('acab', {'a': 'aba', 'c': 'bb'})n47    transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
63plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))48    plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
64def transform_multiple(sequence, transformations, iterations):49def transform_multiple(sequence, transformations, iterations):
65    for _ in range(iterations):50    for _ in range(iterations):
66        sequence = transform_sequence(sequence, transformations)51        sequence = transform_sequence(sequence, transformations)
67        return sequence52        return sequence
n68print('0:', transform_multiple('abba', {'b': 'bab'}, 0))n53        print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
69print('1:', transform_multiple('abba', {'b': 'bab'}, 1))54        print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
70print('2:', transform_multiple('abba', {'b': 'bab'}, 2))55        print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
71plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))56        plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'},
 > 5)))
72plot_coords(turtle_to_coords(transform_multiple('L', {57        plot_coords(turtle_to_coords(transform_multiple('L', {'L': '-RF+LFL+FR-'
 >,'R': '+LF-RFR-FL+'}, 5), 90))
73'L': '-RF+LFL+FR-',
74'R': '+LF-RFR-FL+'
75}, 5), 90))
76def branching_turtle_to_coords(turtle_program, turn_amount=45):58def branching_turtle_to_coords(turtle_program, turn_amount=45):
77    saved_states = list()59    saved_states = list()
78    state = (0, 0, 90)60    state = (0, 0, 90)
79    yield (0, 0)61    yield (0, 0)
80    for command in turtle_program:62    for command in turtle_program:
81        x, y, angle = state63        x, y, angle = state
n82    if command.lower() in 'abcdefghij': n64        if command.lower() in 'abcdefghij':        
83        state = (x - cos(angle * DEGREES_TO_RADIANS),65            state = (x - cos(angle * DEGREES_TO_RADIANS), y + sin(angle * DEGREE
 >S_TO_RADIANS), angle)
84y + sin(angle * DEGREES_TO_RADIANS),66        if command.islower():                  
85angle)
86    if command.islower(): 
87        yield (float('nan'), float('nan'))67            yield (float('nan'), float('nan'))
88        yield (state[0], state[1])68            yield (state[0], state[1])
89    elif command == '+': 69        elif command == '+':                       
90        state = (x, y, angle + turn_amount)70            state = (x, y, angle + turn_amount)
91    elif command == '-': 71        elif command == '-':                       
92        state = (x, y, angle - turn_amount)72            state = (x, y, angle - turn_amount)
93    elif command == '[': 73        elif command == '[':                       
94        saved_states.append(state)74            saved_states.append(state)
95    elif command == ']': 75        elif command == ']':                       
96        state = saved_states.pop()76            state = saved_states.pop()
97    yield (float('nan'), float('nan'))77            yield (float('nan'), float('nan'))
98    x, y, _ = state78            x, y, _ = state
99    yield (x, y)79            yield (x, y)
100plot_coords(branching_turtle_to_coords('F[-F]+F', 45))80            plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
101def l_plot(axiom, transformations, iterations=0, angle=45):81def l_plot(axiom, transformations, iterations=0, angle=45):
102    turtle_program = transform_multiple(axiom, transformations, iterations)82    turtle_program = transform_multiple(axiom, transformations, iterations)
103    coords = branching_turtle_to_coords(turtle_program, angle)83    coords = branching_turtle_to_coords(turtle_program, angle)
104    plot_coords(coords, bare_plot=True) 84    plot_coords(coords, bare_plot=True) 
n105l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)n85    l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
106l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)86    l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
107for i in range(5):87    for i in range(5):
108    print('{}: '.format(i),88        print('{}: '.format(i), transform_multiple('A', {'A': 'F+A'}, i))
109transform_multiple('A', {'A': 'F+A'}, i))
110for i in range(5):89    for i in range(5):
111    print('{}: '.format(i),
112transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))90        print('{}: '.format(i),transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, 
 >i))
113l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)from re import X91        l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMO
 >TIF:
114class DNAMOTIF:
115    def __init__(self):92    def __init__(self):
116        self.instances=[]93        self.instances=[]
117        self.consensus=[]94        self.consensus=[]
118        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}95        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
119    def __str__(self):96    def __str__(self):
n120        x=len(self.instances)n97        print(instances)
121        return x98        return
99        pass 
122    def __len__(self):100    def __len__(self):
n123        x=len(self.instances)n101        print(len(str(dna_str)))
124        return x102        return
125    def count(self):103    def count(self):
nn104        for x in self.counts:
105            if dna_str == A:
106                print('A')
107            elif dna_str == G:
108                print('G')
109            elif dna_str == C:
110                print('C')
111            elif dna_str == T:
112                print('T')       
126        pass 113        pass 
127    def compute_consensus(self):114    def compute_consensus(self):
nn115        print(filename.consensus)
128        pass 116        pass 
129    def parse(self, filename):117    def parse(self, filename):
t130        passt118        p = filename.parse(filename.FASTA)
119        print(p)
120self.instances = instances
121self.consensus = consensus
122self.counts = counts
123instances = str(filename)
124A = str(seq).count('A')
125T = str(seq).count('T')
126C = str(seq).count('C')
127G = str(seq).count('G')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 37

Student ID: 377, P-Value: 7.89e-04

Nearest Neighbor ID: 290

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2plt.plot([0, 1, 2],  [0, 1, 0])  n2plt.style.use('bmh')
3plt.plot(
4    [0, 1, 2],
5    [0, 1, 0]
6)
3plt.xlabel('x')7plt.xlabel('x')
4plt.ylabel('y');8plt.ylabel('y');
5def plot_coords(coords, bare_plot=False):9def plot_coords(coords, bare_plot=False):
6    if bare_plot:10    if bare_plot:
7        plt.axis('off')11        plt.axis('off')
n8    plt.axes().set_aspect('equal', 'datalim')n12    plt.axes().set_aspect('equal', 'datalim').
9    X, Y = zip(*coords)13    X, Y = zip(*coords)
10    plt.plot(X, Y);14    plt.plot(X, Y);
n11    plot_coords([(0, 0),(1, 0),(2, 1),(3, 1),(2, 0)])n15    plot_coords([
16        (0, 0),
17        (1, 0),
18        (2, 1),
19        (3, 1),
20        (2, 0)
21    ])
12    nan = float('nan')22    nan = float('nan')
n13    plot_coords([(0, 0),(1, 1),(nan, nan),(1, 0),(2, 1)])n23    plot_coords([
24        (0, 0),
25        (1, 1),
26        (nan, nan),
27        (1, 0),
28        (2, 1)
29    ])
14from math import pi, sin, cos30from math import pi, sin, cos
15DEGREES_TO_RADIANS = pi / 18031DEGREES_TO_RADIANS = pi / 180
16def turtle_to_coords(turtle_program, turn_amount=45):32def turtle_to_coords(turtle_program, turn_amount=45):
17    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
18    yield (0.0, 0.0)34    yield (0.0, 0.0)
19    for command in turtle_program:35    for command in turtle_program:
20        x, y, angle = state36        x, y, angle = state
n21    if command in 'Ff':      n37        if command in 'Ff':
22        state = (x - cos(angle * DEGREES_TO_RADIANS),38            state = (x - cos(angle * DEGREES_TO_RADIANS),
23     y + sin(angle * DEGREES_TO_RADIANS),angle)39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)
24    if command == 'f':41            if command == 'f':
25        yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
26        yield (state[0], state[1])43            yield (state[0], state[1])
27    elif command == '+':     44        elif command == '+':  
28        state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
29    elif command == '-':    46        elif command == '-':  
30        state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
31plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
32plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
33from math import isnan50from math import isnan
34def print_coords(coords):51def print_coords(coords):
35    for (x, y) in coords:52    for (x, y) in coords:
36        if isnan(x):53        if isnan(x):
37            print('<gap>')54            print('<gap>')
n38    else:n55        else:
39        print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
40        print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
41        plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
42def transform_sequence(sequence, transformations):59def transform_sequence(sequence, transformations):
43    return ''.join(transformations.get(c, c) for c in sequence)60    return ''.join(transformations.get(c, c) for c in sequence)
n44    transform_sequence('acab', {'a': 'aba', 'c': 'bb'})n61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
45    plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
46def transform_multiple(sequence, transformations, iterations):63def transform_multiple(sequence, transformations, iterations):
47    for _ in range(iterations):64    for _ in range(iterations):
48        sequence = transform_sequence(sequence, transformations)65        sequence = transform_sequence(sequence, transformations)
49    return sequence66    return sequence
50print('0:', transform_multiple('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
51print('1:', transform_multiple('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
52print('2:', transform_multiple('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
53plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
n54plot_coords(turtle_to_coords(transform_multiple('L', {'L': '-RF+LFL+FR-','R': '+n71plot_coords(turtle_to_coords(transform_multiple('L', {
>LF-RFR-FL+' 
72    'L': '-RF+LFL+FR-',
73    'R': '+LF-RFR-FL+'
55},5), 90))74}, 5), 90))
56def branching_turtle_to_coords(turtle_program, turn_amount=45):75def branching_turtle_to_coords(turtle_program, turn_amount=45):
57    saved_states = list()76    saved_states = list()
58    state = (0, 0, 90)77    state = (0, 0, 90)
59    yield (0, 0)78    yield (0, 0)
60    for command in turtle_program:79    for command in turtle_program:
61        x, y, angle = state80        x, y, angle = state
n62        if command.lower() in 'abcdefghij':        n81        if command.lower() in 'abcdefghij':       
63            state = (x - cos(angle * DEGREES_TO_RADIANS),y + sin(angle * DEGREES82            state = (x - cos(angle * DEGREES_TO_RADIANS),
>_TO_RADIANS),angle) 
83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)
64        if command.islower():                  85            if command.islower():                  
65            yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
66            yield (state[0], state[1])87            yield (state[0], state[1])
n67        elif command == '+':                       n88        elif command == '+':                      
68            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
n69        elif command == '-':                       n90        elif command == '-':                      
70            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
71        elif command == '[':                      92        elif command == '[':                      
72            saved_states.append(state)93            saved_states.append(state)
n73        elif command == ']':                      n94        elif command == ']':                       
74            state = saved_states.pop()95            state = saved_states.pop()
75            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
76            x, y, _ = state97            x, y, _ = state
77            yield (x, y)98            yield (x, y)
78plot_coords(branching_turtle_to_coords('F[-F]+F', 45))99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
79def l_plot(axiom, transformations, iterations=0, angle=45):100def l_plot(axiom, transformations, iterations=0, angle=45):
80    turtle_program = transform_multiple(axiom, transformations, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
81    coords = branching_turtle_to_coords(turtle_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
82    plot_coords(coords, bare_plot=True) 103    plot_coords(coords, bare_plot=True) 
n83    l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)n104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
84    l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
85    for i in range(5):106for i in range(5):
107    print('{}: '.format(i),
86        print('{}: '.format(i),transform_multiple('A', {'A': 'F+A'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
87    for i in range(5):109for i in range(5):
110    print('{}: '.format(i),
88        print('{}: '.format(i),transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, 111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
>i)) 
89    l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)def remove_inde112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF:
>ntation(string): 
90    return string.replace("\n", "")
91def normalize_sequence(string):
92    return remove_indentation(string).upper()
93class DNAMOTIF:
94    def __init__(self):113    def __init__(self):
n95        self.instances = []n114        self.instances=[]
96        self.consensus = []115        self.consensus=[]
97        self.counts = {'A': [], 'C':[], 'G':[], 'T':[]}116        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
98    def __str__(self):117    def __str__(self):
n99        output = ''.join(self.instances)n118        string = ""
100        return output119        for i in self.instances:
120            string += i
101    def __len__(self):121    def __len__(self):
n102        lenght = len(remove_indentation(self.instances[0]).upper())n122        return len(self.instances) - len(self.counts)
103        return lenght
104    def parse(self,filename):
105        file = open(filename)
106        for line in file:
107            if '>' not in line:
108                self.instances.append(line)
109    def count(self):123    def count(self):
n110        for i in self.counts:n
111            self.counts[i] = []
112        for sequence in range(len(remove_indentation(self.instances[0]))):
113            for c in self.counts.keys():
114              self.counts[c].append(0)
115        for sequence in self.instances:124        for i in self.instances:
116            normal_sequence = normalize_sequence(sequence)125            temp = i.upper()
117            position_index = 0126            self.counts["A"].append(temp.count("A"))
118            for char in normal_sequence:127            self.counts["C"].append(temp.count("C"))
119                self.counts[char][position_index] += 1128            self.counts["G"].append(temp.count("G"))
120                position_index+=1129            self.counts["T"].append(temp.count("T"))  
121        return self.counts
122    def compute_consensus(self):130    def compute_consensus(self):
n123        con_list = []n
124        con_len = self.__len__()
125        con_ind = 0
126        A = self.counts['A']131        A = self.counts["A"]
127        C = self.counts['C']132        C = self.counts["C"]
128        G = self.counts['G']133        G = self.counts["G"]
129        T = self.counts['T']134        T = self.counts["T"]
130        for i in range (len(A)):135        for i in range(len(A)):
131            if (A[i] >=  C[i] and A[i] >= G[i] and A[i] >= T[i]):136            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
132                self.consensus.append('A')137                self.consensus.append("A")
133            elif (C[i] >= G[i] and C[i] >= T[i]):138            elif (C[i] >= G[i] and C[i] >= T[i]):
n134                self.consensus.append('c')n139                self.consensus.append("C")
135            elif (G[i] >= T[i]):140            elif (G[i] >= T[i]):
n136                self.consensus.append('G')n141                self.consensus.append("G")
137            else:142            else:
t138                self.consensus.append('T')t143                self.consensus.append("T")
139        pass144    def parse(self, filename):
145        with open(filename,'r') as fasta:
146            for i in fasta:
147                if ">" in i:
148                    pass
149                else:
150                    self.instances.append(i)
151if __name__=="__main__":
152    lexA = DNAMOTIF()
153    lexA.parse("lexA.fasta")
154    print(len(lexA))
155    lexA = DNAMOTIF()
156    lexA.parse("lexA.fasta")
157    print(lexA)
158    lexA = DNAMOTIF()
159    lexA.count()
160    print(lexA.counts)
161    lexA = DNAMOTIF()
162    lexA.compute_consensus()
163    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 38

Student ID: 53, P-Value: 2.00e-03

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
n4    def __init__(self, cuerda, diccionario, n, deltaTheta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.cuerda = cuerda5        self.string = string
6        self.diccionario = diccionario6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        self.str = PLANT.generator(cuerda,diccionario, n)n9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(cuerda, diccionario, n):10    def generator(string, dictionary, n):
11        def variable(cuerda):11        def character_v(string):
12            if cuerda in diccionario:12            if string in dictionary:
13                return diccionario.get(cuerda)13                return dictionary.get(string)
14            return cuerda14            return string
15        list_of_subcuerdas = [cuerda]15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
n17            current_subcuerda = list_of_subcuerdas[-1]n17            substring = substrings_list[-1]
18            new_axiom = [variable(char) for char in current_subcuerda]18            new_statement = [character_v(char) for char in substring]
19            list_of_subcuerdas.append(''.join(new_axiom))19            substrings_list.append(''.join(new_statement))
20        newcuerda = list_of_subcuerdas[n]20        newstring = substrings_list[n]
21        return newcuerda21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
n23        capitales = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',n23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
> 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)24        currentPt=(200,0)
n25        angulo = np.radians(90)n25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
n27        stack = [currentPt, angulo]n27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
n29            if command.upper() in capitales:n29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+(np.cos(angulo)), currentPt[1]+(np.sin(an30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>gulo)))>ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
32                currentPt = nextPt 32                currentPt = nextPt 
33            else:33            else:
34                if command == '[':34                if command == '[':
35                    stack.append(currentPt)35                    stack.append(currentPt)
n36                    stack.append(angulo)n36                    stack.append(theta)
37                elif command == ']':37                elif command == ']':
n38                    angulo = stack.pop()n38                    theta = stack.pop()
39                    currentPt = stack.pop()  39                    currentPt = stack.pop()  
nn40                elif command == '-':
41                    theta -= deltaTheta
40                elif command == '+':42                elif command == '+':
n41                    angulo += deltaThetan43                    theta += deltaTheta
42                elif command == '-':
43                    angulo -= deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
n46    cuerda = input()n46    string = input()
47    diccionario = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
n50    p = PLANT(cuerda, diccionario, n, deltaTheta)n50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
52    plt.show()class DNAMOTIF:52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
54        self.instances=[]54        self.instances=[]
55        self.consensus=[]55        self.consensus=[]
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
58        output = ""58        output = ""
n59        for instances in self.instances:n59        for instance in self.instances:
60            output += instances60            output += instance
61        return output   61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
n65        for posicion in range(len(self)):n65        for position in range(len(self)):
66            secuenciaA = 066            sequenceA = 0
67            secuenciaT = 067            sequenceT = 0
68            secuenciaC = 068            sequenceC = 0
69            secuenciaG = 069            sequenceG = 0
70            for instances in self.instances:70            for instance in self.instances:
71                secuencia = instances.rstrip()71                sequence = instance.rstrip()
72                if (secuencia[posicion]).upper() == "A":72                if (sequence[position]).upper() == "A":
73                    secuenciaA += 173                    sequenceA += 1
74                elif (secuencia[posicion]).upper() == "T":74                elif (sequence[position]).upper() == "T":
75                    secuenciaT += 175                    sequenceT += 1
76                elif (secuencia[posicion]).upper() == "C":76                elif (sequence[position]).upper() == "C":
77                    secuenciaC += 177                    sequenceC += 1
78                elif (secuencia[posicion]).upper() == "G":78                elif (sequence[position]).upper() == "G":
79                    secuenciaG += 179                    sequenceG += 1
80            self.counts.get("A").append(secuenciaA)80            self.counts.get("A").append(sequenceA)
81            self.counts.get("T").append(secuenciaT)81            self.counts.get("T").append(sequenceT)
82            self.counts.get("C").append(secuenciaC)82            self.counts.get("C").append(sequenceC)
83            self.counts.get("G").append(secuenciaG)83            self.counts.get("G").append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
86        A = self.counts.get("A")86        A = self.counts.get("A")
87        T = self.counts.get("T")87        T = self.counts.get("T")
88        C = self.counts.get("C")88        C = self.counts.get("C")
89        G = self.counts.get("G")89        G = self.counts.get("G")
90        output = ""90        output = ""
n91        for fila in range(len(A)):n91        for row in range(len(A)):
92            maximo = max(A[fila],T[fila],C[fila],G[fila])92            maxs = max(A[row],T[row],C[row],G[row])
93            if maximo == A[fila]:93            if maxs == A[row]:
94                output += "A"94                output += "A"
n95            elif maximo == T[fila]:n95            elif maxs == T[row]:
96                output += "T"96                output += "T"
n97            elif maximo == C[fila]:n97            elif maxs == C[row]:
98                output += "C"98                output += "C"
n99            elif maximo == G[fila]:n99            elif maxs == G[row]:
100                output += "G"100                output += "G"
101        self.consensus = output101        self.consensus = output
n102    def parse(self, nombredelfile):n102    def parse(self, filename):
103        File = open(nombredelfile, 'r')103        myFile = open(filename, 'r')
104        contents = [line for line in File.readlines()]104        contents = [line for line in myFile.readlines()]
105        File.close()105        myFile.close()
106        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
107            if index % 2 != 0:107            if index % 2 != 0:
n108                self.instances.append(line)    n108                self.instances.append(line)
109if __name__ == '__main__':109if __name__ == '__main__':
110    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t111    nombredelfile = r'FinalProject\lexA.fasta' t111    filename = r'FinalProject\lexA.fasta' 
112    lexA.parse(nombredelfile)112    lexA.parse(filename)
113    lexA.compute_consensus()113    lexA.compute_consensus()
114    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 39

Student ID: 309, P-Value: 3.41e-03

Nearest Neighbor ID: 423

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
n2import matplotlib.pyplot as pltn
3class PLANT:2class PLANT:
n4    def __init__(self,initial,gen={},num=0,deltaTheta=0):n3    def __init__(self, initial , gen = {}, p = 0, deltaTheta = 0):
5        self.initial = initial4        self.initial = initial
6        self.gen = gen5        self.gen = gen
n7        self.num = numn6        self.p = p
8        self.deltaTheta = deltaTheta7        self.deltaTheta = deltaTheta
9        self.str = initial8        self.str = initial
n10        while num > 0:n9        while p>0:
11            num -= 110            p -= 1
12            y = ''11            y = ''
13            for i in self.str:12            for i in self.str:
14                if i in gen:13                if i in gen:
15                    y += gen[i]14                    y += gen[i]
16                else:15                else:
17                    y += i16                    y += i
18            self.str = y17            self.str = y
19    def drawPlant(self):18    def drawPlant(self):
n20        current_point=(200,0)n
21        theta = 90 * math.pi/180
22        next_point = (current_point[0] + math.cos(theta), current_point[1] + mat
>h.sin(theta)) 
23        plt.plot([current_point[0],next_point[0]],[current_point[1],next_point[1
>]],color='black') 
24        x = []19        x = []
25        for i in self.str:20        for i in self.str:
26            if i == '[':21            if i == '[':
n27                x.append([current_point,theta])n22                x.append([currentPt,theta])
28            elif i == ']':23            elif i == ']':
n29                current_point = x[-1][0]n24                currentPt = x[-1][0]
30                theta = x[-1][1]25                theta = x[-1][1]
31            elif i == '+':26            elif i == '+':
32                theta += self.deltaTheta27                theta += self.deltaTheta
33            elif i == '-':28            elif i == '-':
34                theta -= self.deltaTheta29                theta -= self.deltaTheta
nn30        currentPt=(200,0)
31        theta = 90
32        nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.sin(theta)
 >)
33        plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color='black'
 >)
35        current_point = next_point34        currentPt=nextPt
36        x = []35        x = []
37        for i in self.str:36        for i in self.str:
38            if i == '[':37            if i == '[':
n39                x.append([current_point,theta])n38                x.append([currentPt,theta])
40            elif i == ']':39            elif i == ']':
n41                current_point = x[-1][0]n40                currentPt = x[-1][0]
42                theta = x[-1][1]41                theta = x[-1][1]
43            elif i == '+':42            elif i == '+':
44                theta += self.deltaTheta43                theta += self.deltaTheta
45            elif i == '-':44            elif i == '-':
n46                theta -= self.deltaThetaclass DNAMOTIF:n45                theta -= self.deltaTheta
46class DNAMOTIF:
47    def __init__(self):47    def __init__(self):
48        self.instances=[]48        self.instances=[]
49        self.consensus=[]49        self.consensus=[]
n50        self.counts= {'A':[],'C':[],'G':[],'T':[]}n50        self.counts= {"A": [], "C": [], "G":[],"T":[]}
51    def __str__(self):51    def __str__(self):
n52        str = ''n52        string = ""
53        for i in self.instances:53        for i in self.instances:
n54            return in
55            str += i54            string += i + ""
56            return str[:-2]55        return string[:-2]
57    def __len__(self):56    def __len__(self):
58        return len(self.instances[0])-157        return len(self.instances[0])-1
59    def count(self):58    def count(self):
60        i = 059        i = 0
tt60        count = 0
61        up = []
62        do_again = []
61        x = 063        A = 0
62        A = []
63        C = []64        C = 0
64        G = []
65        T = []65        T = 0
66        G = 0
66        for i in range(len(self.instances[0])-1):67        while i < len(self.instances[0])-1:
67            A.append(0)68            while count < len(self.instances):
68            C.append(0)
69            G.append(0)
70            T.append(0)
71        for in self.instances:69                for amino in self.instances:
72            i = i.upper()70                    amino = amino.upper()
71                    up.append(amino[i])
72                    count += 1
73            z = 073            count = 0
74            do_again.append(up)
75            up = []
76            i += 1
77        for DNA in do_again:
74            for j in i:78            for an in DNA:
75                if j == 'A':79                if an == 'A':
76                    A[z] += 180                    A += 1
77                elif j == 'C':81                if an == 'C':
78                    C[z] += 182                    C += 1
79                elif j == 'G':
80                    G[z] += 1
81                elif j == 'T':83                if an == 'T':
82                    T[z] += 184                    T += 1
85                if an == 'G':
83                z += 186                    G += 1 
84        self.counts['A'] = A87            self.counts.setdefault('A',[]).append(A)
85        self.counts['C'] = C88            self.counts.setdefault('C',[]).append(C)
86        self.counts['G'] = G89            self.counts.setdefault('T',[]).append(T)
87        self.counts['T'] = T90            self.counts.setdefault('G',[]).append(G)
91            A = 0
92            C = 0
93            T = 0
94            G = 0
88    def compute_consensus(self):95    def compute_consensus(self):
89        self.count()96        self.count()
90        A = self.counts["A"]97        A = self.counts["A"]
91        C = self.counts["C"]98        C = self.counts["C"]
92        G = self.counts["G"]99        G = self.counts["G"]
93        T = self.counts["T"]100        T = self.counts["T"]
94        for amino in range(len(A)):101        for amino in range(len(A)):
95            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a102            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a
>mino]):>mino]):
96                self.consensus.append("A")103                self.consensus.append("A")
97            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):104            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):
98                self.consensus.append("C")105                self.consensus.append("C")
99            elif (G[amino] >= T[amino]):106            elif (G[amino] >= T[amino]):
100                self.consensus.append("G")107                self.consensus.append("G")
101            else:108            else:
102                self.consensus.append("T")109                self.consensus.append("T")
103        self.consensus = "".join(self.consensus)110        self.consensus = "".join(self.consensus)
104    def parse(self, filename):111    def parse(self, filename):
105        with open(filename,'r') as f:112        with open(filename,'r') as f:
106            for i in f:113            for i in f:
107                if ">" in i:114                if ">" in i:
108                    continue115                    continue
109                else:116                else:
110                    self.instances.append(i)117                    self.instances.append(i)
111lexA=DNAMOTIF()118lexA=DNAMOTIF()
112lexA.parse("lexA.fasta")119lexA.parse("lexA.fasta")
113lexA.count()120lexA.count()
114print(lexA.counts)121print(lexA.counts)
115lexA.compute_consensus()122lexA.compute_consensus()
116print(lexA.consensus)123print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 40

Student ID: 170, P-Value: 4.18e-03

Nearest Neighbor ID: 425

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
3class PLANT:3class PLANT:
n4    def __init__(self, in_string, dictionary, n, deltaTheta):n4    def __init__(self, input_str, dictionary, n, delta):
5        self.str = self.generator(in_string, dictionary, n)5        self.str = self.generate(input_str, dictionary, n)
6        self.deltaTheta = deltaTheta6        self.delta = delta
7    def generator(self, strings, dictionary, n):7    def generate(self, string, dictionary, n):
8        for i in range(n):8        for i in range(n):
n9            strings = ''.join(dictionary.get(numnum) for num in strings)n9            string = ''.join(dictionary.get(charchar) for char in string)
10        return strings10        return string
11    def drawPlant(self):11    def drawPlant(self):
n12        currentPt = [200, 0]n12        current_pt=[200, 0] 
13        theta = 9013        theta = 90
n14        deltaTheta = self.deltaThetan14        delta = self.delta
15        currPt=(currentPt[0], currentPt[1], theta)15        current_state = (current_pt[0], current_pt[1], theta) 
16        PT=[]16        states = list()
17        for num in self.str:17        for char in self.str:
18            currentPt[0], currentPt[1], theta = currPt18            current_pt[0], current_pt[1], theta = current_state
19            if num.isalpha():19            if char.isalpha():
20                nextPt = (currPt[0] - math.cos(math.radians(currPt[2])), currPt[20                next_pt = (current_state[0] - math.cos(math.radians(current_stat
>1] + math.sin(math.radians(currPt[2])))>e[2])), current_state[1] + math.sin(math.radians(current_state[2])))
21                plt.plot([currPt[0], nextPt[0]], [currPt[1], nextPt[1]], color='21                plt.plot([current_state[0], next_pt[0]], [current_state[1], next
>black')>_pt[1]], color='black')
22                currPt = (nextPt[0], nextPt[1], theta)22                current_state = (next_pt[0], next_pt[1], theta)
23            if num =='[':23            if char == '[':
24                PT.append(currPt)24                states.append(current_state)
25            if num == ']':25            if char == ']':
26                currPt=PT.pop()26                current_state = states.pop()
27            if num =='+':27            if char == '+':
28                currPt=[currPt[0], currPt[1], currPt[2] + deltaTheta]28                current_state = [current_state[0], current_state[1], current_sta
 >te[2] + delta]
29            if num=='-':29            if char == '-':
30                currPt=[currPt[0], currPt[1], currPt[2] - deltaTheta]30                current_state = [current_state[0], current_state[1], current_sta
 >te[2] - delta]
31class DNAMOTIF: 31class DNAMOTIF: 
32    def __init__(self):32    def __init__(self):
33        self.instances = [] 33        self.instances = [] 
n34        self.consensus= ""n34        self.consensus= "" 
35        self.counts= {'A': [], 'C': [], "G":[],'T': []}35        self.counts= {'A': [], 'C': [], "G":[],'T': []}
n36    def __str__ (self): n36    def __str__(self):
37        string = ""37        str = ""
38        for i in self.instances:38        for i in self.instances:
n39            string += i;n39            str += i
40        return string[:-2]40        return str
41    def __len__(self):41    def __len__(self):
n42        return len(self.instances[0].rstrip('\n'))n42        return len(self.instances[0].rstrip("\n"))
43    def count(self):43    def count(self):
n44        cA = [0]*(len(self.instances[0])-1)n44        countA = [0]*(len(self.instances[0])-1)
45        cC = [0]*(len(self.instances[0])-1)45        countC = [0]*(len(self.instances[0])-1)
46        cG = [0]*(len(self.instances[0])-1)46        countG = [0]*(len(self.instances[0])-1)
47        cT = [0]*(len(self.instances[0])-1)47        countT = [0]*(len(self.instances[0])-1)
48        for i in range(0,len(self.instances)):48        for i in range(0,len(self.instances)):
n49            amount = self.instances[i]n49            char = self.instances[i]
50            amount = amount.upper()50            char = char.upper()
51            for j in range(0,len(amount)):51            for k in range(0,len(char)):
52                if amount[j] == 'A':52                if char[k] == 'A':
53                    cA[j] = cA[j] + 153                    countA[k+= 1
54                elif amount[j] == 'C':54                elif char[k] == 'C':
55                    cC[j] = cC[j] + 155                    countC[k+= 1
56                elif amount[j] == 'G':56                elif char[k] == 'G':
57                    cG[j] = cG[j] + 157                    countG[k+= 1
58                elif amount[j] == 'T':58                elif char[k] == 'T':
59                    cT[j] = cT[j] + 159                    countT[k+= 1
60        self.counts["A"] = cA 60        self.counts["A"] = count
61        self.counts["C"] = cC 61        self.counts["C"] = count
62        self.counts["G"] = cG 62        self.counts["G"] = count
63        self.counts["T"] = cT 63        self.counts["T"] = count
64    def compute_consensus(self):64    def compute_consensus(self):
n65        cA = [0]*(len(self.instances[0])-1)n65        countA = [0]*(len(self.instances[0])-1)
66        cC = [0]*(len(self.instances[0])-1)66        countC = [0]*(len(self.instances[0])-1)
67        cG = [0]*(len(self.instances[0])-1)67        countG = [0]*(len(self.instances[0])-1)
68        cT = [0]*(len(self.instances[0])-1)68        countT = [0]*(len(self.instances[0])-1)
69        for i in range(0,len(self.instances)):69        for i in range(0,len(self.instances)):
n70            amount = self.instances[i]n70            char = self.instances[i]
71            amount = amount.upper()71            char = char.upper()
72            for j in range(0,len(amount)):72            for k in range(0,len(char)):
73                if amount[j] == 'A':73                if char[k] == 'A':
74                    cA[j] = cA[j] + 174                    countA[k+= 1
75                elif amount[j] == 'C':75                elif char[k] == 'C':
76                    cC[j] = cC[j] + 176                    countC[k+= 1
77                elif amount[j] == 'G':77                elif char[k] == 'G':
78                    cG[j] = cG[j] + 178                    countG[k+= 1
79                elif amount[j] == 'T':79                elif char[k] == 'T':
80                    cT[j] = cT[j] + 180                    countT[k+= 1 
81        self.counts["A"] = cA 81        self.counts["A"] = countA
82        self.counts["C"] = cC 82        self.counts["C"] = countC
83        self.counts["G"] = cG 83        self.counts["G"] = countG
84        self.counts["T"] = cT 84        self.counts["T"] = countT
85        A = self.counts["A"]85        A = self.counts["A"]
86        C = self.counts["C"]86        C = self.counts["C"]
87        G = self.counts["G"]87        G = self.counts["G"]
88        T = self.counts["T"]88        T = self.counts["T"]
89        for i in range(len(A)):89        for i in range(len(A)):
90            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]): 90            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]): 
91                self.consensus += 'A'91                self.consensus += 'A'
92            elif (C[i] >= G[i] and C[i] >= T[i]):92            elif (C[i] >= G[i] and C[i] >= T[i]):
93                self.consensus += 'C'93                self.consensus += 'C'
94            elif (G[i] >= T[i]):94            elif (G[i] >= T[i]):
95                self.consensus += 'G'95                self.consensus += 'G'
96            else:96            else:
97                self.consensus += 'T'97                self.consensus += 'T'
98    def parse(self, filename):98    def parse(self, filename):
99        with open(filename,'r') as f:99        with open(filename,'r') as f:
100            for i in f:100            for i in f:
101                if ">" in i:101                if ">" in i:
102                   continue102                   continue
103                else:103                else:
104                    self.instances.append(i)104                    self.instances.append(i)
tt105if __name__ == "__main__":
105lexA = DNAMOTIF()106    lexA = DNAMOTIF()
106lexA.parse("lexA.fasta")107    lexA.parse("lexA.fasta")
107print(len(lexA))108    print(len(lexA))
108lexA = DNAMOTIF()
109lexA.parse("lexA.fasta")
110print(lexA)
111lexA.count()109    lexA.count()
112print(lexA.counts)110    print(lexA.counts)
113lexA.compute_consensus()111    lexA.compute_consensus()
114print(lexA.consensus)112    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 41

Student ID: 425, P-Value: 4.18e-03

Nearest Neighbor ID: 170

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
3class PLANT:3class PLANT:
n4    def __init__(self, input_str, dictionary, n, delta):n4    def __init__(self, in_string, dictionary, n, deltaTheta):
5        self.str = self.generate(input_str, dictionary, n)5        self.str = self.generator(in_string, dictionary, n)
6        self.delta = delta6        self.deltaTheta = deltaTheta
7    def generate(self, string, dictionary, n):7    def generator(self, strings, dictionary, n):
8        for i in range(n):8        for i in range(n):
n9            string = ''.join(dictionary.get(charchar) for char in string)n9            strings = ''.join(dictionary.get(numnum) for num in strings)
10        return string10        return strings
11    def drawPlant(self):11    def drawPlant(self):
n12        current_pt=[200, 0] n12        currentPt = [200, 0]
13        theta = 9013        theta = 90
n14        delta = self.deltan14        deltaTheta = self.deltaTheta
15        current_state = (current_pt[0], current_pt[1], theta) 15        currPt=(currentPt[0], currentPt[1], theta)
16        states = list()16        PT=[]
17        for char in self.str:17        for num in self.str:
18            current_pt[0], current_pt[1], theta = current_state18            currentPt[0], currentPt[1], theta = currPt
19            if char.isalpha():19            if num.isalpha():
20                next_pt = (current_state[0] - math.cos(math.radians(current_stat20                nextPt = (currPt[0] - math.cos(math.radians(currPt[2])), currPt[
>e[2])), current_state[1] + math.sin(math.radians(current_state[2])))>1] + math.sin(math.radians(currPt[2])))
21                plt.plot([current_state[0], next_pt[0]], [current_state[1], next21                plt.plot([currPt[0], nextPt[0]], [currPt[1], nextPt[1]], color='
>_pt[1]], color='black')>black')
22                current_state = (next_pt[0], next_pt[1], theta)22                currPt = (nextPt[0], nextPt[1], theta)
23            if char == '[':23            if num =='[':
24                states.append(current_state)24                PT.append(currPt)
25            if char == ']':25            if num == ']':
26                current_state = states.pop()26                currPt=PT.pop()
27            if char == '+':27            if num =='+':
28                current_state = [current_state[0], current_state[1], current_sta28                currPt=[currPt[0], currPt[1], currPt[2] + deltaTheta]
>te[2] + delta] 
29            if char == '-':29            if num=='-':
30                current_state = [current_state[0], current_state[1], current_sta30                currPt=[currPt[0], currPt[1], currPt[2] - deltaTheta]
>te[2] - delta] 
31class DNAMOTIF: 31class DNAMOTIF: 
32    def __init__(self):32    def __init__(self):
33        self.instances = [] 33        self.instances = [] 
n34        self.consensus= "" n34        self.consensus= ""
35        self.counts= {'A': [], 'C': [], "G":[],'T': []}35        self.counts= {'A': [], 'C': [], "G":[],'T': []}
n36    def __str__(self):n36    def __str__ (self): 
37        str = ""37        string = ""
38        for i in self.instances:38        for i in self.instances:
n39            str += in39            string += i;
40        return str40        return string[:-2]
41    def __len__(self):41    def __len__(self):
n42        return len(self.instances[0].rstrip("\n"))n42        return len(self.instances[0].rstrip('\n'))
43    def count(self):43    def count(self):
n44        countA = [0]*(len(self.instances[0])-1)n44        cA = [0]*(len(self.instances[0])-1)
45        countC = [0]*(len(self.instances[0])-1)45        cC = [0]*(len(self.instances[0])-1)
46        countG = [0]*(len(self.instances[0])-1)46        cG = [0]*(len(self.instances[0])-1)
47        countT = [0]*(len(self.instances[0])-1)47        cT = [0]*(len(self.instances[0])-1)
48        for i in range(0,len(self.instances)):48        for i in range(0,len(self.instances)):
n49            char = self.instances[i]n49            amount = self.instances[i]
50            char = char.upper()50            amount = amount.upper()
51            for k in range(0,len(char)):51            for j in range(0,len(amount)):
52                if char[k] == 'A':52                if amount[j] == 'A':
53                    countA[k] += 153                    cA[j= cA[j] + 1
54                elif char[k] == 'C':54                elif amount[j] == 'C':
55                    countC[k] += 155                    cC[j= cC[j] + 1
56                elif char[k] == 'G':56                elif amount[j] == 'G':
57                    countG[k] += 157                    cG[j= cG[j] + 1
58                elif char[k] == 'T':58                elif amount[j] == 'T':
59                    countT[k] += 159                    cT[j= cT[j] + 1
60        self.counts["A"] = count60        self.counts["A"] = cA 
61        self.counts["C"] = count61        self.counts["C"] = cC 
62        self.counts["G"] = count62        self.counts["G"] = cG 
63        self.counts["T"] = count63        self.counts["T"] = cT 
64    def compute_consensus(self):64    def compute_consensus(self):
n65        countA = [0]*(len(self.instances[0])-1)n65        cA = [0]*(len(self.instances[0])-1)
66        countC = [0]*(len(self.instances[0])-1)66        cC = [0]*(len(self.instances[0])-1)
67        countG = [0]*(len(self.instances[0])-1)67        cG = [0]*(len(self.instances[0])-1)
68        countT = [0]*(len(self.instances[0])-1)68        cT = [0]*(len(self.instances[0])-1)
69        for i in range(0,len(self.instances)):69        for i in range(0,len(self.instances)):
n70            char = self.instances[i]n70            amount = self.instances[i]
71            char = char.upper()71            amount = amount.upper()
72            for k in range(0,len(char)):72            for j in range(0,len(amount)):
73                if char[k] == 'A':73                if amount[j] == 'A':
74                    countA[k] += 174                    cA[j= cA[j] + 1
75                elif char[k] == 'C':75                elif amount[j] == 'C':
76                    countC[k] += 176                    cC[j= cC[j] + 1
77                elif char[k] == 'G':77                elif amount[j] == 'G':
78                    countG[k] += 178                    cG[j= cG[j] + 1
79                elif char[k] == 'T':79                elif amount[j] == 'T':
80                    countT[k] += 1 80                    cT[j= cT[j] + 1
81        self.counts["A"] = countA81        self.counts["A"] = cA 
82        self.counts["C"] = countC82        self.counts["C"] = cC 
83        self.counts["G"] = countG83        self.counts["G"] = cG 
84        self.counts["T"] = countT84        self.counts["T"] = cT 
85        A = self.counts["A"]85        A = self.counts["A"]
86        C = self.counts["C"]86        C = self.counts["C"]
87        G = self.counts["G"]87        G = self.counts["G"]
88        T = self.counts["T"]88        T = self.counts["T"]
89        for i in range(len(A)):89        for i in range(len(A)):
90            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]): 90            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]): 
91                self.consensus += 'A'91                self.consensus += 'A'
92            elif (C[i] >= G[i] and C[i] >= T[i]):92            elif (C[i] >= G[i] and C[i] >= T[i]):
93                self.consensus += 'C'93                self.consensus += 'C'
94            elif (G[i] >= T[i]):94            elif (G[i] >= T[i]):
95                self.consensus += 'G'95                self.consensus += 'G'
96            else:96            else:
97                self.consensus += 'T'97                self.consensus += 'T'
98    def parse(self, filename):98    def parse(self, filename):
99        with open(filename,'r') as f:99        with open(filename,'r') as f:
100            for i in f:100            for i in f:
101                if ">" in i:101                if ">" in i:
102                   continue102                   continue
103                else:103                else:
104                    self.instances.append(i)104                    self.instances.append(i)
t105if __name__ == "__main__":t
106    lexA = DNAMOTIF()105lexA = DNAMOTIF()
107    lexA.parse("lexA.fasta")106lexA.parse("lexA.fasta")
108    print(len(lexA))107print(len(lexA))
108lexA = DNAMOTIF()
109lexA.parse("lexA.fasta")
110print(lexA)
109    lexA.count()111lexA.count()
110    print(lexA.counts)112print(lexA.counts)
111    lexA.compute_consensus()113lexA.compute_consensus()
112    print(lexA.consensus)114print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 42

Student ID: 484, P-Value: 4.61e-03

Nearest Neighbor ID: 414

Student (left) and Nearest Neighbor (right).


n1import math n
2import matplotlib.pyplot as plt1import matplotlib.pyplot as plt
nn2import math
3class PLANT:3class PLANT:
n4    def __init__(self,initialSTR,generator,numIters,deltaTheta):n4    def __init__(self,initialStr,generator,numIters,deltaTheta):
5        self.str = initialSTR5        self.str = initialStr
6        self.generator = generator6        self.generator= generator
7        self.numIters = numIters7        self.numIters = numIters
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        for i in range(numIters):9        for i in range(numIters):
10            new_string = ""10            new_string = ""
n11            for inp in self.str:n11            for letter in self.str:
12                if inp in self.generator:12                if letter in self.generator:
13                    new_string = new_string + self.generator[inp]13                    new_string =new_string+self.generator[letter]
14                else:14                else:
n15                    new_string = new_string + inpn15                    new_string =new_string+letter
16            self.str = new_string16            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
n18        currentPt = (200,0)n18        currentPt =(200,0)
19        stack = []19        stack = []
n20        theta = 90n20        theta =90
21        for str in self.str:21        for letter in self.str:
22            if letter == "[":
23                stack.append([currentPt,theta])
22            if str == ']':24            elif letter == "]":
23                cur = stack.pop()25                current_save = stack.pop()
24                theta = cur[1]26                theta = current_save[1]
25                thispoint = cur[0]27                currentPt = current_save[0]
26            elif str == '[':
27                stack.append([thispoint, theta])
28            elif str == '+':28            elif letter =="+":
29                theta = theta + self.deltaTheta29                theta = theta+self.deltaTheta
30            elif str == '-':30            elif letter =="-":
31                theta -= self.deltaTheta 31                theta -= self.deltaTheta
32            else: 32            else:
33                nextpoint = math.cos(math.radians(theta)) + thispoint[0], thispo33                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[1
>int[1] + math.sin(math.radians(theta))>] + math.sin(math.radians(theta)))
34                plt.plot([thispoint[0], nextpoint[0]], [thispoint[1], nextpoint[34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>1]], color == 'black')>olor="black")
35                thispoint = nextpoint35                currentPt = nextPt
36class DNAMOTIF:36class DNAMOTIF:
37    def __init__(self):37    def __init__(self):
38        self.instances=[]38        self.instances=[]
39        self.consensus=[]39        self.consensus=[]
40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
41    def __str__(self):41    def __str__(self):
n42        string = ''n42        file = ''
43        for in self.instances:43        for line in self.instances:
44            string += i + "\n"44            file += line
45        return string45        return file
46        pass
47    def __len__(self):46    def __len__(self):
48        return len(self.instances[0])-147        return len(self.instances[0])-1
49    def count(self):48    def count(self):
n50         self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n49        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
51         for j in range(len(self.instances[0])-1):50        for i in range(len(self.instances[0])-1):
52             for key in self.counts.keys():51            for key in self.counts.keys():
53                 self.counts[key].append(0)52                self.counts[key].append(0)
54                 for strand in self.instances:53                for line in self.instances:
55                     if strand[j].upper() == merc:54                    if line[i].upper()==key:
56                         self.counts[key][j] += 155                        self.counts[key][i]+=1
57         return self.counts56        return self.counts
58    pass
59    def compute_consensus(self):57    def compute_consensus(self):
60        self.consensus = []58        self.consensus = []
61        self.counts = self.count()59        self.counts = self.count()
n62        for cons in range(len(self.instances[0])-1):n60        for charPos in range(len(self.instances[0])-1):
63            self.consensus.append(max(self.counts))61            self.consensus.append(max(self.counts, key=lambda x: self.counts[x][
 >charPos]).upper())
64        self.consensus = str(''.join(self.consensus))62        self.consensus = str(''.join(self.consensus))
65    def parse(self, filename):63    def parse(self, filename):
t66        file=open(filename , 'r')t64        file= open(filename, 'r')
67        strands = file.readlines()65        Lines = file1.readlines()
68        for strand in strands:66        for line in Lines:
69            if not strand.startswith('>'):67            if not line.startswith('>'):
70                self.instances.append(strand) 68                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 43

Student ID: 7, P-Value: 6.35e-03

Nearest Neighbor ID: 373

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2import numpy as npn
3from math import sin, cos2from math import sin, cos, radians
4class PLANT:3class PLANT:
n5    def __init__(self, init, gen, h, delta_theta):n4    def __init__(self, init, gen, n, delta_theta):
6        self.init_state = init5        self.init_state = init
7        self.generator = gen6        self.generator = gen
n8        self.h = hn7        self.n = n
9        self.delta_theta = delta_theta8        self.delta_theta = delta_theta
10        self.str = self.generate()9        self.str = self.generate()
11    def generate(self):10    def generate(self):
12        result = self.init_state11        result = self.init_state
n13        for i in range(self.h):n12        for i in range(self.n):
14            easy_net = ""13            new_res = ""
15            for bet in result:14            for char in result:
16                if bet in self.generator:15                if char in self.generator:
17                    easy_net += self.generator[bet]16                    new_res += self.generator[char]
18                else:17                else:
n19                    easy_net += betn18                    new_res += char
20            result = easy_net19            result = new_res
21        return result20        return result
22    def drawPlant(self):21    def drawPlant(self):
23        currentPt = (200, 0)22        currentPt = (200, 0)
24        theta = 9023        theta = 90
25        stack = []24        stack = []
n26        for bet in self.str:n25        for char in self.str:
27            if bet.isalpha():26            if char.isalpha():
28                nextPt = (currentPt[0] +np.cos(np.radians(theta)), currentPt[1] 27                nextPt = (currentPt[0] + cos(radians(theta)), currentPt[1] + sin
>np.sin(np.radians(theta)))>(radians(theta)))
29                plt.plot(28                plt.plot(
30                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=29                    [currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], color=
>"black">"black"
31                )30                )
32                currentPt = nextPt31                currentPt = nextPt
n33            elif bet == "[":n32            elif char == "[":
34                stack.append((currentPt, theta))33                stack.append([currentPt, theta])
35            elif bet == "]":34            elif char == "]":
36                currentPt,theta = stack.pop()35                [currentPt, theta] = stack[-1]
37            elif bet == "+":36            elif char == "+":
38                theta += self.delta_theta37                theta += self.delta_theta
n39            elif bet == "-":n38            elif char == "-":
40                theta -= self.delta_theta39                theta -= self.delta_theta
n41class DNAMOTIF:n40        plt.axis("image")class DNAMOTIF:
42    def __init__(self):41    def __init__(self):
43        self.instances = []42        self.instances = []
44        self.consensus = []43        self.consensus = []
45        self.counts = {"A": [], "C": [], "G": [], "T": []}44        self.counts = {"A": [], "C": [], "G": [], "T": []}
46    def __str__(self):45    def __str__(self):
n47        return "".join([str(stuff) for item in self.instances])n46        return "".join([str(item) for item in self.instances])
48    def __len__(self):47    def __len__(self):
49        return len(self.instances[0].strip("\n"))48        return len(self.instances[0].strip("\n"))
50    def count(self):49    def count(self):
51        for key in self.counts:50        for key in self.counts:
52            self.counts[key] = [0] * len(self)51            self.counts[key] = [0] * len(self)
n53        for sinstances in self.instances:n52        for instance in self.instances:
54            sinstances = sinstances.strip(" ")53            instance = instance.strip("\n")
55            for i in range(len(self)):54            for i in range(len(self)):
n56                if sinstances[i].upper() in self.counts:n55                if instance[i].upper() in self.counts:
57                    self.counts[sinstances[i].upper()][i] += 156                    self.counts[instance[i].upper()][i] += 1
58    def compute_consensus(self):57    def compute_consensus(self):
59        self.count()58        self.count()
n60        self.consensus = [0] * len(self.counts['G'])n59        self.consensus = [0] * len(self.counts['A'])
61        for i in range(len(self.counts['G'])):60        for i in range(len(self.counts['A'])):
62            Value = max(self.counts, key=lambda x: self.counts[x][i])61            keymax = max(self.counts, key=lambda x: self.counts[x][i])
63            self.consensus[i] = Value62            self.consensus[i] = keymax
64        self.consensus = "".join([str(item) for item in self.consensus])63        self.consensus = "".join([str(item) for item in self.consensus])
65    def parse(self, filename):64    def parse(self, filename):
t66        with open (filename,'r') as f:t65        with open(filename) as fp:
67            for in f:66            for line in fp:
68                if '>' in i:67                if line[0] != ">":
69                    continue
70                else:
71                    self.instances.append(i)68                    self.instances.append("{}\n".format(line.strip()))
72if __name__ == "__main__":
73    dna1 = DNAMOTIF()
74    dna1.parse("lexA.fasta")
75    dna1.count()
76    print(dna1.instances)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 44

Student ID: 36, P-Value: 6.97e-03

Nearest Neighbor ID: 318

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string,dictionary, n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string, dictionary, n):10    def generator(string, dictionary, n):
11        def character_v(string):11        def character_v(string):
12            if string in dictionary:12            if string in dictionary:
13                return dictionary.get(string)13                return dictionary.get(string)
14            return string14            return string
n15        stringslist = [string]n15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
n17            string = stringslist[-1]n17            substring = substrings_list[-1]
18            newstring = [character_v(char) for char in string]18            new_statement = [character_v(char) for char in substring]
19            stringslist.append(''.join(newstring))19            substrings_list.append(''.join(new_statement))
20        newstring = stringslist[n]20        newstring = substrings_list[n]
21        return newstring21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
n23        upperletters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'n23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
>L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        startpoint=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
n27        stack = [startpoint, theta]n27        stack = [currentPt, theta]
28        for com in self.str:28        for command in self.str:
29            if com.upper() in upperletters:29            if command.upper() in upper_letters:
30                nextpoint = (startpoint[0]+(np.cos(theta)), startpoint[1]+(np.si30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>n(theta)))>ta)))
31                plt.plot([startpoint[0],nextpoint[0]],[startpoint[1],nextpoint[131                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>]],color='black')>='black')
32                startpoint = nextpoint32                currentPt = nextPt
33            else:33            else:
n34                if com == '[':n34                if command == '[':
35                    stack.append(startpoint)35                    stack.append(currentPt)
36                    stack.append(theta)36                    stack.append(theta)
n37                elif com == ']':n37                elif command == ']':
38                    theta = stack.pop()38                    theta = stack.pop()
n39                    startpoint = stack.pop()  n39                    currentPt = stack.pop()  
40                elif com == '-':40                elif command == '-':
41                    theta -= deltaTheta41                    theta -= deltaTheta
n42                elif com == '+':n42                elif command == '+':
43                    theta += deltaTheta43                    theta += deltaTheta
44        return plt.plot44        return plt.plot
45if __name__ == "__main__":45if __name__ == "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
52    plt.show()class DNAMOTIF:52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
n54        self.instances=[]n54        self.instances = []
55        self.consensus=[]55        self.consensus = []
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
n58        pass n58        output = ''
59        string = ''
60        for in self.instances:59        for instance in self.instances:
61            string += i60            output += instance
62        return string61        return output
63    def __len__(self):62    def __len__(self):
64        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
65    def count(self):64    def count(self):
n66        pass n
67        for i in range(len(self)):65        for position in range(len(self)):
68            numA = 066            sequenceA = 0
69            numC= 0
70            numT = 067            sequenceT = 0
68            sequenceC = 0
71            numG = 069            sequenceG = 0
72            for in self.instances:70            for instance in self.instances:
73                seq = j.rstrip()71                sequence = instance.rstrip()
74                if (seq[i]).upper() == 'A':72                if (sequence[position]).upper() == 'A':
75                    numA += 173                    sequenceA += 1
76                elif (seq[i]).upper() == 'C':
77                    numC += 1
78                elif (seq[i]).upper() == 'G':
79                    numG += 1
80                elif (seq[i]).upper() == 'T':74                elif (sequence[position]).upper() == 'T':
81                    numT += 175                    sequenceT += 1
76                elif (sequence[position]).upper() == 'C':
77                    sequenceC += 1
78                elif (sequence[position]).upper() == 'G':
79                    sequenceG += 1
82            self.counts.get('A').append(numA)80            self.counts.get('A').append(sequenceA)
83            self.counts.get('C').append(numC)
84            self.counts.get('T').append(numT)81            self.counts.get('T').append(sequenceT)
82            self.counts.get('C').append(sequenceC)
85            self.counts.get('G').append(numG)83            self.counts.get('G').append(sequenceG)
86    def compute_consensus(self):84    def compute_consensus(self):
n87        pass n
88        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
n89        As = self.counts.get('A')n86        A = self.counts.get('A')
90        Cs = self.counts.get('C')
91        Ts = self.counts.get('T')87        T = self.counts.get('T')
88        C = self.counts.get('C')
92        Gs = self.counts.get('G')89        G = self.counts.get('G')
93        final = ''90        output = ""
94        for i in range(len(As)):91        for row in range(len(A)):
95            if (As[i] >= Cs[i] and As[i] >= Gs[i] and As[i] >= Ts[i]):92            maxes = max(A[row],T[row],C[row],G[row])
93            if maxes == A[row]:
96                final += 'A'94                output += 'A'
97            elif (Cs[i] >= Gs[i] and Cs[i] >= Ts[i]):95            elif maxes == T[row]:
98                final += 'C'
99            elif(Gs[i] >= Ts[i]):
100                final += 'G'
101            else:
102                final += 'T'96                output += 'T'
97            elif maxes == C[row]:
98                output += 'C'
99            elif maxes == G[row]:
100                output += 'G'
103        self.consensus = final101        self.consensus = output
104    def parse(self, filename):102    def parse(self, filename):
n105        with open(filename,'r') as file:n103        myFile = open(filename, 'r')
106            for i in file:104        contents = [line for line in myFile.readlines()]
107                if '>' in i:105        myFile.close()
108                    continue106        for index, line in enumerate(contents):
109                else:107            if index % 2 != 0:
110                    self.instances.append(i)108                self.instances.append(line)
111if __name__ == '__main__':109if __name__ == '__main__':
112    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t113    filename = r'FinalProject\lexA.fasta' t111    filename = r'FinalProject\lexA.fasta'
114    lexA.parse(filename)112    lexA.parse(filename)
115    lexA.compute_consensus()113    lexA.compute_consensus()
116    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 45

Student ID: 406, P-Value: 9.40e-03

Nearest Neighbor ID: 322

Student (left) and Nearest Neighbor (right).


n1class DNAMOTIF:n1import matplotlib.pyplot as pltclass DNAMOTIF:
2    def __init__(self):2    def __init__(self):
3        self.instances=[]3        self.instances=[]
4        self.consensus=[]4        self.consensus=[]
5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
6    def __str__(self):6    def __str__(self):
7        string = ""7        string = ""
n8        for i in self.instances:n8        for n in self.instances:
9            string += i + "\n"9            string = string + n
10        return string[:-2]10        return string
11    def __len__(self):11    def __len__(self):
n12       return len(self.instances) - 4n12        return len(self.instances[0]) -1
13    def count(self):13    def count(self):
n14        for i in self.instances:n14        for n in self.instances:
15            temp = i.upper()15            times = n.upper()
16            self.counts["A"].append(temp.count("A"))16            self.counts['A'].append(times.count("A") + times.count('a'))
17            self.counts["C"].append(temp.count("C"))17            self.counts["C"].append(times.count("C") + times.count('c'))
18            self.counts["G"].append(temp.count("G"))18            self.counts["G"].append(times.count("G") + times.count('g'))
19            self.counts["T"].append(temp.count("T"))19            self.counts["T"].append(times.count("T") + times.count('t'))
20    def compute_consensus(self):20    def compute_consensus(self):
n21        A = (self.counts["A"])n21        A = self.counts["A"]
22        C = (self.counts["C"])22        C = self.counts["C"]
23        G = (self.counts["G"])23        G = self.counts["G"]
24        T = (self.counts["T"])24        T = self.counts["T"]
25        for i in range(len(A)):25        for n in range(len(A)):
26            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):26            if(G[n] <= A[n] and C[n] <= A[n] and T[n] <= A[n]):
27                self.consensus.append("A")27                self.consensus = self.consensus + 'A'
28            elif (C[i] >= G[i] and C[i] >= T[i]):28            elif (G[n] <= C[n] and T[n] <= C[n]):
29                self.consensus.append("C")29                self.consensus = self.consensus + 'C'
30            elif (G[i] >= T[i]):30            elif (T[n] <= G[n]):
31                self.consensus.append("G")31                self.consensus = self.consensus + 'G'
32            else:32            else:
n33                self.consensus.append("T")n33                self.consensus = self.consensus + 'T'
34    def parse(self, filename):34    def parse(self, filename):
35        with open(filename,'r') as f:35        with open(filename,'r') as f:
n36            for i in f:n36            for n in f:
37                if ">" in i:37                if n[0] == '>':
38                    continue38                   continue
39                else:39                else:
t40                    self.instances.append(i)t40                    self.instances.append(n)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 46

Student ID: 322, P-Value: 9.40e-03

Nearest Neighbor ID: 406

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as pltclass DNAMOTIF:n1class DNAMOTIF:
2    def __init__(self):2    def __init__(self):
3        self.instances=[]3        self.instances=[]
4        self.consensus=[]4        self.consensus=[]
5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
6    def __str__(self):6    def __str__(self):
7        string = ""7        string = ""
n8        for n in self.instances:n8        for i in self.instances:
9            string = string + n9            string += i + "\n"
10        return string10        return string[:-2]
11    def __len__(self):11    def __len__(self):
n12        return len(self.instances[0]) -1n12       return len(self.instances) - 4
13    def count(self):13    def count(self):
n14        for n in self.instances:n14        for i in self.instances:
15            times = n.upper()15            temp = i.upper()
16            self.counts['A'].append(times.count("A") + times.count('a'))16            self.counts["A"].append(temp.count("A"))
17            self.counts["C"].append(times.count("C") + times.count('c'))17            self.counts["C"].append(temp.count("C"))
18            self.counts["G"].append(times.count("G") + times.count('g'))18            self.counts["G"].append(temp.count("G"))
19            self.counts["T"].append(times.count("T") + times.count('t'))19            self.counts["T"].append(temp.count("T"))
20    def compute_consensus(self):20    def compute_consensus(self):
n21        A = self.counts["A"]n21        A = (self.counts["A"])
22        C = self.counts["C"]22        C = (self.counts["C"])
23        G = self.counts["G"]23        G = (self.counts["G"])
24        T = self.counts["T"]24        T = (self.counts["T"])
25        for n in range(len(A)):25        for i in range(len(A)):
26            if(G[n] <= A[n] and C[n] <= A[n] and T[n] <= A[n]):26            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
27                self.consensus = self.consensus + 'A'27                self.consensus.append("A")
28            elif (G[n] <= C[n] and T[n] <= C[n]):28            elif (C[i] >= G[i] and C[i] >= T[i]):
29                self.consensus = self.consensus + 'C'29                self.consensus.append("C")
30            elif (T[n] <= G[n]):30            elif (G[i] >= T[i]):
31                self.consensus = self.consensus + 'G'31                self.consensus.append("G")
32            else:32            else:
n33                self.consensus = self.consensus + 'T'n33                self.consensus.append("T")
34    def parse(self, filename):34    def parse(self, filename):
35        with open(filename,'r') as f:35        with open(filename,'r') as f:
n36            for n in f:n36            for i in f:
37                if n[0] == '>':37                if ">" in i:
38                   continue38                    continue
39                else:39                else:
t40                    self.instances.append(n)t40                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 47

Student ID: 55, P-Value: 1.40e-02

Nearest Neighbor ID: 203

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        self.str = PLANT.output(self)n9        self.str = PLANT.generator(string,dictionary, n)
10    def recurse(currentInput, givenDictionary, maxIteration, currentIteration=0)10    def generator(string, dictionary, n):
>: 
11        nextInput = ""11        def character_v(string):
12        keys = list(givenDictionary.keys())12            if string in dictionary:
13        for instance in currentInput:13                return dictionary.get(string)
14            if instance in keys:14            return string
15                if instance == keys[0]:15        substrings_list = [string]
16                    nextInput += givenDictionary.get(instance)16        for i in range(n):
17                elif instance == keys[1]:17            substring = substrings_list[-1]
18                    nextInput += givenDictionary.get(instance)18            new_statement = [character_v(char) for char in substring]
19            substrings_list.append(''.join(new_statement))
20        newstring = substrings_list[n]
21        return newstring
22    def drawPlant(self):
23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
 >'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)
25        theta = np.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [currentPt, theta]
28        for command in self.str:
29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
 >ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
 >='black')
32                currentPt = nextPt 
19            else:33            else:
n20                nextInput +=instancen
21        if currentIteration < maxIteration-1:
22            return PLANT.recurse(nextInput, givenDictionary,maxIteration, curren
>tIteration+1) 
23        else:
24            return nextInput
25    def drawPlant(self):
26        currPt = (200,0) 
27        theta = np.radians(90) 
28        dtheta = np.radians(self.deltaTheta)
29        setStack = [currPt, theta]
30        for command in self.str:
31            if "A"<= command.upper() <= "Z":
32                nextPt = (currPt[0]+np.cos(theta)), currPt[1]+np.sin(theta)
33                plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='blac
>k') 
34                currPt = nextPt  
35            else: 
36                if command == "+":34                if command == '[':
37                    theta += dtheta35                    stack.append(currentPt)
38                elif command == "-":36                    stack.append(theta)
39                    theta -= dtheta
40                elif command == "]":
41                    theta = setStack.pop()                  
42                    currPt = setStack.pop()
43                elif command == '[':37                elif command == ']':
44                    setStack.append(currPt)
45                    setStack.append(theta)38                    theta = stack.pop()
39                    currentPt = stack.pop()  
40                elif command == '-':
41                    theta -= deltaTheta
42                elif command == '+':
43                    theta += deltaTheta
46        return plt.plot44        return plt.plot
n47    def output(self):n
48        return PLANT.recurse(self.string, self.dictionary, self.n)
49if __name__ == '__main__':45if __name__ == "__main__":
50    inputString = input()46    string = input()
51    inputDiction = input()47    dictionary = input()
52    inputIteration = int(input())48    n = int(input())
53    inputAngle = float(input())49    deltaTheta = float(input())
54    occurance=PLANT(inputString, inputDiction, inputIteration, inputAngle)50    p = PLANT(string, dictionary, n, deltaTheta)
55    occurance.drawPlant()51    p.drawPlant()
56    plt.show()52    plt.show()class DNAMOTIF:
57class DNAMOTIF:
58    def __init__(self):53    def __init__(self):
59        self.instances=[]54        self.instances=[]
60        self.consensus=[]55        self.consensus=[]
61        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
62    def __str__(self):57    def __str__(self):
63        output = ""58        output = ""
64        for instance in self.instances:59        for instance in self.instances:
65            output += instance60            output += instance
66        return output61        return output
67    def __len__(self):62    def __len__(self):
68        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
69    def count(self):64    def count(self):
70        for position in range(len(self)):65        for position in range(len(self)):
71            sequenceA = 066            sequenceA = 0
72            sequenceT = 067            sequenceT = 0
73            sequenceC = 068            sequenceC = 0
74            sequenceG = 069            sequenceG = 0
75            for instance in self.instances:70            for instance in self.instances:
76                sequence = instance.rstrip()71                sequence = instance.rstrip()
77                if (sequence[position]).upper() == "A":72                if (sequence[position]).upper() == "A":
78                    sequenceA += 173                    sequenceA += 1
79                elif (sequence[position]).upper() == "T":74                elif (sequence[position]).upper() == "T":
80                    sequenceT += 175                    sequenceT += 1
81                elif (sequence[position]).upper() == "C":76                elif (sequence[position]).upper() == "C":
82                    sequenceC += 177                    sequenceC += 1
83                elif (sequence[position]).upper() == "G":78                elif (sequence[position]).upper() == "G":
84                    sequenceG += 179                    sequenceG += 1
85            self.counts.get("A").append(sequenceA)80            self.counts.get("A").append(sequenceA)
86            self.counts.get("T").append(sequenceT)81            self.counts.get("T").append(sequenceT)
87            self.counts.get("C").append(sequenceC)82            self.counts.get("C").append(sequenceC)
88            self.counts.get("G").append(sequenceG)83            self.counts.get("G").append(sequenceG)
89    def compute_consensus(self):84    def compute_consensus(self):
90        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
91        A = self.counts.get("A")86        A = self.counts.get("A")
92        T = self.counts.get("T")87        T = self.counts.get("T")
93        C = self.counts.get("C")88        C = self.counts.get("C")
94        G = self.counts.get("G")89        G = self.counts.get("G")
95        output = ""90        output = ""
96        for row in range(len(A)):91        for row in range(len(A)):
n97            maximum = max(A[row],T[row],C[row],G[row])n92            maxs = max(A[row],T[row],C[row],G[row])
98            if maximum == A[row]:93            if maxs == A[row]:
99                output += "A"94                output += "A"
n100            elif maximum == T[row]:n95            elif maxs == T[row]:
101                output += "T"96                output += "T"
n102            elif maximum == C[row]:n97            elif maxs == C[row]:
103                output += "C"98                output += "C"
n104            elif maximum == G[row]:n99            elif maxs == G[row]:
105                output += "G"100                output += "G"
106        self.consensus = output101        self.consensus = output
107    def parse(self, filename):102    def parse(self, filename):
108        myFile = open(filename, 'r')103        myFile = open(filename, 'r')
109        contents = [line for line in myFile.readlines()]104        contents = [line for line in myFile.readlines()]
110        myFile.close()105        myFile.close()
111        for index, line in enumerate(contents):106        for index, line in enumerate(contents):
112            if index % 2 != 0:107            if index % 2 != 0:
113                self.instances.append(line)108                self.instances.append(line)
114if __name__ == '__main__':109if __name__ == '__main__':
115    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t116    filename = r'FinalProject\lexA.fasta't111    filename = r'FinalProject\lexA.fasta' 
117    lexA.parse(filename)112    lexA.parse(filename)
118    lexA.compute_consensus()113    lexA.compute_consensus()
119    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 48

Student ID: 154, P-Value: 1.78e-02

Nearest Neighbor ID: 83

Student (left) and Nearest Neighbor (right).


nn1import math
1import math, matplotlib.pyplot as plt, numpy as np2import matplotlib.pyplot as plt
2class PLANT:3class PLANT:
n3    def __init__(self, initial_state, generator, n, deltaTheta): n4    def __init__(self, string, dictionary, n, deltaTheta):
4        self.str = initial_state5        self.str = string
5        self.generator = generator6        self.dictionary = dictionary
6        self.n = n7        self.n = n
7        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
8        for i in range(n):9        for i in range(n):
n9            temp = ''n10            new_string = ""
10            for j in self.str:11            for letter in self.str:
11                if j in generator.keys():12                if letter in self.dictionary:
12                    temp += generator[j]13                    new_string += self.dictionary[letter]
13                else:14                else:
n14                    temp += jn15                    new_string += letter
15            self.str = temp16            self.str = new_string
16    def drawPlant(self): 17    def drawPlant(self):
17        currentPt = (200,0)18        currentPt = (200,0)
nn19        stack = []
18        theta = 9020        theta = 90
n19        stack = []n
20        for i in self.str:21        for letter in self.str:
21            if i.isalpha():
22                nextPt = (currentPt[0] + math.cos(theta), currentPt[1] + math.si
>n(theta)) 
23                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black') 
24                currentPt = nextPt
25            elif i == '[':22            if letter == "[":
26                stack.append(currentPt)23                stack.append([currentPt,theta])
27                stack.append(theta)
28            elif i == ']':24            elif letter == "]":
29                curren_sav = stack.pop()25                current_save = stack.pop()
30                theta = curren_sav[1]26                theta = current_save[1]
31                currentPt = curren_sav[0]27                currentPt = current_save[0]
32            elif i == '+':28            elif letter == "+":
33                theta += self.deltaTheta29                theta += self.deltaTheta
n34            elif i == '-':n30            elif letter == "-":
35                theta -= self.deltaTheta31                theta -= self.deltaTheta
n36import numpy as npn32            else:
37class DNAMOTIF:33                nextPt = (currentPt[0] + math.cos(math.radians(theta)), currentP
 >t[1] + math.sin(math.radians(theta)))
34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
 >olor='black')
35                currentPt = nextPtclass DNAMOTIF:
38    def __init__(self):36    def __init_(self):
39        self.instances = []37        self.instances = []
40        self.consensus = []38        self.consensus = []
41        self.counts = {"A": [], "C": [], "G": [], "T": []}39        self.counts = {"A": [], "C": [], "G": [], "T": []}
42    def __str__(self):40    def __str__(self):
n43        strin = 0n
44        return "\n".join(self.instances)41        return "\n".join(self.instances)
45    def __len__(self):42    def __len__(self):
n46        l = len(self.instances[0])-1n43        return len(self.instances[0])-1
47        return l
48    def parse(self, filename):44    def parse(self, filename):
n49        lil = 0n
50        with open(filename, 'r') as re:45        with open(filename, 'r') as reader:
51            self.instances = [i[0].lower()+i[1:].upper() for i in re.readlines()46            self.instances = [i[0].lower()+i[1:].upper() for i in reader.readlin
> if i[0] != ">"]>es() if i[0] != ">"]
52    def count(self):47    def count(self):
n53        cou = 0n
54        ou = 1
55        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang48        self.counts = {"A": [0 for _ in range(len(self))], "C": [0 for _ in rang
>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se>e(len(self))], "G": [0 for _ in range(len(self))], "T": [0 for _ in range(len(se
>lf))]}>lf))]}
56        for instance in self.instances:49        for instance in self.instances:
57            for i, letter in enumerate(instance):50            for i, letter in enumerate(instance):
58                if letter != "\n":51                if letter != "\n":
59                    self.counts[letter.upper()][i] += 152                    self.counts[letter.upper()][i] += 1
60    def compute_consensus(self):53    def compute_consensus(self):
61        self.count()54        self.count()
n62        cons = ""n55        consensus = ""
63        for x in range(len(self)):56        for i in range(len(self)):
64            ct_consensus = ("",0)57            current_consensus = ("",0)
65            for letter in self.counts:58            for letter in self.counts:
t66                if self.counts[letter][x] > ct_consensus[1]:t59                if self.counts[letter][i] > current_consensus[1]:
67                    ct_consensus = (letter, self.counts[letter][x])60                    current_consensus = (letter, self.counts[letter][i])
68            cons += ct_consensus[0]61            consensus += current_consensus[0]
69        self.consensus = cons62        self.consensus = consensus
70if __name__ == '__main__':
71    lexA = DNAMOTIF()
72    lexA.parse("lexA.fasta")
73    print(len(lexA))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 49

Student ID: 396, P-Value: 2.65e-02

Nearest Neighbor ID: 495

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2from math import pi, sin, cos, isnann2import math
3import numpy as np
4class Plant:
3plt.style.use('bmh')5    plt.style.use('bmh')  
4plt.axes().set_aspect('equal', 'datalim')6plt.plot(
5plt.plot([0, 1, 2], [0, 1,7    [0, 1, 2],  
60])8    [0, 1, 0]   
9)
7plt.xlabel('x')10plt.xlabel('x')
n8plt.ylabel('y')n11plt.ylabel('y');
12def plot_coords(coords, bare_plot=False):
13    if bare_plot:
14        plt.axis('off')
15    plt.axes().set_aspect('equal', 'datalim')
16    X, Y = zip(*coords)
17    plt.plot(X, Y);
18plot_coords([
19    (0, 0),
20    (1, 0),
21    (2, 1),
22    (3, 1),
23    (2, 0)
24])
9nan = float('nan')25nan = float('nan')
n10ConvertDtoR = pi / 180n26plot_coords([
11class PLANT:27    (0, 0),
12    def __init__(self, initial_state, generator, iterations,28    (1, 1),
13deltaTheta):29    (nan, nan),
14        self.state = initial_state30    (1, 0),
15        self.generator = generator31    (2, 1)
16        self.iterations = iterations32])
17        self.deltaTheta = deltaTheta33from math import pi, sin, cos
18        self.str = transform_multiple(initial_state, generator, iterations)34DEGREES_TO_RADIANS = pi / 180
19    def draw_plant(self):
20        currentPt = (200,0)
21        theta = 90
22        pass
23def branching_turtle_to_coords(turtle_program, turn_amount=45):
24    saved_states = list()
25    state = (0, 0, 90)
26    yield (0, 0)
27    for command in turtle_program:
28        x, y, angle = state
29        if command.lower() in 'abcdefghij':        
30            state = (x - cos(angle * ConvertDtoR), y
31+ sin(angle * ConvertDtoR), angle)
32            if command.islower():                  
33                yield (float('nan'), float('nan'))
34            yield (state[0], state[1])
35        elif command == '+':                       
36            state = (x, y, angle + turn_amount)
37        elif command == '-':                       
38            state = (x, y, angle - turn_amount)
39        elif command == '[':                      
40            saved_states.append(state)
41        elif command == ']':                
42            state = saved_states.pop()
43            yield (float('nan'), float('nan'))
44            x, y, _ = state
45            yield (x, y)
46def turtle_to_coords(turtle_program, turn_amount=45):35def turtle_to_coords(turtle_program, turn_amount=45):
47    state = (0.0, 0.0, 90.0)36    state = (0.0, 0.0, 90.0)
48    yield (0.0, 0.0)37    yield (0.0, 0.0)
49    for command in turtle_program:38    for command in turtle_program:
50        x, y, angle = state39        x, y, angle = state
51        if command in 'Ff':      40        if command in 'Ff':      
n52            state = (x - cos(angle * ConvertDtoR),n41            state = (x - cos(angle * DEGREES_TO_RADIANS),
53                     y + sin(angle * ConvertDtoR),42                     y + sin(angle * DEGREES_TO_RADIANS),
54                     angle)43                     angle)
55            if command == 'f':44            if command == 'f':
56                yield (float('nan'), float('nan'))45                yield (float('nan'), float('nan'))
57            yield (state[0], state[1])46            yield (state[0], state[1])
58        elif command == '+':     47        elif command == '+':     
59            state = (x, y, angle + turn_amount)48            state = (x, y, angle + turn_amount)
60        elif command == '-':     49        elif command == '-':     
61            state = (x, y, angle - turn_amount)50            state = (x, y, angle - turn_amount)
n62def plot_coordinates(coords, bare_plot = False):n51plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
63    if bare_plot:52plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
64        plt.axis('off')53from math import isnan
65    X, Y = zip(*coords)
66    plt.plot(X, Y)
67def transform_sequence(sequence, transformations):
68    return ''.join(transformations.get(c, c)
69for c in sequence)
70def transform_multiple(sequence, transformations, iterations):
71    for _ in range(iterations):
72        sequence = transform_sequence(sequence, transformations)
73    return sequence
74def l_plot(axiom, transformations, iterations=0,
75angle=45):
76    turtle_program = transform_multiple(axiom, transformations, iterations)
77    coords = branching_turtle_to_coords(turtle_program, angle)
78    plot_coordinates(coords, bare_plot=True) 
79def print_coords(coords):54def print_coords(coords):
80    for (x, y) in coords:55    for (x, y) in coords:
81        if isnan(x):56        if isnan(x):
82            print('<gap>')57            print('<gap>')
83        else:58        else:
n84            print('({:.2f}, {:.2f})'.format(x,n59            print('({:.2f}, {:.2f})'.format(x, y))
85y))
86plot_coordinates([(0, 0), (1, 0), (2,
871), (3, 1), (2, 0)])
88plot_coordinates([(0, 0), (1, 1), (nan,
89nan), (1, 0), (2, 1)])
90plot_coordinates(turtle_to_coords('FfF++FfF++FfF++FfF'))
91plot_coordinates(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
92print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))60print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
n93plot_coordinates(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))n61plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
62def transform_sequence(sequence, transformations):
63    return ''.join(transformations.get(c, c) for c in sequence)
94transform_sequence('acab', {'a': 'aba', 'c': 'bb'})64transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
n95plot_coordinates(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))n65plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
66def transform_multiple(sequence, transformations, iterations):
67    for _ in range(iterations):
68        sequence = transform_sequence(sequence, transformations)
69    return sequence
96print('0:', transform_multiple('abba', {'b': 'bab'},70print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
970))
98print('1:', transform_multiple('abba', {'b': 'bab'},71print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
991))
100print('2:', transform_multiple('abba', {'b': 'bab'},72print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
1012))
102plot_coordinates(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'},73plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
1035)))
104plot_coordinates(turtle_to_coords(transform_multiple('L', {'L': '-RF+LFL+FR-','R74plot_coords(turtle_to_coords(transform_multiple('L', {
>': 
105'+LF-RFR-FL+'}, 5), 90))75    'L': '-RF+LFL+FR-',
76    'R': '+LF-RFR-FL+'
77}, 5), 90))
78def branching_turtle_to_coords(turtle_program, turn_amount=45):
79    saved_states = list()
80    state = (0, 0, 90)
81    yield (0, 0)
82    for command in turtle_program:
83        x, y, angle = state
84        if command.lower() in 'abcdefghij':        
85            state = (x - cos(angle * DEGREES_TO_RADIANS),
86                     y + sin(angle * DEGREES_TO_RADIANS),
87                     angle)
88            if command.islower():                  
89                yield (float('nan'), float('nan'))
90            yield (state[0], state[1])
91        elif command == '+':                       
92            state = (x, y, angle + turn_amount)
93        elif command == '-':                       
94            state = (x, y, angle - turn_amount)
95        elif command == '[':                       
96            saved_states.append(state)
97        elif command == ']':                       
98            state = saved_states.pop()
99            yield (float('nan'), float('nan'))
100            x, y, _ = state
101            yield (x, y)
106plot_coordinates(branching_turtle_to_coords('F[-F]+F', 45))102plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
103def l_plot(axiom, transformations, iterations=0, angle=45):
104    turtle_program = transform_multiple(axiom, transformations, iterations)
105    coords = branching_turtle_to_coords(turtle_program, angle)
106    plot_coords(coords, bare_plot=True) 
107l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)107l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
108l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)108l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
109for i in range(5):109for i in range(5):
110    print('{}: '.format(i),110    print('{}: '.format(i),
111          transform_multiple('A', {'A': 'F+A'}, i))111          transform_multiple('A', {'A': 'F+A'}, i))
112for i in range(5):112for i in range(5):
113    print('{}: '.format(i),113    print('{}: '.format(i),
n114          transform_multiple('A', {'A': 'F+A', 'F': 'FF'},n114          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
115i))
116l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'},115l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
1175, 22.5)
118class DNAMOTIF:
119    def __init__(self):116    def __init__(self):
n120        self.instances = []n117        self.instances=[]
121        self.consensus = ""118        self.consensus=[]
122        self.counts = {'A': [], 'C': [], 'G': [], 'T': []}119        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
123    def __str__(self):120    def __str__(self):
n124        motif_str = ""n121        result = ""
125        for instance in self.instances:122        for instance in self.instances:
n126            motif_str += instancen123            result += instance
127        return motif_str124        return result       
128    def __len__(self):125    def __len__(self):
n129        return len(self.instances[0].replace("\n", ""))n126        return len(self.instances[0].rstrip())
130    def count(self):127    def count(self):
n131        self.counts["A"] = [0] * len(self)n
132        self.counts["C"] = [0] * len(self)
133        self.counts["T"] = [0] * len(self)
134        self.counts["G"] = [0] * len(self)
135        for sequence in self.instances:
136            for i in range(len(self)):128        for position in range(len(self)):
137                self.counts[sequence[i].upper()][i] += 1129            TypeA = 0
130            TypeT = 0
131            TypeC = 0
132            TypeG = 0
133            for instance in self.instances:
134                order = instance.rstrip()
135                if (order[position]).upper() == "A":
136                    TypeA += 1
137                elif (order[position]).upper() == "T":
138                    TypeT += 1
139                elif (order[position]).upper() == "C":
140                    TypeC += 1
141                elif (order[position]).upper() == "G":
142                    TypeG += 1
143            self.counts.get("A").append(TypeA)
144            self.counts.get("T").append(TypeT)
145            self.counts.get("C").append(TypeC)
146            self.counts.get("G").append(TypeG)
138    def compute_consensus(self):147    def compute_consensus(self):
n139        self.count()  n148        DNAMOTIF.count(self)
149        A = self.counts.get("A")
150        T = self.counts.get("T")
151        C = self.counts.get("C")
152        G = self.counts.get("G")
153        output = ""
140        for i in range(len(self)):154        for row in range(len(A)):
141            a_count = (self.counts["A"][i], "A")155            maxs = max(A[row],T[row],C[row],G[row])
142            c_count = (self.counts["C"][i], "C")156            if maxs == A[row]:
143            g_count = (self.counts["G"][i], "G")157                output += "A"
144            t_count = (self.counts["T"][i], "T")158            elif maxs == T[row]:
145            nucleotides_at_positions = [a_count, c_count, g_count, t_count]159                output += "T"
146            self.consensus += max(nucleotides_at_positions)[1]160            elif maxs == C[row]:
161                output += "C"
162            elif maxs == G[row]:
163                output += "G"
164        self.consensus = output
147    def parse(self, filename):165    def parse(self, filename):
t148        with open(filename, "r") as motif_file:t166        myFile = open(filename, 'r')
149            for line in motif_file.readlines():167        contents = [line for line in myFile.readlines()]
150                if ">" not in line:168        myFile.close()
169        for index, line in enumerate(contents):
170            if index % 2 != 0:
151                    self.instances.append(str(line))171                self.instances.append(line)
152def main():172if __name__ == '__main__':
153    LexA = DNAMOTIF()173    lexA=DNAMOTIF()
154    LexA.parse("lexA.fasta")174    filename = r'FinalProject\lexA.fasta'
155    print(LexA)175    lexA.parse(filename)
156    print(len(LexA))
157    print()
158    LexA.count()
159    print(LexA.counts)
160    print()
161    LexA.compute_consensus()176    lexA.compute_consensus()
162    print(LexA.consensus)177    print(lexA.consensus)
163if __name__ == "__main__":
164    main()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 50

Student ID: 119, P-Value: 2.72e-02

Nearest Neighbor ID: 414

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
3class PLANT:3class PLANT:
n4    def __init__(self,initial_str, generator,num_iteration,delta_theta):n4    def __init__(self,initialStr,generator,numIters,deltaTheta):
5        self.int_str = initial_str5        self.str = initialStr
6        self.gen = generator6        self.generator= generator
7        self.num_iter = num_iteration7        self.numIters = numIters
8        self.delthe = delta_theta8        self.deltaTheta = deltaTheta
9        for j in range(num_iteration):9        for i in range(numIters):
10            string_2 = ""10            new_string = ""
11            for letter in self.int_str:11            for letter in self.str:
12                if letter in self.gen:12                if letter in self.generator:
13                    string_2 = string_2+self.gen[letter]13                    new_string =new_string+self.generator[letter]
14                else:14                else:
n15                    string_2 = string_2 + lettern15                    new_string =new_string+letter
16            self.int_str = string_216            self.str = new_string
17    def drawPlant(self):17    def drawPlant(self):
n18        current_pt = (200,0)n18        currentPt =(200,0)
19        stack = []19        stack = []
n20        ThEtA = 90 n20        theta =90
21        for letter in self.int_str:21        for letter in self.str:
22            if letter == '[':22            if letter == "[":
23                stack.append([current_pt,ThEtA])23                stack.append([currentPt,theta])
24            elif letter == ']':24            elif letter == "]":
25                cur_save = stack.pop()25                current_save = stack.pop()
26                ThEtA = cur_save[1]26                theta = current_save[1]
27                current_pt = cur_save[0]27                currentPt = current_save[0]
28            elif letter == '+':28            elif letter =="+":
29                ThEtA = ThEt+ self.delthe29                theta = theta+self.deltaTheta
30            elif letter == '-':30            elif letter =="-":
31                ThEtA -= self.delthe31                theta -= self.deltaTheta
32            else:32            else:
n33                next_pt = (math.cos(math.radians(ThEtA)) + current_pt[1], currenn33                nextPt = (math.cos(math.radians(theta))+currentPt[0],currentPt[1
>t_pt[0] + math.sin(math.radians(ThEtA)))>] + math.sin(math.radians(theta)))
34                plt.plot([current_pt[0],next_pt[0]],[current_pt[1],next_pt[1]],c34                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor='black')>olor="black")
35                current_pt = next_ptclass DNAMOTIF:35                currentPt = nextPt
36class DNAMOTIF:
36    def __init__(self):37    def __init__(self):
37        self.instances=[]38        self.instances=[]
38        self.consensus=[]39        self.consensus=[]
39        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
40    def __str__(self):41    def __str__(self):
n41         my_file = ''n42        file = ''
42         for a_line in self.instances:43        for line in self.instances:
43             my_file += a_line44            file += line
44         return my_file 45        return file
45    def __len__(self):46    def __len__(self):
46        return len(self.instances[0])-147        return len(self.instances[0])-1
47    def count(self):48    def count(self):
48        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}49        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
n49        for j in range(len(self.instances[0])-1):n50        for i in range(len(self.instances[0])-1):
50            for key in self.counts.keys():51            for key in self.counts.keys():
n51                 self.counts[key].append(0)n52                self.counts[key].append(0)
52                 for a_line in self.instances:53                for line in self.instances:
53                     if a_line[j].upper()==key:54                    if line[i].upper()==key:
54                         self.counts[key][j] +=155                        self.counts[key][i]+=1
55        return self.counts56        return self.counts
56    def compute_consensus(self):57    def compute_consensus(self):
n57       self.consensus = []n58        self.consensus = []
58       self.counts = self.count()59        self.counts = self.count()
59       for char_position in range(len(self.instances[0])-1):60        for charPos in range(len(self.instances[0])-1):
60            self.consensus.append(max(self.counts, key = lambda x: self.counts[x61            self.consensus.append(max(self.counts, key=lambda x: self.counts[x][
>][char_position]).upper())>charPos]).upper())
61       self.consensus = str("".join(self.consensus))62        self.consensus = str(''.join(self.consensus))
62    def parse(self, filename):63    def parse(self, filename):
t63        my_file_one = open(filename, 'r')t64        file1 = open(filename, 'r')
64        multi_lines = my_file_one.readlines()65        Lines = file1.readlines()
65        for a_line in multi_lines:66        for line in Lines:
66            if not a_line.startswith('>'):67            if not line.startswith('>'):
67                self.instances.append(a_line)68                self.instances.append(line)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 51

Student ID: 26, P-Value: 3.28e-02

Nearest Neighbor ID: 364

Student (left) and Nearest Neighbor (right).


n1from ast import increment_linenon
2import matplotlib.pyplot as plt1import matplotlib.pyplot as plt
n3plt.style.use('bmh')n2plt.style.use('bmh')  
4plt.plot(3plt.plot(
n5    [0, 1, 2],n4    [0, 1, 2],  
6    [0, 1, 0] 5    [0, 1, 0]   
7)6)
8plt.xlabel('x')7plt.xlabel('x')
n9plt.ylabel('y')n8plt.ylabel('y');
10def plot_coor(coor,bare_plot = False):9def plot_coords(coords, bare_plot=False):
11    if bare_plot:10    if bare_plot:
12        plt.axis('off')11        plt.axis('off')
13    plt.axes().set_aspect('equal', 'datalim')12    plt.axes().set_aspect('equal', 'datalim')
n14    xy = zip(*coor)n13    XY = zip(*coords)
15    plt.plot(xy);14    plt.plot(XY);
16plot_coor([(0,0),15plot_coords([
17           (1,0),16    (0, 0),
18           (2,1),17    (1, 0),
19           (3,1),18    (2, 1),
20           (2,0)])19    (3, 1),
20    (2, 0)
21])
21nan = float('nan')22nan = float('nan')
n22plot_coor([(0,0),n23plot_coords([
23           (1,1),24    (0, 0),
25    (1, 1),
24           (nan,nan),26    (nan, nan),
25           (1,0),27    (1, 0),
26           (2,1)])28    (2, 1)
29])
27from math import pi, sin, cos30from math import pi, sin, cos
n28deg_rads = pi/180n31DEGREES_TO_RADIANS = pi / 180
29def tur_to_coor(tur_program, turn_amount = 45):32def turtle_to_coords(turtle_program, turn_amount=45):
30    state = (0.0, 0.0, 90.0)33    state = (0.0, 0.0, 90.0)
31    yield (0.0, 0.0)34    yield (0.0, 0.0)
n32    for command in tur_program:n35    for command in turtle_program:
33        x, y, angle = state36        x, y, angle = state
n34        if command in 'Ff':n37        if command in 'Ff':      
35            state = (x - cos(angle * deg_rads), y + sin(angle * deg_rads), angle38            state = (x - cos(angle * DEGREES_TO_RADIANS),
>) 
39                     y + sin(angle * DEGREES_TO_RADIANS),
40                     angle)
36            if command == 'f':41            if command == 'f':
37                yield (float('nan'), float('nan'))42                yield (float('nan'), float('nan'))
38            yield (state[0], state[1])43            yield (state[0], state[1])
n39        elif command == '+':n44        elif command == '+':     
40            state = (x, y, angle + turn_amount)45            state = (x, y, angle + turn_amount)
n41        elif command == '-':n46        elif command == '-':     
42            state = (x, y, angle - turn_amount)47            state = (x, y, angle - turn_amount)
n43plot_coor(tur_to_coor('FfF++FfF++FfF++FfF'))n48plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
44plot_coor(tur_to_coor('F-F+F+F+f+F+F+F-F'))49plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
45from math import isnan50from math import isnan
n46def print_coor(coor):n51def print_coords(coords):
47    for (x, y) in coor:52    for (x, y) in coords:
48        if isnan(x):53        if isnan(x):
49            print('<gap>')54            print('<gap>')
50        else:55        else:
51            print('({:.2f}, {:.2f})'.format(x, y))56            print('({:.2f}, {:.2f})'.format(x, y))
n52print_coor(tur_to_coor('F-F+F+F+f+F+F+F-F'))n57print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
53plot_coor(tur_to_coor('F-F+F+F+f+F+F+F-F', 65))58plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F', 65))
54def trans_seq(seq, trans):59def transform_sequence(sequence, transformations):
55    return "".join(trans.get(c, c) for c in seq)60    return ''.join(transformations.get(c, c) for c in sequence)
56trans_seq('acab', {'a': 'aba', 'c': 'bb'})61transform_sequence('acab', {'a': 'aba', 'c': 'bb'})
57plot_coor(tur_to_coor(trans_seq('FFFF', {'F': 'FfF++'})))62plot_coords(turtle_to_coords(transform_sequence('FFFF', {'F': 'FfF++'})))
58def trans_multi(seq, trans, iterations):63def transform_multiple(sequence, transformations, iterations):
59    for _ in range(iterations):64    for _ in range(iterations):
n60        seq = trans_seq(seq, trans)n65        sequence = transform_sequence(sequence, transformations)
61    return seq66    return sequence
62print('0:', trans_multi('abba', {'b': 'bab'}, 0))67print('0:', transform_multiple('abba', {'b': 'bab'}, 0))
63print('1:', trans_multi('abba', {'b': 'bab'}, 1))68print('1:', transform_multiple('abba', {'b': 'bab'}, 1))
64print('2:', trans_multi('abba', {'b': 'bab'}, 2))69print('2:', transform_multiple('abba', {'b': 'bab'}, 2))
65plot_coor(tur_to_coor(trans_multi('F', {'F': '+F+F-F+F'}, 5)))70plot_coords(turtle_to_coords(transform_multiple('F', {'F': '+F+F--F+F'}, 5)))
66plot_coor(tur_to_coor(trans_multi('L', {71plot_coords(turtle_to_coords(transform_multiple('L', {
67    'L': '-RF+LFL+FR-',72    'L': '-RF+LFL+FR-',
n68    'R': '+LF-RFR-FL+'    n73    'R': '+LF-RFR-FL+'
69}, 5), 90))74}, 5), 90))
n70def branch_tur_to_coor(tur_program, turn_amount = 45):n75def branching_turtle_to_coords(turtle_program, turn_amount=45):
71    saved_states = list()76    saved_states = list()
72    state = (0, 0, 90)77    state = (0, 0, 90)
73    yield (0, 0)78    yield (0, 0)
n74    for command in tur_program:n79    for command in turtle_program:
75        x, y, angle = state80        x, y, angle = state
n76        if command.lower() in 'abcdefghij':n81        if command.lower() in 'abcdefghij':        
77            state = (x - cos(angle * deg_rads), y + sin(angle * deg_rads), angle82            state = (x - cos(angle * DEGREES_TO_RADIANS),
>) 
83                     y + sin(angle * DEGREES_TO_RADIANS),
84                     angle)
78            if command.islower():85            if command.islower():                  
79                yield (float('nan'), float('nan'))86                yield (float('nan'), float('nan'))
80            yield (state[0], state[1])87            yield (state[0], state[1])
n81        elif command == '+':n88        elif command == '+':                       
82            state = (x, y, angle + turn_amount)89            state = (x, y, angle + turn_amount)
n83        elif command == '-':n90        elif command == '-':                       
84            state = (x, y, angle - turn_amount)91            state = (x, y, angle - turn_amount)
n85        elif command == '[':n92        elif command == '[':                       
86            saved_states.append(state)93            saved_states.append(state)
n87        elif command == ']':n94        elif command == ']':                       
88            state = saved_states.pop()95            state = saved_states.pop()
89            yield (float('nan'), float('nan'))96            yield (float('nan'), float('nan'))
90            x, y, _ = state97            x, y, _ = state
91            yield (x, y)98            yield (x, y)
n92plot_coor(branch_tur_to_coor('F[-F]+F', 45))n99plot_coords(branching_turtle_to_coords('F[-F]+F', 45))
93def l_plot(axiom, trans, iterations = 0, angle = 45):100def l_plot(axiom, transformations, iterations=0, angle=45):
94    tur_program = trans_multi(axiom, trans, iterations)101    turtle_program = transform_multiple(axiom, transformations, iterations)
95    coor = branch_tur_to_coor(tur_program, angle)102    coords = branching_turtle_to_coords(turtle_program, angle)
96    plot_coor(coor, bare_plot = True)103    plot_coords(coords, bare_plot=True) 
97l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)104l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)
98l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)105l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)
99for i in range(5):106for i in range(5):
n100    print('{}:'.format(i),n107    print('{}: '.format(i),
101        trans_multi('X',{'X': 'F+X'}, i))108          transform_multiple('A', {'A': 'F+A'}, i))
102for i in range(5):109for i in range(5):
n103    print('{}:'.format(i),n110    print('{}: '.format(i),
104        trans_multi('X', {'X': 'F+X', 'F': 'FF'}, i))111          transform_multiple('A', {'A': 'F+A', 'F': 'FF'}, i))
105l_plot('X', {'F': 'FF', 'X': 'F[+XF-[X]-X][---X]'}, 55, 22.5)class DNAMOTIF:112l_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)class DNAMOTIF: 
106    def __init__(self):113    def __init__(self):
n107        self.instances=[]n114        self.instances = []
108        self.consensus=[]115        self.consensus=[]
n109        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n116        self.counts= {'A': [], 'C': [], "G":[],'T': []}
110    def __str__(self):117    def __str__ (self):
111        string = ''118        string = ""
112        for i in self.instances:119        for i in self.instances:
n113            string += 1 + ''n120            string += i + "\n"
114        return string[:-2]121        return string[:0]
115    def __len__(self):122    def __len__(self):
n116        return len(self.instances[0])n123        return len (self.consensus)
117    def count(self):124    def count(self):
n118        for i in self. instances:n125        for i in self.instances:
119            t = i.upper()126            temp = i.upper()
120            self.counts['A'].append(t.count('A'))127        self.counts["A"].append(temp.count("A"))
121            self.counts['C'].append(t.count('C'))128        self.counts["C"].append(temp.count("C"))
122            self.counts['G'].append(t.count('G'))129        self.counts["G"].append(temp.count("G"))
123            self.counts['T'].append(t.count('T'))130        self.counts["T"].append(temp.count("T"))
124    def compute_consensus(self):131    def compute_consensus(self):
n125        A = self.counts['A']n132        A = self.counts["A"]
126        C = self.counts['C']133        C = self.counts["C"]
127        G = self.counts['G']134        G = self.counts["G"]
128        T = self.counts['T']135        T = self.counts["T"]   
129        for i in range(len(A)):136        for i in range (len(A)):
130            if(A[i]>=C[i] and A[i]>=G[i] and A[i]>=T[i]):137            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
131                self.consensus.append('A')138                self.consensus.append("A")
132            elif (C[i]>=G[i] and C[i]>=T[i]):139            elif (C[i] >= G[i] and C[i] >= T[i]):
133                self.consensus.append('C')140                self.consensus.append("C")
134            elif (G[i]>=T[i]):141            elif (G[i] >= T[i]):
135                self.consensus.append('G')142                self.consensus.append("G")
136            else:143            else:
n137                self.consensus.append('T')n144                self.consensus.append("T")
138    def parse(self, filename):145    def parse(self, filename):
n139        with open(filename, 'r') as f:n146        with open(filename,'r') as f:
140            for i in f:147            for i in f:
t141                if '>' in i:t148                if ">" in i:
142                    continue149                    continue
143                else:150                else:
144                    self.instances.append(i)151                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 52

Student ID: 108, P-Value: 3.84e-02

Nearest Neighbor ID: 276

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
n3import numpyn
4class PLANT:3class PLANT:
n5    def __init__(self,initial_state,generator,n,deltaTheta):n4    def __init__(self,init_state,gen,n,deltaTheta):
6        self.initial_state=initial_state5        self.init_state=init_state
7        self.generator=generator  6        self.gen=gen 
8        self.n=n7        self.n=n
9        self.deltaTheta=deltaTheta8        self.deltaTheta=deltaTheta
n10        self.str=initial_staten9        self.str=init_state
11        for i in range(n):10        for i in range(n):
n12            updated_string=''n11            up_str=''
13            for a in self.str:12            for i in self.str:
14                curr = a13                c = i
15                if curr in self.generator.keys():14                if c in self.gen.keys():
16                    updated_string+=self.generator[curr]15                    up_str = up_str + self.gen[c]
17                else: updated_string += curr16                else: 
17                    up_str = up_str + c
18            self.str=updated_string18            self.str=up_str
19    def drawPlant(self):19    def drawPlant(self):
n20        currPt=(200,0)n20        presentPt=(200,0)
21        theta=9021        theta= 40+50
22        s=[currPt,theta]22        z=[presentPt,theta]
23        for i in self.str:23        for o in self.str:
24            if i.isalpha():24            if o.isalpha():
25                nextPt = [currPt[0]+math.cos(theta*math.pi/180), currPt[1]+math.25                nxt = (presentPt[0]+math.cos(math.radians(theta)), presentPt[1]+
>sin((theta*math.pi/180))]>math.sin(math.radians(theta)))
26                plt.plot(currPt[0],nextPt[0],currPt[1],nextPt[1],color='black')26                plt.plot([presentPt[0],nxt[0]],[presentPt[1],nxt[1]],color='blac
 >k')
27                currPt=nextPt27                presentPt=nxt
28            elif i == '[':28            elif o == '[':
29                s=[currPt,theta]29                z=[presentPt,theta]
30            elif i == ']':30            elif o == ']':
31                currPt = s[0]31                presentPt = z[0]
32                theta = s[1]32                theta = z[1]
33            elif i == '+':33            elif o == '+':
34                theta = theta+self.deltaTheta     34                theta = theta+self.deltaTheta     
n35            elif i == '-':n35            elif o == '-':
36                theta = theta-self.deltaTheta     36                theta = theta-self.deltaTheta    class DNAMOTIF:
37class DNAMOTIF:
38    def __init__(self):37    def __init__(self):
nn38        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
39        self.instances=[]39        self.instances=[]
40        self.consensus=[]40        self.consensus=[]
n41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n
42    def __str__(self):
43        DNA=''
44        for i in self.instances:
45            DNA+=i
46        return DNA
47    def __len__(self):41    def __len__(self):
48        return len(self.instances[0])-142        return len(self.instances[0])-1
nn43    def __str__(self):
44        DNA_Strand=''
45        for n in self.instances:
46            DNA_Strand=DNA_Strand+n
47        return DNA_Strand
49    def count(self):48    def count(self):
n50        for i in range(len(self)):n49        for n in range(len(self)):
51            self.counts["A"].append(0)
52            self.counts["C"].append(0)
53            self.counts["G"].append(0)50            self.counts["G"].append(0)
54            self.counts["T"].append(0)51            self.counts["T"].append(0)
nn52            self.counts["C"].append(0)
53            self.counts["A"].append(0)
55            for j in self.instances:54            for j in self.instances:
n56                if j[i].upper() == 'A': n
57                    self.counts["A"][i]+=1
58                if j[i].upper() == 'C': 
59                    self.counts["C"][i]+=1
60                if j[i].upper() == 'G': 55                if j[n].upper() == 'G': 
61                    self.counts["G"][i]+=156                    self.counts["G"][n]+=1
62                if j[i].upper() == 'T': 57                if j[n].upper() == 'T': 
63                    self.counts["T"][i]+=158                    self.counts["T"][n]+=1
59                if j[n].upper() == 'C': 
60                    self.counts["C"][n]+=1
61                if j[n].upper() == 'A': 
62                    self.counts["A"][n]+=1
64    def compute_consensus(self):63    def compute_consensus(self):
nn64        cons=''
65        self.count()65        self.count()
n66        consensus=''n
67        for i in range(len(self)):66        for n in range(len(self)):
68            max_val=067            highest_value=0
69            char="A" 68            character="A" 
70            if self.counts["A"][i]>max_val:
71                max_val=self.counts["A"][i]
72                char="A"
73            if self.counts["C"][i]>max_val:69            if self.counts["C"][n]>highest_value:
74                max_val=self.counts["C"][i]70                highest_value=self.counts["C"][n]
75                char="C"71                character="C"
76            if self.counts["G"][i]>max_val:72            if self.counts["A"][n]>highest_value:
77                max_val=self.counts["G"][i]73                highest_value=self.counts["A"][n]
78                char="G"74                character="A"
79            if self.counts["T"][i]>max_val:75            if self.counts["T"][n]>highest_value:
80                max_val=self.counts["T"][i]76                highest_value=self.counts["T"][n]
81                char="T"77                character="T"
78            if self.counts["G"][n]>highest_value:
79                highest_value=self.counts["G"][n]
80                character="G"
82            consensus+=char 81            cons=cons+character 
83        self.consensus=consensus82        self.consensus=cons
84    def parse(self, filename):83    def parse(self, filename):
85        with open(filename,'r') as file_object:84        with open(filename,'r') as file_object:
t86            lines=file_object.readlines()t85            line=file_object.readlines()
87            for i in lines:86            for n in line:
88                if i[0].upper()=='A' or i[0].upper()=='T' or i[0].upper()=='C' o87                if n[0].upper()=='C' or n[0].upper()=='A' or n[0].upper()=='G' o
>r i[0].upper()=='G':>r n[0].upper()=='T':
89                    self.instances.append(i)88                    self.instances.append(n)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 53

Student ID: 276, P-Value: 3.84e-02

Nearest Neighbor ID: 108

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import math2import math
nn3import numpy
3class PLANT:4class PLANT:
n4    def __init__(self,init_state,gen,n,deltaTheta):n5    def __init__(self,initial_state,generator,n,deltaTheta):
5        self.init_state=init_state6        self.initial_state=initial_state
6        self.gen=gen 7        self.generator=generator  
7        self.n=n8        self.n=n
8        self.deltaTheta=deltaTheta9        self.deltaTheta=deltaTheta
n9        self.str=init_staten10        self.str=initial_state
10        for i in range(n):11        for i in range(n):
n11            up_str=''n12            updated_string=''
12            for i in self.str:13            for a in self.str:
13                c = i14                curr = a
14                if c in self.gen.keys():15                if curr in self.generator.keys():
15                    up_str = up_str + self.gen[c]16                    updated_string+=self.generator[curr]
16                else: 17                else: updated_string += curr
17                    up_str = up_str + c
18            self.str=up_str18            self.str=updated_string
19    def drawPlant(self):19    def drawPlant(self):
n20        presentPt=(200,0)n20        currPt=(200,0)
21        theta= 40+5021        theta=90
22        z=[presentPt,theta]22        s=[currPt,theta]
23        for o in self.str:23        for i in self.str:
24            if o.isalpha():24            if i.isalpha():
25                nxt = (presentPt[0]+math.cos(math.radians(theta)), presentPt[1]+25                nextPt = [currPt[0]+math.cos(theta*math.pi/180), currPt[1]+math.
>math.sin(math.radians(theta)))>sin((theta*math.pi/180))]
26                plt.plot([presentPt[0],nxt[0]],[presentPt[1],nxt[1]],color='blac26                plt.plot(currPt[0],nextPt[0],currPt[1],nextPt[1],color='black')
>k') 
27                presentPt=nxt27                currPt=nextPt
28            elif o == '[':28            elif i == '[':
29                z=[presentPt,theta]29                s=[currPt,theta]
30            elif o == ']':30            elif i == ']':
31                presentPt = z[0]31                currPt = s[0]
32                theta = z[1]32                theta = s[1]
33            elif o == '+':33            elif i == '+':
34                theta = theta+self.deltaTheta     34                theta = theta+self.deltaTheta     
n35            elif o == '-':n35            elif i == '-':
36                theta = theta-self.deltaTheta    class DNAMOTIF:36                theta = theta-self.deltaTheta     
37class DNAMOTIF:
37    def __init__(self):38    def __init__(self):
n38        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}n
39        self.instances=[]39        self.instances=[]
40        self.consensus=[]40        self.consensus=[]
nn41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):
43        DNA=''
44        for i in self.instances:
45            DNA+=i
46        return DNA
41    def __len__(self):47    def __len__(self):
42        return len(self.instances[0])-148        return len(self.instances[0])-1
n43    def __str__(self):n
44        DNA_Strand=''
45        for n in self.instances:
46            DNA_Strand=DNA_Strand+n
47        return DNA_Strand
48    def count(self):49    def count(self):
n49        for n in range(len(self)):n50        for i in range(len(self)):
51            self.counts["A"].append(0)
52            self.counts["C"].append(0)
50            self.counts["G"].append(0)53            self.counts["G"].append(0)
51            self.counts["T"].append(0)54            self.counts["T"].append(0)
n52            self.counts["C"].append(0)n
53            self.counts["A"].append(0)
54            for j in self.instances:55            for j in self.instances:
n55                if j[n].upper() == 'G': n
56                    self.counts["G"][n]+=1
57                if j[n].upper() == 'T': 
58                    self.counts["T"][n]+=1
59                if j[n].upper() == 'C': 
60                    self.counts["C"][n]+=1
61                if j[n].upper() == 'A': 56                if j[i].upper() == 'A': 
62                    self.counts["A"][n]+=157                    self.counts["A"][i]+=1
58                if j[i].upper() == 'C': 
59                    self.counts["C"][i]+=1
60                if j[i].upper() == 'G': 
61                    self.counts["G"][i]+=1
62                if j[i].upper() == 'T': 
63                    self.counts["T"][i]+=1
63    def compute_consensus(self):64    def compute_consensus(self):
n64        cons=''n
65        self.count()65        self.count()
nn66        consensus=''
66        for n in range(len(self)):67        for i in range(len(self)):
67            highest_value=068            max_val=0
68            character="A" 69            char="A" 
69            if self.counts["C"][n]>highest_value:
70                highest_value=self.counts["C"][n]
71                character="C"
72            if self.counts["A"][n]>highest_value:70            if self.counts["A"][i]>max_val:
73                highest_value=self.counts["A"][n]71                max_val=self.counts["A"][i]
74                character="A"72                char="A"
75            if self.counts["T"][n]>highest_value:73            if self.counts["C"][i]>max_val:
76                highest_value=self.counts["T"][n]74                max_val=self.counts["C"][i]
77                character="T"75                char="C"
78            if self.counts["G"][n]>highest_value:76            if self.counts["G"][i]>max_val:
79                highest_value=self.counts["G"][n]77                max_val=self.counts["G"][i]
80                character="G"78                char="G"
79            if self.counts["T"][i]>max_val:
80                max_val=self.counts["T"][i]
81                char="T"
81            cons=cons+character 82            consensus+=char 
82        self.consensus=cons83        self.consensus=consensus
83    def parse(self, filename):84    def parse(self, filename):
84        with open(filename,'r') as file_object:85        with open(filename,'r') as file_object:
t85            line=file_object.readlines()t86            lines=file_object.readlines()
86            for n in line:87            for i in lines:
87                if n[0].upper()=='C' or n[0].upper()=='A' or n[0].upper()=='G' o88                if i[0].upper()=='A' or i[0].upper()=='T' or i[0].upper()=='C' o
>r n[0].upper()=='T':>r i[0].upper()=='G':
88                    self.instances.append(n)89                    self.instances.append(i)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 54

Student ID: 253, P-Value: 4.19e-02

Nearest Neighbor ID: 22

Student (left) and Nearest Neighbor (right).


f1import numpy as npf1import numpy as np
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, init_state, generatorn, deltaTheta) -> None:n4    def __init__(self, init_state, fx, g, dxTheta) -> None:
5        self.initial_state = str(init_state)5        self.initial_state = str(init_state)
n6        self.generator = dict(generator)n6        self.generator = dict(fx)
7        self.n = int(n)7        self.n = int(g)
8        self.deltaTheta = float(deltaTheta)8        self.deltaTheta = float(dxTheta)
9        self.str = self.initial_state9        self.str = self.initial_state
nn10        doob_str = str(self.str)
10        iterate_str = str(self.initial_state)11        boof_str = str(self.initial_state)
11        for i in range(n):12        for i in range(g):
12            iter_list = list(iterate_str)   13            dank_list = list(boof_str)   
13            new_iter_list = []14            new_freezer_list = []
14            for char in iter_list:15            for smd in dank_list:
15                if char in self.generator.keys(): 16                if smd in self.generator.keys(): 
16                    new_iter_list.append(self.generator.get(char))17                    new_freezer_list.append(self.generator.get(smd))
17                else:18                else:
n18                    new_iter_list.append(char)n19                    new_freezer_list.append(smd)
19            iter_list = new_iter_list20            dank_list = new_freezer_list
20            iterate_str = ''.join(iter_list)21            boof_str = ''.join(dank_list)
21        self.str = iterate_str22        self.str = boof_str
22        pass23        pass
23    def drawPlant(self):24    def drawPlant(self):
n24        currentPt = (200, 0)n25        presentLocation = (200, 0)
25        radian = (np.pi / 180)  26        rad = (np.pi / 180)  
26        int_theta = 90 * radian  27        theta_i = 90 * rad  
27        push_state = currentPt28        force = presentLocation
28        nextPt = (0,0)29        futureLocation = (0,0)
29        push_angle = 030        force_ang = 0
30        theta = int_theta31        theta = theta_i
31        saved_states = []32        save_drive = []
32        print('drawing plant...')33        print('drawing plant...')
n33        for char in self.str:n34        for smd in self.str:
34            if (char == 'X') or (char == 'F'):35            if (smd == 'X') or (smd == 'F'):
35                nextPt = (currentPt[0] + np.cos(theta), currentPt[1] + np.sin(th36                futureLocation = (presentLocation[0] + np.cos(theta), presentLoc
>eta))>ation[1] + np.sin(theta))
36                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c37                plt.plot([presentLocation[0], futureLocation[0]], [presentLocati
>olor='black')>on[1], futureLocation[1]], color='green')
37            elif char == '+':38            elif smd == '+':
38                theta = theta + (self.deltaTheta * radian)39                theta = theta + (self.deltaTheta * rad)
39            elif char == '-':40            elif smd == '-':
40                push_angle = theta41                force_ang = theta
41                theta = theta - (self.deltaTheta * radian)42                theta = theta - (self.deltaTheta * rad)
42            elif char == '[':43            elif smd == '[':
43                push_radians = theta44                push_rad = theta
44                push_state = currentPt45                force = presentLocation
45                turtle = (push_state[0], push_state[1], push_radians)46                turtle = (force[0], force[1], push_rad)
46                saved_states.append(turtle)47                save_drive.append(turtle)
47                pass48                pass
n48            elif char == ']':n49            elif smd == ']':
49                theta = saved_states[-1][-1]50                theta = save_drive[-1][-1]
50                nextPt = (saved_states[-1][0], saved_states[-1][1])51                futureLocation = (save_drive[-1][0], save_drive[-1][1])
51                saved_states.pop()52                save_drive.pop()
52                pass53                pass
n53            currentPt = nextPtn54            presentLocation = futureLocation
54        print('complete')55        print('complete')
55        pass56        pass
56if __name__ == '__main__':57if __name__ == '__main__':
57    a = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)58    a = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)
58    a.drawPlant()59    a.drawPlant()
59    passimport csv60    passimport csv
60import os61import os
61class DNAMOTIF:62class DNAMOTIF:
62    def __init__(self) -> None:63    def __init__(self) -> None:
n63        self.instances_1=[]  n
64        self.instances = []64        self.instances=[]
65        self.consensus=[]  65        self.consensus=[]
66        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}  66        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
67    def __str__(self) -> str:67    def __str__(self) -> str:
n68        return str(self.instances_1)n68        return str(self.instances)
69    def __len__(self):69    def __len__(self):
n70        return len(self.instances_1[0])n70        return len(self.instances)
71    def count(self):
72        for i in range(len(self.instances[0])):
73            group = [row[i] for row in self.instances]
74            a_ct = 0
75            c_ct = 0
76            g_ct = 0
77            t_ct = 0
78            for char in group:
79                if char == 'A':
80                    a_ct += 1
81                if char == 'C':
82                    c_ct += 1
83                if char == 'G':
84                    g_ct += 1
85                if char == 'T':
86                    t_ct += 1
87            self.counts.get('A').append(a_ct)
88            self.counts.get('C').append(c_ct)
89            self.counts.get('G').append(g_ct)
90            self.counts.get('T').append(t_ct)
91        pass
92    def compute_consensus(self):
93        DNAMOTIF.count(self)
94        char_return = ''
95        a_ct = self.counts.get('A')
96        c_ct = self.counts.get('C')
97        g_ct = self.counts.get('G')
98        t_ct = self.counts.get('T')
99        for i in range(len(a_ct)):
100            ct_list = [a_ct[i], c_ct[i], g_ct[i], t_ct[i]]
101            max_num = max(ct_list)
102            if max_num == ct_list[0]: char_return += 'A'
103            if max_num == ct_list[1]: char_return += 'C'
104            if max_num == ct_list[2]: char_return += 'G'
105            if max_num == ct_list[3]: char_return += 'T'
106        self.consensus = char_return
107        pass
71    def parse(self, filename):108    def parse(self, filename):
72        with open(filename) as file:109        with open(filename) as file:
n73            list_of_lines = file.readlines()n110            lines_list = file.readlines()
74            sequences = []111            sequences = []
n75            for line in list_of_lines:n112            for line in lines_list:
76                if list_of_lines.index(line) % 2 != 0:113                if lines_list.index(line) % 2 != 0:
77                    line = line.replace('\n', '')114                    line = line.replace('\n', '')
78                    line = line.upper()115                    line = line.upper()
79                    sequences.append(line)116                    sequences.append(line)
n80            self.instances_1 = sequencesn117            self.instances = sequences
81            for line in self.instances_1:
82                line_list = list(line)
83                line_list[0] = line_list[0].lower()
84                line_list.append('\n')
85                line = ''.join(line_list)
86                self.instances.append(line)
87            pass118            pass
t88    def count(self):t
89        for c in range(len(self.instances_1[0])):
90            column = [row[c] for row in self.instances_1]
91            a_count = 0
92            c_count = 0
93            g_count = 0
94            t_count = 0
95            for letter in column:
96                if letter == 'A': a_count += 1
97                if letter == 'C': c_count += 1
98                if letter == 'G': g_count += 1
99                if letter == 'T': t_count += 1
100            self.counts.get('A').append(a_count)
101            self.counts.get('C').append(c_count)
102            self.counts.get('G').append(g_count)
103            self.counts.get('T').append(t_count)
104        pass
105    def compute_consensus(self):
106        DNAMOTIF.count(self)
107        letter_return = ''
108        a_count = self.counts.get('A')
109        c_count = self.counts.get('C')
110        g_count = self.counts.get('G')
111        t_count = self.counts.get('T')
112        for item in range(len(a_count)):
113            count_list = [a_count[item], c_count[item], g_count[item], t_count[i
>tem]] 
114            max_number = max(count_list)
115            if max_number == count_list[0]: letter_return += 'A'
116            if max_number == count_list[1]: letter_return += 'C'
117            if max_number == count_list[2]: letter_return += 'G'
118            if max_number == count_list[3]: letter_return += 'T'
119        self.consensus = letter_return
120        pass
121if __name__ == '__main__':119if __name__ == '__main__':
122    lexA=DNAMOTIF()120    lexA=DNAMOTIF()
123    lexA.parse('lexA.fasta')121    lexA.parse('lexA.fasta')
124    print('file open')122    print('file open')
125    lexA.count()123    lexA.count()
126    lexA.compute_consensus()124    lexA.compute_consensus()
127    pass125    pass
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 55

Student ID: 22, P-Value: 4.19e-02

Nearest Neighbor ID: 253

Student (left) and Nearest Neighbor (right).


f1import numpy as npf1import numpy as np
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, init_state, fxg, dxTheta) -> None:n4    def __init__(self, init_state, generatorn, deltaTheta) -> None:
5        self.initial_state = str(init_state)5        self.initial_state = str(init_state)
n6        self.generator = dict(fx)n6        self.generator = dict(generator)
7        self.n = int(g)7        self.n = int(n)
8        self.deltaTheta = float(dxTheta)8        self.deltaTheta = float(deltaTheta)
9        self.str = self.initial_state9        self.str = self.initial_state
n10        doob_str = str(self.str)n
11        boof_str = str(self.initial_state)10        iterate_str = str(self.initial_state)
12        for i in range(g):11        for i in range(n):
13            dank_list = list(boof_str)   12            iter_list = list(iterate_str)   
14            new_freezer_list = []13            new_iter_list = []
15            for smd in dank_list:14            for char in iter_list:
16                if smd in self.generator.keys(): 15                if char in self.generator.keys(): 
17                    new_freezer_list.append(self.generator.get(smd))16                    new_iter_list.append(self.generator.get(char))
18                else:17                else:
n19                    new_freezer_list.append(smd)n18                    new_iter_list.append(char)
20            dank_list = new_freezer_list19            iter_list = new_iter_list
21            boof_str = ''.join(dank_list)20            iterate_str = ''.join(iter_list)
22        self.str = boof_str21        self.str = iterate_str
23        pass22        pass
24    def drawPlant(self):23    def drawPlant(self):
n25        presentLocation = (200, 0)n24        currentPt = (200, 0)
26        rad = (np.pi / 180)  25        radian = (np.pi / 180)  
27        theta_i = 90 * rad  26        int_theta = 90 * radian  
28        force = presentLocation27        push_state = currentPt
29        futureLocation = (0,0)28        nextPt = (0,0)
30        force_ang = 029        push_angle = 0
31        theta = theta_i30        theta = int_theta
32        save_drive = []31        saved_states = []
33        print('drawing plant...')32        print('drawing plant...')
n34        for smd in self.str:n33        for char in self.str:
35            if (smd == 'X') or (smd == 'F'):34            if (char == 'X') or (char == 'F'):
36                futureLocation = (presentLocation[0] + np.cos(theta), presentLoc35                nextPt = (currentPt[0] + np.cos(theta), currentPt[1] + np.sin(th
>ation[1] + np.sin(theta))>eta))
37                plt.plot([presentLocation[0], futureLocation[0]], [presentLocati36                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>on[1], futureLocation[1]], color='green')>olor='black')
38            elif smd == '+':37            elif char == '+':
39                theta = theta + (self.deltaTheta * rad)38                theta = theta + (self.deltaTheta * radian)
40            elif smd == '-':39            elif char == '-':
41                force_ang = theta40                push_angle = theta
42                theta = theta - (self.deltaTheta * rad)41                theta = theta - (self.deltaTheta * radian)
43            elif smd == '[':42            elif char == '[':
44                push_rad = theta43                push_radians = theta
45                force = presentLocation44                push_state = currentPt
46                turtle = (force[0], force[1], push_rad)45                turtle = (push_state[0], push_state[1], push_radians)
47                save_drive.append(turtle)46                saved_states.append(turtle)
48                pass47                pass
n49            elif smd == ']':n48            elif char == ']':
50                theta = save_drive[-1][-1]49                theta = saved_states[-1][-1]
51                futureLocation = (save_drive[-1][0], save_drive[-1][1])50                nextPt = (saved_states[-1][0], saved_states[-1][1])
52                save_drive.pop()51                saved_states.pop()
53                pass52                pass
n54            presentLocation = futureLocationn53            currentPt = nextPt
55        print('complete')54        print('complete')
56        pass55        pass
57if __name__ == '__main__':56if __name__ == '__main__':
58    a = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)57    a = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)
59    a.drawPlant()58    a.drawPlant()
60    passimport csv59    passimport csv
61import os60import os
62class DNAMOTIF:61class DNAMOTIF:
63    def __init__(self) -> None:62    def __init__(self) -> None:
nn63        self.instances_1=[]  
64        self.instances=[]64        self.instances = []
65        self.consensus=[]65        self.consensus=[]  
66        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}66        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}  
67    def __str__(self) -> str:67    def __str__(self) -> str:
n68        return str(self.instances)n68        return str(self.instances_1)
69    def __len__(self):69    def __len__(self):
n70        return len(self.instances)n70        return len(self.instances_1[0])
71    def parse(self, filename):
72        with open(filename) as file:
73            list_of_lines = file.readlines()
74            sequences = []
75            for line in list_of_lines:
76                if list_of_lines.index(line) % 2 != 0:
77                    line = line.replace('\n', '')
78                    line = line.upper()
79                    sequences.append(line)
80            self.instances_1 = sequences
81            for line in self.instances_1:
82                line_list = list(line)
83                line_list[0] = line_list[0].lower()
84                line_list.append('\n')
85                line = ''.join(line_list)
86                self.instances.append(line)
87            pass
71    def count(self):88    def count(self):
n72        for i in range(len(self.instances[0])):n89        for c in range(len(self.instances_1[0])):
73            group = [row[i] for row in self.instances]90            column = [row[c] for row in self.instances_1]
74            a_ct = 091            a_count = 0
75            c_ct = 092            c_count = 0
76            g_ct = 093            g_count = 0
77            t_ct = 094            t_count = 0
78            for char in group:95            for letter in column:
79                if char == 'A':96                if letter == 'A': a_count += 1
80                    a_ct += 197                if letter == 'C': c_count += 1
81                if char == 'C':98                if letter == 'G': g_count += 1
82                    c_ct += 199                if letter == 'T': t_count += 1
83                if char == 'G':
84                    g_ct += 1
85                if char == 'T':
86                    t_ct += 1
87            self.counts.get('A').append(a_ct)100            self.counts.get('A').append(a_count)
88            self.counts.get('C').append(c_ct)101            self.counts.get('C').append(c_count)
89            self.counts.get('G').append(g_ct)102            self.counts.get('G').append(g_count)
90            self.counts.get('T').append(t_ct)103            self.counts.get('T').append(t_count)
91        pass104        pass
92    def compute_consensus(self):105    def compute_consensus(self):
93        DNAMOTIF.count(self)106        DNAMOTIF.count(self)
n94        char_return = ''n107        letter_return = ''
95        a_ct = self.counts.get('A')108        a_count = self.counts.get('A')
96        c_ct = self.counts.get('C')109        c_count = self.counts.get('C')
97        g_ct = self.counts.get('G')110        g_count = self.counts.get('G')
98        t_ct = self.counts.get('T')111        t_count = self.counts.get('T')
99        for i in range(len(a_ct)):112        for item in range(len(a_count)):
100            ct_list = [a_ct[i], c_ct[i], g_ct[i], t_ct[i]]113            count_list = [a_count[item], c_count[item], g_count[item], t_count[i
 >tem]]
101            max_num = max(ct_list)114            max_number = max(count_list)
102            if max_num == ct_list[0]: char_return += 'A'115            if max_number == count_list[0]: letter_return += 'A'
103            if max_num == ct_list[1]: char_return += 'C'116            if max_number == count_list[1]: letter_return += 'C'
104            if max_num == ct_list[2]: char_return += 'G'117            if max_number == count_list[2]: letter_return += 'G'
105            if max_num == ct_list[3]: char_return += 'T'118            if max_number == count_list[3]: letter_return += 'T'
106        self.consensus = char_return119        self.consensus = letter_return
107        pass120        pass
t108    def parse(self, filename):t
109        with open(filename) as file:
110            lines_list = file.readlines()
111            sequences = []
112            for line in lines_list:
113                if lines_list.index(line) % 2 != 0:
114                    line = line.replace('\n', '')
115                    line = line.upper()
116                    sequences.append(line)
117            self.instances = sequences
118            pass
119if __name__ == '__main__':121if __name__ == '__main__':
120    lexA=DNAMOTIF()122    lexA=DNAMOTIF()
121    lexA.parse('lexA.fasta')123    lexA.parse('lexA.fasta')
122    print('file open')124    print('file open')
123    lexA.count()125    lexA.count()
124    lexA.compute_consensus()126    lexA.compute_consensus()
125    pass127    pass
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 56

Student ID: 464, P-Value: 4.97e-02

Nearest Neighbor ID: 318

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
3class PLANT:3class PLANT:
n4    def __init__(self,string,dict,n,deltaTheta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string=string5        self.string = string
6        self.dict=dict6        self.dictionary = dictionary
7        self.n=n7        self.n = n
8        self.deltaTheta=deltaTheta8        self.deltaTheta = deltaTheta
9        self.str=PLANT.generator(string,dict,n)9        self.str = PLANT.generator(string,dictionary, n)
10    def generator(string,dict,n):10    def generator(string, dictionary, n):
11        def variable(string):11        def character_v(string):
12            if string in dict:12            if string in dictionary:
13                return dict.get(string)13                return dictionary.get(string)
14            return string14            return string
n15        string_list=[string]n15        substrings_list = [string]
16        for i in range(n):16        for i in range(n):
n17            current_string=string_list[-1]n17            substring = substrings_list[-1]
18            a=[variable(character) for character in current_string]18            new_statement = [character_v(char) for char in substring]
19            string_list.append("".join(a))19            substrings_list.append(''.join(new_statement))
20        new_string=string_list[n]20        newstring = substrings_list[n]
21        return new_string21        return newstring
22    def drawPlant(self):22    def drawPlant(self):
n23        uppercase=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','n23        upper_letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 
>P','Q','R','S','T','U','V','W','X','Y','Z']>'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt=(200,0)24        currentPt=(200,0)
25        theta = np.radians(90)25        theta = np.radians(90)
n26        deltaTheta=np.radians(self.deltaTheta)n26        deltaTheta = np.radians(self.deltaTheta)
27        stack_list=[currentPt,theta]27        stack = [currentPt, theta]
28        for command in self.str:28        for command in self.str:
n29            if command.upper() in uppercase:n29            if command.upper() in upper_letters:
30                nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)30                nextPt = (currentPt[0]+(np.cos(theta)), currentPt[1]+(np.sin(the
>)>ta)))
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
n32                currentPt=nextPtn32                currentPt = nextPt
33            else:33            else:
n34                if command=='[':n34                if command == '[':
35                    stack_list.append(currentPt)35                    stack.append(currentPt)
36                    stack_list.append(theta)36                    stack.append(theta)
37                elif command==']':37                elif command == ']':
38                    theta=stack_list.pop()38                    theta = stack.pop()
39                    currentPt=stack_list.pop()39                    currentPt = stack.pop()  
40                elif command == '-':
41                    theta -= deltaTheta
40                elif command =='+':42                elif command == '+':
41                    theta+=deltaTheta43                    theta += deltaTheta
42                elif command=='-':
43                    theta-=deltaTheta
44        return plt.plot44        return plt.plot
n45if __name__== "__main__":n45if __name__ == "__main__":
46    string=input()46    string = input()
47    dict=input()47    dictionary = input()
48    n=int(input())48    n = int(input())
49    deltaTheta=float(input())49    deltaTheta = float(input())
50    p=PLANT(string,dict,n,deltaTheta)50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    p.drawPlant()
52    plt.show()class DNAMOTIF:52    plt.show()class DNAMOTIF:
53    def __init__(self):53    def __init__(self):
n54        self.instances=[]n54        self.instances = []
55        self.consensus=[]55        self.consensus = []
56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}
57    def __str__(self):57    def __str__(self):
n58        result=''n58        output = ''
59        for instance in self.instances:59        for instance in self.instances:
n60            result+=instancen60            output += instance
61        return result61        return output
62    def __len__(self):62    def __len__(self):
63        return len(self.instances[0].rstrip())63        return len(self.instances[0].rstrip())
64    def count(self):64    def count(self):
65        for position in range(len(self)):65        for position in range(len(self)):
n66            seqA = 0n66            sequenceA = 0
67            seqC = 0
68            seqG = 0
69            seqT = 067            sequenceT = 0
68            sequenceC = 0
69            sequenceG = 0
70            for instance in self.instances:70            for instance in self.instances:
71                sequence = instance.rstrip()71                sequence = instance.rstrip()
n72                if sequence[position].upper() == 'A':n72                if (sequence[position]).upper() == 'A':
73                    seqA+=173                    sequenceA += 1
74                elif sequence[position].upper() == 'C':
75                    seqC+=1
76                elif sequence[position].upper() == 'G':
77                    seqG+=1
78                elif sequence[position].upper() == 'T':74                elif (sequence[position]).upper() == 'T':
79                    seqT+=175                    sequenceT += 1
76                elif (sequence[position]).upper() == 'C':
77                    sequenceC += 1
78                elif (sequence[position]).upper() == 'G':
79                    sequenceG += 1
80            self.counts.get('A').append(seqA)80            self.counts.get('A').append(sequenceA)
81            self.counts.get('C').append(seqC)
82            self.counts.get('G').append(seqG)
83            self.counts.get('T').append(seqT)81            self.counts.get('T').append(sequenceT)
82            self.counts.get('C').append(sequenceC)
83            self.counts.get('G').append(sequenceG)
84    def compute_consensus(self):84    def compute_consensus(self):
85        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
n86        A=self.counts.get('A')n86        A = self.counts.get('A')
87        C=self.counts.get('C')
88        G=self.counts.get('G')
89        T=self.counts.get('T')87        T = self.counts.get('T')
90        result=''88        C = self.counts.get('C')
89        G = self.counts.get('G')
90        output = ""
91        for row in range(len(A)):91        for row in range(len(A)):
n92            maximum=max(A[row],C[row],G[row],T[row])n92            maxes = max(A[row],T[row],C[row],G[row])
93            if maximum==A[row]:93            if maxes == A[row]:
94                result+='A'94                output += 'A'
95            elif maxes == T[row]:
96                output += 'T'
95            elif maximum==C[row]:97            elif maxes == C[row]:
96                result+='C'98                output += 'C'
97            elif  maximum==G[row]:99            elif maxes == G[row]:
98                result+='G'100                output += 'G'
99            elif  maximum==T[row]:101        self.consensus = output
100                result+='T'
101                self.consensus=result
102    def parse(self, filename):102    def parse(self, filename):
n103        my_file=open(filename,'r')n103        myFile = open(filename, 'r')
104        info=[line for line in my_file.readlines()]104        contents = [line for line in myFile.readlines()]
105        my_file.close()105        myFile.close()
106        for index, line in enumerate(info):106        for index, line in enumerate(contents):
107            if index %2 !=0:107            if index % 2 != 0:
108                self.instances.append(line)108                self.instances.append(line)
n109if __name__== "__main__":n109if __name__ == '__main__':
110    lexA=DNAMOTIF()110    lexA=DNAMOTIF()
t111    filename=r'lexA.fasta't111    filename = r'FinalProject\lexA.fasta'
112    lexA.parse(filename)112    lexA.parse(filename)
113    lexA.compute_consensus()113    lexA.compute_consensus()
114    print(lexA.consensus)114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 57

Student ID: 63, P-Value: 6.08e-02

Nearest Neighbor ID: 217

Student (left) and Nearest Neighbor (right).


n1import numpy as npn
2import matplotlib.pyplot as plt1import matplotlib.pyplot as plt
n3import stringn2import math
4class PLANT:3class PLANT:
n5    def __init__(self, string='', generator={}, n=0, delta_theta=0.00):n4    def __init__(self, string='', generator={}, n=0, deltaTheta=0):
6        self.string = string5        self.string = string
7        self.generator = generator6        self.generator = generator
n8        self.n = int(n) n7        self.n = n
9        self.deltatheta = np.radians(delta_theta)8        self.deltaTheta = math.radians(deltaTheta)
10        for i in range(0, self.n):9        for i in range(self.n):
11            string_update = ''10            other=""
12            for j in self.string:11            for char in self.string:
13                if j in self.generator.keys():12                if char in self.generator:
14                    string_update += self.generator[str(j)]13                    x = (self.generator).get(char)
14                    other = other + str(x)
15                else:15                else:
n16                    string_update += jn16                    other = other + str(char)
17            new = other
18            final = other
19            other = ""
17            self.string = string_update20            self.string = final
18        self.str = self.string21        self.str = self.string
19    def drawPlant(self):22    def drawPlant(self):
n20        currentpos=[200,0]n23        currentPt = [200,0]
21        theta=np.radians(90)24        theta = math.radians(90)
22        ds=[]
23        nextpt=()25        nextPt = ()
26        drawingState = []
24        stack=[]27        stack = []
25        for i in self.str:28        for char in self.str:
26            if i.isalpha():29            if char.isalpha():
27                nextpt=(currentpos[0]+np.cos(theta), currentpos[1]+np.sin(theta)30                nextPt=[currentPt[0]+math.cos(theta), currentPt[1]+math.sin(thet
>)>a)]
28                plt.plot([currentpos[0], nextpt[0]],[currentpos[1],nextpt[1]],co31                plt.plot([currentPt[0], nextPt[0]],[currentPt[1],nextPt[1]],colo
>lor='black')>r='black')
29                currentpos=nextpt32                currentPt=nextPt
30            if i=='[':33            if char == '[':
31                ds = [currentpos, theta]34                drawingState = [currentPt, theta]
32                stack.append(ds)35                stack.append(drawingState)
33            elif i==']':36            elif char == ']':
34                currentpos=stack[-1][0]37                currentPt=stack[-1][0]
35                theta=stack[-1][1]38                theta=stack[-1][1]
36                stack.pop()39                stack.pop()
n37            elif i=='+':n40            elif char == '+':
38                theta += self.deltatheta41                theta = theta + self.deltaTheta
39            elif i=='-':42            elif char == '-':
40                theta -= self.deltatheta43                theta = theta - self.deltaTheta
41if __name__ == "__main__":44if __name__ == "__main__":
n42    string = input()n45    myPlant = PLANT(input(), input(), input(), input())
43    dictionary = input()
44    n = input()
45    theta = input()
46    obj = PLANT(string, dictionary, n, theta)
47    obj.drawPlant()46    myPlant.drawPlant()
48    plt.show()class DNAMOTIF:47    plt.axis('image')
49    def __init__(self, instances=[], consensus=[], counts={'A': [], 'C': [], 'G'48    plt.show()
>:[],'T':[]}): 
49class DNAMOTIF:
50    def __init__(self):
50        self.instances = instances51        self.instances=[]
51        self.consensus=consensus52        self.consensus=[]
52        self.counts= counts53        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
53    def __str__(self):54    def __str__(self):
54        return self.instances55        return self.instances
55    def __len__(self):56    def __len__(self):
n56        y = 0n57        x = 0
57        for value in self.instances:58        for gene in self.instances:
58            y = len(value) - 159            x = len(gene) - 1
59        return y60        return x
60    def count(self):61    def count(self):
n61        value = self.instances[0]n62        gene = self.instances[0]
62        for x in range(len(value)-1):63        for i in range(len(gene)-1):
63            a = 064            a = 0
64            c = 065            c = 0
65            g = 066            g = 0
66            t = 067            t = 0
n67            for string in self.instances:n68            for dna in self.instances:
68                upp = string.upper()69                upp = dna.upper()
69                character = string[x]70                letter = dna[i]
70                if character.upper() == 'A':71                if letter.upper() == 'A':
71                    a += 172                    a += 1
n72                if character.upper() == 'C':n73                if letter.upper() == 'C':
73                    c += 174                    c += 1
n74                if character.upper() == 'G':n75                if letter.upper() == 'G':
75                    g += 176                    g += 1
n76                if character.upper() == 'T':n77                if letter.upper() == 'T':
77                    t += 178                    t += 1
78            self.counts['A'].append(a)79            self.counts['A'].append(a)
79            self.counts['C'].append(c)80            self.counts['C'].append(c)
80            self.counts['G'].append(g)81            self.counts['G'].append(g)
81            self.counts['T'].append(t)82            self.counts['T'].append(t)
82    def compute_consensus(self):83    def compute_consensus(self):
83        DNAMOTIF.count(self)84        DNAMOTIF.count(self)
84        print(self.counts)85        print(self.counts)
n85        length = len(self)n86        x = DNAMOTIF.__len__(self)
86        s = ""87        string = ""
87        for n in range(length):88        for i in range(x):
88            a = (self.counts['A'])[n]89            a = (self.counts['A'])[i]
89            c = (self.counts['C'])[n]90            c = (self.counts['C'])[i]
90            g = (self.counts['G'])[n]91            g = (self.counts['G'])[i]
91            t = (self.counts['T'])[n]92            t = (self.counts['T'])[i]
92            if (a > c and a > g and a > t):93            if (a > c and a > g and a > t):
n93                s = s + 'A'n94                string = string + 'A'
94            elif (c > a and c > g and c > t):95            elif (c > a and c > g and c > t):
n95                s = s + 'C'n96                string = string + 'C'
96            elif (g > c and g > a and g > t):97            elif (g > c and g > a and g > t):
n97                s = s + 'G'n98                string = string + 'G'
98            elif (t > c and t > g and t > a):99            elif (t > c and t > g and t > a):
n99                s = s + 'T'n100                string = string + 'T'
100        s =''.join([str(letter) for letter in s])101        string=''.join([str(letter) for letter in string])
101        self.consensus = s102        self.consensus = string
102    def parse(self, filename):103    def parse(self, filename):
103        f = open(filename, "r")104        f = open(filename, "r")
104        lines = f.readlines()105        lines = f.readlines()
105        f = open(filename, "w")106        f = open(filename, "w")
t106        for l in lines:t107        for line in lines:
107            if l[0] != '>':108            if line[0] != '>':
108                f.write(l)109                f.write(line)
109                self.instances.append(l)110                self.instances.append(line)
110        f.close()111        f.close()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 58

Student ID: 217, P-Value: 6.08e-02

Nearest Neighbor ID: 63

Student (left) and Nearest Neighbor (right).


nn1import numpy as np
1import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n2import mathn3import string
3class PLANT:4class PLANT:
n4    def __init__(self, string='', generator={}, n=0, deltaTheta=0):n5    def __init__(self, string='', generator={}, n=0, delta_theta=0.00):
5        self.string = string6        self.string = string
6        self.generator = generator7        self.generator = generator
n7        self.n = nn8        self.n = int(n) 
8        self.deltaTheta = math.radians(deltaTheta)9        self.deltatheta = np.radians(delta_theta)
9        for i in range(self.n):10        for i in range(0, self.n):
10            other=""11            string_update = ''
11            for char in self.string:12            for j in self.string:
12                if char in self.generator:13                if j in self.generator.keys():
13                    x = (self.generator).get(char)14                    string_update += self.generator[str(j)]
14                    other = other + str(x)
15                else:15                else:
n16                    other = other + str(char)n16                    string_update += j
17            new = other
18            final = other
19            other = ""
20            self.string = final17            self.string = string_update
21        self.str = self.string18        self.str = self.string
22    def drawPlant(self):19    def drawPlant(self):
n23        currentPt = [200,0]n20        currentpos=[200,0]
24        theta = math.radians(90)21        theta=np.radians(90)
22        ds=[]
25        nextPt = ()23        nextpt=()
26        drawingState = []
27        stack = []24        stack=[]
28        for char in self.str:25        for i in self.str:
29            if char.isalpha():26            if i.isalpha():
30                nextPt=[currentPt[0]+math.cos(theta), currentPt[1]+math.sin(thet27                nextpt=(currentpos[0]+np.cos(theta), currentpos[1]+np.sin(theta)
>a)]>)
31                plt.plot([currentPt[0], nextPt[0]],[currentPt[1],nextPt[1]],colo28                plt.plot([currentpos[0], nextpt[0]],[currentpos[1],nextpt[1]],co
>r='black')>lor='black')
32                currentPt=nextPt29                currentpos=nextpt
33            if char == '[':30            if i=='[':
34                drawingState = [currentPt, theta]31                ds = [currentpos, theta]
35                stack.append(drawingState)32                stack.append(ds)
36            elif char == ']':33            elif i==']':
37                currentPt=stack[-1][0]34                currentpos=stack[-1][0]
38                theta=stack[-1][1]35                theta=stack[-1][1]
39                stack.pop()36                stack.pop()
n40            elif char == '+':n37            elif i=='+':
41                theta = theta + self.deltaTheta38                theta += self.deltatheta
42            elif char == '-':39            elif i=='-':
43                theta = theta - self.deltaTheta40                theta -= self.deltatheta
44if __name__ == "__main__":41if __name__ == "__main__":
n45    myPlant = PLANT(input(), input(), input(), input())n42    string = input()
43    dictionary = input()
44    n = input()
45    theta = input()
46    obj = PLANT(string, dictionary, n, theta)
46    myPlant.drawPlant()47    obj.drawPlant()
47    plt.axis('image')48    plt.show()class DNAMOTIF:
48    plt.show()49    def __init__(self, instances=[], consensus=[], counts={'A': [], 'C': [], 'G'
 >:[],'T':[]}):
49class DNAMOTIF:
50    def __init__(self):
51        self.instances=[]50        self.instances = instances
52        self.consensus=[]51        self.consensus=consensus
53        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}52        self.counts= counts
54    def __str__(self):53    def __str__(self):
55        return self.instances54        return self.instances
56    def __len__(self):55    def __len__(self):
n57        x = 0n56        y = 0
58        for gene in self.instances:57        for value in self.instances:
59            x = len(gene) - 158            y = len(value) - 1
60        return x59        return y
61    def count(self):60    def count(self):
n62        gene = self.instances[0]n61        value = self.instances[0]
63        for i in range(len(gene)-1):62        for x in range(len(value)-1):
64            a = 063            a = 0
65            c = 064            c = 0
66            g = 065            g = 0
67            t = 066            t = 0
n68            for dna in self.instances:n67            for string in self.instances:
69                upp = dna.upper()68                upp = string.upper()
70                letter = dna[i]69                character = string[x]
71                if letter.upper() == 'A':70                if character.upper() == 'A':
72                    a += 171                    a += 1
n73                if letter.upper() == 'C':n72                if character.upper() == 'C':
74                    c += 173                    c += 1
n75                if letter.upper() == 'G':n74                if character.upper() == 'G':
76                    g += 175                    g += 1
n77                if letter.upper() == 'T':n76                if character.upper() == 'T':
78                    t += 177                    t += 1
79            self.counts['A'].append(a)78            self.counts['A'].append(a)
80            self.counts['C'].append(c)79            self.counts['C'].append(c)
81            self.counts['G'].append(g)80            self.counts['G'].append(g)
82            self.counts['T'].append(t)81            self.counts['T'].append(t)
83    def compute_consensus(self):82    def compute_consensus(self):
84        DNAMOTIF.count(self)83        DNAMOTIF.count(self)
85        print(self.counts)84        print(self.counts)
n86        x = DNAMOTIF.__len__(self)n85        length = len(self)
87        string = ""86        s = ""
88        for i in range(x):87        for n in range(length):
89            a = (self.counts['A'])[i]88            a = (self.counts['A'])[n]
90            c = (self.counts['C'])[i]89            c = (self.counts['C'])[n]
91            g = (self.counts['G'])[i]90            g = (self.counts['G'])[n]
92            t = (self.counts['T'])[i]91            t = (self.counts['T'])[n]
93            if (a > c and a > g and a > t):92            if (a > c and a > g and a > t):
n94                string = string + 'A'n93                s = s + 'A'
95            elif (c > a and c > g and c > t):94            elif (c > a and c > g and c > t):
n96                string = string + 'C'n95                s = s + 'C'
97            elif (g > c and g > a and g > t):96            elif (g > c and g > a and g > t):
n98                string = string + 'G'n97                s = s + 'G'
99            elif (t > c and t > g and t > a):98            elif (t > c and t > g and t > a):
n100                string = string + 'T'n99                s = s + 'T'
101        string=''.join([str(letter) for letter in string])100        s =''.join([str(letter) for letter in s])
102        self.consensus = string101        self.consensus = s
103    def parse(self, filename):102    def parse(self, filename):
104        f = open(filename, "r")103        f = open(filename, "r")
105        lines = f.readlines()104        lines = f.readlines()
106        f = open(filename, "w")105        f = open(filename, "w")
t107        for line in lines:t106        for l in lines:
108            if line[0] != '>':107            if l[0] != '>':
109                f.write(line)108                f.write(l)
110                self.instances.append(line)109                self.instances.append(l)
111        f.close()110        f.close()
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 59

Student ID: 386, P-Value: 7.10e-02

Nearest Neighbor ID: 193

Student (left) and Nearest Neighbor (right).


n1import numpy as np n1import numpy 
2import matplotlib.pyplot as plt 2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
n6        self.dictionary = dictionary n6        self.dictionary = dictionary
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string, dictionary, n)9        self.str = PLANT.generator(string, dictionary, n)
n10    def generator(string, dictionary, n):n10    def generator(line, dictionary, n):
11        def variable(string):11        def unknown(line):
12            if string in dictionary:12            if line in dictionary:
13                return dictionary.get(string)13                return dictionary.get(line)
14            return string14            return line
15        list_substring = [string]15        subparts = [line]
16        for i in range(n):16        for i in range(n):
n17            currentsub = list_substring[-1]n17            beginning = subparts[-1]
18            new_ax = [variable(char) for char in currentsub]18            middle = [unknown(quan) for quan in beginning]
19            list_substring.append(''.join(new_ax))19            subparts.append(''.join(middle))
20        new = list_substring[n]20        finish = subparts[n]
21        return new21        return finish
22    def drawPlant(self):22    def drawPlant(self):
n23        uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',n23        alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'
> 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>,'Q','R','S','T','U','V','W','X','Y','Z']
24        currPt = (200, 0)24        currentPt = (200,0)
25        theta = np.radians(90)25        theta = numpy.radians(90)
26        deltaTheta = np.radians(self.deltaTheta)26        deltaTheta = numpy.radians(self.deltaTheta)
27        st = [currPt, theta]27        stack = [currentPt, theta]
28        for commands in self.str:28        for offer in self.str:
29            if commands.upper() in uppercase:29            if offer.upper() in alpha:
30                nextPt = (currPt[0]+np.cos(theta), currPt[1]+np.sin(theta))30                nextPt = (currentPt[0]+(numpy.cos(theta)), currentPt[1]+(numpy.s
 >in(theta)))
31                plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='blac31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>k')>='black')
32                currPt = nextPt32                currentPt = nextPt
33            else:33            else: 
34                if commands == "[": 34                if offer == '[':
35                    st.append(currPt)35                    stack.append(currentPt)
36                    st.append(theta)36                    stack.append(theta)
37                elif commands == ']': 37                elif offer == ']':
38                    theta = st.pop()38                    theta = stack.pop()
39                    currPt = st.pop()39                    currentPt = stack.pop()
40                elif commands == '+': 40                elif offer == '+':
41                    theta += deltaTheta41                    theta += deltaTheta
n42                elif commands == '-': n42                elif offer == '-':
43                    theta -= deltaTheta43                    theta -= deltaTheta
44        return plt.plot44        return plt.plot
n45if __name__=='__main__':n45if __name__== "__main__":
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
n50    plant = PLANT(string, dictionary, n, deltaTheta)n50    p = PLANT(string, dictionary, n, deltaTheta)
51    plant.drawPlant()51    p.drawPlant()
52    plt.show()52    plt.show()
53class DNAMOTIF:53class DNAMOTIF:
54    def __init__(self):54    def __init__(self):
55        self.instances=[]55        self.instances=[]
56        self.consensus=[]56        self.consensus=[]
57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
58    def __str__(self):58    def __str__(self):
n59        str = ""n59        chain = ''
60        for inst in self.instances:60        for insta in self.instances:
61            mystr += inst61            chain += insta
62        return str62        return string
63    def __len__(self):63    def __len__(self):
n64        return len(self.instances[0].rstrip("\n"))n64        return len(self.instances[0].rstrip('\n'))  
65    def count(self):
66        for insta in range(self.__len__()):
67            countA = 0
68            countC = 0
69            countG = 0
70            countT = 0
71            for instances in self.instances:
72                if instances[insta].upper()   ==   'A':
73                    countA  +=  1
74                elif instances[insta].upper()   ==   'C':
75                    countC  +=  1
76                elif instances[insta].upper()   ==   'G':
77                    countG  +=  1
78                elif instances[insta].upper()   ==   'T':
79                    countT  +=  1
80            self.counts['A'].append(countA)
81            self.counts['C'].append(countC)
82            self.counts['G'].append(countG)
83            self.counts['T'].append(countT)
84    def compute_consensus(self):
85        self.counts = {'A': [],'C': [], 'G':[], 'T':[]}
86        self.count()
87        self.consensus = ''
88        for insta in range(self.__len__()):
89            ultimate = max([self.counts['A'][insta], self.counts['C'][insta], se
 >lf.counts['G'][insta], self.counts['T'][insta]])
90            if ultimate == self.counts['A'][insta]:
91                self.consensus += 'A'
92            elif ultimate == self.counts['C'][insta]:
93                self.consensus += 'C'
94            elif ultimate == self.counts['G'][insta]:
95                self.consensus += 'G'
96            elif ultimate == self.counts['T'][insta]:
97                self.consensus += 'T'
98        return self.consensus
65    def parse(self, filename):99    def parse(self, filename):
66        file = open(filename)100        file = open(filename)
67        lines = file.readlines()101        lines = file.readlines()
68        file.close()102        file.close()
t69        for lin in lines:t103        for line in lines:
70            if lin[0] != ">":104            if line[0] != '>':
71                self.instances.append(lin)105                self.instances.append(line)
72    def count(self):
73        for ind in range(self.__len__()):
74            numA = 0
75            numC = 0
76            numG = 0
77            numT = 0
78            for itm in self.instances:
79                if itm[ind].upper() == "A":
80                    numA += 1
81                elif itm[ind].upper() == "C":
82                    numC += 1
83                elif itm[ind].upper() == "G":
84                    numG += 1
85                elif itm[ind].upper() == "T":
86                    numT += 1
87            self.counts["A"].append(numA)
88            self.counts["C"].append(numC)
89            self.counts["G"].append(numG)
90            self.counts["T"].append(numT)
91    def compute_consensus(self):
92        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
93        self.count()
94        self.consensus = ""
95        for i in range(self.__len__()):
96            maxim = max([self.counts["A"][i], self.counts["C"][i], self.counts["
>G"][i], self.counts["T"][i]]) 
97            if maxim == self.counts["A"][i]:
98                self.consensus += "A"
99            elif maxim == self.counts["C"][i]:
100                self.consensus += "C"
101            elif maxim == self.counts["G"][i]:
102                self.consensus += "G"
103            elif maxim == self.counts["T"][i]:
104                self.consensus += "T"
105        return self.consensus
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 60

Student ID: 193, P-Value: 7.10e-02

Nearest Neighbor ID: 386

Student (left) and Nearest Neighbor (right).


n1import numpy n1import numpy as np 
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt 
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.string = string5        self.string = string
n6        self.dictionary = dictionaryn6        self.dictionary = dictionary 
7        self.n = n7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string, dictionary, n)9        self.str = PLANT.generator(string, dictionary, n)
n10    def generator(line, dictionary, n):n10    def generator(string, dictionary, n):
11        def unknown(line):11        def variable(string):
12            if line in dictionary:12            if string in dictionary:
13                return dictionary.get(line)13                return dictionary.get(string)
14            return line14            return string
15        subparts = [line]15        list_substring = [string]
16        for i in range(n):16        for i in range(n):
n17            beginning = subparts[-1]n17            currentsub = list_substring[-1]
18            middle = [unknown(quan) for quan in beginning]18            new_ax = [variable(char) for char in currentsub]
19            subparts.append(''.join(middle))19            list_substring.append(''.join(new_ax))
20        finish = subparts[n]20        new = list_substring[n]
21        return finish21        return new
22    def drawPlant(self):22    def drawPlant(self):
n23        alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'n23        uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
>,'Q','R','S','T','U','V','W','X','Y','Z']> 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
24        currentPt = (200,0)24        currPt = (200, 0)
25        theta = numpy.radians(90)25        theta = np.radians(90)
26        deltaTheta = numpy.radians(self.deltaTheta)26        deltaTheta = np.radians(self.deltaTheta)
27        stack = [currentPt, theta]27        st = [currPt, theta]
28        for offer in self.str:28        for commands in self.str:
29            if offer.upper() in alpha:29            if commands.upper() in uppercase:
30                nextPt = (currentPt[0]+(numpy.cos(theta)), currentPt[1]+(numpy.s30                nextPt = (currPt[0]+np.cos(theta), currPt[1]+np.sin(theta))
>in(theta))) 
31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='blac
>='black')>k')
32                currentPt = nextPt32                currPt = nextPt
33            else: 33            else:
34                if offer == '[':34                if commands == "[": 
35                    stack.append(currentPt)35                    st.append(currPt)
36                    stack.append(theta)36                    st.append(theta)
37                elif offer == ']':37                elif commands == ']': 
38                    theta = stack.pop()38                    theta = st.pop()
39                    currentPt = stack.pop()39                    currPt = st.pop()
40                elif offer == '+':40                elif commands == '+': 
41                    theta += deltaTheta41                    theta += deltaTheta
n42                elif offer == '-':n42                elif commands == '-': 
43                    theta -= deltaTheta43                    theta -= deltaTheta
44        return plt.plot44        return plt.plot
n45if __name__== "__main__":n45if __name__=='__main__':
46    string = input()46    string = input()
47    dictionary = input()47    dictionary = input()
48    n = int(input())48    n = int(input())
49    deltaTheta = float(input())49    deltaTheta = float(input())
n50    p = PLANT(string, dictionary, n, deltaTheta)n50    plant = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()51    plant.drawPlant()
52    plt.show()52    plt.show()
53class DNAMOTIF:53class DNAMOTIF:
54    def __init__(self):54    def __init__(self):
55        self.instances=[]55        self.instances=[]
56        self.consensus=[]56        self.consensus=[]
57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
58    def __str__(self):58    def __str__(self):
n59        chain = ''n59        str = ""
60        for insta in self.instances:60        for inst in self.instances:
61            chain += insta61            mystr += inst
62        return string62        return str
63    def __len__(self):63    def __len__(self):
n64        return len(self.instances[0].rstrip('\n'))  n64        return len(self.instances[0].rstrip("\n"))
65    def count(self):
66        for insta in range(self.__len__()):
67            countA = 0
68            countC = 0
69            countG = 0
70            countT = 0
71            for instances in self.instances:
72                if instances[insta].upper()   ==   'A':
73                    countA  +=  1
74                elif instances[insta].upper()   ==   'C':
75                    countC  +=  1
76                elif instances[insta].upper()   ==   'G':
77                    countG  +=  1
78                elif instances[insta].upper()   ==   'T':
79                    countT  +=  1
80            self.counts['A'].append(countA)
81            self.counts['C'].append(countC)
82            self.counts['G'].append(countG)
83            self.counts['T'].append(countT)
84    def compute_consensus(self):
85        self.counts = {'A': [],'C': [], 'G':[], 'T':[]}
86        self.count()
87        self.consensus = ''
88        for insta in range(self.__len__()):
89            ultimate = max([self.counts['A'][insta], self.counts['C'][insta], se
>lf.counts['G'][insta], self.counts['T'][insta]]) 
90            if ultimate == self.counts['A'][insta]:
91                self.consensus += 'A'
92            elif ultimate == self.counts['C'][insta]:
93                self.consensus += 'C'
94            elif ultimate == self.counts['G'][insta]:
95                self.consensus += 'G'
96            elif ultimate == self.counts['T'][insta]:
97                self.consensus += 'T'
98        return self.consensus
99    def parse(self, filename):65    def parse(self, filename):
100        file = open(filename)66        file = open(filename)
101        lines = file.readlines()67        lines = file.readlines()
102        file.close()68        file.close()
t103        for line in lines:t69        for lin in lines:
104            if line[0] != '>':70            if lin[0] != ">":
105                self.instances.append(line)71                self.instances.append(lin)
72    def count(self):
73        for ind in range(self.__len__()):
74            numA = 0
75            numC = 0
76            numG = 0
77            numT = 0
78            for itm in self.instances:
79                if itm[ind].upper() == "A":
80                    numA += 1
81                elif itm[ind].upper() == "C":
82                    numC += 1
83                elif itm[ind].upper() == "G":
84                    numG += 1
85                elif itm[ind].upper() == "T":
86                    numT += 1
87            self.counts["A"].append(numA)
88            self.counts["C"].append(numC)
89            self.counts["G"].append(numG)
90            self.counts["T"].append(numT)
91    def compute_consensus(self):
92        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
93        self.count()
94        self.consensus = ""
95        for i in range(self.__len__()):
96            maxim = max([self.counts["A"][i], self.counts["C"][i], self.counts["
 >G"][i], self.counts["T"][i]])
97            if maxim == self.counts["A"][i]:
98                self.consensus += "A"
99            elif maxim == self.counts["C"][i]:
100                self.consensus += "C"
101            elif maxim == self.counts["G"][i]:
102                self.consensus += "G"
103            elif maxim == self.counts["T"][i]:
104                self.consensus += "T"
105        return self.consensus
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 61

Student ID: 160, P-Value: 7.37e-02

Nearest Neighbor ID: 135

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as pltn1import matplotlib.pyplot as plt, math
2from math import sin, cos
3class PLANT:2class PLANT:
n4    def __init__(self, string, dictionary, n, deltaTheta):n3    def __init__(self, string = "", dictionary = {}, n = 0, deltaTheta = 0):
5        self.string = string4        self.str = string
6        self.dictionary = dictionary5        self.dictionary = dictionary
7        self.n = n6        self.n = n
8        self.deltaTheta = deltaTheta7        self.deltaTheta = deltaTheta
9    def __str__(self):8    def __str__(self):
n10        myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)n9        pass
11        myPlant.str =='abaababa'
12    def drawPlant(self):10    def drawPlant():
13        currPt = (200,0)11        currentPt=(200,0)
14        theta = 9012        theta = 90
n15        nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))n13        nextPt = (currentPt[0]+math.cos(theta), currentPt[1]+math.sin(theta))
14        return nextPt
15if __name__=="__main__":
16    currPt=(200,0)
17    theta = 90
18    nextPt = (currPt[0]+math.cos(theta), currPt[1]+math.sin(theta))
19    myPlant= PLANT(input())
16        plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black')20    plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black')
17        currentPt=nextPtclass DNAMOTIF:21    plt.axis('image')
22class DNAMOTIF:
18    def __init__(self):23    def __init__(self):
19        self.instances=[]24        self.instances=[]
20        self.consensus=[]25        self.consensus=[]
21        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
22    def __str__(self):27    def __str__(self):
n23        filename = 'lexA.fasta'n28        for n in f: 
24        with open(filename) as f:
25            for line in f:
26                if line[0] == '<':
27                    self.instances = self.instances
28                else:
29                    sequence = line.split()
30                    self.instances.append(sequence)29            self.instances.append(n)
31        return self.instances30        return(self.instances)
32        pass 
33    def __len__(self):31    def __len__(self):
n34        return len(self.instances[0])n32        return len("tAGGCTGATTT")
35    def count(self):33    def count(self):
n36        n = 0n
37        while n <= len(self.instances):
38            self.instances[n].upper()
39        pass 34        pass
40    def compute_consensus(self):35    def compute_consensus(self):
n41        pass n36        pass
42    def parse(self, filename):37    def parse(self, filename):
n43        i = 0n38        for n in self.instances:
44        while i<= len(self.instances):39            return(n,"/n")
45            return self.instances[i]
46if __name__ == "__main__":40if __name__=="__main__": 
41    file = input()
42    f = open(file)
47    lexA=DNAMOTIF()43    lexA=DNAMOTIF()
n48    lexA.parse("lexA.fasta")n44    lexA.parse(f)
49    print(len(lexA))45    print(len(lexA))
t50    def parse(self, filename):t46    lexA.count()
47    lexA.compute_consensus()
48    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 62

Student ID: 135, P-Value: 7.37e-02

Nearest Neighbor ID: 160

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as plt, mathn1import matplotlib.pyplot as plt
2from math import sin, cos
2class PLANT:3class PLANT:
n3    def __init__(self, string = "", dictionary = {}, n = 0, deltaTheta = 0):n4    def __init__(self, string, dictionary, n, deltaTheta):
4        self.str = string5        self.string = string
5        self.dictionary = dictionary6        self.dictionary = dictionary
6        self.n = n7        self.n = n
7        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
8    def __str__(self):9    def __str__(self):
n9        passn10        myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
11        myPlant.str =='abaababa'
10    def drawPlant():12    def drawPlant(self):
11        currentPt=(200,0)13        currPt = (200,0)
12        theta = 9014        theta = 90
n13        nextPt = (currentPt[0]+math.cos(theta), currentPt[1]+math.sin(theta))n15        nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))
14        return nextPt
15if __name__=="__main__":
16    currPt=(200,0)
17    theta = 90
18    nextPt = (currPt[0]+math.cos(theta), currPt[1]+math.sin(theta))
19    myPlant= PLANT(input())
20    plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black')16        plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='black')
21    plt.axis('image')17        currentPt=nextPtclass DNAMOTIF:
22class DNAMOTIF:
23    def __init__(self):18    def __init__(self):
24        self.instances=[]19        self.instances=[]
25        self.consensus=[]20        self.consensus=[]
26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}21        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
27    def __str__(self):22    def __str__(self):
n28        for n in f: n23        filename = 'lexA.fasta'
24        with open(filename) as f:
25            for line in f:
26                if line[0] == '<':
27                    self.instances = self.instances
28                else:
29                    sequence = line.split()
29            self.instances.append(n)30                    self.instances.append(sequence)
30        return(self.instances)31        return self.instances
32        pass 
31    def __len__(self):33    def __len__(self):
n32        return len("tAGGCTGATTT")n34        return len(self.instances[0])
33    def count(self):35    def count(self):
nn36        n = 0
37        while n <= len(self.instances):
38            self.instances[n].upper()
34        pass39        pass 
35    def compute_consensus(self):40    def compute_consensus(self):
n36        passn41        pass 
37    def parse(self, filename):42    def parse(self, filename):
n38        for n in self.instances:n43        i = 0
39            return(n,"/n")44        while i<= len(self.instances):
45            return self.instances[i]
40if __name__=="__main__": 46if __name__ == "__main__":
41    file = input()
42    f = open(file)
43    lexA=DNAMOTIF()47    lexA=DNAMOTIF()
n44    lexA.parse(f)n48    lexA.parse("lexA.fasta")
45    print(len(lexA))49    print(len(lexA))
t46    lexA.count()t50    def parse(self, filename):
47    lexA.compute_consensus()
48    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 63

Student ID: 166, P-Value: 1.14e-01

Nearest Neighbor ID: 249

Student (left) and Nearest Neighbor (right).


n1import mathn1import math 
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
n5        self.string = stringn5        self.string = string 
6        self.dictionary = dictionary6        self.dictionary = dictionary
n7        self.n = nn7        self.n = n 
8        self.str = self.string_generator()
9        self.deltaTheta = deltaTheta8        self.deltaTheta= deltaTheta
9        self.str = self.generator()
10    def string_generator(self):10    def generator(self):
11        for i in range(self.n):11        for i in range(self.n): 
12            new_string = ''12            string = ""
13            for j in range(len(self.string)):13            for x in self.string: 
14                if self.string[j] in self.dictionary:14                if in self.dictionary: 
15                    new_string += self.dictionary[self.string[j]]15                    string += self.dictionary[x]
16                else:16                else: 
17                    new_string += self.string[j]17                    string += x
18            self.string = new_string18            self.string = string
19        return self.string19        return self.string
20    def drawPlant(self):20    def drawPlant(self):
21        currentPt=(200,0)21        currentPt=(200,0)
22        theta = 9022        theta = 90
n23        stack = []n23        stack= []
24        for i in range(len(self.string)):24        for i in self.string: 
25            if self.string[i].isalpha():25            if i.isalpha():
26                nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[26               nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[1
>1]+math.sin(math.radians(theta)))>]+math.sin(math.radians(theta)))
27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27               plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color=
>='black')>'black')
28                currentPt = nextPt28               currentPt=nextPt
29            elif self.string[i] =='[':29            elif i =="[":
30                stack.append((currentPt,theta))30                stack.append((currentPt,theta))
n31            elif self.string[i] ==']':n31            elif  i =="]":
32                currentPt,theta = stack.pop()32                currentPt,theta = stack.pop()
n33            elif self.string[i] =='+':n33            elif i == '+':
34                theta += self.deltaTheta34                theta += self.deltaTheta
n35            elif self.string[i] =='-':n35            elif i == '-':
36                theta -= self.deltaTheta36                theta -= self.deltaTheta
nn37if __name__ == "__main__":
38    myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
39    print(myPlant.str =='abaababa')
37class DNAMOTIF:40class DNAMOTIF:
38    def __init__(self):41    def __init__(self):
39        self.instances=[]42        self.instances=[]
40        self.consensus=[]43        self.consensus=[]
41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}44        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):45    def __str__(self):
n43        for i in range(len(self.instances)):n46        pass
44            print(self.instances[i])
45    def __len__(self):47    def __len__(self):
n46        new = self.instances[0].strip()n48        return (len(self.instances) - 4)
47        length = len(new)
48        return length
49    def count(self):49    def count(self):
n50        self.counts['A'] = [2, 4, 0, 0, 0, 6, 1, 0, 2, 6, 2, 7, 4, 2, 3]n50       for x in range(15):
51        self.counts['C'] = [0, 0, 1, 0, 0, 0, 0, 5, 6, 1, 6, 1, 1, 0, 2]51           countA=0
52        self.counts['G'] = [4, 1, 4, 1, 0, 0, 1, 1, 0, 0, 0, 0, 3, 4, 2]52           countC=0
53        self.counts['T'] = [2, 3, 3, 7, 8, 2, 6, 2, 0, 1, 0, 0, 0, 2, 1]53           countG=0
54           countT=0
55           for col in self.instances:
56                if col[x] == 'A' or col[x]== 'a':
57                   countA+=1
58                if col[x] == 'C' or col[x]== 'c':
59                   countC+=1
60                if col[x] == 'G' or col[x]== 'g':
61                   countG+=1
62                if col[x] == 'T' or col[x]== 't':
63                   countT+=1
64           self.counts['A'] += [countA]
65           self.counts['C'] += [countC]
66           self.counts['G'] += [countG]
67           self.counts['T'] += [countT]
54        return self.counts68       return self.counts
55    def compute_consensus(self):69    def compute_consensus(self):
n56        self.consensus = 'TCAACTGAATT'n70        pass 
57        return self.consensus
58    def parse(self, filename):71    def parse(self, filename):
t59        f = open(filename)t72        with open(filename,'r') as f:
60        lines = f.readlines()
61        f.close()
62        for i in range(1,len(lines),2):
63            self.instances.append(lines[i])73            self.instances = f.readlines()[1::2]
64        print(self.instances)74            print(self.instances)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 64

Student ID: 249, P-Value: 1.14e-01

Nearest Neighbor ID: 166

Student (left) and Nearest Neighbor (right).


n1import math n1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
4    def __init__(self, string, dictionary, n, deltaTheta):4    def __init__(self, string, dictionary, n, deltaTheta):
n5        self.string = string n5        self.string = string
6        self.dictionary = dictionary6        self.dictionary = dictionary
n7        self.n = n n7        self.n = n
8        self.str = self.string_generator()
8        self.deltaTheta= deltaTheta9        self.deltaTheta = deltaTheta
9        self.str = self.generator()
10    def generator(self):10    def string_generator(self):
11        for i in range(self.n): 11        for i in range(self.n):
12            string = ""12            new_string = ''
13            for x in self.string: 13            for j in range(len(self.string)):
14                if in self.dictionary: 14                if self.string[j] in self.dictionary:
15                    string += self.dictionary[x]15                    new_string += self.dictionary[self.string[j]]
16                else: 16                else:
17                    string += x17                    new_string += self.string[j]
18            self.string = string18            self.string = new_string
19        return self.string19        return self.string
20    def drawPlant(self):20    def drawPlant(self):
21        currentPt=(200,0)21        currentPt=(200,0)
22        theta = 9022        theta = 90
n23        stack= []n23        stack = []
24        for i in self.string: 24        for i in range(len(self.string)):
25            if i.isalpha():25            if self.string[i].isalpha():
26               nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[126                nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[
>]+math.sin(math.radians(theta)))>1]+math.sin(math.radians(theta)))
27               plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color=27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>'black')>='black')
28               currentPt=nextPt28                currentPt = nextPt
29            elif i =="[":29            elif self.string[i] =='[':
30                stack.append((currentPt,theta))30                stack.append((currentPt,theta))
n31            elif  i =="]":n31            elif self.string[i] ==']':
32                currentPt,theta = stack.pop()32                currentPt,theta = stack.pop()
n33            elif i == '+':n33            elif self.string[i] =='+':
34                theta += self.deltaTheta34                theta += self.deltaTheta
n35            elif i == '-':n35            elif self.string[i] =='-':
36                theta -= self.deltaTheta36                theta -= self.deltaTheta
n37if __name__ == "__main__":n
38    myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
39    print(myPlant.str =='abaababa')
40class DNAMOTIF:37class DNAMOTIF:
41    def __init__(self):38    def __init__(self):
42        self.instances=[]39        self.instances=[]
43        self.consensus=[]40        self.consensus=[]
44        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
45    def __str__(self):42    def __str__(self):
n46        passn43        for i in range(len(self.instances)):
44            print(self.instances[i])
47    def __len__(self):45    def __len__(self):
n48        return (len(self.instances) - 4)n46        new = self.instances[0].strip()
47        length = len(new)
48        return length
49    def count(self):49    def count(self):
n50       for x in range(15):n50        self.counts['A'] = [2, 4, 0, 0, 0, 6, 1, 0, 2, 6, 2, 7, 4, 2, 3]
51           countA=051        self.counts['C'] = [0, 0, 1, 0, 0, 0, 0, 5, 6, 1, 6, 1, 1, 0, 2]
52           countC=052        self.counts['G'] = [4, 1, 4, 1, 0, 0, 1, 1, 0, 0, 0, 0, 3, 4, 2]
53           countG=053        self.counts['T'] = [2, 3, 3, 7, 8, 2, 6, 2, 0, 1, 0, 0, 0, 2, 1]
54           countT=0
55           for col in self.instances:
56                if col[x] == 'A' or col[x]== 'a':
57                   countA+=1
58                if col[x] == 'C' or col[x]== 'c':
59                   countC+=1
60                if col[x] == 'G' or col[x]== 'g':
61                   countG+=1
62                if col[x] == 'T' or col[x]== 't':
63                   countT+=1
64           self.counts['A'] += [countA]
65           self.counts['C'] += [countC]
66           self.counts['G'] += [countG]
67           self.counts['T'] += [countT]
68       return self.counts54        return self.counts
69    def compute_consensus(self):55    def compute_consensus(self):
n70        pass n56        self.consensus = 'TCAACTGAATT'
57        return self.consensus
71    def parse(self, filename):58    def parse(self, filename):
t72        with open(filename,'r') as f:t59        f = open(filename)
60        lines = f.readlines()
61        f.close()
62        for i in range(1,len(lines),2):
73            self.instances = f.readlines()[1::2]63            self.instances.append(lines[i])
74            print(self.instances)64        print(self.instances)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 65

Student ID: 244, P-Value: 1.25e-01

Nearest Neighbor ID: 398

Student (left) and Nearest Neighbor (right).


nn1import matplotlib.pyplot as plt
1from math import cos,sin,radians2from math import cos,sin,radians
n2import matplotlib.pyplot as pltn
3class PLANT:3class PLANT:
n4    def __init__(self,int,gen,n,deltaTheta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.int=int5        self.string = string
6        self.gen=gen6        self.dictionary = dictionary
7        self.n=n7        self.n = n
8        self.deltaTheta=deltaTheta8        self.deltaTheta = radians(deltaTheta)
9        state = self.int9        new = ''
10        for i in range(0,n):10        for _ in range(n):
11            newstr = ''11            for symbol in self.string:
12            for j in state:12                if symbol in dictionary:
13                if j in self.gen.keys():13                    new += dictionary[symbol]
14                    newstr += self.gen[j]
15                else:14                else:
n16                    newstr += jn15                    new += symbol
17            state = newstr16            self.string = new
17            new = ''
18        self.str = state18        self.str = self.string
19    def drawPlant(self):19    def drawPlant(self):
nn20        dogwater = []
20        currentPt=(200,0)21        currentPt=(200,0)
n21        theta = 90n22        theta = radians(90)
22        stack = []
23        for k in self.str:23        for i in self.str:
24            if (ord(k) >= ord('A') and ord(k) <= ord('Z')) or (ord(k) >= ord('a'24            if i.isalpha():
>) and ord(k) <= ord('z')): 
25                nextPt = (currentPt[0]+cos(radians(theta)), currentPt[1]+sin(rad25                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))
>ians(theta))) 
26                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color26                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
27                currentPt = nextPt27                currentPt = nextPt
n28            if k == '[':n28            elif i == '[':
29                stack.append(theta)
30                stack.append(currentPt)29                dogwater.append(currentPt)
30                dogwater.append(theta)
31            if k == ']':31            elif i == ']':
32                theta = dogwater.pop(-1)
32                currentPt = stack.pop(-1)33                currentPt = dogwater.pop(-1)
33                theta = stack.pop(-1)   
34            if k == '+':34            elif i == '+':
35                theta += self.deltaTheta35                theta += self.deltaTheta
n36            if k == '-':n36            elif i == '-':
37                theta -= self.deltaTheta37                theta -= self.deltaTheta
nn38        plt.savefig('my_plot.png')
38if __name__ == '__main__':39if __name__=='__main__':
39    myPlant=PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)40    myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)
40    myPlant.drawPlant()41    myPlant.drawPlant()
n41    plt.axis('image')n42class DNAMOTIF:
42    plt.show()class DNAMOTIF:
43    def __init__(self):43    def __init__(self):
44        self.instances=[]44        self.instances=[]
45        self.consensus=[]45        self.consensus=[]
46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
47    def __str__(self):47    def __str__(self):
n48        instant = ''n48        dogwater = ''
49        for i in self.instances:49        for _ in self.instances:
50            instant += f'{i}'50            dogwater = dogwater + f'{_}'
51        return instant51        return dogwater
52    def __len__(self):52    def __len__(self):
53        return (len(self.instances[1])-1)53        return (len(self.instances[1])-1)
54    def count(self):54    def count(self):
n55        for n in range(0,(len(self.instances)+7)):n55        for w in range(0,(len(self.instances[1])-1)):
56            A = 056            A = 0
57            C = 057            C = 0
58            G = 058            G = 0
59            T = 059            T = 0
n60            for seq in self.instances:n60            for m in self.instances:
61                seq = seq.upper()61                m = m.upper()
62                if seq[n] == 'A':62                if m[w] == 'A':
63                    A += 163                    A += 1
n64                if seq[n] == 'C':n64                if m[w] == 'C':
65                    C += 165                    C += 1
n66                if seq[n] == 'G':n66                if m[w] == 'G':
67                    G += 167                    G += 1
n68                if seq[n] == 'T':n68                if m[w] == 'T':
69                    T += 169                    T += 1
70            self.counts['A'].append(A)70            self.counts['A'].append(A)
71            self.counts['C'].append(C)71            self.counts['C'].append(C)
72            self.counts['G'].append(G)72            self.counts['G'].append(G)
73            self.counts['T'].append(T)73            self.counts['T'].append(T)
74    def compute_consensus(self):74    def compute_consensus(self):
n75        for m in range(0,(len(self.counts))):n75        for z in range((len(self.instances[0])-1),(len(self.instances[1])-1)):
76            numA = self.counts['A'][m]76            countA = self.counts['A'][z]
77            numC = self.counts['C'][m]77            countC = self.counts['C'][z]
78            numG = self.counts['G'][m]78            countG = self.counts['G'][z]
79            numT = self.counts['T'][m]79            countT = self.counts['T'][z]
80            if numA >= numC and numA >= numG and numA >= numT:80            if countA >= countC and countA >= countG and countA >= countT:
81                self.consensus.append('A')81                self.consensus.append('A')
n82            elif numC >= numA and numC >= numG and numC >= numT:n82            if countC >= countA and countC >= countG and countC >= countT:
83                self.consensus.append('C')83                self.consensus.append('C')
n84            elif numG >= numC and numG >= numA and numG >= numT:n84            if countG >= countA and countG >= countC and countG >= countT:
85                self.consensus.append('G')85                self.consensus.append('G')
n86            elif numT >= numC and numT >= numG and numT >= numA:n86            if countT >= countC and countT >= countG and countT >= countA:
87                self.consensus.append('T')87                self.consensus.append('T')
88        consensus = ''88        consensus = ''
n89        for k in self.consensus:n89        for l in self.consensus:
90            consensus += k90            consensus += l
91        self.consensus = consensus
92        self.consensus = 'TCAACTGAATT'
93        return consensus
91    def parse(self, filename):94    def parse(self, filename):
92        with open(filename, 'r') as content:95        with open(filename, 'r') as content:
93            for word in content:96            for word in content:
94                if word[0] != '>':97                if word[0] != '>':
95                    self.instances.append(word)98                    self.instances.append(word)
tt99student = 'TCAACTGAATT'
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 66

Student ID: 398, P-Value: 1.25e-01

Nearest Neighbor ID: 244

Student (left) and Nearest Neighbor (right).


nn1from math import cos,sin,radians
1import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n2from math import cos,sin,radiansn
3class PLANT:3class PLANT:
n4    def __init__(self, string, dictionary, n, deltaTheta):n4    def __init__(self,int,gen,n,deltaTheta):
5        self.strin= string5        self.int=int
6        self.dictionary = dictionary6        self.gen=gen
7        self.n = n7        self.n=n
8        self.deltaTheta = radians(deltaTheta)8        self.deltaTheta=deltaTheta
9        new = ''9        state = self.int
10        for _ in range(n):10        for i in range(0,n):
11            for symbol in self.string:11            newstr = ''
12                if symbol in dictionary:12            for j in state:
13                    new += dictionary[symbol]13                if j in self.gen.keys():
14                    newstr += self.gen[j]
14                else:15                else:
n15                    new += symboln16                    newstr += j
16            self.string = new17            state = newstr
17            new = ''
18        self.str = self.string18        self.str = state
19    def drawPlant(self):19    def drawPlant(self):
n20        dogwater = []n
21        currentPt=(200,0)20        currentPt=(200,0)
n22        theta = radians(90)n21        theta = 90
22        stack = []
23        for i in self.str:23        for k in self.str:
24            if i.isalpha():24            if (ord(k) >= ord('A') and ord(k) <= ord('Z')) or (ord(k) >= ord('a'
 >) and ord(k) <= ord('z')):
25                nextPt = (currentPt[0]+cos(theta), currentPt[1]+sin(theta))25                nextPt = (currentPt[0]+cos(radians(theta)), currentPt[1]+sin(rad
 >ians(theta)))
26                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color26                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
27                currentPt = nextPt27                currentPt = nextPt
n28            elif i == '[':n28            if k == '[':
29                stack.append(theta)
29                dogwater.append(currentPt)30                stack.append(currentPt)
30                dogwater.append(theta)
31            elif i == ']':31            if k == ']':
32                theta = dogwater.pop(-1)
33                currentPt = dogwater.pop(-1)32                currentPt = stack.pop(-1)
33                theta = stack.pop(-1)   
34            elif i == '+':34            if k == '+':
35                theta += self.deltaTheta35                theta += self.deltaTheta
n36            elif i == '-':n36            if k == '-':
37                theta -= self.deltaTheta37                theta -= self.deltaTheta
n38        plt.savefig('my_plot.png')n
39if __name__=='__main__':38if __name__ == '__main__':
40    myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)39    myPlant=PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)
41    myPlant.drawPlant()40    myPlant.drawPlant()
n42class DNAMOTIF:n41    plt.axis('image')
42    plt.show()class DNAMOTIF:
43    def __init__(self):43    def __init__(self):
44        self.instances=[]44        self.instances=[]
45        self.consensus=[]45        self.consensus=[]
46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
47    def __str__(self):47    def __str__(self):
n48        dogwater = ''n48        instant = ''
49        for _ in self.instances:49        for i in self.instances:
50            dogwater = dogwater + f'{_}'50            instant += f'{i}'
51        return dogwater51        return instant
52    def __len__(self):52    def __len__(self):
53        return (len(self.instances[1])-1)53        return (len(self.instances[1])-1)
54    def count(self):54    def count(self):
n55        for w in range(0,(len(self.instances[1])-1)):n55        for n in range(0,(len(self.instances)+7)):
56            A = 056            A = 0
57            C = 057            C = 0
58            G = 058            G = 0
59            T = 059            T = 0
n60            for m in self.instances:n60            for seq in self.instances:
61                m = m.upper()61                seq = seq.upper()
62                if m[w] == 'A':62                if seq[n] == 'A':
63                    A += 163                    A += 1
n64                if m[w] == 'C':n64                if seq[n] == 'C':
65                    C += 165                    C += 1
n66                if m[w] == 'G':n66                if seq[n] == 'G':
67                    G += 167                    G += 1
n68                if m[w] == 'T':n68                if seq[n] == 'T':
69                    T += 169                    T += 1
70            self.counts['A'].append(A)70            self.counts['A'].append(A)
71            self.counts['C'].append(C)71            self.counts['C'].append(C)
72            self.counts['G'].append(G)72            self.counts['G'].append(G)
73            self.counts['T'].append(T)73            self.counts['T'].append(T)
74    def compute_consensus(self):74    def compute_consensus(self):
n75        for z in range((len(self.instances[0])-1),(len(self.instances[1])-1)):n75        for m in range(0,(len(self.counts))):
76            countA = self.counts['A'][z]76            numA = self.counts['A'][m]
77            countC = self.counts['C'][z]77            numC = self.counts['C'][m]
78            countG = self.counts['G'][z]78            numG = self.counts['G'][m]
79            countT = self.counts['T'][z]79            numT = self.counts['T'][m]
80            if countA >= countC and countA >= countG and countA >= countT:80            if numA >= numC and numA >= numG and numA >= numT:
81                self.consensus.append('A')81                self.consensus.append('A')
n82            if countC >= countA and countC >= countG and countC >= countT:n82            elif numC >= numA and numC >= numG and numC >= numT:
83                self.consensus.append('C')83                self.consensus.append('C')
n84            if countG >= countA and countG >= countC and countG >= countT:n84            elif numG >= numC and numG >= numA and numG >= numT:
85                self.consensus.append('G')85                self.consensus.append('G')
n86            if countT >= countC and countT >= countG and countT >= countA:n86            elif numT >= numC and numT >= numG and numT >= numA:
87                self.consensus.append('T')87                self.consensus.append('T')
88        consensus = ''88        consensus = ''
n89        for l in self.consensus:n89        for k in self.consensus:
90            consensus += l90            consensus += k
91        self.consensus = consensus
92        self.consensus = 'TCAACTGAATT'
93        return consensus
94    def parse(self, filename):91    def parse(self, filename):
95        with open(filename, 'r') as content:92        with open(filename, 'r') as content:
96            for word in content:93            for word in content:
97                if word[0] != '>':94                if word[0] != '>':
98                    self.instances.append(word)95                    self.instances.append(word)
t99student = 'TCAACTGAATT't
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 67

Student ID: 393, P-Value: 1.25e-01

Nearest Neighbor ID: 105

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as pltn1plt.style.use('bmh')
2plt.plot(
3    [0,1,2]
4    [0,1,0]
5)
6plt.xlabel('x')
7plt.ylabel('y');
8def plot_coords(coords,bare_plot=False):
9    if bae_plot:
10        plt.axis('off')
11    plt.axes().set_apsect('equal','datalim')
12    X,Y = zip(coords)
13    plt.plot(X,Y);
14plot_coords([
15    (0,0),
16    (1,0),
17    (2,1),
18    (3,1),
19    (2,0)
20])
21nan = float('nan')
22plot_coords([
23    (0,0),
24    (1,1),
25    (nan,nan),
26    (1,0),
27    (2,1)
28])
2from math import pi, sin, cos29from math import pi, sin, cos
n3from math import isnann
4plt.plot([0,1,2],[0,1,0])
5plt.xlabel('x')
6plt.ylabel('y')
7def plot_coordinates(cooridnates, bare_plot=False):
8    if bare_plot:
9        plt.axis('off')
10    plt.axes().set_aspect('equal','datalim')
11    X,Y = zip(*coordinates)
12    plt.plot(X,Y)
13plot_coordinates([(0,0),(1,0),(2,1),(3,1),(2,0)])
14nan = float('nan')
15plot_coordinates([(0,0),(1,1),(nan,nan),(1,0),(2,1)])
16deg_to_rad = pi/18030deg_to_rad = pi / 180
17def direction_to_coordinates(direction_program,turn_amount=45):31def turtle_to_coords(turtle_program,turn_amount=45):
18    state = (0.0,0.0,90.0)32    state = (0.0,0.0,90.0)
n19    yield(0.0,0.0)n33    yield (0.0,0.0)
20    for command in direction_program:34    for command in turtle_program:
21        x,y,angle=state35        x,y, angle = state
22        if command in'Ff':36        if command in 'Ff':
23            state = (x-cos(angle*deg_to_rad),y+sin(angle*deg_to_rad),angle)37            state = (x - cos(angle * deg_to_rad),
38                y + sin(angle * deg_to_rad),
39                angle)
24            if command == 'f':40            if command == 'f':
25                yield(float('nan'),float('nan'))41                yield(float('nan'),float('nan'))
26            yield(state[0],state[1])42            yield(state[0],state[1])
27        elif command =='+':43        elif command =='+':
n28            state = (x,y, angle+turn_amount)n44            state = (x,y,angle + turn_amount)
29        elif command == '-':45        elif command == '-':
n30            state = (x,y,angle-turn_amount)n46            state = (x,y,angle - turn_amount)
31plot_coordinates(direction_to_coordinates('FfF++FfF++FfF++FfF'))47plot_coords(turtle_to_coords('FfF++FfF++FfF++FfF'))
32plot_coordinates(direction_to_coordinates('F-F+F+F+f+F+F+F-F'))48plot_coords(turtle_to_coords('F-F+F+F+F+f+F+F+F-F'))
49from math import isnan
33def print_coordinates(coordinates):50def print_coords(coords):
34    for (x,y) in coordinates:51    for (x,y) in coords:
35        if isnan(x):52        if isnan(x):
36            print('<gap>')53            print('<gap>')
37        else:54        else:
38            print('({:.2f},{:.2f}'.format(x,y))55            print('({:.2f},{:.2f}'.format(x,y))
n39print_coordinates(direction_to_coordinates('F-F+F+F+f+F+F+F-F'))n56print_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F'))
40print_coordinates(direction_to_coordinates('F-F+F+F+f+F+F+F-F',65))57plot_coords(turtle_to_coords('F-F+F+F+f+F+F+F-F',65))
41def transform_sequence(sequence,transformations):58def transform_sequence(sequence,transformations):
n42    return ".join(transformations.get(c,c) for c in sequence)n59    return ''.join(transformations.get(c, c) for c in sequence)
43transform_sequence('acab',{'a':'aba','c':'bb'})60transform_sequence('acab',{'a':'aba','c':'bb'})
n44plot_coordinates(direction_to_coordinates(transform_sequence('FFFF',{'F':'FfF++'n61plot_coords(turtle_to_coords(transform_sequece('FFFF',{'F':'FfF++'})))
>}))) 
45def transform_multiple(sequence,transformations,iterations):62def transfomr_multiple(sequence,transformations,iterations):
46    for_in range(iterations):63    for _ in range(iterations):
47        sequence = transform_sequence(sequence,transformations)64        sequence = transform_seqence(sequence,transformations)
48        return sequence 65    return sequence
49print('0:', transform_multiple('abba', {'b': 'bab'}, 0))66print('0:',transform_multiple('abba',{'b':'bab'},0))
50print('1:', transform_multiple('abba', {'b': 'bab'}, 1))67print('1:',transform_multiple('abba',{'b':'bab'},1))
51print('2:', transform_multiple('abba', {'b': 'bab'}, 2))68print('2:',transform_multiple('abba',{'b':'bab'},2))
52plot_coordinates(direction_to_coordinates(transform_multiple('F', {'F': '+F+F--F69plot_coords(turtle_to_coords(transform_multiple('F',{'F':'+F+F--F+F'},5)))
>+F'}, 5))) 
53plot_coordinates(direction_to_coordinates(transform_multiple('L',{'L': '-RF+LFL+70plot_coords(turtle_to_coords(transform_multiple('L',{
>FR-','R':'+LF-RFR-FL+'}, 5), 90)) 
71    'L': '-RF+LFL+FR-',
72    'R': '+LF-RFR-FL+'
73},5),90))
54def branching_direction_to_coordinates(direction_program,turn_amount=45):74def branching_turtle_to_coords(turtle_program,turn_amount=45):
55    saved_states=list()75    saved_states = list()
56    state=(0,0,90)76    state = (0,0,90)
57    yield(0,0)77    yield(0,0)
n58    for command in direction_program:n78    for command in turtle_program:
59        x,y,angle = state79        x,y,angle = state
n60        if command.lower() in 'abcdefghij':n80        if command.lower() in 'abcdefghuj':
61            state = (x-cos(angle*deg_to_rad),81            state = (c-cose(angle * deg_to_rad),
62            y+sin(angle*deg_to_rad),angle)82                y + sin(angle * deg_to_rad),
83                angle)
63            if command.islower():84            if command.islower():
n64                yield(float('nan'),float('nan')n85                yield(float('nan'),float('nan'))
65            yield(state[0],state[1])86            yield(state[0],state[1])
n66        elif command =='+':n87        elif command == '+':
67            state = (x,y,angle+turn_amount)88            state = (x,y,angle + turn_amount)
68        elif command =='-':89        elif command =='-':
n69            state = (x,y, angle-turn_amount)n90            state = (x,y,angle - turn_amount)
70        elif command == '[':91        elif command == '[':
71            saved_states.append(state)92            saved_states.append(state)
72        elif command == ']':93        elif command == ']':
n73            sate = saved_states.pop()n94            state = saved_states.pop()
74            yield (float('nan'),float('nan'))95            yield(float('nan'),float('nan'))
75            x,y,_=state96            x,y,_ = state
76            yield(x,y)
77plot_cooridnates(branching_direction_to_coordinates('F[-F]+F', 45))97plot_coords(branching_turtle_to_coords('F[-F]+F',45))
78def l_plot(axiom, transformations, iterations=0, angle=45):98def l_plot(axiom,transformations,iterations=0,angle=45):
79    direction_program = transform_multiple(axiom,transformations,iterations)99    turtle_program = transform_multiple(axiom,transformations,iterations)
80    coordinates = branching_direction_to_coordinates(direction_program,angle)100    coords = branching_turtle_to_coords(turtle_program,angle)
81    plot_coordinates(coordinates,bare_plot=True)101    plot_coords(coords,bare_plot=True)
82l_plot('F', {'F': 'F[-F][+F]'}, 4, 30)102l_plot('F',{'F[-F][+F]'},4,30)
83l_plot('F', {'F': 'FF[++F][-FF]'}, 5, 22)103l_plot('F',{'F':'FF[++F][-FF]'},5,22)
84for i in range(5):104for i in range(5):
85    print('{}:'.format(i),105    print('{}:'.format(i),
n86        transform_multiple('A':'F+A'},i))n106        transform_multiple('A',{'A':'F+A'},i))
87for i in range(5):107for i in range(5):
88    print('{}:'.format(i),108    print('{}:'.format(i),
89        transform_multiple('A',{'A':'F+A','F':'FF'},i))109        transform_multiple('A',{'A':'F+A','F':'FF'},i))
n901_plot('A', {'F': 'FF', 'A': 'F[+AF-[A]--A][---A]'}, 5, 22.5)n110l_plot('A',{'F':'FF','A':'F[+AF-[A]--A][---A]'},5,22.5)class DNAMOTIF:
91class DNAMOTIF:
92    def __init__(self):111    def __init__(self):
93        self.instances=[]112        self.instances=[]
94        self.consensus=[]113        self.consensus=[]
95        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}114        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
96    def __str__(self):115    def __str__(self):
n97        motif = ''n116        string = ""
98        for i in range(len(self.instances)):117        for i in self.instances:
99            motif += (self.instances[i])118            string += i + ""
100        return (motif)119            return string[:-2]
101    def __len__(self):120    def __len__(self):
n102        return(len(self.instances[0])-1)n121        return len(self.instances)
103    def count(self):122    def count(self):
n104        for index in range(len(self.instances[0])-1):n
105            self.counts['A'].append(0)
106            self.counts['C'].append(0)
107            self.counts['G'].append(0)
108            self.counts['T'].append(0)
109            for line in self.instances:123        for in self.instances:
110                letter = line[index].upper()124            temp = i.upper()
111                self.counts[letter][index] += 1125        self.counts["A"].append(temp.count("A"))
126        self.counts["C"].append(temp.count("C"))
127        self.counts["G"].append(temp.count("G"))
128        self.counts["T"].append(temp.count("T"))
112    def compute_consensus(self):129    def compute_consensus(self):
n113        self.count()n130        A = self.counts["A"]
114        most_frequent =''131        C = self.counts["C"]
115        for index in range(len(self.instances[0])-1):132        G = self.counts["G"]
116            highest = (self.counts['A'][index],'A')133        T = self.counts["T"]
117            if self.counts['C'][index] > highest[0]:134        for i in range(len(A)):
118                highest = (self.counts['C'][index],'C')135            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
119            if self.counts['G'][index] > highest[0]:136                self.consensus.append("A")
120                highest = (self.counts['G'][index],'G')137            elif (C[i] >= G[i] and C[i] >= T[i]):
121            if self.counts['T'][index] > highest[0]:138                self.consensus.append("C")
122                highest = (self.counts['T'][index], 'T')139            elif (G[i] >= T[i]):
123            most_frequent += highest[1]140                self.consensus.append("G")
124        self.consensus = most_frequent141            else:
142                self.consensus.append("T")
125    def parse(self, filename):143    def parse(self, filename):
n126        with open(filename, 'r') as f:n144        with open(filename,'r') as f:
127            for line in f:145            for in f:
128                if line[0] == '>':146                if ">" in i:
129                    pass147                    continue
130                else:148                else:
t131                    self.instances.append(line)t149                    self.instances.append(i)
132if __name__ == '__main__':
133    lexA=DNAMOTIF()150lexA = DNAMOTIF()
134    lexA.parse("lexA.fasta")151lexA.parse("lexA.fasta")
135    lexA.compute_consensus()152print(len(lexA))
136    print(lexA.consensus)15319
154lexA = DNAMOTIF()
155lexA.parse("lexA.fasta")
156print(lexA)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 68

Student ID: 431, P-Value: 1.31e-01

Nearest Neighbor ID: 249

Student (left) and Nearest Neighbor (right).


n1import mathn1import math 
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self,state,gen,num,deltaTheta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        self.state = state5        self.string = string 
6        self.dictionary = dictionary
6        self.gen = gen7        self.n = n 
7        self.num = num
8        self.deltaTheta = deltaTheta8        self.deltaTheta= deltaTheta
9        self.str = self.generate_str()9        self.str = self.generator()
10    def generate_str(self):10    def generator(self):
11        string = ""
12        for x in range(self.num):11        for i in range(self.n): 
13            for c in self.state:
14                if c in self.gen:
15                    string += self.gen[c]
16                else:
17                    string += c
18            self.state = string
19            string = ""12            string = ""
nn13            for x in self.string: 
14                if x in self.dictionary: 
15                    string += self.dictionary[x]
16                else: 
17                    string += x
18            self.string = string
20        return self.state19        return self.string
21    def drawPlant(self):20    def drawPlant(self):
n22        currentPt = (200,0)n21        currentPt=(200,0)
23        theta = 9022        theta = 90
n24        stack = []n23        stack= []
25        for i in self.str:24        for i in self.string: 
26            if i.isalpha():25            if i.isalpha():
n27                nextPt = (currentPt[0]+ math.cos(math.radians(theta)), currentPtn26               nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[1
>[1] + math.sin(math.radians(theta)))>]+math.sin(math.radians(theta)))
28                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27               plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color=
>='black')>'black')
29                currentPt = nextPt28               currentPt=nextPt
30            else:
31                if i == '[':29            elif i =="[":
32                    stack.append((currentPt,theta))30                stack.append((currentPt,theta))
33                if i == ']':31            elif  i =="]":
34                    currentPt,theta = stack.pop()32                currentPt,theta = stack.pop()
35                if i == '+':33            elif i == '+':
36                    theta += self.deltaTheta34                theta += self.deltaTheta
37                if i == '-':35            elif i == '-':
38                    theta -= self.deltaTheta36                theta -= self.deltaTheta
39if __name__ == '__main__':37if __name__ == "__main__":
40    myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)
41    print(myPlant.str)
42    myPlant2 = PLANT('b', {'b':'a', 'a':'ab'},5,25)38    myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
43    print(myPlant2.str)39    print(myPlant.str =='abaababa')
44class DNAMOTIF:40class DNAMOTIF:
45    def __init__(self):41    def __init__(self):
46        self.instances=[]42        self.instances=[]
47        self.consensus=[]43        self.consensus=[]
48        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}44        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
49    def __str__(self):45    def __str__(self):
n50        for x in self.instances:n46        pass
51            string += x
52        return string
53    def __len__(self):47    def __len__(self):
n54        return len(self.instances[0])-1n48        return (len(self.instances) - 4)
55    def count(self):49    def count(self):
n56        for i in range(len(self.instances[0])-1):n50       for x in range(15):
57            A = 051           countA=0
58            C = 052           countC=0
59            G = 053           countG=0
60            T = 054           countT=0
61            for lines in self.instances:55           for col in self.instances:
62                char = lines[i].upper()56                if col[x] == 'A' or col[x]== 'a':
63                if char == "A":
64                    A+=157                   countA+=1
65                elif char == "C":58                if col[x] == 'C' or col[x]== 'c':
66                    C+=159                   countC+=1
67                elif char =="G":60                if col[x] == 'G' or col[x]== 'g':
68                    G+=161                   countG+=1
69                elif char == "T":62                if col[x] == 'T' or col[x]== 't':
70                    T+=163                   countT+=1
71            self.counts["A"].append(A)64           self.counts['A'] += [countA]
72            self.counts["C"].append(C)65           self.counts['C'] += [countC]
73            self.counts["G"].append(G)66           self.counts['G'] += [countG]
74            self.counts["T"].append(T)67           self.counts['T'] += [countT]
75        string = ''68       return self.counts
69    def compute_consensus(self):
70        pass 
76    def parse(self, filename):71    def parse(self, filename):
t77        f = open(filename)t72        with open(filename,'r') as f:
78        lines = f.readlines()73            self.instances = f.readlines()[1::2]
79        for x in lines:74            print(self.instances)
80            if ">" not in x:
81                self.instances.append(x)
82if __name__ == "__main__":
83    pass
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 69

Student ID: 130, P-Value: 1.39e-01

Nearest Neighbor ID: 434

Student (left) and Nearest Neighbor (right).


n1from math import radians, cos, sinn1from math import radians,cos,sin 
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, carpet = '', rugs = {}, crocs = 0, vans = 0):n4    def __init__ (self, inital_state, generator =[], iterations= 0 , angle = 0):
5        self.carpet = carpet5        self.inital_state = inital_state
6        self.rugs = rugs6        self.generator = generator
7        self.crocs = crocs7        self.iterations = iterations
8        self.vans = vans8        self.angle = angle
9        answers = ''9        answers = ""
10        for i in range(crocs):10        for l in range(iterations):
11            for token in carpet:11            for i in inital_state:
12                if token in rugs:12                if i in generator:
13                    answers = answers + str(rugs[token])13                    answers += (generator[i])
14                else:14                else:
n15                    answers = answers + tokenn15                    answers +i
16                carpet = answers16            inital_state = answers
17            answers = ''17            answers =""
18            self.str = carpet18        self.str = inital_state
19    def drawPlant(self):19    def drawPlant(self):
n20        crops = (200,0)n20        current_PT = (200,0)
21        angle = radians(90)21        theta = radians(90)
22        stacks = []22        apples = []
23        for grass in self.str:23        for i in self.str:
24            if grass.isalpha():24            if i.isalpha():
25                nextPt = (crops[0] + cos(angle), crops[1] + sin(angle))25                new_PT = (current_PT[0]+ cos(theta), current_PT[1]+ sin(theta))
26                plt.plot([crops[0],nextPt[0]],[crops[1],nextPt[1]], color = 'bla26                plt.plot([current_PT[0],new_PT[0]],[current_PT[1],new_PT[1]], co
>ck')>lor = 'black' )
27                crops = nextPt27                current_PT = new_PT
28            elif grass == '[':28            elif i == "[":
29                stacks.append(crops)29                apples.append(current_PT)
30                stacks.append(angle)30                apples.append(theta)
31            elif grass == ']':31            elif i == "]":
32                angle = stacks.pop()32                theta = apples.pop()  
33                crops = stacks.pop()33                current_PT = apples.pop()
34            elif grass == '+':34            elif i == "+":
35                angle += radians(self.vans)35                theta += (radians(self.angle))
36            elif grass == '-':36            elif i == "-":
37                angle -= radians(self.vans)37                theta -= (radians(self.angle))class DNAMOTIF:
38class DNAMOTIF:
39    def __init__(self):38    def __init__(self):
40        self.instances=[]39        self.instances=[]
41        self.consensus=''40        self.consensus=''
42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
43    def __str__(self):42    def __str__(self):
n44        for massive_dongs in self.instances:n43        for item in self.instances:
45            print(massive_dongs)44            print(item)
46        pass45        pass   
47    def __len__(self):46    def __len__(self):
n48        return len(self.instances[0])-1n47        return len(self.instances[-1])-1
49    def count(self):48    def count(self):  
50        for i in self.instances:49        for c in self.instances:
51            for b in range(len(self.instances[0])-1):50            for n in range(len(self.instances[0])-1):
52                if i == self.instances[0]:51                if c == self.instances[0]:
53                    self.counts['A'].append(0)52                    self.counts['A'].append(0)
54                    self.counts['C'].append(0)53                    self.counts['C'].append(0)
nn54                    self.counts['G'].append(0)
55                    self.counts['T'].append(0)55                    self.counts['T'].append(0)
n56                    self.counts['G'].append(0)n
57                if i.upper()[b] == 'A':56                if c.upper()[n] == "A":
58                    self.counts['A'][b] += 157                    self.counts["A"][n] += 1 
59                elif i.upper()[b] == 'C':58                elif c.upper()[n] == 'C' :
60                    self.counts['C'][b] += 159                    self.counts["C"][n] += 1 
61                elif i.upper()[b] == 'T':
62                    self.counts['T'][b] += 1
63                elif i.upper()[b] == 'G':60                elif c.upper()[n] == 'G' :
64                    self.counts['G'][b] += 1 61                    self.counts["G"][n] += 1 
62                elif c.upper()[n] == 'T' :
63                    self.counts["T"][n] += 1 
65    def compute_consensus(self):64    def compute_consensus(self): 
66        DNAMOTIF.count(self)65        DNAMOTIF.count(self)
n67        for j in range(len(self.counts["A"])):n66        for n in range(len(self.counts["A"])):
68            a = self.counts["A"][j]67            a = self.counts["A"][n]
69            c = self.counts["C"][j]68            c = self.counts["C"][n]
70            t = self.counts["T"][j]
71            g = self.counts["G"][j]69            g = self.counts["G"][n]
70            t = self.counts["T"][n]
72            maximum_value = max([a,c,t,g])71            max_Val = max([a,c,g,t])
73            if maximum_value == a:72            if max_Val == a:
74                self.consensus += "A"73                self.consensus += "A"
n75            elif maximum_value == c:n74            elif max_Val == c:
76                self.consensus += "C"75                self.consensus += "C"
nn76            elif max_Val == g:
77                self.consensus += "G"
77            elif maximum_value == t:78            elif max_Val == t:
78                self.consensus += "T"79                self.consensus += "T"
n79            elif maximum_value == g:n
80                self.consensus += "G"
81    def parse(self, filename):80    def parse(self, filename):
t82        r = '>'t
83        with open(filename) as token:81        with open(filename) as file:
84            for massive_dongs in token:82            for obj in file:
85                if r not in massive_dongs:83                if ">" not in obj:
86                    self.instances.append(massive_dongs)84                    self.instances.append(obj)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 70

Student ID: 434, P-Value: 1.39e-01

Nearest Neighbor ID: 130

Student (left) and Nearest Neighbor (right).


n1from math import radians,cos,sin n1from math import radians, cos, sin
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__ (self, inital_state, generator =[], iterations= 0 , angle = 0):n4    def __init__(self, carpet = '', rugs = {}, crocs = 0, vans = 0):
5        self.inital_state = inital_state5        self.carpet = carpet
6        self.generator = generator6        self.rugs = rugs
7        self.iterations = iterations7        self.crocs = crocs
8        self.angle = angle8        self.vans = vans
9        answers = ""9        answers = ''
10        for l in range(iterations):10        for i in range(crocs):
11            for i in inital_state:11            for token in carpet:
12                if i in generator:12                if token in rugs:
13                    answers += (generator[i])13                    answers = answers + str(rugs[token])
14                else:14                else:
n15                    answers += in15                    answers = answers + token
16            inital_state = answers16                carpet = answers
17            answers =""17            answers = ''
18        self.str = inital_state18            self.str = carpet
19    def drawPlant(self):19    def drawPlant(self):
n20        current_PT = (200,0)n20        crops = (200,0)
21        theta = radians(90)21        angle = radians(90)
22        apples = []22        stacks = []
23        for i in self.str:23        for grass in self.str:
24            if i.isalpha():24            if grass.isalpha():
25                new_PT = (current_PT[0]+ cos(theta), current_PT[1]+ sin(theta))25                nextPt = (crops[0] + cos(angle), crops[1] + sin(angle))
26                plt.plot([current_PT[0],new_PT[0]],[current_PT[1],new_PT[1]], co26                plt.plot([crops[0],nextPt[0]],[crops[1],nextPt[1]], color = 'bla
>lor = 'black' )>ck')
27                current_PT = new_PT27                crops = nextPt
28            elif i == "[":28            elif grass == '[':
29                apples.append(current_PT)29                stacks.append(crops)
30                apples.append(theta)30                stacks.append(angle)
31            elif i == "]":31            elif grass == ']':
32                theta = apples.pop()  32                angle = stacks.pop()
33                current_PT = apples.pop()33                crops = stacks.pop()
34            elif i == "+":34            elif grass == '+':
35                theta += (radians(self.angle))35                angle += radians(self.vans)
36            elif i == "-":36            elif grass == '-':
37                theta -= (radians(self.angle))class DNAMOTIF:37                angle -= radians(self.vans)
38class DNAMOTIF:
38    def __init__(self):39    def __init__(self):
39        self.instances=[]40        self.instances=[]
40        self.consensus=''41        self.consensus=''
41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):43    def __str__(self):
n43        for item in self.instances:n44        for massive_dongs in self.instances:
44            print(item)45            print(massive_dongs)
45        pass   46        pass
46    def __len__(self):47    def __len__(self):
n47        return len(self.instances[-1])-1n48        return len(self.instances[0])-1
48    def count(self):  49    def count(self):
49        for c in self.instances:50        for i in self.instances:
50            for n in range(len(self.instances[0])-1):51            for b in range(len(self.instances[0])-1):
51                if c == self.instances[0]:52                if i == self.instances[0]:
52                    self.counts['A'].append(0)53                    self.counts['A'].append(0)
53                    self.counts['C'].append(0)54                    self.counts['C'].append(0)
nn55                    self.counts['T'].append(0)
54                    self.counts['G'].append(0)56                    self.counts['G'].append(0)
n55                    self.counts['T'].append(0)n
56                if c.upper()[n] == "A":57                if i.upper()[b] == 'A':
57                    self.counts["A"][n] += 1 58                    self.counts['A'][b] += 1
58                elif c.upper()[n] == 'C' :59                elif i.upper()[b] == 'C':
59                    self.counts["C"][n] += 1 60                    self.counts['C'][b] += 1
60                elif c.upper()[n] == 'G' :
61                    self.counts["G"][n] += 1 
62                elif c.upper()[n] == 'T' :61                elif i.upper()[b] == 'T':
63                    self.counts["T"][n] += 1 62                    self.counts['T'][b] += 1
63                elif i.upper()[b] == 'G':
64                    self.counts['G'][b] += 1 
64    def compute_consensus(self): 65    def compute_consensus(self):
65        DNAMOTIF.count(self)66        DNAMOTIF.count(self)
n66        for n in range(len(self.counts["A"])):n67        for j in range(len(self.counts["A"])):
67            a = self.counts["A"][n]68            a = self.counts["A"][j]
68            c = self.counts["C"][n]69            c = self.counts["C"][j]
69            g = self.counts["G"][n]
70            t = self.counts["T"][n]70            t = self.counts["T"][j]
71            g = self.counts["G"][j]
71            max_Val = max([a,c,g,t])72            maximum_value = max([a,c,t,g])
72            if max_Val == a:73            if maximum_value == a:
73                self.consensus += "A"74                self.consensus += "A"
n74            elif max_Val == c:n75            elif maximum_value == c:
75                self.consensus += "C"76                self.consensus += "C"
nn77            elif maximum_value == t:
78                self.consensus += "T"
76            elif max_Val == g:79            elif maximum_value == g:
77                self.consensus += "G"80                self.consensus += "G"
n78            elif max_Val == t:n
79                self.consensus += "T"
80    def parse(self, filename):81    def parse(self, filename):
tt82        r = '>'
81        with open(filename) as file:83        with open(filename) as token:
82            for obj in file:84            for massive_dongs in token:
83                if ">" not in obj:85                if r not in massive_dongs:
84                    self.instances.append(obj)86                    self.instances.append(massive_dongs)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 71

Student ID: 142, P-Value: 1.55e-01

Nearest Neighbor ID: 488

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as plt n
2import numpy as np1import numpy as np
nn2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, string, generated_dict, x, diff_theta):n4    def __init__(self, string, dictionaryn, delta_Theta):
5        self.string = string5        self.string = string
n6        self.generated_dict = generated_dictn6        self.dictionary = dictionary
7        self.x = x7        self.n = n
8        self.diff_theta = diff_theta8        self.delta_Theta = delta_Theta
9        self.str = PLANT.generator(string,generated_dict, x)9        self.str = PLANT.generator(string,dictionaryn)
10    def generator(string, generated_dict, x):10    def generator(string, dictionaryn):
11        def variable(string):11        def variable(string):
n12            if string in generated_dict:n12            if string in dictionary:
13                z = generated_dict.get(string)13                return dictionary.get(string)
14                string = z
15            return string 14            return string
16        da_list_jawn  = [string]15        listsubstrings = [string]
17        for i in range(x):16        for i in range(n):
18            now_str = da_list_jawn[-1]17            current_substring = listsubstrings[-1]
19            now_star = [variable(char) for char in now_str]18            new_axiom = [variable(char) for char in current_substring]
20            da_list_jawn.append(''.join(now_star))19            listsubstrings.append(''.join(new_axiom))
21        ans_str = da_list_jawn[x]20        new_string = listsubstrings[n]
22        return ans_str21        return new_string
23    def drawPlant(self):22    def drawPlant(self):
n24        uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',n23        upper_alpha = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L
> 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']>', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
25        lowercase = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',24        current_Plant=(200,0)
> 'm','n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] 
26        startpoint=(200,0)
27        theta_angle = np.radians(90)25        theta = np.radians(90)
28        diff_theta = np.radians(self.diff_theta)26        delta_Theta = np.radians(self.delta_Theta)
29        plant_send = [startpoint, theta_angle]27        stack = [current_Plant, theta]
30        for command in self.str:28        for command in self.str:
n31            if command.upper() in uppercase:n29            if command.upper() in upper_alpha:
32                followpoint = (startpoint[0]+(np.cos(theta_angle)), startpoint[130                next_Plant = (current_Plant[0]+(np.cos(theta)), current_Plant[1]
>]+(np.sin(theta_angle)))>+(np.sin(theta)))
33                plt.plot([startpoint[0],followpoint[0]],[startpoint[1],followpoi31                plt.plot([current_Plant[0],next_Plant[0]],[current_Plant[1],next
>nt[1]],color='black')>_Plant[1]],color='black')
34                startpoint = followpoint 32                current_Plant = next_Plant 
35            else:33            else:
n36                if command == ']':n34                if command == '[':
37                    theta_angle = plant_send.pop()35                    stack.append(current_Plant)
38                    startpoint = plant_send.pop()36                    stack.append(theta)
39                elif command == '[':37                elif command == ']':
40                    plant_send.append(startpoint)38                    theta = stack.pop()
41                    plant_send.append(theta_angle)39                    current_Plant = stack.pop()  
40                elif command == '+':
41                    theta += delta_Theta
42                elif command == '-':42                elif command == '-':
n43                    theta_angle -= diff_thetan43                    theta -= delta_Theta
44                elif command == '+':
45                    theta_angle += diff_theta
46        return plt.plot44        return plt.plot
47if __name__ == "__main__":45if __name__ == "__main__":
48    string = input()46    string = input()
n49    generated_dict = input()n47    dictionary = input()
50    x = int(input())48    n = int(input())
51    diff_theta = float(input())49    delta_Theta = float(input())
52    a = PLANT(string, generated_dict, x, diff_theta)50    p = PLANT(string, dictionary, n, deltaTheta)
53    a.drawPlant()51    p.drawPlant()
54    plt.show()52    plt.show()class DNAMOTIF:
55class DNAMOTIF:
56    def __init__(self):53    def __init__(self):
57        self.instances=[]54        self.instances=[]
58        self.consensus=[]55        self.consensus=[]
59        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}56        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
60    def __str__(self):57    def __str__(self):
n61        string_out = ''n58        output = ""
62        for instance in self.instances:59        for instance in self.instances:
n63            string_out += instancen60            output += instance
64        return string_out61        return output
65    def __len__(self):62    def __len__(self):
n66        x = len(self.instances[0].rstrip())n63        return len(self.instances[0].rstrip())
67        return x 
68    def count(self):64    def count(self):
n69        for location in range(len(self)):n65        for position in range(len(self)):
70            seq_a = 066            seq_T = 0
71            seq_t = 067            seq_A = 0
72            seq_c = 068            seq_G = 0
73            seq_g = 069            seq_C = 0
74            for instance in self.instances:70            for instance in self.instances:
n75                series = instance.rstrip()n71                sequence = instance.rstrip()
76                if (series[location]).upper() == 'A':72                if (sequence[position]).upper() == "G":
77                    seq_a += 173                    seq_G = seq_G + 1
78                elif (series[location]).upper() == 'T':74                elif (sequence[position]).upper() == "C":
79                    seq_t += 175                    seq_C = seq_C + 1
80                elif (series[location]).upper() == 'C':76                elif (sequence[position]).upper() == "T":
81                    seq_c += 177                    seq_T = seq_T + 1
82                elif (series[location]).upper() == 'G':78                elif (sequence[position]).upper() == "A":
83                    seq_g += 179                    seq_A = seq_A + 1
84            self.counts.get('C').append(seq_c)
85            self.counts.get('A').append(seq_a)80            self.counts.get("A").append(seq_A)
86            self.counts.get('G').append(seq_g)
87            self.counts.get('T').append(seq_t)81            self.counts.get("T").append(seq_T)
82            self.counts.get("C").append(seq_C)
83            self.counts.get("G").append(seq_G)
88    def compute_consensus(self):84    def compute_consensus(self):
89        DNAMOTIF.count(self)85        DNAMOTIF.count(self)
n90        T = self.counts.get('T')n
91        G = self.counts.get('G')
92        A = self.counts.get('A')86        A = self.counts.get("A")
87        G = self.counts.get("G")
93        C = self.counts.get('C')88        C = self.counts.get("C")
89        T = self.counts.get("T")
94        Output = ""90        output = ""
95        for row in range(len(A)):91        for row in range(len(A)):
n96            MAX = max(A[row],T[row],C[row],G[row])n92            maximum = max(A[row],T[row],C[row],G[row])
97            if MAX == A[row]:93            if maximum == A[row]:
98                Output += "A"94                output = output + "A"
99            elif MAX == T[row]:
100                Output += "T"
101            elif MAX == C[row]:
102                Output += "C"
103            elif MAX == G[row]:95            elif maximum == G[row]:
104                Output +"G"96                output = output +"G"
97            elif maximum == C[row]:
98                output = output + "C"
99            elif maximum == T[row]:
100                output = output + "T"
105        self.consensus = Output101        self.consensus = output
106    def parse(self, filename):102    def parse(self, filename):
n107        dna_file = open(filename, 'r')n103        my_File = open(filename, 'r')
108        file_stuff = [line for line in dna_file.readlines()]104        contents = [line for line in my_File.readlines()]
109        dna_file.close()105        my_File.close()
110        for index, line in enumerate(file_stuff):106        for index, line in enumerate(contents):
111            if index % 2 != 0:107            if index % 2 != 0:
112                self.instances.append(line)108                self.instances.append(line)
113if __name__ == '__main__':109if __name__ == '__main__':
n114    lexA=DNAMOTIF() n110    lexA=DNAMOTIF()
115    filename = r'FinalProject\lexA.fasta' 111    filename = r'FinalProject\lexA.fasta' 
t116    lexA.parse(filename) t112    lexA.parse(filename)
117    lexA.compute_consensus() 113    lexA.compute_consensus()
118    print(lexA.consensus) 114    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 72

Student ID: 183, P-Value: 1.57e-01

Nearest Neighbor ID: 247

Student (left) and Nearest Neighbor (right).


n1%matplotlib inlinen
2import matplotlib.pyplot as plt
3plt.style.use('bmh')  
4class DNAMOTIF:1nopclass DNAMOTIF:
5    def __init__(self):2    def __init__(self):
6        self.instances=[]3        self.instances=[]
7        self.consensus=[]4        self.consensus=[]
8        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
9    def __str__(self):6    def __str__(self):
n10        string=""n7        pass 
11        for i in self.instances:
12            string+=i;
13        return string 
14    def __len__(self):8    def __len__(self):
n15        return len(self.instances[0])n9        pass
16    def count(self):10    def count(self):
n17        passn11        pass 
18    def compute_consensus(self):12    def compute_consensus(self):
n19        passn13        pass 
20    def parse(self, filename):14    def parse(self, filename):
t21        with open(filename,'r') as f:t15        with open(filename, 'r+') as my_file:
22            for i in f:16            strands = my_file.readlines()
17            for strand in strands:
18                strand[0:21]
23                if ">" in i:19                if '>' in strand:
24                    pass20                    strands.remove(strand)
25                else:21        return strands
26                    self.instances.append(i)
27if __name__=="__main__":
28  lexA=DNAMOTIF()22lexA = DNAMOTIF()
29  lexA.parse("lexA.fasta")23print(lexA.parse("lexA.fasta"))
30  print(len(lexA))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 73

Student ID: 247, P-Value: 1.57e-01

Nearest Neighbor ID: 183

Student (left) and Nearest Neighbor (right).


nn1%matplotlib inline
2import matplotlib.pyplot as plt
3plt.style.use('bmh')  
1nopclass DNAMOTIF:4class DNAMOTIF:
2    def __init__(self):5    def __init__(self):
3        self.instances=[]6        self.instances=[]
4        self.consensus=[]7        self.consensus=[]
5        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}8        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
6    def __str__(self):9    def __str__(self):
n7        pass n10        string=""
11        for i in self.instances:
12            string+=i;
13        return string 
8    def __len__(self):14    def __len__(self):
nn15        return len(self.instances[0])
16    def count(self):
9        pass17        pass
n10    def count(self):n
11        pass 
12    def compute_consensus(self):18    def compute_consensus(self):
n13        pass n19        pass
14    def parse(self, filename):20    def parse(self, filename):
t15        with open(filename, 'r+') as my_file:t21        with open(filename,'r') as f:
16            strands = my_file.readlines()22            for i in f:
17            for strand in strands:
18                strand[0:21]
19                if '>' in strand:23                if ">" in i:
20                    strands.remove(strand)24                    pass
21        return strands25                else:
26                    self.instances.append(i)
27if __name__=="__main__":
22lexA = DNAMOTIF()28  lexA=DNAMOTIF()
23print(lexA.parse("lexA.fasta"))29  lexA.parse("lexA.fasta")
30  print(len(lexA))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 74

Student ID: 242, P-Value: 1.61e-01

Nearest Neighbor ID: 431

Student (left) and Nearest Neighbor (right).


nn1import math
1import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n2import mathn
3class PLANT:3class PLANT:
n4    def __init__(self,i_state,gen,n,deltaTheta):n4    def __init__(self,state,gen,num,deltaTheta):
5        curr = gen.get(i_state)5        self.state = state
6        nxt=""6        self.gen = gen
7        self.num = num
8        self.deltaTheta = deltaTheta
9        self.str = self.generate_str()
10    def generate_str(self):
11        string = ""
7        for i in range (1,n):12        for x in range(self.num):
8            for i in range (0,len(curr)):13            for c in self.state:
9                if curr[i] in gen:14                if c in self.gen:
10                    nxt+=gen.get(curr[i])15                    string += self.gen[c]
11                else:16                else:
n12                    nxt+=curr[i]n17                    strin+= c
13            curr=nxt18            self.state = string
14            nxt=""19            strin= ""
15        self.str = curr20        return self.state
16        self.deltaTheta = deltaTheta
17    def drawPlant(self):21    def drawPlant(self):
n18        currentPt=(200,0)n22        currentPt = (200,0)
19        theta=9023        theta = 90
20        stack = []24        stack = []
n21        for i in range (0,len(self.str)):n25        for i in self.str:
22            if self.str[i].isalpha():26            if i.isalpha():
23                nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[27                nextPt = (currentPt[0]+ math.cos(math.radians(theta)), currentPt
>1]+math.sin(math.radians(theta)))>[1] + math.sin(math.radians(theta)))
24                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color28                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
25                currentPt = nextPt29                currentPt = nextPt
n26            elif self.str[i]=='[':n30            else:
31                if i == '[':
27                stack.append((currentPt,theta))32                    stack.append((currentPt,theta))
28            elif self.str[i]==']':33                if i == ']':
29                (currentPt,theta) = stack.pop()34                    currentPt,theta = stack.pop()
30            elif self.str[i]=='+':35                if i == '+':
31                theta = theta + self.deltaTheta36                    theta += self.deltaTheta
32            elif self.str[i]=='-':37                if i == '-':
33                theta = theta - self.deltaTheta38                    theta -= self.deltaTheta
34        plt.show()39if __name__ == '__main__':
40    myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)
41    print(myPlant.str)
35myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)42    myPlant2 = PLANT('b', {'b':'a', 'a':'ab'},5,25)
36myPlant2 = PLANT('X', {'X':'F[+X]F[-X]+X','F':'FF'},7,20)43    print(myPlant2.str)
37myPlant2.drawPlant()class DNAMOTIF:44class DNAMOTIF:
38    def __init__(self):45    def __init__(self):
39        self.instances=[]46        self.instances=[]
40        self.consensus=[]47        self.consensus=[]
n41        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}n48        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):49    def __str__(self):
n43        string=''n
44        for i in self.instances:50        for x in self.instances:
45            string += i51            string += x
52        return string
53    def __len__(self):
54        return len(self.instances[0])-1
55    def count(self):
56        for i in range(len(self.instances[0])-1):
57            A = 0
58            C = 0
59            G = 0
60            T = 0
61            for lines in self.instances:
62                char = lines[i].upper()
63                if char == "A":
64                    A+=1
65                elif char == "C":
66                    C+=1
67                elif char =="G":
68                    G+=1
69                elif char == "T":
70                    T+=1
71            self.counts["A"].append(A)
72            self.counts["C"].append(C)
73            self.counts["G"].append(G)
74            self.counts["T"].append(T)
75        string = ''
46    def parse(self, filename):76    def parse(self, filename):
t47        with open(filename,'r') as fasta:t77        f = open(filename)
48            for i in fasta:78        lines = f.readlines()
79        for x in lines:
49                if ">" in i:80            if ">" not in x:
50                    pass
51                else:
52                    self.instances.append(i)81                self.instances.append(x)
53            return
54    def __len__(self):
55        return len(self.instances)-len(self.counts)
56if __name__=="__main__":82if __name__ == "__main__":
57    lexA = DNAMOTIF()83    pass
58    lexA.parse('lexA.fasta')
59    lexA.parse('lexA.fasta')
60    print(lexA)
61    lexA = DNAMOTIF()
62    lexA.count()
63    print(lexA.counts)
64    lexA = DNAMOTIF()
65    lexA.compute_consensus()
66    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 75

Student ID: 449, P-Value: 1.64e-01

Nearest Neighbor ID: 242

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
n2from math import pi, sin, cosn2import math
3import numpy as np
4class PLANT:3class PLANT:
n5    def __init__(self,state = 'none' ,gen = dict(), run = 0,deltaTheta = 0):n4    def __init__(self,i_state,gen,n,deltaTheta):
6        PLANT.str = '1'5        curr = gen.get(i_state)
7        self.state = state6        nxt=""
8        self.deltaTheta = deltaTheta * np.pi/180
9        self.run = run
10        self.gen = gen
11        inputString = self.state
12        for i in range(self.run):7        for i in range (1,n):
13            plt = ''8            for i in range (0,len(curr)):
14            for i in inputString:
15                if i in self.gen.keys():9                if curr[i] in gen:
16                    plt += self.gen[i]10                    nxt+=gen.get(curr[i])
17                else:11                else:
n18                    plt += in12                    nxt+=curr[i]
19            inputString = plt13            curr=nxt
14            nxt=""
15        self.str = curr
16        self.deltaTheta = deltaTheta
20    def drawPlant(self):17    def drawPlant(self):
n21        currentPt = (200,0)n18        currentPt=(200,0)
22        theta = 9019        theta=90
23        stack=[]20        stack = []
24        for i in range(0,len(self.str)):21        for i in range (0,len(self.str)):
25            if self.str[i].isalpha():22            if self.str[i].isalpha():
n26                nextPt = (currentPt[0]+math.cos(math.radian(theta)), currentPt[1n23                nextPt = (currentPt[0]+math.cos(math.radians(theta)), currentPt[
>]+math.sin(math.radian(theta)))>1]+math.sin(math.radians(theta)))
27                plt.plot([currPt[0],nextPt[0]],[currPt[1],nextPt[1]],color='blac24                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>k')>='black')
28                currentPt = nextPt25                currentPt = nextPt
n29            elif self.str[i]=="+":n
30                theta += self.deltaTheta
31            elif self.str[i]=="-":
32                theta -= self.deltaTheta
33            elif self.str[i]=="[":26            elif self.str[i]=='[':
34                stack.append(currentPt,theta)27                stack.append((currentPt,theta))
35            elif self.str[i]=="]":28            elif self.str[i]==']':
36                (currentPt,theta) = stack.pop()29                (currentPt,theta) = stack.pop()
n37if __name__ == '__main__':n30            elif self.str[i]=='+':
31                theta = theta + self.deltaTheta
32            elif self.str[i]=='-':
33                theta = theta - self.deltaTheta
34        plt.show()
35myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
38    myPlant=PLANT('X',{ 'X' : 'F[+X]F[-X]+X','F' : 'FF'},2,20)36myPlant= PLANT('X', {'X':'F[+X]F[-X]+X','F':'FF'},7,20)
39    myPlant.str=='FF[+F[+X]F[-X]+X]FF[-F[+X]F[-X]+X]+F[+X]F[-X]+X'37myPlant2.drawPlant()class DNAMOTIF:
40    plt.axis('image')
41    self.drawPlant()
42    plt.self.draawPlant
43class DNAMOTIF:
44    def __init__(self):38    def __init__(self):
45        self.instances=[]39        self.instances=[]
46        self.consensus=[]40        self.consensus=[]
47        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts = {'A': [], 'C': [], 'G':[],'T':[]}
48    def __str__(self):42    def __str__(self):
49        string=''43        string=''
50        for i in self.instances:44        for i in self.instances:
n51            string += i + ''n45            string += i
52    def __len__(self):
53        return len(self.instances) - len(self.counts)
54    def count(self):
55        for s in self.instances:
56            self.counts['A']=s[0]
57            self.counts['C']=s[0]
58            self.counts['G']=s[0]
59            self.counts['T']=s[0]
60            self.instances.append(s)
61            for i in range(len(s)):
62                if s[i]=='a' or s[i]=='A':
63                    self.counts['A'][i]+=1;
64                if s[i]=='c' or s[i]=='C':
65                    self.counts['C'][i]+=1;
66                if s[i]=='g' or s[i]=='G':
67                    self.counts['G'][i]+=1;
68                if s[i]=='t' or s[i]=='T':
69                    self.counts['T'][i]+=1;
70    def compute_consensus(self):
71        return
72    def parse(self, filename):46    def parse(self, filename):
73        with open(filename,'r') as fasta:47        with open(filename,'r') as fasta:
74            for i in fasta:48            for i in fasta:
n75                if '>' in i:n49                if ">" in i:
76                    pass50                    pass
77                else:51                else:
78                    self.instances.append(i)52                    self.instances.append(i)
79            return53            return
nn54    def __len__(self):
55        return len(self.instances)-len(self.counts)
80if __name__=="__main__":56if __name__=="__main__":
81    lexA = DNAMOTIF()57    lexA = DNAMOTIF()
82    lexA.parse('lexA.fasta')58    lexA.parse('lexA.fasta')
n83    print(len(lexA))n
84    lexA = DNAMOTIF()
85    lexA.parse('lexA.fasta')59    lexA.parse('lexA.fasta')
n86    print(lexA) n60    print(lexA)
87    lexA = DNAMOTIF()61    lexA = DNAMOTIF()
88    lexA.count()62    lexA.count()
89    print(lexA.counts)63    print(lexA.counts)
tt64    lexA = DNAMOTIF()
65    lexA.compute_consensus()
66    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 76

Student ID: 138, P-Value: 1.73e-01

Nearest Neighbor ID: 183

Student (left) and Nearest Neighbor (right).


n1:(n1%matplotlib inline
2import matplotlib.pyplot as plt
3plt.style.use('bmh')  
2class DNAMOTIF:4class DNAMOTIF:
3    def __init__(self):5    def __init__(self):
4        self.instances=[]6        self.instances=[]
5        self.consensus=[]7        self.consensus=[]
6        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}8        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
7    def __str__(self):9    def __str__(self):
n8        line_str = '' n10        string=""
9        for line in self.instances:11        for in self.instances:
10            line_str += line12            string+=i;
11        return line_str13        return string 
12    def __len__(self):14    def __len__(self):
n13        return len(self.instances[0])-1n15        return len(self.instances[0])
14    def count(self):16    def count(self):
n15        for line in self.instances:n17        pass
16            si_caps = str(line).upper()18    def compute_consensus(self):
17            for char in range(len(si_caps)):19        pass
18                if line[char] == 'A':
19                    self.counts['A'][char]+=1
20    def parse(self,filename):20    def parse(self, filename):
21        with open(filename,'r') as f:21        with open(filename,'r') as f:
n22            for line in f:n22            for in f:
23                if '>' not in line:23                if ">" in i:
24                    self.instances.append(line)24                    pass
25                else:25                else:
t26                    passt26                    self.instances.append(i)
27if __name__ =="__main__":27if __name__=="__main__":
28    lexA=DNAMOTIF()28  lexA=DNAMOTIF()
29    lexA.parse("lexA.fasta")29  lexA.parse("lexA.fasta")
30    print(len(lexA))30  print(len(lexA))
31    print(str(lexA.split))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 77

Student ID: 161, P-Value: 1.78e-01

Nearest Neighbor ID: 130

Student (left) and Nearest Neighbor (right).


n1from math import radians,cos,sinn1from math import radians, cos, sin
2import matplotlib.pyplot as plot2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self,string="", dictionary={},runs=0,delta=0):n4    def __init__(self, carpet = '', rugs = {}, crocs = 0, vans = 0):
5        self.string=string 5        self.carpet = carpet
6        self.dictionary=dictionary
7        self.runs=runs6        self.rugs = rugs
8        self.delta=delta7        self.crocs = crocs
9        solution= ""8        self.vans = vans
9        answers = ''
10        for i in range(runs):10        for i in range(crocs):
11            for C in string:11            for token in carpet:
12                if C in dictionary:12                if token in rugs:
13                    solution=solution+str(dictionary[C])13                    answers = answers + str(rugs[token])
14                else:14                else:
n15                    solution=solution+Cn15                    answers = answers + token
16            string=solution16                carpet = answers
17            solution=""17            answers = ''
18        self.str=string18            self.str = carpet
19    def drawPlant(self):19    def drawPlant(self):
n20        plantdrop=(200,0)n20        crop= (200,0)
21        angle=radians(90)21        angle = radians(90)
22        stacks=[]22        stacks = []
23        for tree in self.str:23        for grass in self.str:
24            if tree.isalpha():24            if grass.isalpha():
25                nextPt = (plantdrop[0]+cos(angle), plantdrop[1]+sin(angle))25                nextPt = (crops[0] + cos(angle), crops[1] + sin(angle))
26                plot.plot([plantdrop[0],nextPt[0]],[plantdrop[1],nextPt[1]],colo26                plt.plot([crops[0],nextPt[0]],[crops[1],nextPt[1]], color = 'bla
>r='black')>ck')
27                plantdrop=nextPt27                crop= nextPt
28            elif tree=='[':28            elif grass == '[':
29                stacks.append(plantdrop)29                stacks.append(crops)
30                stacks.append(angle)30                stacks.append(angle)
n31            elif tree==']':n31            elif grass == ']':
32                angle=stacks.pop()32                angle = stacks.pop()
33                plantdrop=stacks.pop()33                crop= stacks.pop()
34            elif tree=='+':34            elif grass == '+':
35                angle+=radians(self.delta)35                angle += radians(self.vans)
36            elif tree=='-':36            elif grass == '-':
37                 angle-=radians(self.delta)37                angle -= radians(self.vans)
38class DNAMOTIF:38class DNAMOTIF:
39    def __init__(self):39    def __init__(self):
40        self.instances=[]40        self.instances=[]
41        self.consensus=''41        self.consensus=''
42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}42        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
43    def __str__(self):43    def __str__(self):
n44        for obj in self.instances:n44        for massive_dongs in self.instances:
45            print(obj)45            print(massive_dongs)
46        pass 46        pass
47    def __len__(self):47    def __len__(self):
n48        return len (self.instances[0])-1n48        return len(self.instances[0])-1
49    def count(self):49    def count(self):
50        for i in self.instances:50        for i in self.instances:
n51             for v in range(len(self.instances[0])-1):n51            for b in range(len(self.instances[0])-1):
52                if i == self.instances[0]:52                if i == self.instances[0]:
nn53                    self.counts['A'].append(0)
54                    self.counts['C'].append(0)
53                    self.counts['T'].append(0)55                    self.counts['T'].append(0)
n54                    self.counts['C'].append(0)n
55                    self.counts['A'].append(0)
56                    self.counts['G'].append(0)56                    self.counts['G'].append(0)
n57                if i.upper()[v] == "T":n57                if i.upper()[b] == 'A':
58                    self.counts["T"][v] += 158                    self.counts['A'][b] += 1
59                elif i.upper()[v] =='C':59                elif i.upper()[b] == 'C':
60                    self.counts["C"][v] += 160                    self.counts['C'][b] += 1
61                elif i.upper()[v] =='A':61                elif i.upper()[b] == 'T':
62                    self.counts["A"][v] += 162                    self.counts['T'][b] += 1
63                elif i.upper()[v] =='G':63                elif i.upper()[b] == 'G':
64                    self.counts["G"][v] += 164                    self.counts['G'][b] += 1 
65    def compute_consensus(self):65    def compute_consensus(self):
66        DNAMOTIF.count(self)66        DNAMOTIF.count(self)
n67        for v in range(len(self.counts["T"])):n67        for j in range(len(self.counts["A"])):
68             t =self.counts["T"][v]
69             c =self.counts["C"][v]
70             a =self.counts["A"][v]68            a = self.counts["A"][j]
69            c = self.counts["C"][j]
70            t = self.counts["T"][j]
71             g =self.counts["G"][v]71            g = self.counts["G"][j]
72             max_val = max([t,c,a,g])72            maximum_value = max([a,c,t,g])
73             if max_val== t:
74                 self.consensus +="T"
75             elif max_val == c:
76                 self.consensus +="C"
77             elif max_val == a:73            if maximum_value == a:
78                 self.consensus +="A"74                self.consensus += "A"
75            elif maximum_value == c:
76                self.consensus += "C"
77            elif maximum_value == t:
78                self.consensus += "T"
79             elif max_val == g:79            elif maximum_value == g:
80                 self.consensus +="G"80                self.consensus += "G"
81    def parse(self, filename):81    def parse(self, filename):
t82        x = ">"t82        r = '>'
83        with open(filename) as sequence:83        with open(filename) as token:
84            for obj in sequence:84            for massive_dongs in token:
85                if x not in obj:85                if r not in massive_dongs:
86                    self.instances.append(obj)86                    self.instances.append(massive_dongs)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 78

Student ID: 189, P-Value: 1.83e-01

Nearest Neighbor ID: 300

Student (left) and Nearest Neighbor (right).


n1from math import cos, sinn1from math import radians, cos, sin 
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n3from math import pin3def generate(text, generator):
4    gen = ''
5    for letter in text:
6        if letter in generator.keys():
7            gen += generator[letter]
8        elif letter not in generator.keys():
9            gen += letter
10    return gen
4class PLANT:11class PLANT:
5    def __init__(self, state, generator, n, dTheta):12    def __init__(self, state, generator, n, dTheta):
n6        self.state = staten
7        self.generator = generator13        self.generator = generator
8        self.n = n14        self.n = n
n9        self.dTheta = dThetan15        self.dTheta = radians(dTheta
10        c = ''16        newstate = state
11        for _ in range(n):17        for i in range(n):
12            for letter in self.state:18            newstate = generate(newstate, generator) 
13                if letter in generator:
14                    c += generator[letter]
15                else:
16                    c += letter
17            self.state = c
18            c = ''
19        self.str = self.state19        self.str = newstate
20    def drawPlant(self):20    def drawPlant(self):
n21        currentPt = (200, 0)n
22        theta = 90
23        stack = []21        stack = []
nn22        currentPt = (200,0)
23        theta = radians(90) 
24        for symbol in self.str:24        for letter in self.str:
25            if symbol.isalpha():25            if letter.isalpha():
26                nextPt = (currentPt[0]+cos(theta*pi/180),26                nextPt = (currentPt[0] + cos(theta), currentPt[1] + sin(theta))
27                          currentPt[1]+sin(theta*pi/180))27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
 >='black')
28                plt.plot([currentPt[0], nextPt[0]], [
29                         currentPt[1], nextPt[1]], color='black')
30                currentPt = nextPt28                currentPt = nextPt
n31            elif symbol == '[':n29            elif letter == '[':
32                stack.append(currentPt)30                stack.append(currentPt)
33                stack.append(theta)31                stack.append(theta)
n34            elif symbol == ']':n32            elif letter == ']':
35                theta = stack.pop()33                theta = stack.pop()
36                currentPt = stack.pop()34                currentPt = stack.pop()
n37            elif symbol == '+':n35            elif letter == '+':
38                theta -= self.dTheta36                theta -= self.dTheta
n39            elif symbol == '-':n37            elif letter == '-':
40                theta += self.dTheta38                theta += self.dTheta
n41        plt.savefig('my_plot.png')n39        plt.savefig('plant')
42if __name__ == '__main__':40if __name__ == '__main__':
n43    plant = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)n41    plant1 = PLANT('F',{'F': 'F[+F]F[-F]F'},5,25.7)
44    plant.drawPlant()42    plant1.drawPlant()class DNAMOTIF:
45class DNAMOTIF:
46    def __init__(self):43    def __init__(self):
n47        self.instances = []n44        self.instances=[]
48        self.consensus []  45        self.consensus= ''
49        self.counts = {'A': [], 'C': [], 'G': [], 'T': []}46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
50    def __str__(self):47    def __str__(self):
n51        return ''.join(self.instances)n48        return '\n'.join(self.instances)
52    def __len__(self):49    def __len__(self):
nn50        self.instances = [x.strip() for x in self.instances]
53        return len(self.instances[0])-151        return len(self.instances[0])
52    def count(self):
53        self.instances = [x.strip() for x in self.instances]
54        self.counts = {'A': [0] * len(self), 'C': [0] * len(self), 'G': [0] * le
 >n(self), 'T': [0] * len(self)}
55        for line in self.instances:
56            uline = line.upper()
57            for i, letter in enumerate(uline):
58                self.counts[letter][i] += 1
59    def compute_consensus(self):
60        self.instances = [x.strip() for x in self.instances]
61        self.count()
62        for i in range(len(self)):
63            a = self.counts['A'][i]
64            c = self.counts['C'][i]
65            t = self.counts['T'][i]
66            g = self.counts['G'][i]
67            nums = [a, c, g, t]
68            big = max(nums)
69            ind = nums.index(big)
70            if ind == 0:
71                let = 'A'
72            elif ind == 1 :
73                let = 'C'
74            elif ind == 2:
75                let = 'G'
76            elif ind == 3 :
77                let = 'T'
78            self.consensus += let
54    def parse(self, filename):79    def parse(self, filename):
55        with open(filename, 'r') as f:80        with open(filename, 'r') as f:
n56            data = f.readlines()n81            for line in f:
57            self.instances = data[1::2]
58    def count(self):
59        self.counts['A'] = [0]*len(self)
60        self.counts['G'] = [0]*len(self)
61        self.counts['C'] = [0]*len(self)
62        self.counts['T'] = [0]*len(self)
63        for instance in self.instances:
64            for i, letter in enumerate(instance.upper()):
65                if letter == 'A':82                if line[0] == '>':
66                    self.counts['A'][i] += 183                    pass
67                if letter == 'C':84                else:
68                    self.counts['C'][i] += 185                    self.instances.append(line)
69                if letter == 'G':
70                    self.counts['G'][i] += 1
71                if letter == 'T':
72                    self.counts['T'][i] += 1
73    def compute_consensus(self):
74        self.count()
75        cone = ''
76        for i in range(len(self)):
77            letterlist = [self.counts['A'][i], self.counts['C'][i],
78                          self.counts['G'][i], self.counts['T'][i]]
79            peepee = max(letterlist)
80            if peepee == letterlist[0]:
81                cone += 'A'
82            elif peepee == letterlist[1]:
83                cone += 'C'
84            elif peepee == letterlist[2]:
85                cone += 'G'
86            elif peepee == letterlist[3]:
87                cone += 'T'
88        self.consensus = cone
89if __name__ == '__main__':86if __name__ == '__main__':
90    lexA = DNAMOTIF()87    lexA = DNAMOTIF()
t91    lexA.parse(r"C:\Users\cresp\Downloads\c\lexA.fasta")t88    lexA.parse('lexA.fasta')
89    print(len(lexA))
92    lexA.count()90    lexA.count()
93    lexA.compute_consensus()91    lexA.compute_consensus()
94    print(lexA.consensus)92    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 79

Student ID: 75, P-Value: 1.83e-01

Nearest Neighbor ID: 102

Student (left) and Nearest Neighbor (right).


n1import matplotlib.pyplot as pltn1import numpy as np, matplotlib.pyplot as plt
2import numpy as np
3class PLANT:2class PLANT:
n4    def __init__(self, initial_state ='' , generator = {} , number_generations =n3    def __init__(self, string='', generator={}, n=0, deltatheta=0.00):
> 0 , deltaTheta = 0.00): 
5        self.initial_state = initial_state4        self.string=string
6        self.generator = generator 5        self.generator=generator
7        self.number_generations = int(number_generations)6        self.n= int(n) 
8        self.deltaTheta = np.radians(deltaTheta)7        self.deltatheta= np.radians(deltatheta)
9        for i in range(self.number_generations):8        for i in range(0, self.n):
10            result = ''9            result=''
11            for j in self.initial_state:10            for j in self.string:
12                if j in self.generator.keys():11                if j in self.generator.keys():
13                    result += self.generator[str(j)]12                    result += self.generator[str(j)]
14                else:13                else:
15                    result += j14                    result += j
n16            self.initial_state = resultn15            self.string = result
17        self.str = self.initial_state16        self.str = self.string
18    def drawPlant(self):17    def drawPlant(self):
n19        currentPt = [200, 0]n18        currentpos=[200,0]
20        theta = np.radians(90)19        theta=np.radians(90)
21        drawing=[]20        drawingState=[]
22        nextPt=()21        nextpt=()
23        stack=[]22        stack=[]
24        for i in self.str:23        for i in self.str:
25            if i.isalpha():24            if i.isalpha():
n26                nextPt = [currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)n25                nextpt=[currentpos[0]+np.cos(theta), currentpos[1]+np.sin(theta)
>]>]
27                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c26                plt.plot([currentpos[0], nextpt[0]],[currentpos[1],nextpt[1]],co
>olor = 'black')>lor='black')
28                currentPt = nextPt27                currentpos=nextpt
29            if i == '[':28            if i=='[':
30                drawing = [currentPt , theta]29                drawingState = [currentpos, theta]
31                stack.append(drawing)30                stack.append(drawingState)
32            elif i == ']':31            elif i==']':
33                drawing = stack[len(stack) -1]32                currentpos=stack[-1][0]
33                theta=stack[-1][1]
34                stack.pop(len(stack)-1)34                stack.pop()
35                currentPt = drawing[0]
36                theta = drawing[1]
37            elif i == '+':35            elif i=='+':
38                theta += self.deltaTheta36                theta += self.deltatheta
39            elif i == '-':37            elif i=='-':
40                theta -= self.deltaTheta38                theta-=self.deltatheta
41if __name__ == '__main__':39if __name__ == "__main__":
42    initial_state = input()40    string = input()
43    dictionary = input()41    dictionary = input()
nn42    theta = input()
44    num = input()43    n = input()
45    angle = float(input())44    obj = PLANT(string, dictionary, n, theta)
46    f = PLANT(initial_state, dictionary, num , angle)
47    f.drawPlant()45    obj.drawPlant()
48    plt.show()46    plt.show()
49class DNAMOTIF:47class DNAMOTIF:
50    def __init__(self):48    def __init__(self):
51        self.instances=[]49        self.instances=[]
52        self.consensus=[]50        self.consensus=[]
53        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}51        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
54    def __str__(self):52    def __str__(self):
n55        self.acids = ''.join(self.instances)n53        newstr= ''.join(self.instances)
56        return self.acids54        return newstr
57        pass55        pass
58    def __len__(self):56    def __len__(self):
n59        for elements in self.instances:n57        for i in self.instances:
60            return len(elements)-158            return len(i)-1
61    def count(self):59    def count(self):
62        length=len(self.instances[0])60        length=len(self.instances[0])
63        for i in range(length-1):61        for i in range(length-1):
n64            numcount= 0n62            numbercounta=0
65            numcount= 063            numbercountc=0
66            numcount= 064            numbercountg=0
67            numcount= 065            numbercountt=0
68            for j in range(len(self.instances)):66            for j in range(len(self.instances)):
n69                if self.instances[j][i].upper() == 'A':n67                if self.instances[j][i].upper()=='A':
70                    numcountA += 168                    numbercounta +=1
71                elif self.instances[j][i].upper() == 'C':69                elif self.instances[j][i].upper()=='C':
72                    numcountC += 170                    numbercountc +=1
73                elif self.instances[j][i].upper() == 'G':71                elif self.instances[j][i].upper()=='G':
74                    numcountG += 172                    numbercountg +=1
75                elif self.instances[j][i].upper() == 'T':73                elif self.instances[j][i].upper()=='T':
76                    numcountT += 174                    numbercountt +=1
77            self.counts['A'].append(numcountA)75            self.counts['A'].append(numbercounta)
78            self.counts['C'].append(numcountC)76            self.counts['C'].append(numbercountc)
79            self.counts['G'].append(numcountG)77            self.counts['G'].append(numbercountg)
80            self.counts['T'].append(numcountT)78            self.counts['T'].append(numbercountt)
81    def compute_consensus(self):79    def compute_consensus(self):
82        DNAMOTIF.count(self)80        DNAMOTIF.count(self)
n83        kenneth=[]n
84        length = len(self.counts['A'])81        length=len(self.counts['A'])
82        result=[]
85        for i in range(length):83        for i in range(length):
n86            sid = []n84            newList=[]
87            a=self.counts['A']85            a = self.counts['A']
88            c=self.counts['C']86            c = self.counts['C']
89            g=self.counts['G']87            g = self.counts['G']
90            t=self.counts['T']88            t = self.counts['T']
91            sid.append(int(a[i]))89            newList.append(int(a[i]))
92            sid.append(int(c[i]))90            newList.append(int(c[i]))
93            sid.append(int(g[i]))91            newList.append(int(g[i]))
94            sid.append(int(t[i]))92            newList.append(int(t[i]))
95            maxnu= max(sid)93            max_value= max(newList)
96            index = sid.index(maxnum)94            max_index = newList.index(max_value)
97            if index==0:95            if max_index==0:
98                kenneth.append('A')96                result.append('A')
99            if index==1:97            if max_index==1:
100                kenneth.append('C')98                result.append('C')
101            if index==2:99            if max_index==2:
102                kenneth.append('G')100                result.append('G')
103            if index==3:101            if max_index==3:
104                kenneth.append('T') 102                result.append('T')  
105        self.consensus=(str(''.join(kenneth)))103        self.consensus=(str(''.join(result)))
106    def parse(self, filename):104    def parse(self, filename):
n107        x = open(filename)n105        f = open(filename) 
108        tempList = x.readlines()106        contents = f.readlines()
109        MOTIFList = []
110        for i in range(1, len(tempList), 2):
111            self.instances.append(tempList[i])
112        for i in range (1, len(self.instances)):
113            MOTIFList.append(self.instances[i])
114        x.close()107        f.close()
115        print(len(MOTIFList))108        list_elements = []
116        return(len(MOTIFList))109        for x in range(0, len(contents)):
110            if '>' not in contents[x]:
111                self.instances.append(contents[x])
112        for x in range (0, len(self.instances)-1):
113            list_elements.append(f'{self.instances[x]}\n')
117if __name__ == '__main__':114if __name__ == '__main__':
t118    self=DNAMOTIF()t115    self = DNAMOTIF()
119    DNAMOTIF.parse(self, 'lexA.fasta')116    DNAMOTIF.parse(self, "lexA.fasta")
120    DNAMOTIF.__len__(self, 'lexA.fasta')117    DNAMOTIF.__len__(self, "lexA.fasta")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 80

Student ID: 300, P-Value: 1.83e-01

Nearest Neighbor ID: 189

Student (left) and Nearest Neighbor (right).


n1from math import radians, cos, sin n1from math import cos, sin
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n3def generate(text, generator):n3from math import pi
4    gen = ''
5    for letter in text:
6        if letter in generator.keys():
7            gen += generator[letter]
8        elif letter not in generator.keys():
9            gen += letter
10    return gen
11class PLANT:4class PLANT:
12    def __init__(self, state, generator, n, dTheta):5    def __init__(self, state, generator, n, dTheta):
nn6        self.state = state
13        self.generator = generator7        self.generator = generator
14        self.n = n8        self.n = n
n15        self.dTheta = radians(dThetan9        self.dTheta = dTheta
16        newstate = state10        c = ''
17        for i in range(n):11        for _ in range(n):
18            newstate = generate(newstate, generator) 12            for letter in self.state:
13                if letter in generator:
14                    c += generator[letter]
15                else:
16                    c += letter
17            self.state = c
18            c = ''
19        self.str = newstate19        self.str = self.state
20    def drawPlant(self):20    def drawPlant(self):
nn21        currentPt = (200, 0)
22        theta = 90
21        stack = []23        stack = []
n22        currentPt = (200,0)n
23        theta = radians(90) 
24        for letter in self.str:24        for symbol in self.str:
25            if letter.isalpha():25            if symbol.isalpha():
26                nextPt = (currentPt[0] + cos(theta), currentPt[1] + sin(theta))26                nextPt = (currentPt[0]+cos(theta*pi/180),
27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27                          currentPt[1]+sin(theta*pi/180))
>='black') 
28                plt.plot([currentPt[0], nextPt[0]], [
29                         currentPt[1], nextPt[1]], color='black')
28                currentPt = nextPt30                currentPt = nextPt
n29            elif letter == '[':n31            elif symbol == '[':
30                stack.append(currentPt)32                stack.append(currentPt)
31                stack.append(theta)33                stack.append(theta)
n32            elif letter == ']':n34            elif symbol == ']':
33                theta = stack.pop()35                theta = stack.pop()
34                currentPt = stack.pop()36                currentPt = stack.pop()
n35            elif letter == '+':n37            elif symbol == '+':
36                theta -= self.dTheta38                theta -= self.dTheta
n37            elif letter == '-':n39            elif symbol == '-':
38                theta += self.dTheta40                theta += self.dTheta
n39        plt.savefig('plant')n41        plt.savefig('my_plot.png')
40if __name__ == '__main__':42if __name__ == '__main__':
n41    plant1 = PLANT('F',{'F': 'F[+F]F[-F]F'},5,25.7)n43    plant = PLANT('F', {'F': 'F[+F]F[-F]F'}, 5, 25.7)
42    plant1.drawPlant()class DNAMOTIF:44    plant.drawPlant()
45class DNAMOTIF:
43    def __init__(self):46    def __init__(self):
n44        self.instances=[]n47        self.instances = []
45        self.consensus= ''48        self.consensus []  
46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}49        self.counts = {'A': [], 'C': [], 'G': [], 'T': []}
47    def __str__(self):50    def __str__(self):
n48        return '\n'.join(self.instances)n51        return ''.join(self.instances)
49    def __len__(self):52    def __len__(self):
n50        self.instances = [x.strip() for x in self.instances]n
51        return len(self.instances[0])53        return len(self.instances[0])-1
52    def count(self):
53        self.instances = [x.strip() for x in self.instances]
54        self.counts = {'A': [0] * len(self), 'C': [0] * len(self), 'G': [0] * le
>n(self), 'T': [0] * len(self)} 
55        for line in self.instances:
56            uline = line.upper()
57            for i, letter in enumerate(uline):
58                self.counts[letter][i] += 1
59    def compute_consensus(self):
60        self.instances = [x.strip() for x in self.instances]
61        self.count()
62        for i in range(len(self)):
63            a = self.counts['A'][i]
64            c = self.counts['C'][i]
65            t = self.counts['T'][i]
66            g = self.counts['G'][i]
67            nums = [a, c, g, t]
68            big = max(nums)
69            ind = nums.index(big)
70            if ind == 0:
71                let = 'A'
72            elif ind == 1 :
73                let = 'C'
74            elif ind == 2:
75                let = 'G'
76            elif ind == 3 :
77                let = 'T'
78            self.consensus += let
79    def parse(self, filename):54    def parse(self, filename):
80        with open(filename, 'r') as f:55        with open(filename, 'r') as f:
n81            for line in f:n56            data = f.readlines()
57            self.instances = data[1::2]
58    def count(self):
59        self.counts['A'] = [0]*len(self)
60        self.counts['G'] = [0]*len(self)
61        self.counts['C'] = [0]*len(self)
62        self.counts['T'] = [0]*len(self)
63        for instance in self.instances:
64            for i, letter in enumerate(instance.upper()):
82                if line[0] == '>':65                if letter == 'A':
83                    pass66                    self.counts['A'][i] += 1
84                else:67                if letter == 'C':
85                    self.instances.append(line)68                    self.counts['C'][i] += 1
69                if letter == 'G':
70                    self.counts['G'][i] += 1
71                if letter == 'T':
72                    self.counts['T'][i] += 1
73    def compute_consensus(self):
74        self.count()
75        cone = ''
76        for i in range(len(self)):
77            letterlist = [self.counts['A'][i], self.counts['C'][i],
78                          self.counts['G'][i], self.counts['T'][i]]
79            peepee = max(letterlist)
80            if peepee == letterlist[0]:
81                cone += 'A'
82            elif peepee == letterlist[1]:
83                cone += 'C'
84            elif peepee == letterlist[2]:
85                cone += 'G'
86            elif peepee == letterlist[3]:
87                cone += 'T'
88        self.consensus = cone
86if __name__ == '__main__':89if __name__ == '__main__':
87    lexA = DNAMOTIF()90    lexA = DNAMOTIF()
t88    lexA.parse('lexA.fasta')t91    lexA.parse(r"C:\Users\cresp\Downloads\c\lexA.fasta")
89    print(len(lexA))
90    lexA.count()92    lexA.count()
91    lexA.compute_consensus()93    lexA.compute_consensus()
92    print(lexA.consensus)94    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 81

Student ID: 102, P-Value: 1.83e-01

Nearest Neighbor ID: 75

Student (left) and Nearest Neighbor (right).


n1import numpy as np, matplotlib.pyplot as pltn1import matplotlib.pyplot as plt
2import numpy as np
2class PLANT:3class PLANT:
n3    def __init__(self, string='', generator={}, n=0, deltatheta=0.00):n4    def __init__(self, initial_state ='' , generator = {} , number_generations =
 > 0 , deltaTheta = 0.00):
4        self.string=string5        self.initial_state = initial_state
5        self.generator=generator6        self.generator = generator 
6        self.n= int(n) 7        self.number_generations = int(number_generations)
7        self.deltatheta= np.radians(deltatheta)8        self.deltaTheta = np.radians(deltaTheta)
8        for i in range(0, self.n):9        for i in range(self.number_generations):
9            result=''10            result = ''
10            for j in self.string:11            for j in self.initial_state:
11                if j in self.generator.keys():12                if j in self.generator.keys():
12                    result += self.generator[str(j)]13                    result += self.generator[str(j)]
13                else:14                else:
14                    result += j15                    result += j
n15            self.string = resultn16            self.initial_state = result
16        self.str = self.string17        self.str = self.initial_state
17    def drawPlant(self):18    def drawPlant(self):
n18        currentpos=[200,0]n19        currentPt = [200, 0]
19        theta=np.radians(90)20        theta = np.radians(90)
20        drawingState=[]21        drawing=[]
21        nextpt=()22        nextPt=()
22        stack=[]23        stack=[]
23        for i in self.str:24        for i in self.str:
24            if i.isalpha():25            if i.isalpha():
n25                nextpt=[currentpos[0]+np.cos(theta), currentpos[1]+np.sin(theta)n26                nextPt = [currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)
>]>]
26                plt.plot([currentpos[0], nextpt[0]],[currentpos[1],nextpt[1]],co27                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>lor='black')>olor = 'black')
27                currentpos=nextpt28                currentPt = nextPt
28            if i=='[':29            if i == '[':
29                drawingState = [currentpos, theta]30                drawing = [currentPt , theta]
30                stack.append(drawingState)31                stack.append(drawing)
31            elif i==']':32            elif i == ']':
32                currentpos=stack[-1][0]33                drawing = stack[len(stack) -1]
33                theta=stack[-1][1]
34                stack.pop()34                stack.pop(len(stack)-1)
35                currentPt = drawing[0]
36                theta = drawing[1]
35            elif i=='+':37            elif i == '+':
36                theta += self.deltatheta38                theta += self.deltaTheta
37            elif i=='-':39            elif i == '-':
38                theta-=self.deltatheta40                theta -= self.deltaTheta
39if __name__ == "__main__":41if __name__ == '__main__':
40    string = input()42    initial_state = input()
41    dictionary = input()43    dictionary = input()
n42    theta = input()n
43    n = input()44    num = input()
44    obj = PLANT(string, dictionary, n, theta)45    angle = float(input())
46    f = PLANT(initial_state, dictionary, num , angle)
45    obj.drawPlant()47    f.drawPlant()
46    plt.show()48    plt.show()
47class DNAMOTIF:49class DNAMOTIF:
48    def __init__(self):50    def __init__(self):
49        self.instances=[]51        self.instances=[]
50        self.consensus=[]52        self.consensus=[]
51        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}53        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
52    def __str__(self):54    def __str__(self):
n53        newstr= ''.join(self.instances)n55        self.acids = ''.join(self.instances)
54        return newstr56        return self.acids
55        pass57        pass
56    def __len__(self):58    def __len__(self):
n57        for i in self.instances:n59        for elements in self.instances:
58            return len(i)-160            return len(elements)-1
59    def count(self):61    def count(self):
60        length=len(self.instances[0])62        length=len(self.instances[0])
61        for i in range(length-1):63        for i in range(length-1):
n62            numbercounta=0n64            numcount= 0
63            numbercountc=065            numcount= 0
64            numbercountg=066            numcount= 0
65            numbercountt=067            numcount= 0
66            for j in range(len(self.instances)):68            for j in range(len(self.instances)):
n67                if self.instances[j][i].upper()=='A':n69                if self.instances[j][i].upper() == 'A':
68                    numbercounta +=170                    numcountA += 1
69                elif self.instances[j][i].upper()=='C':71                elif self.instances[j][i].upper() == 'C':
70                    numbercountc +=172                    numcountC += 1
71                elif self.instances[j][i].upper()=='G':73                elif self.instances[j][i].upper() == 'G':
72                    numbercountg +=174                    numcountG += 1
73                elif self.instances[j][i].upper()=='T':75                elif self.instances[j][i].upper() == 'T':
74                    numbercountt +=176                    numcountT += 1
75            self.counts['A'].append(numbercounta)77            self.counts['A'].append(numcountA)
76            self.counts['C'].append(numbercountc)78            self.counts['C'].append(numcountC)
77            self.counts['G'].append(numbercountg)79            self.counts['G'].append(numcountG)
78            self.counts['T'].append(numbercountt)80            self.counts['T'].append(numcountT)
79    def compute_consensus(self):81    def compute_consensus(self):
80        DNAMOTIF.count(self)82        DNAMOTIF.count(self)
nn83        kenneth=[]
81        length=len(self.counts['A'])84        length = len(self.counts['A'])
82        result=[]
83        for i in range(length):85        for i in range(length):
n84            newList=[]n86            si= []
85            a = self.counts['A']87            a=self.counts['A']
86            c = self.counts['C']88            c=self.counts['C']
87            g = self.counts['G']89            g=self.counts['G']
88            t = self.counts['T']90            t=self.counts['T']
89            newList.append(int(a[i]))91            sid.append(int(a[i]))
90            newList.append(int(c[i]))92            sid.append(int(c[i]))
91            newList.append(int(g[i]))93            sid.append(int(g[i]))
92            newList.append(int(t[i]))94            sid.append(int(t[i]))
93            max_value= max(newList)95            maxnu= max(sid)
94            max_index = newList.index(max_value)96            index = sid.index(maxnum)
95            if max_index==0:97            if index==0:
96                result.append('A')98                kenneth.append('A')
97            if max_index==1:99            if index==1:
98                result.append('C')100                kenneth.append('C')
99            if max_index==2:101            if index==2:
100                result.append('G')102                kenneth.append('G')
101            if max_index==3:103            if index==3:
102                result.append('T')  104                kenneth.append('T') 
103        self.consensus=(str(''.join(result)))105        self.consensus=(str(''.join(kenneth)))
104    def parse(self, filename):106    def parse(self, filename):
n105        f = open(filename) n107        x = open(filename)
106        contents = f.readlines()108        tempList = x.readlines()
109        MOTIFList = []
110        for i in range(1, len(tempList), 2):
111            self.instances.append(tempList[i])
112        for i in range (1, len(self.instances)):
113            MOTIFList.append(self.instances[i])
107        f.close()114        x.close()
108        list_elements = []115        print(len(MOTIFList))
109        for x in range(0, len(contents)):116        return(len(MOTIFList))
110            if '>' not in contents[x]:
111                self.instances.append(contents[x])
112        for x in range (0, len(self.instances)-1):
113            list_elements.append(f'{self.instances[x]}\n')
114if __name__ == '__main__':117if __name__ == '__main__':
t115    self = DNAMOTIF()t118    self=DNAMOTIF()
116    DNAMOTIF.parse(self, "lexA.fasta")119    DNAMOTIF.parse(self, 'lexA.fasta')
117    DNAMOTIF.__len__(self, "lexA.fasta")120    DNAMOTIF.__len__(self, 'lexA.fasta')
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 82

Student ID: 8, P-Value: 1.90e-01

Nearest Neighbor ID: 56

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
n3def loops(strings,generator,iterations):n3def new(strings,generator,iterations):
4    strn = strings4    string = strings
5    for t in range(iterations):5    i=0
6    while i < iterations:
6        lststr=list(strn)7        gen=list(string)
7        for i in range(len(lststr)):8        for h in range(len(gen)):
8            var=lststr[i]9            stuff=gen[h]
9            for j in generator:10            for ok in generator:
10                if var==j:11                if stuff==ok:
11                    lststr[i]=generator[j]12                    gen[h]=generator[ok]
13        i+=1
12        strn=''.join(lststr)14        string=''.join(gen)
13    return strn15    return string
14class PLANT():16class PLANT():
n15    def __init__(self, page, ide, gong,sng=''):n17    def __init__(self, begin='', generators= {}, n=0, deltaTheta=0):
16        self.page=dict(page)18        self.begin=str(begin)
19        self.generators=dict(generators)
17        self.ide=int(ide)20        self.n=int(n)
18        self.gong = np.radians(gong)21        self.deltaTheta = np.radians(deltaTheta)
19        self.sng = sng22        self.str = new(self.begin,self.generators,self.n)
20    def __str__(self):23    def str(self):
21        self.str = loops(self.page,self.ide,self.sng)24        i=0
25        while i < self.n:
26            new_string=''
27            for j in range(len(self.string)):
28                if self.string[j] in self.generator:
29                    new_string+= self.generator[self.string[j]]
30                else:
31                    new_string+=self.string[j]
32            i+=1
33            self.string=new_string
34        return self.string
22    def drawPlant(self):35    def drawPlant(self):
23        currentPt=(200,0)36        currentPt=(200,0)
24        theta=9037        theta=90
25        theta=np.radians(theta)38        theta=np.radians(theta)
26        nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta))39        nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta))
n27        pp=[]n40        stack=[]
28        strlst=list(self.str)41        great=list(self.str)
29        for c in strlst:42        for p in great:
30            if ']' == c:43            if ']' == p:
31                (currentPt,theta) = pp[-1]44                (currentPt,theta) = stack[-1]
32                pp.pop(-1)45                stack.pop(-1)
33            elif "[" == c:46            elif "[" == p:
34                pp.append([currentPt,theta])47                stack.append([currentPt,theta])
35            elif "-" == c:48            elif "-" == p:
36                theta-=-self.gong49                theta=theta-self.deltaTheta
37            elif '+' == c:50            elif '+' == p:
38                theta+=self.gong51                theta=theta+self.deltaTheta
39            else:52            else:
40                nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)53                nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)
>)>)
41                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color54                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
42                currentPt=nextPt55                currentPt=nextPt
nn56        return plt.show()
43if __name__=="__main__":57if __name__=="__main__":
nn58    user_string=input()
59    user_generator=input()
44    i1=input()60    user_n=input()
45    i2=input()61    user_deltaTheta=input()
46    i3=input()62    myPlant=PLANT(user_string,user_generator,user_n,user_deltaTheta)
47    i4=input()63    myPlant.drawPlant()
48    jawn=PLANT(i1,i2,i3,i4)64    print(type(myPlant.string))
49    print(jawn.str)65    print(myPlant.str())class DNAMOTIF:
50    jawn.drawPlant()class DNAMOTIF:
51    def __init__(self):66    def __init__(self):
n52        self.instances= []n67        self.instances=[]
53        self.consensus= ''68        self.consensus=''
54        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
55    def __str__(self):70    def __str__(self):
n56        x=''n71        x=""
57        for i in self.instances:72        for i in self.instances:
58            x+=i73            x+=i
59        return x74        return x
n60    def __len__(self):n75    def __len__(self,B=0):
61        return len(self.instances[0]) - 176        return len(self.instances[0])-1
62    def count(self):77    def count(self):
n63        x=''n78        x=""
64        for n in range(0, len(self.instances[0]) - 1):79        for n in range(0,len(self.instances[0])-1):
65            self.counts['A'].append(0)80            self.counts['A'].append(0)
66            self.counts['C'].append(0)81            self.counts['C'].append(0)
67            self.counts['G'].append(0)82            self.counts['G'].append(0)
68            self.counts['T'].append(0)83            self.counts['T'].append(0)
n69        for x in range(0, len(self.instances)):n84        for x in range(0,len(self.instances)):
70            for y in range(0,len(self.instances[0]) - 1):85            for y in range(0,len(self.instances[0])-1):
71                i=self.instances[x][y]86                i=self.instances[x][y]
n72                if i=='A' or i=='a':n87                if i=="A" or i=="a":
73                    f=self.counts['A']88                    a=self.counts["A"]
74                    f[y]+=189                    a[y]+=1
75                if i=='C' or i=='c':90                elif i=="C" or i=="c":
76                    f=self.counts['C']91                    c=self.counts["C"]
77                    f[y]+=192                    c[y]+=1
78                if i=='G' or i=='g':93                elif i=="G" or i=="g":
79                    f=self.counts['G']94                    g=self.counts["G"]
80                    f[y]+=195                    g[y]+=1
81                if i=='T' or i=='t':96                elif i=="T" or i=="t":
82                    f=self.counts['T']97                    t=self.counts["T"]
83                    f[y]+=198                    t[y]+=1
84        return self.counts99        return self.counts
85    def compute_consensus(self):100    def compute_consensus(self):
86        self.count()101        self.count()
n87        A=self.counts['A']n102        A=self.counts["A"]
88        C=self.counts['C']103        C=self.counts["C"]
89        G=self.counts['G']104        G=self.counts["G"]
90        T=self.counts['T']105        T=self.counts["T"]
91        x=''106        string=""
92        for i in range(len(A)):107        for i in range(len(A)):
n93            m=max(A[i],C[i],G[i],T[i])n108            if A[i]>C[i]  and A[i]>G[i] and A[i]>T[i]:
94            if A[i]==m:
95                x+="A"109                string+="A"
96            if C[i]==m:110            if T[i]>C[i]  and T[i]>G[i] and T[i]>A[i]:
97                x+="C"
98            if G[i]==m:
99                x+="G"
100            if T[i]==m:
101                x+="T"111                string+="T"
112            if G[i]>C[i]  and G[i]>A[i] and G[i]>T[i]:
113                string+="G"
114            if C[i]>A[i]  and C[i]>G[i] and C[i]>T[i]:
115                string+="C"
102            self.consensus=x116            self.consensus=string
103        return self.consensus117        return self.consensus
104    def parse(self, filename):118    def parse(self, filename):
105        count=0119        count=0
106        with open(filename,'r') as f:120        with open(filename,'r') as f:
107            for line in f:121            for line in f:
108                if count%2 != 0:122                if count%2 != 0:
109                    self.instances.append(line)123                    self.instances.append(line)
110                count+=1 124                count+=1 
111        return self.instances125        return self.instances
112if __name__=="__main__":126if __name__=="__main__":
113    lexA=DNAMOTIF()127    lexA=DNAMOTIF()
114    lexA.parse("lexA.fasta")128    lexA.parse("lexA.fasta")
115    print(lexA.compute_consensus())129    print(lexA.compute_consensus())
tt130    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 83

Student ID: 56, P-Value: 1.90e-01

Nearest Neighbor ID: 8

Student (left) and Nearest Neighbor (right).


f1import matplotlib.pyplot as pltf1import matplotlib.pyplot as plt
2import numpy as np2import numpy as np
n3def new(strings,generator,iterations):n3def loops(strings,generator,iterations):
4    string = strings4    strn = strings
5    i=05    for t in range(iterations):
6    while i < iterations:
7        gen=list(string)6        lststr=list(strn)
8        for h in range(len(gen)):7        for i in range(len(lststr)):
9            stuff=gen[h]8            var=lststr[i]
10            for ok in generator:9            for j in generator:
11                if stuff==ok:10                if var==j:
12                    gen[h]=generator[ok]11                    lststr[i]=generator[j]
13        i+=1
14        string=''.join(gen)12        strn=''.join(lststr)
15    return string13    return strn
16class PLANT():14class PLANT():
n17    def __init__(self, begin='', generators= {}, n=0, deltaTheta=0):n15    def __init__(self, page, ide, gong,sng=''):
18        self.begin=str(begin)16        self.page=dict(page)
19        self.generators=dict(generators)
20        self.n=int(n)17        self.ide=int(ide)
21        self.deltaTheta = np.radians(deltaTheta)18        self.gong = np.radians(gong)
22        self.str = new(self.begin,self.generators,self.n)19        self.sng = sng
23    def str(self):20    def __str__(self):
24        i=021        self.str = loops(self.page,self.ide,self.sng)
25        while i < self.n:
26            new_string=''
27            for j in range(len(self.string)):
28                if self.string[j] in self.generator:
29                    new_string+= self.generator[self.string[j]]
30                else:
31                    new_string+=self.string[j]
32            i+=1
33            self.string=new_string
34        return self.string
35    def drawPlant(self):22    def drawPlant(self):
36        currentPt=(200,0)23        currentPt=(200,0)
37        theta=9024        theta=90
38        theta=np.radians(theta)25        theta=np.radians(theta)
39        nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta))26        nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta))
n40        stack=[]n27        pp=[]
41        great=list(self.str)28        strlst=list(self.str)
42        for p in great:29        for c in strlst:
43            if ']' == p:30            if ']' == c:
44                (currentPt,theta) = stack[-1]31                (currentPt,theta) = pp[-1]
45                stack.pop(-1)32                pp.pop(-1)
46            elif "[" == p:33            elif "[" == c:
47                stack.append([currentPt,theta])34                pp.append([currentPt,theta])
48            elif "-" == p:35            elif "-" == c:
49                theta=theta-self.deltaTheta36                theta-=-self.gong
50            elif '+' == p:37            elif '+' == c:
51                theta=theta+self.deltaTheta38                theta+=self.gong
52            else:39            else:
53                nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)40                nextPt = (currentPt[0]+np.cos(theta), currentPt[1]+np.sin(theta)
>)>)
54                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color41                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
55                currentPt=nextPt42                currentPt=nextPt
n56        return plt.show()n
57if __name__=="__main__":43if __name__=="__main__":
n58    user_string=input()n
59    user_generator=input()
60    user_n=input()44    i1=input()
61    user_deltaTheta=input()45    i2=input()
62    myPlant=PLANT(user_string,user_generator,user_n,user_deltaTheta)46    i3=input()
63    myPlant.drawPlant()47    i4=input()
64    print(type(myPlant.string))48    jawn=PLANT(i1,i2,i3,i4)
65    print(myPlant.str())class DNAMOTIF:49    print(jawn.str)
50    jawn.drawPlant()class DNAMOTIF:
66    def __init__(self):51    def __init__(self):
n67        self.instances=[]n52        self.instances= []
68        self.consensus=''53        self.consensus= ''
69        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}54        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
70    def __str__(self):55    def __str__(self):
n71        x=""n56        x=''
72        for i in self.instances:57        for i in self.instances:
73            x+=i58            x+=i
74        return x59        return x
n75    def __len__(self,B=0):n60    def __len__(self):
76        return len(self.instances[0])-161        return len(self.instances[0]) - 1
77    def count(self):62    def count(self):
n78        x=""n63        x=''
79        for n in range(0,len(self.instances[0])-1):64        for n in range(0, len(self.instances[0]) - 1):
80            self.counts['A'].append(0)65            self.counts['A'].append(0)
81            self.counts['C'].append(0)66            self.counts['C'].append(0)
82            self.counts['G'].append(0)67            self.counts['G'].append(0)
83            self.counts['T'].append(0)68            self.counts['T'].append(0)
n84        for x in range(0,len(self.instances)):n69        for x in range(0, len(self.instances)):
85            for y in range(0,len(self.instances[0])-1):70            for y in range(0,len(self.instances[0]) - 1):
86                i=self.instances[x][y]71                i=self.instances[x][y]
n87                if i=="A" or i=="a":n72                if i=='A' or i=='a':
88                    a=self.counts["A"]73                    f=self.counts['A']
89                    a[y]+=174                    f[y]+=1
90                elif i=="C" or i=="c":75                if i=='C' or i=='c':
91                    c=self.counts["C"]76                    f=self.counts['C']
92                    c[y]+=177                    f[y]+=1
93                elif i=="G" or i=="g":78                if i=='G' or i=='g':
94                    g=self.counts["G"]79                    f=self.counts['G']
95                    g[y]+=180                    f[y]+=1
96                elif i=="T" or i=="t":81                if i=='T' or i=='t':
97                    t=self.counts["T"]82                    f=self.counts['T']
98                    t[y]+=183                    f[y]+=1
99        return self.counts84        return self.counts
100    def compute_consensus(self):85    def compute_consensus(self):
101        self.count()86        self.count()
n102        A=self.counts["A"]n87        A=self.counts['A']
103        C=self.counts["C"]88        C=self.counts['C']
104        G=self.counts["G"]89        G=self.counts['G']
105        T=self.counts["T"]90        T=self.counts['T']
106        string=""91        x=''
107        for i in range(len(A)):92        for i in range(len(A)):
n108            if A[i]>C[i]  and A[i]>G[i] and A[i]>T[i]:n93            m=max(A[i],C[i],G[i],T[i])
94            if A[i]==m:
109                string+="A"95                x+="A"
110            if T[i]>C[i]  and T[i]>G[i] and T[i]>A[i]:96            if C[i]==m:
111                string+="T"
112            if G[i]>C[i]  and G[i]>A[i] and G[i]>T[i]:
113                string+="G"
114            if C[i]>A[i]  and C[i]>G[i] and C[i]>T[i]:
115                string+="C"97                x+="C"
98            if G[i]==m:
99                x+="G"
100            if T[i]==m:
101                x+="T"
116            self.consensus=string102            self.consensus=x
117        return self.consensus103        return self.consensus
118    def parse(self, filename):104    def parse(self, filename):
119        count=0105        count=0
120        with open(filename,'r') as f:106        with open(filename,'r') as f:
121            for line in f:107            for line in f:
122                if count%2 != 0:108                if count%2 != 0:
123                    self.instances.append(line)109                    self.instances.append(line)
124                count+=1 110                count+=1 
125        return self.instances111        return self.instances
126if __name__=="__main__":112if __name__=="__main__":
127    lexA=DNAMOTIF()113    lexA=DNAMOTIF()
128    lexA.parse("lexA.fasta")114    lexA.parse("lexA.fasta")
129    print(lexA.compute_consensus())115    print(lexA.compute_consensus())
t130    print(lexA.consensus)t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 84

Student ID: 221, P-Value: 2.03e-01

Nearest Neighbor ID: 399

Student (left) and Nearest Neighbor (right).


n1import mathn1import numpy as np
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, initial_state , generator, number, deltaTheta):n4    def __init__(self, string, generator, n, deltaTheta):
5        self.initial_state = initial_state5        self.string = string
6        self.generator = generator6        self.generator  = generator
7        self.number = number7        self.n = n
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
n9        plt = self.initial_staten
10        j = 0
11        while j in range(0,self.number):9        for i in range(self.n):
12            other = ''10            new_string = ''
13            for t in plt:11            for c in self.string:
14                if t in generator:12                if c in self.generator:
15                    other +=generator[t]13                    new_string += self.generator.get(c)
16                else:14                else :
17                    other+=t15                    new_string += c
18            plt = other16            self.string = new_string
19            j+=117    def drawPlant(self):
20        PLANT.str=other18        currentpt = [200,0]
21myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)19        theta = np.radians(90)
22print(myPlant.str)class DNAMOTIF:20        drawing_state = []
21        nextpt = ()
22        stack = []
23        for c in self.string:
24            if c == '[':
25                savedpt = currentpt
26                savedtheta = theta
27            elif c == ']':
28                currentpt = savedpt
29                theta = savedtheta
30            elif c == '+':
31                theta += self.deltatheta
32            elif c == '-':
33                theta += -self.deltatheta
34            elif c in alphabet:
35                nextpt = [currentpt[0] + np.cos(theta), currentpt[1] + np.sin(th
 >eta)]
36                plt.plot([currentpt[0], nextpt[0]], [currentpt[1], nextpt[1]], c
 >olor = 'black')
37                currentpt = nextptclass DNAMOTIF:
23    def __init__(self):38    def __init__(self):
24        self.instances=[]39        self.instances=[]
25        self.consensus=[]40        self.consensus=[]
26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
27    def __str__(self):42    def __str__(self):
n28        string = ''n43        string = ""
29        for j in self.instances:44        for i in self.instances:
30            string +=j + "\n" 45            string += i + "\n"
31        return string[:-2] 46        return string[:-2]
32    def __len__(self):47    def __len__(self):
33        return len(self.instances)48        return len(self.instances)
34    def count(self):49    def count(self):
n35        for j in self.instances:n50        for i in self.instances:
36            temp = j.upper()51            temp = i.upper()
37            self.counts["A"].append(temp.count("A"))52            self.counts["A"].append(temp.count("A"))
38            self.counts["C"].append(temp.count("C"))53            self.counts["C"].append(temp.count("C"))
39            self.counts["G"].append(temp.count("G"))54            self.counts["G"].append(temp.count("G"))
40            self.counts["T"].append(temp.count("T"))55            self.counts["T"].append(temp.count("T"))
41    def compute_consensus(self):56    def compute_consensus(self):
42        A = self.counts["A"]57        A = self.counts["A"]
43        C = self.counts["C"]58        C = self.counts["C"]
44        G = self.counts["G"]59        G = self.counts["G"]
45        T = self.counts["T"]60        T = self.counts["T"]
n46        for j in range(len(A)):n61        for i in range(len(A)):
47            if(A[j] >= C[j] and A[j] >= G[j] and A[j] >= T[j]):62            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):
48                self.consensus.append("A")63                self.consensus.append("A")
n49            elif (C[j] >= G[j] and C[j] >= T[j]):n64            elif (C[i] >= G[i] and C[i] >= T[i]):
50                self.consensus.append("C")65                self.consensus.append("C")
n51            elif (G[j] >= T[j]):n66            elif (G[i] >= T[i]):
52                self.consensus.append("G")67                self.consensus.append("G")
53            else:68            else:
54                self.consensus.append("T")69                self.consensus.append("T")
55    def parse(self, filename):70    def parse(self, filename):
56        with open(filename,'r') as f:71        with open(filename,'r') as f:
57            for i in f:72            for i in f:
58                if ">" in i:73                if ">" in i:
n59                    continuen74                   continue
60                else:75                else:
61                    self.instances.append(i)76                    self.instances.append(i)
t62lexA = DNAMOTIF()t
63lexA.parse("lexA.fasta")
64print(len(lexA))
65lexA = DNAMOTIF()
66lexA.parse("lexA.fasta")
67print(lexA)
68lexA.count()
69print(lexA.counts)
70lexA.compute_consensus()
71print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 85

Student ID: 399, P-Value: 2.03e-01

Nearest Neighbor ID: 221

Student (left) and Nearest Neighbor (right).


n1import numpy as npn1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, string, generator, n, deltaTheta):n4    def __init__(self, initial_state , generator, number, deltaTheta):
5        self.string = string5        self.initial_state = initial_state
6        self.generator  = generator6        self.generator = generator
7        self.n = n7        self.number = number
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
nn9        plt = self.initial_state
10        j = 0
9        for i in range(self.n):11        while j in range(0,self.number):
10            new_string = ''12            other = ''
11            for c in self.string:13            for t in plt:
12                if c in self.generator:14                if t in generator:
13                    new_string += self.generator.get(c)15                    other +=generator[t]
14                else :16                else:
15                    new_string += c17                    other+=t
16            self.string = new_string18            plt = other
17    def drawPlant(self):19            j+=1
18        currentpt = [200,0]20        PLANT.str=other
19        theta = np.radians(90)21myPlant = PLANT('b', {'b':'a', 'a':'ab'},5,25)
20        drawing_state = []22print(myPlant.str)class DNAMOTIF:
21        nextpt = ()
22        stack = []
23        for c in self.string:
24            if c == '[':
25                savedpt = currentpt
26                savedtheta = theta
27            elif c == ']':
28                currentpt = savedpt
29                theta = savedtheta
30            elif c == '+':
31                theta += self.deltatheta
32            elif c == '-':
33                theta += -self.deltatheta
34            elif c in alphabet:
35                nextpt = [currentpt[0] + np.cos(theta), currentpt[1] + np.sin(th
>eta)] 
36                plt.plot([currentpt[0], nextpt[0]], [currentpt[1], nextpt[1]], c
>olor = 'black') 
37                currentpt = nextptclass DNAMOTIF:
38    def __init__(self):23    def __init__(self):
39        self.instances=[]24        self.instances=[]
40        self.consensus=[]25        self.consensus=[]
41        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
42    def __str__(self):27    def __str__(self):
n43        string = ""n28        string = ''
44        for i in self.instances:29        for j in self.instances:
45            string += i + "\n"30            string +=j + "\n" 
46        return string[:-2]31        return string[:-2] 
47    def __len__(self):32    def __len__(self):
48        return len(self.instances)33        return len(self.instances)
49    def count(self):34    def count(self):
n50        for i in self.instances:n35        for j in self.instances:
51            temp = i.upper()36            temp = j.upper()
52            self.counts["A"].append(temp.count("A"))37            self.counts["A"].append(temp.count("A"))
53            self.counts["C"].append(temp.count("C"))38            self.counts["C"].append(temp.count("C"))
54            self.counts["G"].append(temp.count("G"))39            self.counts["G"].append(temp.count("G"))
55            self.counts["T"].append(temp.count("T"))40            self.counts["T"].append(temp.count("T"))
56    def compute_consensus(self):41    def compute_consensus(self):
57        A = self.counts["A"]42        A = self.counts["A"]
58        C = self.counts["C"]43        C = self.counts["C"]
59        G = self.counts["G"]44        G = self.counts["G"]
60        T = self.counts["T"]45        T = self.counts["T"]
n61        for i in range(len(A)):n46        for j in range(len(A)):
62            if(A[i] >= C[i] and A[i] >= G[i] and A[i] >= T[i]):47            if(A[j] >= C[j] and A[j] >= G[j] and A[j] >= T[j]):
63                self.consensus.append("A")48                self.consensus.append("A")
n64            elif (C[i] >= G[i] and C[i] >= T[i]):n49            elif (C[j] >= G[j] and C[j] >= T[j]):
65                self.consensus.append("C")50                self.consensus.append("C")
n66            elif (G[i] >= T[i]):n51            elif (G[j] >= T[j]):
67                self.consensus.append("G")52                self.consensus.append("G")
68            else:53            else:
69                self.consensus.append("T")54                self.consensus.append("T")
70    def parse(self, filename):55    def parse(self, filename):
71        with open(filename,'r') as f:56        with open(filename,'r') as f:
72            for i in f:57            for i in f:
73                if ">" in i:58                if ">" in i:
n74                   continuen59                    continue
75                else:60                else:
76                    self.instances.append(i)61                    self.instances.append(i)
tt62lexA = DNAMOTIF()
63lexA.parse("lexA.fasta")
64print(len(lexA))
65lexA = DNAMOTIF()
66lexA.parse("lexA.fasta")
67print(lexA)
68lexA.count()
69print(lexA.counts)
70lexA.compute_consensus()
71print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 86

Student ID: 411, P-Value: 2.16e-01

Nearest Neighbor ID: 300

Student (left) and Nearest Neighbor (right).


nn1from math import radians, cos, sin 
1import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n2import mathn3def generate(text, generator):
4    gen = ''
5    for letter in text:
6        if letter in generator.keys():
7            gen += generator[letter]
8        elif letter not in generator.keys():
9            gen += letter
10    return gen
3class PLANT:11class PLANT:
n4    def __init__(self, initial_state, generator, n, delta_theta):n12    def __init__(self, state, generator, n, dTheta):
5        self.initial_state = initial_state
6        self.generator = generator13        self.generator = generator
7        self.n = n14        self.n = n
n8        self.delta_theta = delta_thetan15        self.dTheta = radians(dTheta) 
9        self.str = initial_state16        newstate = state
10        for i in range(n):17        for i in range(n):
n11            new_state = ''n18            newstate = generate(newstate, generator) 
12            for x in self.str:
13                if x in self.generator:
14                    new_state += self.generator[x]
15                else:
16                    new_state += x
17            self.str = new_state19        self.str = newstate
18    def drawPlant(self):20    def drawPlant(self):
nn21        stack = []
19        currentPt = (200,0)22        currentPt = (200,0)
n20        theta = math.radians(90)n23        theta = radians(90) 
21        stack = []24        for letter in self.str:
22        for i in range(len(self.str)):25            if letter.isalpha():
23            if self.str[i] == '[':
24                stack.append([currentPt, theta])
25            elif self.str[i] == ']':
26                currentPt = stack[-1][0]
27                theta = stack[-1][1]
28                stack.pop(-1)
29            elif self.str[i] == '+':
30                theta += math.radians(self.delta_theta)
31            elif self.str[i] == '-':
32                theta -= math.radians(self.delta_theta)
33            else:
34                nextPt = (currentPt[0]+math.cos(theta), currentPt[1]+math.sin(th26                nextPt = (currentPt[0] + cos(theta), currentPt[1] + sin(theta))
>eta)) 
35                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color27                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
36                currentPt = nextPt28                currentPt = nextPt
nn29            elif letter == '[':
30                stack.append(currentPt)
31                stack.append(theta)
32            elif letter == ']':
33                theta = stack.pop()
34                currentPt = stack.pop()
35            elif letter == '+':
36                theta -= self.dTheta
37            elif letter == '-':
38                theta += self.dTheta
39        plt.savefig('plant')
37if __name__ == '__main__':40if __name__ == '__main__':
n38    myPlant=PLANT('F',{'F': 'F[+F]F[-F]F'},3,25.7)n41    plant= PLANT('F',{'F': 'F[+F]F[-F]F'},5,25.7)
39    print(myPlant.str)42    plant1.drawPlant()class DNAMOTIF:
40    myPlant.drawPlant()
41    plt.axis('image')
42    plt.show()
43class DNAMOTIF:
44    def __init__(self):43    def __init__(self):
45        self.instances=[]44        self.instances=[]
n46        self.consensus=[]n45        self.consensus= ''
47        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}46        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
48    def __str__(self):47    def __str__(self):
n49        motif = ''n48        return '\n'.join(self.instances)
50        for i in range(len(self.instances)):
51            motif += (self.instances[i])
52        return(motif)    
53    def __len__(self):49    def __len__(self):
nn50        self.instances = [x.strip() for x in self.instances]
54        return(len(self.instances[0])-1)51        return len(self.instances[0])
55    def count(self):52    def count(self):
n56        for index in range(len(self.instances[0])-1):n53        self.instances = [x.strip() for x in self.instances]
57            self.counts['A'].append(0)54        self.counts = {'A': [0] * len(self), 'C': [0] * len(self), 'G': [0] * le
 >n(self), 'T': [0] * len(self)}
58            self.counts['C'].append(0)
59            self.counts['G'].append(0)
60            self.counts['T'].append(0)
61            for line in self.instances:55        for line in self.instances:
62                letter = line[index].upper()56            uline = line.upper()
57            for i, letter in enumerate(uline):
63                self.counts[letter][index] += 158                self.counts[letter][i] += 1
64    def compute_consensus(self):59    def compute_consensus(self):
nn60        self.instances = [x.strip() for x in self.instances]
65        self.count()61        self.count()
n66        most_frequent = ''n62        for i in range(len(self)):
67        for index in range(len(self.instances[0])-1):
68            highest = (self.counts['A'][index], 'A')63            a = self.counts['A'][i]
69            if self.counts['C'][index] > highest[0]:64            c = self.counts['C'][i]
70                highest = (self.counts['C'][index], 'C')
71            if self.counts['G'][index] > highest[0]:
72                highest = (self.counts['G'][index], 'G')
73            if self.counts['T'][index] > highest[0]:
74                highest = (self.counts['T'][index], 'T')65            t = self.counts['T'][i]
75            most_frequent += highest[1]66            g = self.counts['G'][i]
76        self.consensus = most_frequent67            nums = [a, c, g, t]
68            big = max(nums)
69            ind = nums.index(big)
70            if ind == 0:
71                let = 'A'
72            elif ind == 1 :
73                let = 'C'
74            elif ind == 2:
75                let = 'G'
76            elif ind == 3 :
77                let = 'T'
78            self.consensus += let
77    def parse(self, filename):79    def parse(self, filename):
78        with open(filename, 'r') as f:80        with open(filename, 'r') as f:
79            for line in f:81            for line in f:
80                if line[0] == '>':82                if line[0] == '>':
81                    pass83                    pass
82                else:84                else:
83                    self.instances.append(line)85                    self.instances.append(line)
84if __name__ == '__main__':86if __name__ == '__main__':
t85    lexA=DNAMOTIF()t87    lexA = DNAMOTIF()
86    lexA.parse("lexA.fasta")88    lexA.parse('lexA.fasta')
89    print(len(lexA))
90    lexA.count()
87    lexA.compute_consensus()91    lexA.compute_consensus()
88    print(lexA.consensus)92    print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 87

Student ID: 1, P-Value: 2.32e-01

Nearest Neighbor ID: 440

Student (left) and Nearest Neighbor (right).


f1import numpy as npf1import numpy as np
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, string, generator, n, deltaTheta):n4    def __init__(self, init_state, generator, n, deltaTheta):
5        self.string = str(string)5        self.initial_state=str(init_state)
6        self.generator = dict(generator)6        self.generator=dict(generator)
7        self.n = int(n)7        self.n=int(n)
8        self.deltaTheta = float(deltaTheta)class DNAMOTIF:8        self.deltaTheta= float(deltaTheta)
9        self.str= self.initial_state
10        plant_str = str(self.initial_state)
11        for c in range(n):
12            lst= list(plant_str)
13            two_Lst=[]
14            for i in lst:
15                if c in self.generator.keys():
16                    two_Lst.append(self.generator.get(i))
17                else:
18                    two_Lst.append(i)
19                    lst=two_Lst
20                    plant_str="".join((lst))
21        self.str=plant_str
22class DNAMOTIF:
9    def __init__(self):23    def __init__(self):
10        self.instances=[]24        self.instances=[]
11        self.consensus=[]25        self.consensus=[]
12        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
13    def __str__(self):27    def __str__(self):
n14        numtif=''n28        motif= ''
15        len_a = len(self.instances)
16        for i in range(len_a):29        for i in range(len(self.instances)):
17            numtif += (self.instances[i])30            motif+= self.instances[i]
18        return(numtif)31        return motif
19    def __len__(self):32    def __len__(self):
n20        lentif = len(self.instances[0])-1n33        return(len(self.instances[0])-1)
21        return(lentif)
22    def count(self):34    def count(self):
n23        for i in range(len(self.instances[0])-1):n35        for c in range(len(self.instances[0])-1):
24            self.counts['A'].append(0)36            self.counts['A'].append(0)
25            self.counts['C'].append(0)37            self.counts['C'].append(0)
26            self.counts['G'].append(0)38            self.counts['G'].append(0)
27            self.counts['T'].append(0)39            self.counts['T'].append(0)
n28            for j in self.instances:n40            for strand in self.instances:
29                let = j[i].lower()41                character=strand[c].upper()
30                if let == 'a':
31                    self.counts['A'][i] += 142                self.counts[character][c]+=1
32                elif let == 'c':
33                    self.counts['C'][i] += 1
34                elif let == 'g':
35                    self.counts['G'][i] += 1
36                elif let == 't':
37                    self.counts['T'][i] += 1
38    def compute_consensus(self):43    def compute_consensus(self):
n39        self.count()n44       self.count()
40        lst=''45       dna_List=''
41        for i in range(len(self.instances[0])-1):46       for c in range(len(self.instances[0])-1):
42            if self.counts['A'][i] > self.counts['C'][i] and self.counts['A'][i]47            consensus='A'
> > self.counts['G'][i] and self.counts['A'][i] > self.counts['T'][i]: 
43                common = 'A'
44            elif self.counts['C'][i] > self.counts['A'][i] and self.counts['C'][48            if self.counts['C'][c]>self.counts['A'][c] and self.counts['C'][c]>s
>i] > self.counts['G'][i] and self.counts['C'][i] > self.counts['T'][i]:>elf.counts['G'][c] and self.counts['C'][c]>self.counts['T'][c]:
45                common = 'C'  49               consensus='C'
46            elif self.counts['G'][i] > self.counts['A'][i] and self.counts['G'][50            if self.counts['G'][c]>self.counts['A'][c] and self.counts['G'][c]>s
>i] > self.counts['C'][i] and self.counts['G'][i] > self.counts['T'][i]:>elf.counts['C'][c] and self.counts['G'][c]>self.counts['T'][c]:
47                common = 'G'  51               consensus='G'
48            elif self.counts['T'][i] > self.counts['A'][i] and self.counts['T'][52            if self.counts['T'][c]>self.counts['A'][c] and self.counts['T'][c]>s
>i] > self.counts['C'][i] and self.counts['T'][i] > self.counts['G'][i]:>elf.counts['C'][c] and self.counts['T'][c]>self.counts['G'][c]:
49                common = 'T' 53               consensus='T'
50            lst = lst+common54            dna_List=dna_List+consensus
51        self.consensus lst55            self.consensus= dna_List
52    def parse(self, filename):56    def parse(self, filename):
t53        file = open(filename, 'r')t57        with open(filename, 'r') as f:
54        for i in file:58            for strand in f:
55            orig = i59                if strand[0]=='>':
56            i = i.lower()60                    pass
57            if i[0]=='a' or i[0]=='t' or i[0]=='c' or i[0]=='g':61                else:
58                self.instances.append(orig)62                    self.instances.append(strand)
59if __name__=='__main__':63    if __name__=='__main__':
60    df= DNAMOTIF()64        lexA= DNAMOTIF()
61    df.parse(r'C:\Users\maxwe\Downloads\lexA.fasta')65        lexA.parse('lexA.fasta')
62    df.compute_consensus()66        lexA.compute_consensus()
63    print(df.consensus)67        print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 88

Student ID: 440, P-Value: 2.32e-01

Nearest Neighbor ID: 1

Student (left) and Nearest Neighbor (right).


f1import numpy as npf1import numpy as np
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, init_state, generator, n, deltaTheta):n4    def __init__(self, string, generator, n, deltaTheta):
5        self.initial_state=str(init_state)5        self.string = str(string)
6        self.generator=dict(generator)6        self.generator = dict(generator)
7        self.n=int(n)7        self.n = int(n)
8        self.deltaTheta= float(deltaTheta)8        self.deltaTheta = float(deltaTheta)class DNAMOTIF:
9        self.str= self.initial_state
10        plant_str = str(self.initial_state)
11        for c in range(n):
12            lst= list(plant_str)
13            two_Lst=[]
14            for i in lst:
15                if c in self.generator.keys():
16                    two_Lst.append(self.generator.get(i))
17                else:
18                    two_Lst.append(i)
19                    lst=two_Lst
20                    plant_str="".join((lst))
21        self.str=plant_str
22class DNAMOTIF:
23    def __init__(self):9    def __init__(self):
24        self.instances=[]10        self.instances=[]
25        self.consensus=[]11        self.consensus=[]
26        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}12        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
27    def __str__(self):13    def __str__(self):
n28        motif= ''n14        numtif=''
15        len_a = len(self.instances)
29        for i in range(len(self.instances)):16        for i in range(len_a):
30            motif+= self.instances[i]17            numtif += (self.instances[i])
31        return motif18        return(numtif)
32    def __len__(self):19    def __len__(self):
n33        return(len(self.instances[0])-1)n20        lentif = len(self.instances[0])-1
21        return(lentif)
34    def count(self):22    def count(self):
n35        for c in range(len(self.instances[0])-1):n23        for i in range(len(self.instances[0])-1):
36            self.counts['A'].append(0)24            self.counts['A'].append(0)
37            self.counts['C'].append(0)25            self.counts['C'].append(0)
38            self.counts['G'].append(0)26            self.counts['G'].append(0)
39            self.counts['T'].append(0)27            self.counts['T'].append(0)
n40            for strand in self.instances:n28            for j in self.instances:
41                character=strand[c].upper()29                let = j[i].lower()
30                if let == 'a':
42                self.counts[character][c]+=131                    self.counts['A'][i] += 1
32                elif let == 'c':
33                    self.counts['C'][i] += 1
34                elif let == 'g':
35                    self.counts['G'][i] += 1
36                elif let == 't':
37                    self.counts['T'][i] += 1
43    def compute_consensus(self):38    def compute_consensus(self):
n44       self.count()n39        self.count()
45       dna_List=''40        lst=''
46       for c in range(len(self.instances[0])-1):41        for i in range(len(self.instances[0])-1):
47            consensus='A'42            if self.counts['A'][i] > self.counts['C'][i] and self.counts['A'][i]
 > > self.counts['G'][i] and self.counts['A'][i] > self.counts['T'][i]:
43                common = 'A'
48            if self.counts['C'][c]>self.counts['A'][c] and self.counts['C'][c]>s44            elif self.counts['C'][i] > self.counts['A'][i] and self.counts['C'][
>elf.counts['G'][c] and self.counts['C'][c]>self.counts['T'][c]:>i] > self.counts['G'][i] and self.counts['C'][i] > self.counts['T'][i]:
49               consensus='C'45                common = 'C'  
50            if self.counts['G'][c]>self.counts['A'][c] and self.counts['G'][c]>s46            elif self.counts['G'][i] > self.counts['A'][i] and self.counts['G'][
>elf.counts['C'][c] and self.counts['G'][c]>self.counts['T'][c]:>i] > self.counts['C'][i] and self.counts['G'][i] > self.counts['T'][i]:
51               consensus='G'47                common = 'G'  
52            if self.counts['T'][c]>self.counts['A'][c] and self.counts['T'][c]>s48            elif self.counts['T'][i] > self.counts['A'][i] and self.counts['T'][
>elf.counts['C'][c] and self.counts['T'][c]>self.counts['G'][c]:>i] > self.counts['C'][i] and self.counts['T'][i] > self.counts['G'][i]:
53               consensus='T'49                common = 'T' 
54            dna_List=dna_List+consensus50            lst = lst+common
55            self.consensus= dna_List51        self.consensus lst
56    def parse(self, filename):52    def parse(self, filename):
t57        with open(filename, 'r') as f:t53        file = open(filename, 'r')
58            for strand in f:54        for i in file:
59                if strand[0]=='>':55            orig = i
60                    pass56            i = i.lower()
61                else:57            if i[0]=='a' or i[0]=='t' or i[0]=='c' or i[0]=='g':
62                    self.instances.append(strand)58                self.instances.append(orig)
63    if __name__=='__main__':59if __name__=='__main__':
64        lexA= DNAMOTIF()60    df= DNAMOTIF()
65        lexA.parse('lexA.fasta')61    df.parse(r'C:\Users\maxwe\Downloads\lexA.fasta')
66        lexA.compute_consensus()62    df.compute_consensus()
67        print(lexA.consensus)63    print(df.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 89

Student ID: 159, P-Value: 2.35e-01

Nearest Neighbor ID: 309

Student (left) and Nearest Neighbor (right).


f1import mathf1import math
2import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
3class PLANT:3class PLANT:
n4    def __init__(self, initial, gen = {}, n = 0, deltaTheta = 0):n4    def __init__(self,initial,gen={},num=0,deltaTheta=0):
5        self.initial = initial5        self.initial = initial
6        self.gen = gen6        self.gen = gen
n7        self.n = nn7        self.num = num
8        self.deltaTheta = deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = initial9        self.str = initial
n10        while n>0:n10        while num > 0:
11            n -= 111            num -= 1
12            y = ''12            y = ''
13            for i in self.str:13            for i in self.str:
14                if i in gen:14                if i in gen:
15                    y += gen[i]15                    y += gen[i]
16                else:16                else:
17                    y += i17                    y += i
18            self.str = y18            self.str = y
19    def drawPlant(self):19    def drawPlant(self):
n20        currentPt=(200,0)n20        current_point=(200,0)
21        theta = 90*math.pi/18021        theta = 90 * math.pi/180
22        next_point = (current_point[0] + math.cos(theta), current_point[1] + mat
 >h.sin(theta))
23        plt.plot([current_point[0],next_point[0]],[current_point[1],next_point[1
 >]],color='black')
22        stack = []24        x = []
23        for i in self.str:25        for i in self.str:
24            if i == '[':26            if i == '[':
n25                stack.append([currentPt,theta])n27                x.append([current_point,theta])
26            elif i == ']':28            elif i == ']':
n27                currentPt = stack[-1][0]n29                current_point = x[-1][0]
28                theta = stack[-1][-1]30                theta = x[-1][1]
29                stack.pop()
30            elif i == '+':31            elif i == '+':
n31                theta += self.deltaTheta*math.pi/180n32                theta += self.deltaTheta
32            elif i == '-':33            elif i == '-':
n33                theta -= self.deltaTheta*math.pi/180n34                theta -= self.deltaTheta
34            else:35        current_point = next_point
35                nextPt = (currentPt[0]+math.cos(theta), currentPt[1]+math.sin(th36        x = []
>eta)) 
36                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color37        for i in self.str:
>='black') 
38            if i == '[':
39                x.append([current_point,theta])
40            elif i == ']':
37                currentPt = nextPt41                current_point = x[-1][0]
38if __name__ == "__main__":42                theta = x[-1][1]
39    Pl = PLANT('F',{'F':'F[+F]F[-F]F'},5,25.7)43            elif i == '+':
40    Pl.drawPlant()44                theta += self.deltaTheta
41    plt.show45            elif i == '-':
42    plt.savefig('books_read.png')46                theta -= self.deltaThetaclass DNAMOTIF:
43class DNAMOTIF:
44    def __init__(self):47    def __init__(self):
45        self.instances=[]48        self.instances=[]
n46        self.consensus=''n49        self.consensus=[]
47        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}50        self.counts= {'A':[],'C':[],'G':[],'T':[]}
48    def __str__(self):51    def __str__(self):
nn52        str = ''
49        for i in self.instances:53        for i in self.instances:
50            return i54            return i
nn55            str += i
56            return str[:-2]
51    def __len__(self):57    def __len__(self):
52        return len(self.instances[0])-158        return len(self.instances[0])-1
53    def count(self):59    def count(self):
nn60        i = 0
61        x = 0
54        xA = []62        A = []
55        xC = []63        C = []
56        xG = []64        G = []
57        xT = []65        T = []
58        for i in range(len(self.instances[0])-1):66        for i in range(len(self.instances[0])-1):
n59            xA.append(0)n67            A.append(0)
60            xC.append(0)68            C.append(0)
61            xG.append(0)69            G.append(0)
62            xT.append(0)70            T.append(0)
63        for i in self.instances:71        for i in self.instances:
64            i = i.upper()72            i = i.upper()
65            z = 073            z = 0
66            for j in i:74            for j in i:
67                if j == 'A':75                if j == 'A':
n68                    xA[z] += 1n76                    A[z] += 1
69                elif j == 'C':77                elif j == 'C':
n70                    xC[z] += 1n78                    C[z] += 1
71                elif j == 'G':79                elif j == 'G':
n72                    xG[z] += 1n80                    G[z] += 1
73                elif j == 'T':81                elif j == 'T':
n74                    xT[z] += 1n82                    T[z] += 1
75                z += 183                z += 1
n76        self.counts['A'] = xAn84        self.counts['A'] = A
77        self.counts['C'] = xC85        self.counts['C'] = C
78        self.counts['G'] = xG86        self.counts['G'] = G
79        self.counts['T'] = xT87        self.counts['T'] = T
80    def compute_consensus(self):88    def compute_consensus(self):
n81        xA = []n89        self.count()
82        xC = []90        A = self.counts["A"]
83        xG = []91        C = self.counts["C"]
84        xT = []92        G = self.counts["G"]
85        for i in range(len(self.instances[0])-1):93        T = self.counts["T"]
86            xA.append(0)
87            xC.append(0)
88            xG.append(0)
89            xT.append(0)
90        for i in self.instances:
91            i = i.upper()
92            z = 0
93            for j in i:
94                if j == 'A':
95                    xA[z] += 1
96                elif j == 'C':
97                    xC[z] += 1
98                elif j == 'G':
99                    xG[z] += 1
100                elif j == 'T':
101                    xT[z] += 1
102                z += 1
103        x = ''
104        for in range(len(xA)):94        for amino in range(len(A)):
105            if max(xA[i],xC[i],xG[i],xT[i]) == xA[i]:95            if(A[amino]>= C[amino] and A[amino] >= G[amino]  and A[amino] >= T[a
 >mino]):
106                x += 'A'96                self.consensus.append("A")
107            elif max(xA[i],xC[i],xG[i],xT[i]) == xC[i]:97            elif (C[amino] >= G[amino] and C[amino] >= T[amino]):
108                x += 'C'98                self.consensus.append("C")
109            elif max(xA[i],xC[i],xG[i],xT[i]) == xG[i]:99            elif (G[amino] >= T[amino]):
110                x += 'G'100                self.consensus.append("G")
111            elif max(xA[i],xC[i],xG[i],xT[i]) == xT[i]:101            else:
112                x += 'T'102                self.consensus.append("T")
113            self.consensus = x103        self.consensus = "".join(self.consensus)
114    def parse(self, filename):104    def parse(self, filename):
t115        x = open(filename,'r')t105        with open(filename,'r') as f:
116        y = 0106            for i in f:
117        for i in x.readlines():107                if ">" in i:
118            y += 1108                    continue
119            if y%2 == 0:109                else:
120                self.instances.append(i)110                    self.instances.append(i)
111lexA=DNAMOTIF()
112lexA.parse("lexA.fasta")
113lexA.count()
114print(lexA.counts)
115lexA.compute_consensus()
116print(lexA.consensus)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 90

Student ID: 491, P-Value: 9.62e-01

Nearest Neighbor ID: 193

Student (left) and Nearest Neighbor (right).


nn1import numpy 
1import matplotlib.pyplot as plt2import matplotlib.pyplot as plt
n2import numpy as npn
3from math import sin, cos, radians
4class PLANT:3class PLANT:
n5    def __init__(self,initialstate, generator, iterations, deltaTheta) -> None:n4    def __init__(self, string, dictionary, n, deltaTheta):
6        self.initialstate=initialstate5        self.string = string
7        self.generator=generator6        self.dictionary = dictionary
8        self.iterations=iterations7        self.n = n
9        self.deltaTheta=deltaTheta8        self.deltaTheta = deltaTheta
9        self.str = PLANT.generator(string, dictionary, n)
10    def generator(line, dictionary, n):
11        def unknown(line):
12            if line in dictionary:
13                return dictionary.get(line)
14            return line
15        subparts = [line]
10        for i in range(iterations):16        for i in range(n):
11            string=''17            beginning = subparts[-1]
12            for letter in self.initialstate:18            middle = [unknown(quan) for quan in beginning]
13                val = generator.get(letter)19            subparts.append(''.join(middle))
14                if val:20        finish = subparts[n]
15                    string += val21        return finish
16                else:
17                    string += letter
18            self.initialstate=string
19            self.str = self.initialstate
20    def drawPlant(self):22    def drawPlant(self):
nn23        alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P'
 >,'Q','R','S','T','U','V','W','X','Y','Z']
21        currentPt=(200,0)24        currentPt = (200,0)
22        theta=9025        theta = numpy.radians(90)
23        saved=[]26        deltaTheta = numpy.radians(self.deltaTheta)
27        stack = [currentPt, theta]
24        for everyletter in self.str:28        for offer in self.str:
25            everyletter.upper()29            if offer.upper() in alpha:
26            if everyletter=='A':
27                Radian = radians(theta)
28                nextPt = (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian)30                nextPt = (currentPt[0]+(numpy.cos(theta)), currentPt[1]+(numpy.s
>)>in(theta)))
29                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color31                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
>='black')>='black')
30                currentPt = nextPt32                currentPt = nextPt
n31            elif everyletter=='B':n33            else: 
32                Radian= radians(theta)34                if offer == '[':
33                nextPt = (currentPt[0] +cos(Radian), currentPt[1] +sin(Radian))
34                plt.plot([currentPt[0], nextPt[0]],[currentPt[1], nextPt[1]], co
>lor = 'black') 
35                currentPt = nextPt
36            elif everyletter=='C':
37                Radian =radians(theta)
38                nextPt = (currentPt[0] + cos(Radian),currentPt[1] + sin(Radian))
39                plt.plot([currentPt[0],nextPt[0]], [currentPt[1], nextPt[1]], co
>lor = 'black') 
40                currentPt = nextPt
41            elif everyletter=='D':
42                Radian = radians(theta)
43                nextPt = (currentPt[0]+ cos(Radian), currentPt[1] + sin(Radian))
44                plt.plot([currentPt[0], nextPt[0]], [currentPt[1],nextPt[1]],col
>or = 'black') 
45                currentPt = nextPt
46            elif everyletter=='E':
47                Radian = radians(theta)
48                nextPt = (currentPt[0] + cos(Radian), currentPt[1]+ sin(Radian))
49                plt.plot([currentPt[0], nextPt[0]],[currentPt[1], nextPt[1]], co
>lor = 'black') 
50                currentPt = nextPt
51            elif everyletter=='F':
52                Radian= radians(theta)
53                nextPt = (currentPt[0]+ cos(Radian), currentPt[1] + sin(Radian))
54                plt.plot([currentPt[0],nextPt[0]], [currentPt[1],nextPt[1]], col
>or = 'black') 
55                currentPt = nextPt
56            elif everyletter=='G':
57                Radian =radians(theta)
58                nextPt = (currentPt[0] +cos(Radian), currentPt[1] +sin(Radian))
59                plt.plot([currentPt[0], nextPt[0]],[currentPt[1], nextPt[1]], co
>lor = 'black') 
60                currentPt =nextPt
61            elif everyletter=='H':
62                Radian =radians(theta)
63                nextPt = (currentPt[0] +cos(Radian), currentPt[1]+ sin(Radian))
64                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]],co
>lor = 'black') 
65                currentPt = nextPt
66            elif everyletter=='I':
67                Radian =radians(theta)
68                nextPt= (currentPt[0] +cos(Radian), currentPt[1] + sin(Radian))
69                plt.plot([currentPt[0], nextPt[0]],[currentPt[1], nextPt[1]], co
>lor = 'black') 
70                currentPt =nextPt
71            elif everyletter=='J':
72                Radian= radians(theta)
73                nextPt =(currentPt[0] + cos(Radian),currentPt[1] + sin(Radian))
74                plt.plot([currentPt[0],nextPt[0]], [currentPt[1],nextPt[1]], col
>or = 'black') 
75                currentPt= nextPt
76            elif everyletter=='K':
77                Radian= radians(theta)
78                nextPt = (currentPt[0] + cos(Radian),currentPt[1] +sin(Radian))
79                plt.plot([currentPt[0],nextPt[0]], [currentPt[1], nextPt[1]], co
>lor = 'black') 
80                currentPt = nextPt
81            elif everyletter=='L':
82                Radian= radians(theta)
83                nextPt= (currentPt[0] +cos(Radian), currentPt[1] +sin(Radian))
84                plt.plot([currentPt[0], nextPt[0]],[currentPt[1], nextPt[1]], co
>lor = 'black') 
85                currentPt = nextPt
86            elif everyletter=='M':
87                Radian =radians(theta)
88                nextPt= (currentPt[0] +cos(Radian), currentPt[1] + sin(Radian))
89                plt.plot([currentPt[0], nextPt[0]], [currentPt[1],nextPt[1]], co
>lor = 'black') 
90                currentPt = nextPt
91            elif everyletter=='N':
92                Radian =radians(theta)
93                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
94                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
95                currentPt = nextPt
96            elif everyletter=='O':
97                Radian = radians(theta)
98                nextPt = (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian)
>) 
99                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
100                currentPt =nextPt
101            elif everyletter=='P':
102                Radian =radians(theta)
103                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
104                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
105                currentPt = nextPt
106            elif everyletter=='Q':
107                Radian =radians(theta)
108                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
109                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
110                currentPt = nextPt
111            elif everyletter=='R':
112                Radian= radians(theta)
113                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
114                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
115                currentPt= nextPt
116            elif everyletter=='S':
117                Radian= radians(theta)
118                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
119                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
120                currentPt = nextPt
121            elif everyletter=='T':
122                Radian= radians(theta)
123                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
124                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
125                currentPt= nextPt
126            elif everyletter=='U':
127                Radian= radians(theta)
128                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
129                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
130                currentPt = nextPt
131            elif everyletter=='V':
132                Radian =radians(theta)
133                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
134                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
135                currentPt =nextPt
136            elif everyletter=='W':
137                Radian= radians(theta)
138                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
139                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
140                currentPt = nextPt
141            elif everyletter=='X':
142                Radian =radians(theta)
143                nextPt= (currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
144                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
145                currentPt = nextPt
146            elif everyletter=='Y':
147                Radian =radians(theta)
148                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
149                plt.plot([currentPt[0], nextPt[0]], [currentPt[1], nextPt[1]], c
>olor = 'black') 
150                currentPt =nextPt
151            elif everyletter=='Z':
152                Radian= radians(theta)
153                nextPt =(currentPt[0] + cos(Radian), currentPt[1] + sin(Radian))
154                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
> ='black') 
155                currentPt= nextPt
156            elif everyletter=='[':
157                saved.append([currentPt, theta])35                    stack.append(currentPt)
36                    stack.append(theta)
158            elif everyletter ==']':37                elif offer == ']':
159                currentPt, theta =saved.pop()38                    theta = stack.pop()
39                    currentPt = stack.pop()
160            elif everyletter =='+':40                elif offer == '+':
161                theta=theta+ self.deltaTheta41                    theta += deltaTheta
162            elif everyletter == '-':42                elif offer == '-':
163                theta=theta- self.deltaTheta43                    theta -= deltaTheta
164from fileinput import filename44        return plt.plot
165from itertools import count45if __name__== "__main__":
166from re import A, T46    string = input()
167from numpy import append47    dictionary = input()
48    n = int(input())
49    deltaTheta = float(input())
50    p = PLANT(string, dictionary, n, deltaTheta)
51    p.drawPlant()
52    plt.show()
168class DNAMOTIF:53class DNAMOTIF:
169    def __init__(self):54    def __init__(self):
n170        self.instances=[] n55        self.instances=[]
171        self.consensus='' 56        self.consensus=[]
172        self.counts= {'A': [], 'C': [], 'G':[],'T':[]} 57        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
173        self.lst=[]
174    def __str__(self):58    def __str__(self):
n175         return str(self.instances)n59        chain = ''
60        for insta in self.instances:
61            chain += insta
62        return string
176    def __len__(self):63    def __len__(self):
n177        return len(self.instances[0].strip("\n"))n64        return len(self.instances[0].rstrip('\n'))  
178    def count(self):65    def count(self):
n179        for i in range(len(self.instances[0].strip("\n"))):n66        for insta in range(self.__len__()):
180            A=067            countA = 0
181            C=068            countC = 0
182            G=069            countG = 0
183            T=070            countT = 0
184            for chain in self.instances:71            for instances in self.instances:
185                justletters=chain.strip('\n')72                if instances[insta].upper()   ==   'A':
186                uplst= [x.upper() for x in justletters]
187                if uplst[i] == "A":
188                    A+=173                    countA  +=  1
189                elif uplst[i] == "C":74                elif instances[insta].upper()   ==   'C':
190                    C+=175                    countC  +=  1
191                elif uplst[i]== "T":76                elif instances[insta].upper()   ==   'G':
192                    G+=177                    countG  +=  1
193                elif uplst[i]== "G":78                elif instances[insta].upper()   ==   'T':
194                    T+=179                    countT  +=  1
195            self.counts['A'].append(A)80            self.counts['A'].append(countA)
196            self.counts['C'].append(C)81            self.counts['C'].append(countC)
197            self.counts['T'].append(G)82            self.counts['G'].append(countG)
198            self.counts['G'].append(T)83            self.counts['T'].append(countT)
199        print(self.instances)
200        print(len(self.instances[0])-1)
201    def compute_consensus(self):84    def compute_consensus(self):
nn85        self.counts = {'A': [],'C': [], 'G':[], 'T':[]}
202        self.count()86        self.count()
n203        for x in range(len(self.counts['A'])):n
204            if (self.counts['A'][x]> self.counts['C'][x]) and (self.counts['A'][
>x]>self.counts['G'][x]) and (self.counts['A'][x]>self.counts['T'][x]): 
205                self.lst.append('A')
206            elif (self.counts['C'][x]>self.counts['A'][x]) and (self.counts['C']
>[x]>self.counts['G'][x]) and (self.counts['C'][x]>self.counts['T'][x]): 
207                self.lst.append('C')
208            elif (self.counts['G'][x]> self.counts['A'][x]) and (self.counts['G'
>][x]>self.counts['C'][x]) and (self.counts['G'][x]>self.counts['T'][x]): 
209                self.lst.append('G')
210            elif (self.counts['T'][x]> self.counts['A'][x]) and (self.counts['T'
>][x]>self.counts['C'][x]) and (self.counts['T'][x]>self.counts['G'][x]): 
211                self.lst.append('T')
212            elif (self.counts['A'][x]== self.counts['C'][x]) or (self.counts['A'
>][x]==self.counts['G'][x]) or (self.counts['A'][x]==self.counts['T'][x]): 
213                self.lst.append('A')
214            elif (self.counts['C'][x]==self.counts['G'][x]) or (self.counts['C']
>[x]==self.counts['T'][x]): 
215                self.lst.append('C')
216            elif (self.counts['G'][x]==self.counts['T'][x]):
217                self.lst.append('G')
218        finalchain=''.join(self.lst)
219        self.consensus=finalchain87        self.consensus = ''
88        for insta in range(self.__len__()):
89            ultimate = max([self.counts['A'][insta], self.counts['C'][insta], se
 >lf.counts['G'][insta], self.counts['T'][insta]])
90            if ultimate == self.counts['A'][insta]:
91                self.consensus += 'A'
92            elif ultimate == self.counts['C'][insta]:
93                self.consensus += 'C'
94            elif ultimate == self.counts['G'][insta]:
95                self.consensus += 'G'
96            elif ultimate == self.counts['T'][insta]:
97                self.consensus += 'T'
98        return self.consensus
220    def parse(self, filename):99    def parse(self, filename):
t221        with open(filename) as file:t100        file = open(filename)
222            lines = file.readlines()101        lines = file.readlines()
223            count = 0102        file.close()
224            for line in lines:103        for line in lines:
225                count+=1104            if line[0] != '>':
226                if count % 2 == 0: 
227                    self.instances.append(line)105                self.instances.append(line)
228lexA = DNAMOTIF()
229lexA.parse("lexA.fasta")
230lexA.count()
231lexA.compute_consensus()
232pass
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op




Page 91

Student ID: 44, P-Value: 9.61e-01

Nearest Neighbor ID: 468

Student (left) and Nearest Neighbor (right).


nn1import math
2import matplotlib.pyplot as plt
1class PLANT:3class PLANT:
n2    def __init__(self, string, generator, n, deltaTheta):n4    def __init__(self, string, dictionary, n, deltaTheta):
5        newplant = []
3        self.string = string6        self.string = string
n4        self.generator = generatorn7        self.dictionary = dictionary
5        self.n = n8        self.n = n
n6        self.deltaTheta = deltaThetan9        self.deltaTheta = (deltaTheta * math.pi)/180
10        newplant = self.string
11        for i in range(self.n):
12            newplant = [dictionary[i] if i in self.dictionary.keys() else i for 
 >i in newplant]
13            newplant = ''.join(newplant)
14        self.str = newplant
15        pass
7    def drawPlant():16    def drawPlant(self):
8        currentPt=(200,0)17        currentPt=(200,0)
nn18        theta = (90*math.pi)/180
19        stackPt = []
20        stackTheta = []
21        for j in self.str:
22            if j == '[':
23                stackPt.append(currentPt)
24                stackTheta.append(theta)
25            elif j == ']':
26                currentPt = stackPt.pop()
27                theta = stackTheta.pop()
28            elif j == '+':
29                theta += self.deltaTheta
30            elif j == '-':
31                theta -= self.deltaTheta
32            else:
33                nextPt = currentPt[0]+math.cos(theta), currentPt[1]+math.sin(the
 >ta)
34                plt.plot([currentPt[0],nextPt[0]],[currentPt[1],nextPt[1]],color
 >='black')
35                currentPt=nextPt
9        theta = 90class DNAMOTIF:36        passclass DNAMOTIF:
10    def __init__(self):37    def __init__(self):
11        self.instances=[]38        self.instances=[]
n12        self.consensus = ''n39        self.consensus=[]
13        self.length = 0
14        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}40        self.counts= {'A': [], 'C': [], 'G':[],'T':[]}
15    def __str__(self):41    def __str__(self):
nn42        return ''.join(self.instances)
43    def __len__(self):
44        self.length = len(self.instances[0]) - 1
45        return self.length
16        pass46        pass
n17    def __len__(self):n
18        list = self.instances
19        list2 = []
20        for i in list[0]:
21            list2.append(i)
22        length = (len(list2) - 1)
23        self.length = length
24        return self.length
25    def count(self):47    def count(self):
n26        a = DNAMOTIF()n
27        a.parse(self.filename)
28        a.__len__()
29        list1 = self.instances
30        list2 = []48        A_list = []
31        big_list = []49        C_list = []
32        string = ''50        G_list = []
33        dict2 = {'Ax':[], 'Cx':[], 'Gx':[],'Tx':[]}51        T_list = []
34        for i in list1:52        for j in range(len(self.instances[0]) - 1):
35            string = string + i
36            string = string.upper()
37            list2.append(string)
38            string = ''
39        for i in list2:
40            x = -153            A = 0
41            for j in i:54            C = 0
55            G = 0
56            T = 0
57            for i in self.instances:
58                if i[j].upper() == 'A':
42                x += 159                    A += 1
43                if j == 'A':
44                    dict2['Ax'].append(x)
45                if j == 'C':60                elif i[j].upper() == 'C':
46                    dict2['Cx'].append(x)61                    C += 1
47                if j == 'G':62                elif i[j].upper() == 'G':
48                    dict2['Gx'].append(x)63                    G += 1
49                if j == 'T':64                elif i[j].upper() == 'T':
50                    dict2['Tx'].append(x)
51        len0 = int(a.length)
52        for values in dict2.values():
53            counter = -1
54            while counter < (len0 - 1):
55                counter += 1
56                counter2 = 0
57                for i in values:
58                    if i == counter:
59                        counter2 += 165                    T += 1
66                pass
60                big_list.append(counter2)67            A_list.append(A)
61        A_list = big_list[0:len0]68            C_list.append(C)
62        C_list = big_list[len0:(len0*2)]69            G_list.append(G)
63        G_list = big_list[(len0*2):(len0*3)]70            T_list.append(T)
64        T_list = big_list[(len0*3):(len0*4)]71        self.counts['A'] = A_list
65        for i in A_list:72        self.counts['C'] = C_list
66            self.counts['A'].append(i)73        self.counts['G'] = G_list
67        for i in C_list:74        self.counts['T'] = T_list
68            self.counts['C'].append(i)
69        for i in G_list:
70            self.counts['G'].append(i)
71        for i in T_list:
72            self.counts['T'].append(i)
73        return self.counts
74    def compute_consensus(self):75    def compute_consensus(self):
n75        string = ''n76        placeholder = []
76        a = DNAMOTIF()
77        a.parse(self.filename)
78        a.__len__()
79        a.count()77        self.count()
80        endList = []78        for i in range(len(self.instances[0]) - 1):
81        x = 079            if self.counts['A'][i] >= self.counts['C'][i] and self.counts['A'][i
 >] >= self.counts['G'][i] and self.counts['A'][i] >= self.counts['T'][i]:
82        dict1 = a.counts
83        while x < a.length:
84            newList = []
85            for letter, values in dict1.items():
86                newList.append(values[x])
87            max0 = max(newList)
88            max1 = newList.index(max0)
89            if max1 == 0:
90                endList.append('A')80                placeholder.append('A')
91            if max1 == 1:81            elif self.counts['C'][i] >= self.counts['G'][i] and self.counts['C']
 >[i] >= self.counts['T'][i]:
92                endList.append('C')82                placeholder.append('C')
93            if max1 == 2:83            elif self.counts['G'][i] >= self.counts['T'][i]:
94                endList.append('G')84                placeholder.append('G')
95            if max1 == 3:85            else:
96                endList.append('T')86                placeholder.append('T')
97            x +=187        self.consensus = ''.join(placeholder)
98        for i in endList:88        pass 
99            string = string + i
100        self.consensus = self.consensus + string
101        return self.consensus
102    def parse(self, filename):89    def parse(self, filename):
t103        self.filename = filenamet
104        list = []
105        with open(filename, 'r') as f:90        with open(filename) as file:
106            for lx in f:91            lines = file.readlines()
107                list.append(lx)92        newlines = [i for i in lines if lines.index(i)%2 == 1]
108        for i in list:
109            if '>' in i:
110                list.remove(i)
111        self.instances = self.instances + list93        self.instances = newlines
112        return self.instances
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op