<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Parsing the Causal Biological Network Database
Author
Step1:  Data Acquisition
Data can be downloaded directly from the GetJSONGraphFile endpoint, and are returned in the response as JSON.
Step2:  Parsing
The structure is traversed, and the BELParser is manipulated directly. Normally, during BEL compilation, the usage of this class is hidden from the user.
Step3:  Visualization
Finally, the graph is vizualized in the notebook diretly with pybel_tools.visualization.to_jupyter.
Step4:  Using PyBEL Functions
This pipeline is implemented directly in PyBEL at pybel.from_cbn_jgif
<ASSISTANT_TASK:>
Python Code:
import json
import requests
import os
import time
import networkx as nx
import pybel
from pybel.constants import *
import pybel_tools
from pybel_tools.visualization import to_jupyter
pybel.__version__
pybel_tools.__version__
time.asctime()
Explanation: Parsing the Causal Biological Network Database
Author: Charles Tapley Hoyt
Estimated Run Time: 1 minute
This notebook outlines the process of parsing the JSON Graph File format used in the Causal Biological Network (CBN) Database.
End of explanation
res = requests.get("http://causalbionet.com/Networks/GetJSONGraphFile?networkId=hox_2.0_hs").json()
Explanation: Data Acquisition
Data can be downloaded directly from the GetJSONGraphFile endpoint, and are returned in the response as JSON.
End of explanation
graph = pybel.BELGraph()
parser = pybel.parser.BelParser(graph)
def get_citation(evidence):
    return {
        CITATION_NAME: evidence['citation']['name'],
        CITATION_TYPE: evidence['citation']['type'],
        CITATION_REFERENCE: evidence['citation']['id']
    }
annotation_map = {
    'tissue': 'Tissue',
    'disease': 'Disease',
    'species_common_name': 'Species'
}
species_map = {
    'human': '9606',
    'rat': '10116',
    'mouse': '10090'
}
annotation_value_map = {
    'Species': species_map
}
for edge in res['graph']['edges']:    
    for evidence in edge['metadata']['evidences']:
        if 'citation' not in evidence or not evidence['citation']:
            continue
        
        parser.control_parser.clear()
        parser.control_parser.citation = get_citation(evidence)
        parser.control_parser.evidence = evidence['summary_text'] 
        
        d = {}
        
        if 'biological_context' in evidence:
            annotations = evidence['biological_context']
        
            if annotations['tissue']:
                d['Tissue'] = annotations['tissue']
            if annotations['disease']:
                d['Disease'] = annotations['disease']
            if annotations['species_common_name']:
                d['Species'] = species_map[annotations['species_common_name'].lower()]
        
        parser.control_parser.annotations.update(d)
        bel = '{source} {relation} {target}'.format_map(edge)
        try:
            parser.parseString(bel)
        except Exception as e:
            print(e, bel)
Explanation: Parsing
The structure is traversed, and the BELParser is manipulated directly. Normally, during BEL compilation, the usage of this class is hidden from the user.
End of explanation
to_jupyter(graph)
pybel.to_database(graph)
pybel.get_ver
Explanation: Visualization
Finally, the graph is vizualized in the notebook diretly with pybel_tools.visualization.to_jupyter.
End of explanation
with open(os.path.join(os.environ['BMS_BASE'], 'cbn', 'Human-2.0', 'Hox-2.0-Hs.jgf')) as f:
    graph_jgif_dict = json.load(f)
%%time
graph = pybel.from_cbn_jgif(graph_jgif_dict)
bel_lines = pybel.to_bel_lines(graph)
graph_reloaded = pybel.from_lines(bel_lines)
to_jupyter(graph_reloaded)
Explanation: Using PyBEL Functions
This pipeline is implemented directly in PyBEL at pybel.from_cbn_jgif
End of explanation
<END_TASK>