Commit 01fd54e2 authored by Tiago Peixoto's avatar Tiago Peixoto

Implement compatibility with python 3

parent cc1b6517
......@@ -17,6 +17,7 @@
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include "bytesobject.h"
#define NUMPY_EXPORT
#include "numpy_bind.hh"
......@@ -160,7 +161,7 @@ void graph_exception_translator(const Exception& e)
if (is_same<Exception, ValueException>::value)
error = PyExc_ValueError;
PyObject* message = PyString_FromString(e.what());
PyObject* message = PyUnicode_FromString(e.what());
PyObject_SetAttrString(error, "message", message);
PyErr_SetString(error, e.what());
}
......@@ -314,6 +315,13 @@ bool openmp_enabled()
#endif
}
// numpy array interface weirdness
void* do_import_array()
{
import_array1(NULL);
return NULL;
}
void ungroup_vector_property(GraphInterface& g, boost::any vector_prop,
boost::any prop, size_t pos, bool edge);
void group_vector_property(GraphInterface& g, boost::any vector_prop,
......@@ -327,8 +335,7 @@ void export_python_interface();
BOOST_PYTHON_MODULE(libgraph_tool_core)
{
// numpy
import_array();
do_import_array();
export_python_interface();
register_exception_translator<GraphException>
......
......@@ -330,6 +330,8 @@ struct export_python_interface
class_<PythonIterator<PythonVertex, vertex_iterator> >
("VertexIterator", no_init)
.def("__iter__", objects::identity_function())
.def("__next__", &PythonIterator<PythonVertex,
vertex_iterator>::Next)
.def("next", &PythonIterator<PythonVertex,
vertex_iterator>::Next);
v_iterators.insert(typeid(vertex_iterator).name());
......@@ -339,6 +341,8 @@ struct export_python_interface
class_<PythonIterator<PythonEdge<Graph>,
edge_iterator> >("EdgeIterator", no_init)
.def("__iter__", objects::identity_function())
.def("__next__", &PythonIterator<PythonEdge<Graph>,
edge_iterator>::Next)
.def("next", &PythonIterator<PythonEdge<Graph>,
edge_iterator>::Next);
......@@ -347,6 +351,8 @@ struct export_python_interface
class_<PythonIterator<PythonEdge<Graph>,
out_edge_iterator> >("OutEdgeIterator", no_init)
.def("__iter__", objects::identity_function())
.def("__next__", &PythonIterator<PythonEdge<Graph>,
out_edge_iterator>::Next)
.def("next", &PythonIterator<PythonEdge<Graph>,
out_edge_iterator>::Next);
......@@ -360,6 +366,8 @@ struct export_python_interface
class_<PythonIterator<PythonEdge<Graph>,
in_edge_iterator> >("InEdgeIterator", no_init)
.def("__iter__", objects::identity_function())
.def("__next__", &PythonIterator<PythonEdge<Graph>,
in_edge_iterator>::Next)
.def("next", &PythonIterator<PythonEdge<Graph>,
in_edge_iterator>::Next);
}
......
......@@ -75,6 +75,8 @@ Contents
--------
"""
from __future__ import division, absolute_import, print_function
__author__ = "Tiago de Paula Peixoto <tiago@skewed.de>"
__copyright__ = "Copyright 2007-2012 Tiago de Paula Peixoto"
__license__ = "GPL version 3 or above"
......@@ -88,12 +90,12 @@ import numpy.ma
import scipy
import scipy.stats
from dl_import import *
dl_import("import libgraph_tool_core as libcore")
import libgraph_tool_core as libcore # for pylint
from .dl_import import *
dl_import("from . import libgraph_tool_core as libcore")
__version__ = libcore.mod_info().version
import io # sets up libcore io routines
from . import io # sets up libcore io routines
import sys
import os
......@@ -103,8 +105,8 @@ import bz2
import weakref
import copy
from StringIO import StringIO
from decorators import _wraps, _require, _attrs, _limit_args
from io import StringIO
from .decorators import _wraps, _require, _attrs, _limit_args
from inspect import ismethod
__all__ = ["Graph", "GraphView", "Vertex", "Edge", "Vector_bool",
......@@ -228,14 +230,14 @@ def _convert(prop, val):
def show_config():
"""Show ``graph_tool`` build configuration."""
info = libcore.mod_info()
print "version:", info.version
print "gcc version:", info.gcc_version
print "compilation flags:", info.cxxflags
print "install prefix:", info.install_prefix
print "python dir:", info.python_dir
print "graph filtering:", libcore.graph_filtering_enabled()
print "openmp:", libcore.openmp_enabled()
print "uname:", " ".join(os.uname())
print("version:", info.version)
print("gcc version:", info.gcc_version)
print("compilation flags:", info.cxxflags)
print("install prefix:", info.install_prefix)
print("python dir:", info.python_dir)
print("graph filtering:", libcore.graph_filtering_enabled())
print("openmp:", libcore.openmp_enabled())
print("uname:", " ".join(os.uname()))
################################################################################
# Property Maps
......@@ -640,13 +642,13 @@ def group_vector_property(props, value_type=None, vprop=None, pos=None):
>>> from numpy import array
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> props = [g.new_vertex_property("int") for i in xrange(3)]
>>> for i in xrange(3):
>>> props = [g.new_vertex_property("int") for i in range(3)]
>>> for i in range(3):
... props[i].a = randint(0, 100, g.num_vertices())
>>> gprop = gt.group_vector_property(props)
>>> print gprop[g.vertex(0)].a
>>> print(gprop[g.vertex(0)].a)
[71 40 96]
>>> print array([p[g.vertex(0)] for p in props])
>>> print(array([p[g.vertex(0)] for p in props]))
[71 40 96]
"""
g = props[0].get_graph()
......@@ -723,9 +725,9 @@ def ungroup_vector_property(vprop, pos, props=None):
>>> for v in g.vertices():
... prop[v] = randint(0, 100, 3)
>>> uprops = gt.ungroup_vector_property(prop, [0, 1, 2])
>>> print prop[g.vertex(0)].a
>>> print(prop[g.vertex(0)].a)
[71 60 20]
>>> print array([p[g.vertex(0)] for p in uprops])
>>> print(array([p[g.vertex(0)] for p in uprops]))
[71 60 20]
"""
......@@ -784,7 +786,7 @@ def infect_vertex_property(g, prop, vals=None):
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> prop = g.copy_property(g.vertex_index)
>>> gt.infect_vertex_property(g, prop, [10])
>>> print sum(prop.a == 10)
>>> print(sum(prop.a == 10))
3
"""
libcore.infect_vertex_property(g._Graph__graph, _prop("v", g, prop),
......@@ -814,7 +816,7 @@ def edge_difference(g, prop, ediff=None):
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (3, 3))
>>> ediff = gt.edge_difference(g, g.vertex_index)
>>> print ediff.a
>>> print(ediff.a)
3
"""
val_t = prop.value_type()
......@@ -857,7 +859,7 @@ class PropertyDict(dict):
# The main graph interface
################################################################################
from libgraph_tool_core import Vertex, EdgeBase, Vector_bool, Vector_int32_t, \
from .libgraph_tool_core import Vertex, EdgeBase, Vector_bool, Vector_int32_t, \
Vector_int64_t, Vector_double, Vector_long_double, Vector_string, \
new_vertex_property, new_edge_property, new_graph_property
......@@ -907,7 +909,7 @@ class Graph(object):
if not (vprune or eprune or rprune):
g.pop_filter(vertex=vprune, edge=vprune, reversed=rprune)
for k, v in g.__properties.iteritems():
for k, v in g.__properties.items():
new_p = self.new_property(v.key_type(), v.value_type())
self.copy_property(v, new_p, g=g)
self.properties[k] = new_p
......@@ -917,12 +919,12 @@ class Graph(object):
if not vprune:
v_filt, v_rev = g.__filter_state["vertex_filter"]
if v_filt != None:
if v_filt not in g.vertex_properties.values():
if v_filt not in list(g.vertex_properties.values()):
new_filt = self.new_vertex_property("bool")
self.copy_property(v_filt, new_filt)
else:
for k, v in g.vertex_properties.iteritems():
for k, v in g.vertex_properties.items():
if v == v_filt:
new_filt = self.vertex_properties[k]
self.__stashed_filter_state[0]["vertex_filter"] = (new_filt,
......@@ -930,12 +932,12 @@ class Graph(object):
if not eprune:
e_filt, e_rev = g.__filter_state["edge_filter"]
if e_filt != None:
if e_filt not in g.edge_properties.values():
if e_filt not in list(g.edge_properties.values()):
new_filt = self.new_edge_property("bool")
self.copy_property(e_filt, new_filt)
else:
for k, v in g.edge_properties.iteritems():
for k, v in g.edge_properties.items():
if v == e_filt:
new_filt = self.edge_properties[k]
self.__stashed_filter_state[0]["edge_filter"] = (new_filt,
......@@ -1066,7 +1068,7 @@ class Graph(object):
self.__check_perms("add_vertex")
vlist = []
vfilt = self.get_vertex_filter()
for i in xrange(n):
for i in range(n):
v = libcore.add_vertex(weakref.ref(self))
if vfilt[0] is not None:
vfilt[0][v] = not vfilt[1]
......@@ -1089,7 +1091,7 @@ class Graph(object):
"""Remove all the vertices from the graph for which ``predicate(v)``
evaluates to ``True``. """
N = self.num_vertices()
for i in xrange(0, N):
for i in range(0, N):
v = self.vertex(N - i - 1)
if predicate(v):
self.remove_vertex(v)
......@@ -1177,7 +1179,7 @@ class Graph(object):
""")
def __get_specific_properties(self, t):
props = dict([(k[1], v) for k, v in self.__properties.iteritems() \
props = dict([(k[1], v) for k, v in self.__properties.items() \
if k[0] == t])
return props
......@@ -1231,21 +1233,21 @@ class Graph(object):
if len(self.__properties) == 0:
return
w = max([len(x[0]) for x in self.__properties.keys()]) + 4
w = max([len(x[0]) for x in list(self.__properties.keys())]) + 4
w = w if w > 14 else 14
for k, v in self.__properties.iteritems():
for k, v in self.__properties.items():
if k[0] == "g":
print "%%-%ds (graph) (type: %%s, val: %%s)" % w % \
(k[1], v.value_type(), str(v[self]))
for k, v in self.__properties.iteritems():
print("%%-%ds (graph) (type: %%s, val: %%s)" % w % \
(k[1], v.value_type(), str(v[self])))
for k, v in self.__properties.items():
if k[0] == "v":
print "%%-%ds (vertex) (type: %%s)" % w % (k[1],
v.value_type())
for k, v in self.__properties.iteritems():
print("%%-%ds (vertex) (type: %%s)" % w % (k[1],
v.value_type()))
for k, v in self.__properties.items():
if k[0] == "e":
print "%%-%ds (edge) (type: %%s)" % w % (k[1],
v.value_type())
print("%%-%ds (edge) (type: %%s)" % w % (k[1],
v.value_type()))
# index properties
......@@ -1423,11 +1425,11 @@ class Graph(object):
props = self.__graph.ReadFromFile(file_name, None, fmt)
else:
props = self.__graph.ReadFromFile("", file_name, fmt)
for name, prop in props[0].iteritems():
for name, prop in props[0].items():
self.vertex_properties[name] = PropertyMap(prop, self, "v")
for name, prop in props[1].iteritems():
for name, prop in props[1].items():
self.edge_properties[name] = PropertyMap(prop, self, "e")
for name, prop in props[2].iteritems():
for name, prop in props[2].items():
self.graph_properties[name] = PropertyMap(prop, self, "g",
lambda k: k.__graph)
......@@ -1443,7 +1445,7 @@ class Graph(object):
elif fmt == "auto":
fmt = "xml"
props = [(name[1], prop._PropertyMap__map) for name, prop in \
self.__properties.iteritems()]
self.__properties.items()]
if isinstance(file_name, str):
self.__graph.WriteToFile(file_name, None, fmt, props)
else:
......@@ -1651,7 +1653,7 @@ def value_types():
# Vertex and Edge Types
# =====================
from libgraph_tool_core import Vertex, Edge, EdgeBase
from .libgraph_tool_core import Vertex, Edge, EdgeBase
Vertex.__doc__ = """Vertex descriptor.
......@@ -1743,7 +1745,7 @@ def init_edge_classes():
v_filter = g.new_vertex_property("bool")
v_filter.a = [1]
g.set_vertex_filter(v_filter)
e = g.edges().next()
e = next(g.edges())
e.__class__.__repr__ = _edge_repr
e.__class__.__iter__ = _edge_iter
e.__class__.__doc__ = _edge_doc
......@@ -1864,3 +1866,4 @@ class GraphView(Graph):
def __get_base(self):
return self.__base
base = property(__get_base, doc="Base graph.")
......@@ -22,14 +22,20 @@
Utility module which includes all the sub-modules in graph_tool
"""
from __future__ import division, absolute_import, print_function
from graph_tool import *
import graph_tool
from graph_tool.correlations import *
import graph_tool.correlations
from graph_tool.centrality import *
import graph_tool.centrality
from graph_tool.draw import *
import graph_tool.draw
try:
from graph_tool.draw import *
import graph_tool.draw
except ImportError:
# Proceed despite errors with cairo, matplotlib, etc.
pass
from graph_tool.stats import *
import graph_tool.stats
from graph_tool.generation import *
......
......@@ -41,8 +41,10 @@ Contents
++++++++
"""
from __future__ import division, absolute_import, print_function
from .. dl_import import dl_import
dl_import("import libgraph_tool_centrality")
dl_import("from . import libgraph_tool_centrality")
from .. import _prop, ungroup_vector_property
import sys
......@@ -131,7 +133,7 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> pr = gt.pagerank(g)
>>> print pr.a
>>> print(pr.a)
[ 0.00865316 0.0054067 0.00406312 0.00426668 0.0015 0.00991696
0.00550065 0.00936397 0.00347917 0.00731864 0.00689843 0.00286274
0.00508731 0.01020047 0.00562247 0.00584915 0.02457086 0.00438568
......@@ -158,7 +160,7 @@ def pagerank(g, damping=0.85, pers=None, weight=None, prop=None, epsilon=1e-6,
>>> p.a = random(g.num_vertices())
>>> p.a /= p.a.sum()
>>> pr = gt.pagerank(g, pers=p, weight=w)
>>> print pr.a
>>> print(pr.a)
[ 0.00712999 0.00663336 0.00685722 0.00402663 0.00092715 0.01021926
0.00269502 0.0073301 0.00449892 0.00582793 0.00580542 0.00275149
0.00676363 0.01157972 0.00486918 0.00616345 0.02506695 0.00607967
......@@ -258,7 +260,7 @@ def betweenness(g, vprop=None, eprop=None, weight=None, norm=True):
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g)
>>> print vb.a
>>> print(vb.a)
[ 0.04889806 0.07181892 0.0256799 0.02885791 0. 0.05060927
0.04490836 0.03763462 0.02033383 0.03163202 0.02641248 0.03171598
0.03771112 0.02194663 0.0374907 0.01072567 0. 0.03079281
......@@ -340,7 +342,7 @@ def central_point_dominance(g, betweenness):
>>> seed(42)
>>> g = gt.random_graph(100, lambda: (poisson(3), poisson(3)))
>>> vb, eb = gt.betweenness(g)
>>> print gt.central_point_dominance(g, vb)
>>> print(gt.central_point_dominance(g, vb))
0.0766473408634
References
......@@ -418,9 +420,9 @@ def eigenvector(g, weight=None, vprop=None, epsilon=1e-6, max_iter=None):
>>> w = g.new_edge_property("double")
>>> w.a = random(g.num_edges()) * 42
>>> x = gt.eigenvector(g, w)
>>> print x[0]
>>> print(x[0])
0.0160851991895
>>> print x[1].a
>>> print(x[1].a)
[ 0.1376411 0.07207366 0.02727508 0.05805304 0. 0.10690994
0.04315491 0.01040908 0.02300252 0.08874163 0.04968119 0.06718114
0.05526028 0.20449371 0.02337425 0.07581173 0.19993899 0.14718912
......@@ -524,7 +526,7 @@ def eigentrust(g, trust_map, vprop=None, norm=False, epsilon=1e-6, max_iter=0,
>>> trust = g.new_edge_property("double")
>>> trust.a = random(g.num_edges())*42
>>> t = gt.eigentrust(g, trust, norm=True)
>>> print t.a
>>> print(t.a)
[ 1.12095562e-02 3.97280231e-03 1.31675503e-02 9.61282478e-03
0.00000000e+00 1.73295741e-02 3.53395497e-03 1.06203582e-02
1.36906165e-03 8.64587777e-03 1.12049516e-02 3.18891993e-03
......@@ -650,7 +652,7 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None):
>>> trust = g.new_edge_property("double")
>>> trust.a = random(g.num_edges())
>>> t = gt.trust_transitivity(g, trust, source=g.vertex(0))
>>> print t.a
>>> print(t.a)
[ 1.00000000e+00 9.59916062e-02 4.27717883e-02 7.70755875e-02
0.00000000e+00 2.04476926e-01 5.55315822e-02 2.82854665e-02
5.08479257e-02 1.68128402e-01 3.28567434e-02 7.39525583e-02
......@@ -707,3 +709,4 @@ def trust_transitivity(g, trust_map, source=None, target=None, vprop=None):
if target != -1 and source != -1:
return vprop.a[target]
return vprop
......@@ -41,14 +41,16 @@ Contents
++++++++
"""
from __future__ import division, absolute_import, print_function
from .. dl_import import dl_import
dl_import("import libgraph_tool_clustering as _gt")
dl_import("from . import libgraph_tool_clustering as _gt")
from .. import _degree, _prop, Graph, GraphView
from .. topology import isomorphism
from .. generation import random_rewire
from .. stats import vertex_hist
from itertools import izip
from collections import defaultdict
from numpy import *
from numpy import random
......@@ -114,7 +116,7 @@ def local_clustering(g, prop=None, undirected=True):
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> clust = gt.local_clustering(g)
>>> print gt.vertex_average(g, clust)
>>> print(gt.vertex_average(g, clust))
(0.00908888888888889, 0.0004449824521439575)
References
......@@ -171,7 +173,7 @@ def global_clustering(g):
>>> from numpy.random import seed
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> print gt.global_clustering(g)
>>> print(gt.global_clustering(g))
(0.009114059777509717, 0.0004464454368899158)
References
......@@ -244,9 +246,9 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> clusts = gt.extended_clustering(g, max_depth=5)
>>> for i in xrange(0, 5):
... print gt.vertex_average(g, clusts[i])
...
>>> for i in range(0, 5):
... print(gt.vertex_average(g, clusts[i]))
...
(0.0058850000000000005, 0.0004726257592782405)
(0.026346666666666668, 0.0009562588213100747)
(0.11638833333333333, 0.002086419787711849)
......@@ -263,7 +265,7 @@ def extended_clustering(g, props=None, max_depth=3, undirected=False):
g = GraphView(g, directed=False)
if props == None:
props = []
for i in xrange(0, max_depth):
for i in range(0, max_depth):
props.append(g.new_vertex_property("double"))
_gt.extended_clustering(g._Graph__graph,
[_prop("v", g, p) for p in props])
......@@ -321,9 +323,9 @@ def motifs(g, k, p=1.0, motif_list=None):
>>> seed(42)
>>> g = gt.random_graph(1000, lambda: (5,5))
>>> motifs, counts = gt.motifs(gt.GraphView(g, directed=False), 4)
>>> print len(motifs)
>>> print(len(motifs))
11
>>> print counts
>>> print(counts)
[115104, 389090, 724, 820, 1828, 3208, 791, 4, 12, 12, 3]
......@@ -335,7 +337,7 @@ def motifs(g, k, p=1.0, motif_list=None):
:doi:`10.1109/TCBB.2006.51`
"""
seed = random.randint(0, sys.maxint)
seed = random.randint(0, sys.maxsize)
sub_list = []
directed_motifs = g.is_directed()
......@@ -373,7 +375,7 @@ def motifs(g, k, p=1.0, motif_list=None):
temp.append(mg)
sub_list = temp
list_hist = zip(sub_list, hist)
list_hist = list(zip(sub_list, hist))
# sort according to in-degree sequence
list_hist.sort(lambda x, y: cmp(sorted([v.in_degree() for v in x[0].vertices()]),
sorted([v.in_degree() for v in y[0].vertices()])))
......@@ -394,14 +396,14 @@ def motifs(g, k, p=1.0, motif_list=None):
def _graph_sig(g):
"""return the graph signature, i.e., the in and out degree distribution as
concatenated as a tuple."""
bins = range(0, g.num_vertices() + 1)
bins = list(range(0, g.num_vertices() + 1))
in_dist = vertex_hist(g, "in", bins=bins if g.is_directed() else [0],
float_count=False)
out_dist = vertex_hist(g, "out", bins=bins, float_count=False)
sig = tuple([(in_dist[1][i], in_dist[0][i]) for \
i in xrange(len(in_dist[0]))] +
i in range(len(in_dist[0]))] +
[(out_dist[1][i], out_dist[0][i]) for\
i in xrange(len(out_dist[0]))])
i in range(len(out_dist[0]))])
return sig
......@@ -486,15 +488,15 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
>>> random.seed(10)
>>> g = gt.random_graph(100, lambda: (3,3))
>>> motifs, zscores = gt.motif_significance(g, 3)
>>> print len(motifs)
>>> print(len(motifs))
11
>>> print zscores
>>> print(zscores)
[0.014875553792545083, 0.016154998074953769, 0.002455801898331304, -1.9579019397305546, 0.83542298414538518, 0.84715258999068244, -0.93385230436820643, -0.11, -0.1, -0.31, -0.14]
"""
s_ms, counts = motifs(g, k, p, motif_list)
if threshold > 0:
s_ms, counts = zip(*[x for x in zip(s_ms, counts) if x[1] > threshold])
s_ms, counts = list(zip(*[x for x in zip(s_ms, counts) if x[1] > threshold]))
s_ms = list(s_ms)
counts = list(counts)
s_counts = [0] * len(s_ms)
......@@ -502,19 +504,19 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
# group subgraphs by number of edges
m_e = defaultdict(lambda: [])
for i in xrange(len(s_ms)):
for i in range(len(s_ms)):
m_e[_graph_sig(s_ms[i])].append(i)
# get samples
sg = g.copy()
for i in xrange(0, n_shuffles):
for i in range(0, n_shuffles):
random_rewire(sg, shuffle_strategy, self_loops=self_loops,
parallel_edges=parallel_edges)
m_temp, count_temp = motifs(sg, k, p, motif_list)
if threshold > 0:
m_temp, count_temp = zip(*[x for x in zip(m_temp, count_temp) \
if x[1] > threshold])
for j in xrange(0, len(m_temp)):
m_temp, count_temp = list(zip(*[x for x in zip(m_temp, count_temp) \
if x[1] > threshold]))
for j in range(0, len(m_temp)):
found = False
for l in m_e[_graph_sig(m_temp[j])]:
if isomorphism(s_ms[l], m_temp[j]):
......@@ -530,9 +532,9 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
s_counts = [x / float(n_shuffles) for x in s_counts]
s_dev = [max(sqrt(x[0] / float(n_shuffles) - x[1] ** 2), 1) \
for x in izip(s_dev, s_counts)]
for x in zip(s_dev, s_counts)]
list_hist = zip(s_ms, s_counts, s_dev)
list_hist = list(zip(s_ms, s_counts, s_dev))
# sort according to in-degree sequence
list_hist.sort(lambda x, y: cmp(sorted([v.in_degree()\
for v in x[0].vertices()]),
......@@ -548,11 +550,12 @@ def motif_significance(g, k, n_shuffles=100, p=1.0, motif_list=None,
# sort according to ascending number of edges
list_hist.sort(lambda x, y: cmp(x[0].num_edges(), y[0].num_edges()))
s_ms, s_counts, s_dev = zip(*list_hist)
s_ms, s_counts, s_dev = list(zip(*list_hist))
zscore = [(x[0] - x[1]) / x[2] for x in izip(counts, s_counts, s_dev)]
zscore = [(x[0] - x[1]) / x[2] for x in zip(counts, s_counts, s_dev)]
if full_output:
return s_ms, zscore, counts, s_counts, s_dev
else:
return s_ms, zscore
......@@ -39,8 +39,10 @@ Contents
++++++++
"""