In [1]:
from cno.io import xcnograph
%pylab inline
matplotlib.rcParams['figure.figsize'] = (12,8)


Couldn't import dot_parser, loading of dot files will not be possible.
Populating the interactive namespace from numpy and matplotlib

In [2]:
c = xcnograph.XCNOGraph()

random graph

Let us create a random graph that 'looks like' typical graph used in CellNOpt: some ligands, some readouts (transcripts without output:

  • 5 ligands (green); in degree is zero
  • 14 measured (blue) with 5 transcripts (out degree set to 0)
  • 10 other nodes (white)

Note that there are few inhibitors (10% of the edges) and no self loops, which is optional


In [3]:
c.random_cnograph()

In [4]:
c.png


Out[4]:

double edges swap

two edges are selected randomly:

u v            u v
| |  becomes   | |
x y            y x

Their edges are swapped.

  • If u-y or v-x already exists, no swap is performed
  • and gates are ignored (removed at the beginning). They can then be added back by the user.
  • If the network becomes unconnected, the proposed swap is skipped.
  • If a self loop is created, the proposed swap is skipped
  • If the indegree or outdegree changes, the swap is skipped.

In [5]:
res = c.swap_edges(100)

In [6]:
c.png


Out[6]:

You can figure out the similarity between the orignal and new graph using for isntance the number of common edges as a measure of similarity.


In [7]:
from cno.io import randomisation
reload(randomisation)


Out[7]:
<module 'cno.io.randomisation' from '/home/cokelaer/Work/github/cellnopt/cno/io/randomisation.pyc'>

In [8]:
r = randomisation.RandomGraph()
r.parameters


Out[8]:
{'extraNode': 10, 'nSignals': 4, 'nStimuli': 4, 'nTrans': 4}

In [9]:
# We will (1) create a random graph with default number of nodes
# (2) swap edges 150 times and (3) repeat this 10 times
r.run(100, 100, verbose=False)


fixing stimulus L1
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-9-042761c21f44> in <module>()
      1 # We will (1) create a random graph with default number of nodes
      2 # (2) swap edges 150 times and (3) repeat this 10 times
----> 3 r.run(100, 100, verbose=False)

/home/cokelaer/Work/github/cellnopt/cno/io/randomisation.pyc in run(self, N, Nswaps, verbose)
     67             if verbose:
     68                 print("Creating graph %s " % i)
---> 69             self.create_graph()
     70             if verbose:
     71                 print('Now the swapping')

/home/cokelaer/Work/github/cellnopt/cno/io/randomisation.pyc in create_graph(self, fraction)
     22                 fraction_activation=fraction, nTranscript=self.parameters['nTrans'],
     23                 nExtraNode=self.parameters['extraNode'])
---> 24         self.Nneg = [x[2]['link'] for x in self.c.edges(data=True)].count('-')
     25         self.indeg = self.c.in_degree().copy()
     26         self.outdeg = self.c.out_degree().copy()

KeyError: 'link'

In [10]:
r.parameters['nSignals'] = 25
r.parameters['nTrans'] = 8
r.parameters['nStimuli'] = 10
r.parameters['extraNode'] = 80

In [11]:
r.create_graph()

In [12]:
print r.c


The model contains 115 nodes (and 0 AND node)
344 Hyperedges found (344+0) 


In [13]:
r.run(3, 600 , verbose=True)


Creating graph 0 
Now the swapping
Creating graph 1 
fixing stimulus L4
Now the swapping
Creating graph 2 
fixing stimulus L5
Now the swapping
Creating graph 3 
Now the swapping
Creating graph 4 
fixing stimulus L5
Now the swapping
Creating graph 5 
Now the swapping
Creating graph 6 
fixing stimulus L2
Now the swapping
Creating graph 7 
Now the swapping
Creating graph 8 
Now the swapping
Creating graph 9 
fixing stimulus L6
Now the swapping

conclusions

  • can create 'random' cno-graph
  • can swap edges keeping order degrees constant
  • can swap edges keeping ratio inhibitor/active linkes constant
  • slowish (2-4 seconds to swap 600 times edges on a graph of 400 edges) but seems to work
  • plateau is of course function of the number of edges but probably also on number of stimuli/transcript

In [ ]: