Friday, 4/17/2015
In this tutorial, IPython Notebook is the main workbench to control Cytoscape and other tools.
IPython Notebook is a simple tool to run your code in human-frienfly documents (Notebooks), and you can boost your productivity by learning some basic commands.
There are many keyboard shortcuts, but for now, you just need to learn the following:
Alt-Enter - Run cell, insert below
Esc and Enter - Command mode and edit mode
Complete list of shortcuts is available under Help menu:
OK, let's start!
In [1]:
print('Hello IPython World!')
In [2]:
result1 = 1+1
result2 = 2*3
In [3]:
result2
result1
Out[3]:
In [4]:
print('2nd = ' + str(result2))
print('1st = ' + str(result1))
In [5]:
!ls -alh
In [6]:
# List all installed Python packages
!pip list
In IPython Notebook, there is a nice feature called magic. Magic is a group of commands to execute some usuful functions just like system commands.
Here is the list of handy magics:
In [7]:
# Import NetworkX library, which is already installed in your Docker container
import networkx as nx
# Create a ranom graph with 100 nodes using Barabashi-Albert Model ()
ba=nx.barabasi_albert_graph(100,5)
# Check the performance of a NetworkX function (calculate betweenness centrality) by running 10 times
%timeit -n 10 nx.betweenness_centrality(ba)
In [8]:
%%timeit -n 10
# Or, check performance of the entire cell
ws = nx.watts_strogatz_graph(100,3,0.1)
btw = nx.betweenness_centrality(ws)
In [9]:
%%writefile data/small_network.sif
node1 is_a node2
node2 child_of node3
node3 child_of node1
In [10]:
!cat data/small_network.sif
In [11]:
%%bash
export FOO='Env var 1'
echo $FOO
In [12]:
%%javascript
var foo = function(a) {
return a+1;
};
console.log(foo(2));