Skip to content

Instantly share code, notes, and snippets.

@keiono
Created January 19, 2017 01:57
Show Gist options
  • Select an option

  • Save keiono/bf92000cceb1859e3472b496a1bfc846 to your computer and use it in GitHub Desktop.

Select an option

Save keiono/bf92000cceb1859e3472b496a1bfc846 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## py2cytoscape Tips\n",
"\n",
"### 1. Create PDF files for each network in your current Cytoscape session\n",
"\n",
"This code snippet generates PDF images for all networks in the current session."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Python 3.5.2 :: Anaconda custom (x86_64)\r\n"
]
}
],
"source": [
"!python --version"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Boilerplate: Import required packages\n",
"from py2cytoscape.data.cyrest_client import CyRestClient\n",
"\n",
"# Create Client\n",
"cy = CyRestClient()\n",
"\n",
"all_network_ids = cy.network.get_all()\n",
"\n",
"for id in all_network_ids:\n",
" # Get reference to the network\n",
" net = cy.network.create(id)\n",
" \n",
" # Get network title\n",
" net_name = net.get_network_value('name').decode(\"utf-8\") \n",
"\n",
" # Create PDF for it\n",
" pdf_obj = net.get_pdf()\n",
" \n",
" # Save it into a file\n",
" with open(net_name + \"_\" + str(id) + \".pdf\", \"wb\") as fout:\n",
" fout.write(pdf_obj) "
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment