@@ -0,0 +1,2067 @@
+%0Afrom cno.io import xcnograph%0A%0A%0Aclass RandomGraph(object):%0A    %22%22%22%0A%0A    c = RandomGraph()%0A    c.run(10, 200)%0A    c.parameters%5B'nExtraNode'%5D = 20%0A%0A    %22%22%22%0A    def __init__(self):%0A        self.commons = %5B%5D%0A        self.parameters = %7B'nStimuli':4, 'nSignals':4, 'extraNode':10, 'nTrans':4%7D    %0A%0A    def create_graph(self, fraction=0.7):%0A        self.c = xcnograph.XCNOGraph()%0A        self.c.random_cnograph(nStimuli=self.parameters%5B'nStimuli'%5D, %0A                nSignals=self.parameters%5B'nSignals'%5D, %0A                fraction_activation=fraction, nTranscript=self.parameters%5B'nTrans'%5D, %0A                nExtraNode=self.parameters%5B'extraNode'%5D)%0A        self.Nneg = %5Bx%5B2%5D%5B'link'%5D for x in self.c.edges(data=True)%5D.count('-')%0A        self.indeg = self.c.in_degree().copy()%0A        self.outdeg = self.c.out_degree().copy()%0A        self.deg = self.c.degree().copy()%0A        self.ori = self.c.copy()%0A        self.c = self.c.copy()%0A        self.Nedges = len(self.ori.edges())%0A%0A    def swap(self, N=100):%0A        common = %5B%5D%0A        for i in range(0, N):%0A            self.c.swap_edges(1, self_loop=False)%0A            #c.plot(rank_method='cno')%0A%0A            assert self.Nneg == %5Bx%5B2%5D%5B'link'%5D for x in self.c.edges(data=True)%5D.count('-')%0A            assert self.deg == self.c.degree()%0A            assert self.indeg == self.c.in_degree()%0A            assert self.outdeg == self.c.out_degree()%0A            n = len(%5Be for e in self.c.edges() if e in self.ori.edges()%5D)/float(self.Nedges)%0A            common.append(n)%0A        self.commons.append(common)%0A%0A    def plot(self):%0A        from pylab import plot, show, grid%0A        for common in self.commons:%0A            plot(common)    %0A%0A        import pandas as pd%0A        df = pd.DataFrame(self.commons)%0A        df = plot(df.mean(), lw=2, color='r')%0A%0A    def run(self, N=10, Nswaps=100, verbose=True):%0A        self.commons = %5B%5D%0A        for i in range(0,10):%0A            if verbose:%0A                print(i)%0A            self.create_graph()%0A            self.swap(N=Nswaps)%0A        self.plot()%0A        import pylab%0A        pylab.grid()%0A%0A%0A%0A%0A

add new file to test randomisation of the swap_edge function.