Part 3: Enrichment of the human inflammatory stress response AOP network

The AOP project ► Key objective 1

Author: Shakira Agata

This Jupyter notebook describes the steps needed to enrich your AOP network by addition of molecular pathways from WikiPatwhays and genes through CyTargetLinker. This notebook is dependent on the output: ´Agata,completenodetable.xlsx´ which contains the KE-WP mapping results. This notebook is subdivided into the following ten sections:

  • Section 1: KE-WP mapping
  • Section 2: Importing the tables needed to construct the node table and edge table
  • Section 3: Loading the node table and edge table
  • Section 4: Defining the node table and edge table
  • Section 5: Construction of the molecular AOP network
  • Section 6: Adaptation of stylistic aspects of the molecular AOP network
  • Section 7: Extension of the molecular AOP network using Cytargetlinker and WikiPathways linkset
  • Section 8: Changing the visual style of CytargetLinker-extended molecular AOP ntwork
  • Section 9: Saving results
  • Section 10: Metadata

Section 1: System preparation

In this section, you will install the necessary packages for this notebook.

Step 1: You will import pandas and py4cytoscape by running the following code below.

import pandas as pd
import py4cytoscape as p4c
p4c.cytoscape_ping()
p4c.cytoscape_version_info()
You are connected to Cytoscape!





{'apiVersion': 'v1',
 'cytoscapeVersion': '3.10.1',
 'automationAPIVersion': '1.9.0',
 'py4cytoscapeVersion': '1.9.0'}

Section 2: KE-WP mapping

In this section, you will execute KE-WP mapping. This is a manual process that requires the assignment of molecular pathways to the MIEs, KEs and AOs that are present in the human inflammatory stress response AOP network. This requires usage of the decision tree method available at: https://github.com/marvinm2/KE-WP-mapping. Afterwards, your results should be tabulated in the following order to use in the next sections of the Jupyternotebook: ID (KEID), Name (KEtitle), Group, Type, KE level of organisation, Cell/organ term, WPID, WPtitle, Confidence score and Causative/responsive.

  • An example is provided at section 3.

Section 3: Loading the node table and edge table

In this section, the node table and edge table will be loaded and reorganised in preparation for section 4.

Step 2: You will now import the node table which contains the molecular pathway information. You will rename the columns: ‘Type’ to ’type’ and ‘Causative/responsive’ to ‘association type’ for coherence of the table.

nodetable0 = pd.read_excel('Agata,completenodetable.xlsx')
nodetable0.rename(columns={'Type': 'type', 'Causative/responsive': 'Association'}, inplace=True
Note

For KE-WP mapping, it is advised to use: https://github.com/marvinm2/KE-WP-mapping to ensure smoother documentation of the KE-WP matches.

Section 4: Defining the nodetable and edgetable

In this section you will load your node table and edgetable.

Step 3: First, the nodes of the network are defined as MIE, KE, AO and molecular pathway. You will do this by creating a new dataframe: ‘molecularpathwaytable’ for the molecular pathway information and adding a type: ‘Molecular pathway’ column to it. This ensures easier integration in the final node table using the ‘pd.concat’ function and manipulation of the future molecular AOP network.

preliminarymolecularpathway_table= pd.DataFrame([nodetable0.WPID, nodetable0.WPtitle, nodetable0.Group, nodetable0.Association]).transpose()
molecularpathwaytable= preliminarymolecularpathway_table.rename(columns= {'WPID': 'id', 'WPtitle':'name', 'Group':'group', 'Association':'Association type'})
molecularpathwaytable

id name group Association type
0 WP5095 Overview of proinflammatory and profibrotic me... Liver Responsive
1 WP5083 Neuroinflammation and glutamatergic signaling Brain Other
2 WP1545 miRNAs involved in DNA damage response Lung Causative
3 WP1530 miRNA regulation of DNA damage response Lung Other
4 WP4655 Cytosolic DNA-sensing pathway Lung Responsive
... ... ... ... ...
287 WP408 Oxidative stress response Brain Causative
288 WP1772 Apoptosis modulation and signaling Brain Causative
289 WP254 Apoptosis Brain Causative
290 WP3676 BDNF-TrkB signaling Brain Causative
291 WP5477 Molecular pathway for oxidative stress Brain Causative

292 rows × 4 columns

molecularpathwaytable['type'] = 'Molecular pathway'
molecularpathwaytable.dropna(inplace=True)
molecularpathwaytable

id name group Association type type
0 WP5095 Overview of proinflammatory and profibrotic me... Liver Responsive Molecular pathway
1 WP5083 Neuroinflammation and glutamatergic signaling Brain Other Molecular pathway
2 WP1545 miRNAs involved in DNA damage response Lung Causative Molecular pathway
3 WP1530 miRNA regulation of DNA damage response Lung Other Molecular pathway
4 WP4655 Cytosolic DNA-sensing pathway Lung Responsive Molecular pathway
... ... ... ... ... ...
287 WP408 Oxidative stress response Brain Causative Molecular pathway
288 WP1772 Apoptosis modulation and signaling Brain Causative Molecular pathway
289 WP254 Apoptosis Brain Causative Molecular pathway
290 WP3676 BDNF-TrkB signaling Brain Causative Molecular pathway
291 WP5477 Molecular pathway for oxidative stress Brain Causative Molecular pathway

275 rows × 5 columns

Step 4: The nodes derived from the node table will be joined with the formed molecularpathway table to form the final nodetable. This table organises the nodes in a way that you can easily select node type with organ-system location. For the molecular pathways, this table also allows you to see the association type for the respective molecular pathways.

MIE_nodes = nodetable0[nodetable0['type'] == 'MIE'][['ID (KEID)', 'Name (KEtitle)', 'Group', 'type']].rename(columns={'ID (KEID)': 'id', 'Name (KEtitle)': 'name', 'Group': 'group'})

KE_nodes = nodetable0[nodetable0['type'] == 'KE'][['ID (KEID)', 'Name (KEtitle)', 'Group', 'type']].copy()
KE_nodes.rename(columns={'ID (KEID)': 'id', 'Name (KEtitle)': 'name', 'Group': 'group'}, inplace=True)

AO_nodes = nodetable0[nodetable0['type'] == 'AO'][['ID (KEID)', 'Name (KEtitle)', 'Group', 'type']].rename(columns={'ID (KEID)': 'id', 'Name (KEtitle)': 'name', 'Group': 'group'})

nodetable = pd.concat([MIE_nodes, KE_nodes, AO_nodes, molecularpathwaytable], ignore_index=True)

nodetable

id name group type Association type
0 https://identifiers.org/aop.events/486 systemic inflammation leading to hepatic steat... Liver MIE NaN
1 https://identifiers.org/aop.events/875 Binding of agonist, Ionotropic glutamate recep... Brain MIE NaN
2 https://identifiers.org/aop.events/2007 Non-coding RNA expression profile alteration Lung MIE NaN
3 https://identifiers.org/aop.events/2007 Non-coding RNA expression profile alteration Lung MIE NaN
4 https://identifiers.org/aop.events/1495 Substance interaction with the lung resident c... Lung MIE NaN
... ... ... ... ... ...
562 WP408 Oxidative stress response Brain Molecular pathway Causative
563 WP1772 Apoptosis modulation and signaling Brain Molecular pathway Causative
564 WP254 Apoptosis Brain Molecular pathway Causative
565 WP3676 BDNF-TrkB signaling Brain Molecular pathway Causative
566 WP5477 Molecular pathway for oxidative stress Brain Molecular pathway Causative

567 rows × 5 columns

Step 5: You will load the edge table in the dataframe: ’edgetable1’

edgetable1= pd.read_excel('edgetable.xlsx')

Step 6: Now edgetable2 will be created which will contain the confidence score and association type for the molecular pathways. This is needed as edgetable1 was made before assignment of molecular pathways to the inflammatory-related AOP network in the previous notebook. Secondly, you have to establish the interactions between the molecular pathways and the MIEs,KEs and AOs so that they are present in the network with the following function.

edgetable2 = pd.DataFrame({
    'source': nodetable0['ID (KEID)'], 
    'target': nodetable0['WPID'], 
    'interaction': ['interacts'] * len(nodetable0), 
    'group' : nodetable0['Group'],
    'confidence score': nodetable0['Confidence score'],
    'Association type': nodetable0['Association']
})

edgetable2

source target interaction group confidence score Association type
0 https://identifiers.org/aop.events/486 WP5095 interacts Liver Medium Responsive
1 https://identifiers.org/aop.events/875 WP5083 interacts Brain Medium Other
2 https://identifiers.org/aop.events/2007 WP1545 interacts Lung Medium Causative
3 https://identifiers.org/aop.events/2007 WP1530 interacts Lung Medium Other
4 https://identifiers.org/aop.events/1495 WP4655 interacts Lung High Responsive
... ... ... ... ... ... ...
287 https://identifiers.org/aop.events/352 WP408 interacts Brain High Causative
288 https://identifiers.org/aop.events/352 WP1772 interacts Brain High Causative
289 https://identifiers.org/aop.events/352 WP254 interacts Brain High Causative
290 https://identifiers.org/aop.events/352 WP3676 interacts Brain High Causative
291 https://identifiers.org/aop.events/352 WP5477 interacts Brain High Causative

292 rows × 6 columns

Step 7: For edgetable 2, you also need to identify the valid edges.

edgetable_2 = edgetable2[edgetable2['source'].isin(nodetable['id']) & edgetable2['target'].isin(nodetable['id'])]
edgetable_2

source target interaction group confidence score Association type
0 https://identifiers.org/aop.events/486 WP5095 interacts Liver Medium Responsive
1 https://identifiers.org/aop.events/875 WP5083 interacts Brain Medium Other
2 https://identifiers.org/aop.events/2007 WP1545 interacts Lung Medium Causative
3 https://identifiers.org/aop.events/2007 WP1530 interacts Lung Medium Other
4 https://identifiers.org/aop.events/1495 WP4655 interacts Lung High Responsive
... ... ... ... ... ... ...
287 https://identifiers.org/aop.events/352 WP408 interacts Brain High Causative
288 https://identifiers.org/aop.events/352 WP1772 interacts Brain High Causative
289 https://identifiers.org/aop.events/352 WP254 interacts Brain High Causative
290 https://identifiers.org/aop.events/352 WP3676 interacts Brain High Causative
291 https://identifiers.org/aop.events/352 WP5477 interacts Brain High Causative

275 rows × 6 columns

Step 8: You can now make the final edgetable by merging edgetable1 with the present edges of the edgetable2.

edgetable = pd.concat([edgetable1, edgetable_2], ignore_index=True)

Step 9: Lastly the additional spaces present in the node table and edge table will be removed. This is done to prevent parsing errors when constructing the network.

Step 9a: You first remove the additional spaces in the nodetable.

nodetable['id'] = nodetable['id'].str.strip()

Step 9b: You first remove the additional spaces for the source and target columns in the edgetable.

edgetable['source'] = edgetable['source'].str.strip()
edgetable['target'] = edgetable['target'].str.strip()

Section 5: Construction of the molecular AOP network

In this section, the molecular AOP network will be constructed.

Step 10: You can construct the molecular AOP network and display the output.

p4c.create_network_from_data_frames(nodes=nodetable, edges=edgetable, title='Agata,S.-Molecular inflammatory-process related AOP network')
Applying default style...
Applying preferred layout





51035

Section 6: Adaptation of stylistic aspects of the molecular AOP network

In this section you can change the stylistic aspects of your molecular AOP network.

Step 11: You first have to import the necessary functions.

from py4cytoscape import get_node_color
from py4cytoscape import set_node_color_mapping
from py4cytoscape import gen_node_color_map
from py4cytoscape import set_edge_color_default
from py4cytoscape import set_node_color_default
from py4cytoscape import set_edge_source_arrow_shape_default
from py4cytoscape import set_edge_target_arrow_shape_default
from py4cytoscape import get_arrow_shapes
from py4cytoscape import get_edge_target_arrow_shape
from py4cytoscape import set_edge_target_arrow_shape_mapping
from py4cytoscape import gen_edge_arrow_map
from py4cytoscape import select_nodes
from py4cytoscape import get_table_value
from py4cytoscape import get_network_suid
from py4cytoscape import clear_selection
from py4cytoscape import set_node_color_bypass
from py4cytoscape import set_edge_color_bypass
from py4cytoscape import set_edge_target_arrow_color_default

Step 12: Next, you can define the style for your network and set the nodelabels and edgewidth.

style_name = "default"
defaults = {'NODE_SHAPE': "ELLIPSE", 'NODE_SIZE': 50, 'EDGE_TRANSPARENCY': 140, 'NODE_LABEL_POSITION': "C,C,c,0.00,0.00"}
nodeLabels = p4c.map_visual_property('node label', 'name', 'p') 
edgeWidth = p4c.map_visual_property('edge width', 'weight', 'p') 
arrowShapes = p4c.map_visual_property('Edge Target Arrow Shape','interaction', 'd')
p4c.create_visual_style(style_name, defaults, [nodeLabels, edgeWidth])
p4c.set_visual_style(style_name)
{'message': 'Visual Style applied.'}

Step 13: You can change the edge color and target shape to show the directionality of your network.

set_edge_target_arrow_shape_default('ARROW', style_name='default')
set_edge_target_arrow_color_default('#ffffff', style_name='default')
''

Step 14: In preparation for step 15, you will retrieve the columns of the nodetable.

table_columns = p4c.get_table_columns()
table_columns

SUID shared name id group type Association type name selected
51201 51201 https://identifiers.org/aop.events/1943 https://identifiers.org/aop.events/1943 Brain KE None Hyperphosphorylation of Tau False
51204 51204 https://identifiers.org/aop.events/386 https://identifiers.org/aop.events/386 Brain KE None Decrease of neuronal network function False
51207 51207 https://identifiers.org/aop.events/1944 https://identifiers.org/aop.events/1944 Brain KE None Synaptic dysfunction False
51210 51210 https://identifiers.org/aop.events/1582 https://identifiers.org/aop.events/1582 Brain KE None Impaired axonial transport False
51213 51213 https://identifiers.org/aop.events/1942 https://identifiers.org/aop.events/1942 Brain KE None Accumulation, Cytosolic toxic Tau oligomers False
... ... ... ... ... ... ... ... ...
51705 51705 WP5485 WP5485 Brain Molecular pathway Causative Post-COVID neuroinflammation False
51195 51195 https://identifiers.org/aop.events/1392 https://identifiers.org/aop.events/1392 Brain KE None Oxidative Stress False
51708 51708 WP2371 WP2371 Brain Molecular pathway Other Parkinson's disease pathway False
51198 51198 https://identifiers.org/aop.events/1815 https://identifiers.org/aop.events/1815 Liver KE None Activation of ER stress False
51711 51711 WP4197 WP4197 Liver Molecular pathway Causative Immune response to tuberculosis False

213 rows × 8 columns

Step 15: You can change the color of the nodes by selection of the node type followed by list conversion and color change with the bypass function.

Step 15a: Changing appearance of the MIE nodes to green.

table_columns_df = table_columns[table_columns['type'] == 'MIE']
MIEnodeslist = table_columns_df['name'].tolist()
p4c.select_nodes(MIEnodeslist)
{}
color = '#09d63a' 
new_colors = [color] * len(MIEnodeslist)
p4c.set_node_color_bypass(node_names=MIEnodeslist, new_colors=new_colors, network='current')
''

Step 15b: Changing appearance of the KE nodes to yellow.

table_columns_df2 = table_columns[table_columns['type'] == 'KE']
KEnodeslist = table_columns_df2['name'].tolist()
p4c.select_nodes(KEnodeslist, by_col='SUID')
{'nodes': [51519, 51342], 'edges': []}
color = '#f7ff00' 
new_colors = [color] * len(KEnodeslist)
p4c.set_node_color_bypass(node_names=KEnodeslist, new_colors=new_colors, network='current')
''

Step 15c: Changing appearance of the AO nodes to pink.

table_columns_df3 = table_columns[table_columns['type'] == 'AO']
AOnodeslist = table_columns_df3['name'].tolist()
p4c.select_nodes(AOnodeslist)
{'nodes': [51519, 51342], 'edges': []}
color = '#ff28d5' 
new_colors = [color] * len(AOnodeslist)
p4c.set_node_color_bypass(node_names=AOnodeslist, new_colors=new_colors, network='current')
''

Step 15d: Changing appearance of the molecular pathway nodes to grey.

table_columns_df4 = table_columns[table_columns['type'] == 'Molecular pathway']
molecularpathwaynodeslist = table_columns_df4['name'].tolist()
p4c.select_nodes(molecularpathwaynodeslist)
{'nodes': [51519, 51342], 'edges': []}
color = '#414a4c' 
new_colors = [color] * len(molecularpathwaynodeslist)
p4c.set_node_color_bypass(node_names=molecularpathwaynodeslist, new_colors=new_colors, network='current')
''
set_node_color_default('#a7a5a5',style_name='default')
''

Section 7: Extension of the molecular AOP network using Cytargetlinker and WikiPathways linkset

In this section, the AOP network will be enriched with genes associated to the molecular pathways you matched to your MIEs, KEs and AOs. This will be done using CyTargetLinker.

Step 16: You first install the CyTargetLinker app and check its functionality and status.

p4c.install_app('CyTargetLinker')
{}





{}
p4c.get_app_information('CyTargetLinker')
{'app': 'CyTargetLinker',
 'descriptionName': 'Flexible network extension app',
 'version': '4.1.0'}
p4c.get_app_status('CyTargetLinker')
{'appName': 'CyTargetLinker', 'status': 'Installed'}
p4c.commands_get('cytargetlinker extend')
["Available arguments for 'cytargetlinker extend':",
 'direction',
 'idAttribute',
 'linkSetDirectory',
 'linkSetFiles',
 'network']

Step 17: You import the operating system (os) package in preparation for step 17. Os allows the user to interact with the operating system of Cytoscape.

import os

Step 18: Next you define the filepath by which you retrieve the WikiPathways linkset file in your laptop.

file_path = os.path.join(os.getcwd(), "wikipathways_hsa_20240410 (1).xgmml")
linkset = "linkSetFiles="+file_path
print(linkset)
linkSetFiles=C:\Users\shaki\Downloads\wikipathways_hsa_20240410 (1).xgmml

Step 19: You construct the string for the network extension including: LinkSetFiles, idAttribute and direction.

cmd_cytargetlinker = ['cytargetlinker','extend', linkset, 'idAttribute="id"', 'direction="BOTH"']
cmd_ctl = " ".join(cmd_cytargetlinker)
print(cmd_ctl)
cytargetlinker extend linkSetFiles=C:\Users\shaki\Downloads\wikipathways_hsa_20240410 (1).xgmml idAttribute="id" direction="BOTH"

Step 20: You lastly run the command for the network extension and display the output. You have to use commands.commands_get as this function converts the command string of step 18 into a CyREST query.

p4c.commands.commands_get(cmd_ctl)
['Extension step: 1',
 'Linkset: WikiPathways-20240410_Homo sapiens_20240410',
 'Added edges: 5758',
 'Added nodes: 2739']

Section 8: Changing the visual style of CytargetLinker-extended molecular AOP network

In this section, you will apply the Cytoscape’s preferred layout to the AOP network.

Step 21: You will apply the layout to your extended network which uses Cytoscape’s preferred layout for organising the network.

cmd_cytargetlinker = ['cytargetlinker','applyLayout', 'network="current"']
cmd_ctl = " ".join(cmd_cytargetlinker)
p4c.commands.commands_get(cmd_ctl)
[]

Step 22: You can now apply the previous visual style to our extended network and view the network in Cytoscape.

cmd_cytargetlinker = ['cytargetlinker','applyVisualstyle', 'network="current"']
cmd_ctl = " ".join(cmd_cytargetlinker)
p4c.commands.commands_get(cmd_ctl)
[]
style_name = "default"
defaults = {'NODE_SHAPE': "ELLIPSE", 'NODE_SIZE': 50, 'EDGE_TRANSPARENCY': 140, 'NODE_LABEL_POSITION': "C,C,c,0.00,0.00"}
nodeLabels = p4c.map_visual_property('node label', 'name', 'p') 
edgeWidth = p4c.map_visual_property('edge width', 'weight', 'p') 
arrowShapes = p4c.map_visual_property('Edge Target Arrow Shape','interaction', 'd')
p4c.create_visual_style(style_name, defaults, [nodeLabels, edgeWidth])
p4c.set_visual_style(style_name)
{'message': 'Visual Style applied.'}

Section 9: Saving results

In this section, the Cytoscape network along with the style settings and bypass settings are saved for the next Jupyternotebook:‘Agata,Shakira-The AOP project-Part 4’.

Step 23: You will save your molecular AOP network as a Cytoscape in preparation for the next part.

p4c.save_session('Agata,S.-Part4-Complete Molecular inflammation-process related AOP network')
This file has been overwritten.





{}

Section 10: Metadata

At last, the metadata belonging to this jupyternotebook is displayed which contains the version numbers of packages and system-set-up for interested users. This requires the usage of packages:Watermark and print_versions.

Step 24: At last, the metadata belonging to this jupyternotebook is displayed which contains the version numbers of packages and system-set-up for interested users. This requires the usage of packages:Watermark and print_versions.

%load_ext watermark
!pip install print-versions
Requirement already satisfied: print-versions in c:\users\shaki\anaconda3\lib\site-packages (0.1.0)
%watermark
Last updated: 2025-06-02T18:23:43.809510+02:00

Python implementation: CPython
Python version       : 3.12.3
IPython version      : 8.25.0

Compiler    : MSC v.1938 64 bit (AMD64)
OS          : Windows
Release     : 11
Machine     : AMD64
Processor   : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
CPU cores   : 8
Architecture: 64bit
from print_versions import print_versions
print_versions(globals())
json==2.0.9
ipykernel==6.28.0
numpy==1.26.4
pandas==2.2.2
ipywidgets==8.0.3
xarray==2023.6.0
py4cytoscape==1.9.0

References:

  1. CyTargetLinker app update: A flexible solution for network extension in Cytoscape. Martina Kutmon, Friederike Ehrhart, Egon L Willighagen, Chris T. Evelo, Susan L. Coort F1000Research 2018, 7:743 doi: 10.12688/f1000research.14613.1
  2. Kutmon,M. 2024 . cyTargetLinker-automation.Maastricht:Github; \[accessed 2024 December 18\].https://github.com/CyTargetLinker/cytargetlinker-automation