def phosphorylated_is_active(agent): """ Macro for 'phosphorylated "B" is active'. Arguments: agent: an instance of structure.Structure Returns: a Syndra predicate (that is, an instance of predicate.Predicate) """ return ForAllRules(lambda r: And( Implies(PregraphHas(r, agent.labeled(phosphate)), PregraphHas(r, agent.labeled(active))), Implies(PostgraphHas(r, agent.labeled(phosphate)), PostgraphHas(r, agent.labeled(active)))))
def directly_activates(kinase, substrate): """ Macro for 'activated "kinase" activates "substrate"'. Arguments: kinase: an instance of structure.Structure substrate: an instance of structure.Structure Returns: a Syndra predicate (that is, an instance of predicate.Predicate) """ return ModelHasRule(lambda r: And( PregraphHas(r, kinase.labeled(active)), PregraphHas(r, substrate), PostgraphHas(r, kinase.labeled(active)), PostgraphHas(r, substrate.labeled(active)), Not(PregraphHas(r, substrate.labeled(active))), ))
def detect_ambiguous(*predicates): from datatypes import Rule, Graph, Node, Edge, Nodeset, Edgeset, Labelset, Labelmap pred = And(*predicates) model = pred.get_python_model()
from datatypes import Rule, Graph, Node, Edge, Nodeset, Edgeset, Labelset, Labelmap pred = And(*predicates) model = pred.get_python_model() # TODO assert that the model is not true, etc etc if __name__ == '__main__': print "---" kinase = Agent("kinase") # phosphate = Label("phosphate") # oxalate = Label("oxalate") substrate = Agent("substrate") pred = ModelHasRule(lambda r: And( PregraphHas(r, kinase.bound(substrate)), PostgraphHas(r, kinase), PostgraphHas(r, substrate), )) solver = MySolver("kinase", "substrate") print "---" solver.add(pred) print solver.check() print solver.model() print "---" # RAF = Agent("RAF") # HRAS = Agent("HRAS") # MEK1 = Agent("MEK1") # ERK1 = Agent("ERK1") # SAF1 = Agent("SAF1")
# Get this file working! from predicate import Implies, And from macros import directly_phosphorylates, directly_activates, phosphorylated_is_active i = directly_phosphorylates("MEK", "ERK") ii = phosphorylated_is_active("ERK") iii = directly_activates("MEK", "ERK") # Implies(And(i, ii), iii): check a theorem over all possible models pred1 = Implies(And(i, ii), iii) assert pred1.check_sat() # This should be true. pred2 = Not(Implies(And(i, ii), iii)) assert pred2.check_sat() # This should be false. pred3 = And(i, ii, iii) assert pred3.check_sat() # This should be true. pred4 = Not(And(i, ii, iii)) assert pred4.check_sat() # This should be true. # inconsistencies in a model: And(i, ii, iii) and see what happens # indirectly_activates # be sure to address in thesis: why not just straight inference rules? # (answer: easy to introduce inconsistencies, use different definitions # across different rules) # x: A activates B # y: B activates C