-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesting.py
More file actions
143 lines (106 loc) · 4.25 KB
/
Copy pathtesting.py
File metadata and controls
143 lines (106 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- coding: utf-8 -*-
"""
Created on Wed May 11 19:16:33 2022
@author: asus
"""
import pytest
from enum import Enum
import numpy as np
state = np.array([1, 0, 0, 4])
index_n_active_genes = 0
index_n_inactive_genes = 1
index_n_RNAs = 2
index_n_proteins = 3
class Transition(Enum):
GENE_ACTIVATE = 'gene activate'
GENE_INACTIVATE = 'gene inactivate'
RNA_INCREASE = 'RNA increase'
RNA_DEGRADE = 'RNA degrade'
PROTEIN_INCREASE = 'Protein increase'
PROTEIN_DEGRADE = 'Protein degrade'
def update_state(event, state):
"""This method updates the initial state according to the event occured
Parameters
----------
event : member of Transition class
state : ndarray
ndarray with 4 dimensions: number of active genes, number of
inactive genes, number of RNAs and number of proteins
Returns
-------
updated_state : ndarray
ndarray with 4 dimensions: number of active genes, number of
inactive genes, number of RNAs and number of proteins after
the event has occured.
"""
if event == Transition.GENE_ACTIVATE:
state[index_n_active_genes] +=1
state[index_n_inactive_genes] -=1
state = state
state = state.copy()
elif event == Transition.GENE_INACTIVATE:
state[index_n_active_genes] -=1
state[index_n_inactive_genes] +=1
state = state
state = state.copy()
elif event == Transition.RNA_INCREASE:
state[index_n_RNAs] +=1
state = state
state = state.copy()
elif event == Transition.RNA_DEGRADE:
state[index_n_RNAs] -=1
state = state
state = state.copy()
elif event == Transition.PROTEIN_INCREASE:
state[index_n_proteins] +=1
state = state
state = state.copy()
elif event == Transition.PROTEIN_DEGRADE:
state[index_n_proteins] -=1
state = state
state = state.copy()
elif isinstance(event,str) or isinstance(event, str):
raise TypeError("Do not use string ! Choose transitions from Transition enum members.")
else:
raise ValueError("Transition not recognized")
updated_state = state
return updated_state
#%% Tests
def test_update_state_return_correct_gene_state_when_gene_is_active():
"""Verify that the update_state function updates gene state to 'inactive'
when the initial gene state is active and there is a transition that
inactivates gene and verify that in this transition the number of RNAs
and proteins do not change"""
state = np.array([1, 0, 0, 0])
event = Transition.GENE_INACTIVATE
updated_state = update_state(event, state)
assert updated_state.any() == np.array([0,1,0,0]).any()
def test_update_state_return_correct_gene_state_when_gene_is_inactive():
"""Verify that the update_state function updates gene state to 'active'
when the initial gene state is inactive and when there is a transition
that activates gene and verify that in this transition the number of RNAs
and proteins do not change
"""
state = np.array([0, 1, 0, 0])
event = Transition.GENE_ACTIVATE
updated_state = update_state(event, state)
assert (updated_state == np.array([1,0,0,0])).all()
def test_update_state_return_correct_value_when_gene_is_active_and_RNA_INCREASE():
"""Verify that the update_state function increases the number of RNA
molecules by 1 when gene state is active and the active gene state transition
is Transition.RNA_INCREASE.
"""
state = np.array([1, 0, 0, 0])
event = Transition.RNA_INCREASE
updated_state = update_state(event, state)
assert (updated_state == np.array([1,0,1,0])).all()
def test_update_state_return_correct_value_when_gene_is_active_and_RNA_DECREASE():
state = np.array([1, 0, 0, 0])
event = Transition.RNA_DEGRADE
updated_state = update_state(event, state)
assert (updated_state == np.array([1,0,-1,0])).all()
def test_update_state_return_correct_value_when_gene_is_active_and_Protein_DEGRADE():
state = np.array([1, 0, 1, 1])
event = Transition.PROTEIN_DEGRADE
updated_state = update_state(event, state)
assert (updated_state == np.array([1,0,1,0])).all()