-
Notifications
You must be signed in to change notification settings - Fork 18
/
biological_scoring.py
67 lines (56 loc) · 2.51 KB
/
biological_scoring.py
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
"""
Defines the biological scoring function.
Necessitates random for random scoring, and all rule sets for biological scoring.
"""
import random
from rule_sets_examples import *
from rule_sets_similarity import *
class BiologicalScoring(object):
"""
Defines Biological Scorer object.
Returns the biological score associated to a reaction rule.
"""
def __init__(self, scoring_function):
self.scoring_function = scoring_function
self.name = "Random"
def __repr__(self):
return(self.name)
def calculate(self, rule):
score = self.scoring_function(rule)
return(score)
def pseudo_random(rule):
score = random.uniform(0, 10)
return(score)
class BiologicalScoringOrganism(BiologicalScoring):
"""
Defines Biological Scorer object from an organism with predefined scores.
Inverted converts a penalty to a score.
This will be analysed more in depth when biological score will evolve.
"""
def __init__(self, rules_dictionnary, inverted = False, name = "None"):
BiologicalScoring.__init__(self, scoring_function = None)
self.scoring_function = self.assign_from_dict(rules_dictionnary, inverted)
self.name = name
def __repr__(self):
return(self.name)
def assign_from_dict(self, rules_dictionnary, inverted):
rules_dictionnary = rules_dictionnary
def simple_assign_inside(rule):
score = rules_dictionnary[rule]["biological_score"]
# Inverted if to use penalties instead of scors.
# if inverted:
# try:
# return(1/score)
# except ZeroDivisionError:
# return(33)
# else:
return(score)
return(simple_assign_inside)
RandomBiologicalScorer = BiologicalScoring(scoring_function = pseudo_random)
BiologicalFullScoringRetroH = BiologicalScoringOrganism(rules_dictionnary= full_rules_retro_H, name = "full_rules_retro_H")
BiologicalFullScoringFwdH = BiologicalScoringOrganism(rules_dictionnary= full_rules_forward_H, name = "full_rules_forward_H")
BiologicalFullScoringRetroNoH = BiologicalScoringOrganism(rules_dictionnary= full_rules_retro_no_H, name = "full_rules_retro_no_H")
BiologicalFullScoringFwdNoH = BiologicalScoringOrganism(rules_dictionnary= full_rules_forward_no_H, name = "full_rules_forward_no_H")
full_H = full_rules_retro_H
full_H.update(full_rules_forward_H)
BiologicalFullScoringH = BiologicalScoringOrganism(rules_dictionnary= full_H, name = "full_rules_retro_H")