def test_description_not_list_handling(): mm = MRA_Module(testing=True) content = KQMLList.from_string( '(BUILD-MODEL :DESCRIPTION (' ':TYPE "Inhibition" ' ':SUBJ (:NAME "SB-525334" ' ' :DB--REFS (:+TYPE+ "ONT::GENE-PROTEIN" ' ' :+TEXT+ "SB525334"' ' :+PUBCHEM+ "9967941")) ' ':OBJ (:NAME "TGFBR1"' ' :DB--REFS (:+TYPE+ "ONT::GENE-PROTEIN" ' ' :+TEXT+ "TGFBR1" ' ' :+HGNC+ "11772" ' ' :+UP+ "P36897" ' ' :+NCIT+ "C51730")) ' ':OBJ--ACTIVITY "activity" ' ':BELIEF 1 ' ':EVIDENCE ((:SOURCE--API "trips" ' ' :SOURCE--HASH -1613118243458052451)) ' ':ID "ce486f46-3670-42e6-8f0e-d5f510525352" ' ':MATCHES--HASH "-32031145755534420"))''') try: reply = mm.respond_build_model(content) except InvalidModelDescriptionError: return assert False, "Model should have explicitly failed: " + reply.to_string()
def test_respond_model_undo_no_model_yet(): mm = MRA_Module(testing=True) content = KQMLList.from_string('(MODEL-UNDO)') reply = mm.respond_model_undo(content) assert reply.gets('model-id') == 'NIL' action = reply.get('action') assert action.head() == 'remove_stmts', reply stmts = action.get('statements') assert not stmts
def test_respond_build_model_from_json(): mm = MRA_Module(testing=True) st = sts.Phosphorylation(sts.Agent('MEK'), sts.Agent('ERK')) msg = KQMLList('BUILD-MODEL') msg.sets('description', json.dumps(sts.stmts_to_json([st]))) msg.sets('format', 'indra_json') reply = mm.respond_build_model(msg) assert(reply.get('model')) assert(reply.get('model-id') == '1')
def test_respond_model_get_upstream(): mm = MRA_Module(testing=True) egfr = sts.Agent('EGFR', db_refs={'HGNC': '3236', 'TEXT': 'EGFR'}) kras = sts.Agent('KRAS', db_refs={'HGNC': '6407', 'TEXT': 'KRAS'}) stmts = [sts.Activation(egfr, kras)] model_id = mm.mra.new_model(stmts) kras_term = ekb_from_agent(kras) msg = KQMLList('MODEL-GET-UPSTREAM') msg.sets('target', kras_term) msg.set('model-id', str(model_id)) reply = mm.respond_model_get_upstream(msg) ups = reply.get('upstream') assert(len(ups) == 1)
def test_respond_model_undo(): mm = MRA_Module(testing=True) _, content = _get_build_model_request('HRAS activates RAF') reply = mm.respond_build_model(content) _, content = _get_expand_model_request('NRAS activates RAF', '1') expand_reply = mm.respond_expand_model(content) expand_stmts = expand_reply.gets('model-new') content = KQMLList.from_string('(MODEL-UNDO)') reply = mm.respond_model_undo(content) assert reply.gets('model-id') == '3' action = reply.get('action') assert action.head() == 'remove_stmts' stmts = action.get('statements') assert json.loads(stmts.string_value()) == json.loads(expand_stmts)
def test_respond_expand_model_from_json(): mm = MRA_Module(testing=True) st = stmts_json_from_text('MEK phosphorylates ERK') msg = KQMLList('BUILD-MODEL') msg.sets('description', json.dumps(st)) msg.sets('format', 'indra_json') reply = mm.respond_build_model(msg) assert(reply.get('model')) assert(reply.get('model-id') == '1') st = stmts_json_from_text('Active BRAF inhibits MEK.') msg = KQMLList('EXPAND-MODEL') msg.sets('description', json.dumps(st)) msg.sets('format', 'indra_json') msg.set('model-id', '1') reply = mm.respond_expand_model(msg) assert(reply.get('model')) assert(reply.get('model-id') == '2')
def test_respond_model_undo(): mm = MRA_Module(testing=True) _, content = _get_build_model_request('HRAS activates RAF') reply = mm.respond_build_model(content) _, content = _get_expand_model_request('NRAS activates RAF', '1') expand_reply = mm.respond_expand_model(content) expand_stmts = mm.get_statement(expand_reply.get('model-new')) assert len(expand_stmts) == 1 content = KQMLList.from_string('(MODEL-UNDO)') reply = mm.respond_model_undo(content) assert reply.gets('model-id') == '3' action = reply.get('action') assert action.head() == 'remove_stmts' stmts = mm.get_statement(action.get('statements')) assert len(stmts) == 1 assert stmts[0].equals(expand_stmts[0])