from indra.sources import trips
from indra.assemblers import PybelAssembler
import pybel
import requests
from indra.databases import hgnc_client
from indra.statements import *

def gnd(gene_name):
    return {'HGNC': hgnc_client.get_hgnc_id(gene_name)}

def ag(gene_name, **kwargs):
    return Agent(gene_name, db_refs=gnd(gene_name), **kwargs)

sos1 = ag('SOS1')
rasa1 = ag('RASA1')
kras = ag('KRAS')
braf = ag('BRAF', activity=ActivityCondition('kinase', True))
map2k1 = ag('MAP2K1')
map2k1_p = ag('MAP2K1', mods=[ModCondition('phosphorylation', 'S', '218')])
mapk1 = ag('MAPK1')
mapk1_p = ag('MAPK1', mods=[ModCondition('phosphorylation', 'T', '185')])
elk1 = ag('ELK1')
elk1_p = ag('ELK1', mods=[ModCondition('phosphorylation')])
elk1_tscript = ag('ELK1', activity=ActivityCondition('transcription', True))
fos = ag('FOS')

stmts = [
    Gef(sos1, kras),
    Gap(rasa1, kras),
    GtpActivation(kras, braf, 'kinase'),
    Phosphorylation(braf, map2k1, 'S', '218'),
    Phosphorylation(map2k1_p, mapk1, 'T', '185'),
    Phosphorylation(mapk1_p, elk1),
    ActiveForm(elk1_p, 'transcription', True),
    IncreaseAmount(elk1_tscript, fos),
]
#model_text = """
#    BRAF phosphorylates MAP2K1 at S218.
#    MAP2K1 phosphorylated at S218 phosphorylates MAPK1 at T185.
#    MAPK1 phosphorylated at T185 phosphorylates ELK1.
#    Phosphorylated ELK1 transcribes c-FOS.
#"""
#model_description = ' '.join([line.strip() for line in model_text.split('\n')])
#print("Processing text with TRIPS...")
#tp = trips.process_text(model_text)
model_description = 'Test of INDRA Statement assembly into PyBEL.'
print("Assembling to PyBEL...")

pba = PybelAssembler(stmts, name='INDRA_PyBEL_test',
                     description=model_description, version='0.0.7')
pba.make_model()
with open('pybel_model.json', 'wt') as f:
    pybel.to_json_file(pba.model, f)
url =  'https://pybel.scai.fraunhofer.de/api/receive'
headers = {'content-type': 'application/json'}
requests.post(url, json=pybel.to_json(pba.model), headers=headers)

@@ -820,16 +820,196 @@
 ('FOS')%0A
+hk1 = ag('HK1')%0Aglu = Agent('D-GLUCOSE', db_refs=%7B'CHEBI': 'CHEBI:17634'%7D)%0Ag6p = Agent('GLUCOSE-6-PHOSPHATE', db_refs=%7B'CHEBI': 'CHEBI:4170'%7D)%0Aegfr = ag('EGFR')%0Agrb2 = ag('GRB2')%0A%0A
 %0Astmts =
@@ -1314,17 +1314,86 @@
 , fos),%0A
-%5D
+    Conversion(hk1, %5Bglu%5D, %5Bg6p%5D),%0A    Complex(%5Begfr, grb2, sos1%5D),%0A%5D%0A
 %0A#model_
@@ -1989,17 +1989,18 @@
 on='0.0.
-7
+10
 ')%0Apba.m

Update test pybel model with Conversion and Complex