Combination of Python scripts and KEGGscape

Scripting language support is an experimental feature in Cytoscape 3.

Cytoscape 3 supports scripting language. Here we show a sample of Python + KEGGscape.

We import all Ecoli pathways to Cytoscape.

Importing all KEGG pathways of Escherichia coli K-12 MG1655

First we download all Ecoli pathways with the following Python script. This script requires requests Python package.

import requests

ORGANISM = "eco"

pathways = requests.get('' + ORGANISM)
for line in pathways.content.split('\n'):
    pathwayid = line.split('\t')[0].replace('path:', '')
    kgml = requests.get('' + pathwayid + '/kgml')
    f = open(pathwayid + '.xml', 'w')

You will get all eco KGMLs like this.

Next we show a sample to batch-import kgml files from Python script. To use Python from Cytoscape3, you need to download jython-standalone from here , and move the jython-standalone like this.

Now you can batch-import kgml files with Python. Here we import all carbohydrate metabolism kgml files. (Of course you can import all pathways, but it takes time and cys file get so big.)

mkdir carbohydrate
mv eco00010.xml eco00020.xml eco00030.xml eco00040.xml eco00051.xml
eco00052.xml eco00053.xml eco00500.xml eco00520.xml eco00562.xml
eco00620.xml eco00630.xml eco00640.xml eco00650.xml eco00660.xml

next run cytoscape3, go in osgi shell and run following Python script(save as

from import File

KEGG_DIR = "/ABS_PATH_TO/carbohydrate/"
pathways = ["eco00010.xml", "eco00020.xml", "eco00030.xml", "eco00040.xml", "eco00051.xml", "eco00052.xml", "eco00053.xml", "eco00500.xml", "eco00520.xml", "eco00562.xml", "eco00620.xml", "eco00630.xml", "eco00640.xml", "eco00650.xml", "eco00660.xml"]

loadNetworkTF = cyAppAdapter.get_LoadNetworkFileTaskFactory()
taskManager = cyAppAdapter.getTaskManager()

allTasks = None

for pathway in pathways:
    kgmlpath = File(KEGG_DIR + pathway)
    print str(kgmlpath)
    itr = loadNetworkTF.createTaskIterator(kgmlpath)
    if allTasks is None:
        allTasks = itr


Save this Python script as To run, type (from Cytoscape3 OSGi shell)

cytoscape:script python /ABS_PATH_TO_SCRIPT/