<jupyter_start><jupyter_text>Inspecting INDRA Statements and assembled modelsIn this example we look at how intermediate results of the assembly process from word models to executable models can be inspected. We first import the necessary modules of INDRA.<jupyter_code>%pylab inline
import json
from indra.sources import trips
from indra.statements import draw_stmt_graph, stmts_to_json<jupyter_output>Populating the interactive namespace from numpy and matplotlib<jupyter_text>Collecting Statements from readingFirst, we use the TRIPS system via INDRA's `trips` module to read two sentences which describe distinct mechanistic hypotheses about ATM phosphorylation.<jupyter_code>text = 'Active ATM phosphorylates itself. Active ATM phosphorylates another ATM molecule.'
tp = trips.process_text(text)<jupyter_output><empty_output><jupyter_text>Here `tp` is a `TripsProcessor` object whose extracted Statements can be accessed in a list.  Printing Statements as objectsIt is possible to look at the string representation of the extracted INDRA Statements as below.<jupyter_code>tp.statements<jupyter_output><empty_output><jupyter_text>The first Statement, obtained by reading "Active ATM phosphorylates itself", represents the Autophosphorylation of ATM with ATM being in an active state. Here `activity` stands for generic molecular activity and `True` indicates an active as opposed to an inactive state.The second Statement, obtained from "Active ATM phosphorylates another ATM molecule" is a Phosphorylation with the enzyme ATM being in an active state phosphorylating another ATM as a substrate.  Drawing Statements as graphsNext, we can use the `draw_stmt_graph` function to display the Statements produced by reading and INDRA input processing as a graph. The root of each tree is the type of the Statement, in this case Autophosphorylation. The arguments of the Statement branch off from the root. In this case the enzyme argument of Autophosphorylation is an Agent with name ATM. Its database references can be inspected under the `db_refs` property.<jupyter_code>pylab.rcParams['figure.figsize'] = (12, 8)
draw_stmt_graph(tp.statements[1:])<jupyter_output><empty_output><jupyter_text>Printing / exchanging Statements as JSONINDRA Statements can be serialized into JSON format. This is a human-readable and editable form of INDRA Statements which is independent of Python and can therefore be used as a platform-independent data exchange format for Statements. The function `stmts_to_json` in the `indra.statements` module takes a list of Statements and returns a JSON as a dictionary. Below we pretty-print this JSON as a string with indentations.<jupyter_code>statements_json = stmts_to_json(tp.statements)
print(json.dumps(statements_json, indent=1))<jupyter_output>[
 {
  "type": "Autophosphorylation",
  "enz": {
   "name": "ATM",
   "activity": {
    "activity_type": "activity",
    "is_active": true
   },
   "db_refs": {
    "TEXT": "ATM",
    "HGNC": "795",
    "UP": "Q13315",
    "NCIT": "C17924"
   },
   "sbo": "http://identifiers.org/sbo/SBO:0000460"
  },
  "evidence": [
   {
    "source_api": "trips",
    "text": "Active ATM phosphorylates itself."
   }
  ],
  "id": "35362b6c-2229-436a-862f-fec499713a9d",
  "sbo": "http://identifiers.org/sbo/SBO:0000216"
 },
 {
  "type": "Phosphorylation",
  "enz": {
   "name": "ATM",
   "activity": {
    "activity_type": "activity",
    "is_active": true
   },
   "db_refs": {
    "TEXT": "ATM",
    "HGNC": "795",
    "UP": "Q13315",
    "NCIT": "C17924"
   },
   "sbo": "http://identifiers.org/sbo/SBO:0000460"
  },
  "sub": {
   "name": "ATM",
   "db_refs": {
    "TEXT": "ATM",
    "HGNC": "795",
    "UP": "Q13315",
    "NCIT": "C17924"
   },
   "sbo": "http://identifiers.org/sbo/SBO:0000015"
  },
  "evide[...]<jupyter_text>Inspecting assembled rule-based modelsWe now assemble two PySB models, one for each Statement.<jupyter_code>from indra.assemblers.pysb import PysbAssembler
pa = PysbAssembler()
pa.add_statements([tp.statements[0]])
model1 = pa.make_model()<jupyter_output><empty_output><jupyter_text>We can examine the properties of the PySB model object before exporting it. As seen below, the model has a single Monomer and Rule, and two Parameters.<jupyter_code>model1<jupyter_output><empty_output><jupyter_text>We can look at the ATM Monomer and its sites. ATM has an `activity` site which can be either `active` of `inactive`. It also has a `phospho` site with `u` and `p` states.<jupyter_code>model1.monomers['ATM']<jupyter_output><empty_output><jupyter_text>The rule representing ATM autophosphorylation can be inspected below. The rule is parameterized by the forward rate `kf_a_autophos_1`.<jupyter_code>model1.rules[0]<jupyter_output><empty_output><jupyter_text>We now assemble a model for the second Statement.<jupyter_code>pa = PysbAssembler()
pa.add_statements([tp.statements[1]])
model2 = pa.make_model()
model2
model2.monomers['ATM']
model2.rules[0]<jupyter_output><empty_output><jupyter_text>As we see, the rule assembled for this model contains two distinct ATMs on each side, one acting as the kinase and the other as the substrate. Inspecting assembled model annotationsFinally, models assembled by INDRA carry automatically propagated annotations. Below, the grounding of ATM in the UniProt, HGNC and NCIT databases is annotated; the semantic role of monomers in each rule are also annotated, and finally, the unique ID of the INDRA Statement that a rule was derived from is annotated.<jupyter_code>model1.annotations
model2.annotations<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09344115004492363, 'fraction_numerical': 0.019766397124887692, 'mean_word_length': 5.368421052631579, 'pattern_counts': {'":': 37, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '412281', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 1859, 'n_tokens_neox': 1706, 'n_words': 597, 'path': 'models/indra_statements_demo.ipynb', 'repo_name': 'dianakolusheva/indra', 'size': '5565'}