Skip to content

Commit

Permalink
Merge pull request #1 from jonls/python3
Browse files Browse the repository at this point in the history
Make code Python3 compatible
  • Loading branch information
koteth authored Jul 13, 2016
2 parents 5611c7f + bbd39bb commit 01e8687
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
32 changes: 16 additions & 16 deletions mcl/mcl_clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ def networkx_mcl(G, expand_factor = 2, inflate_factor = 2, max_loop = 10 , mult_
return mcl(np.array(A.todense()), expand_factor, inflate_factor, max_loop, mult_factor)

def print_info(options):
print "-"*60
print "MARKOV CLUSTERING:"
print "-" * 60
print " expand_factor: %s" % options.expand_factor
print " inflate_factor: %s" % options.inflate_factor
print " mult factor: %s" % options.mult_factor
print " max loops: %s\n" % options.max_loop
print("-" * 60)
print("MARKOV CLUSTERING:")
print("-" * 60)
print(" expand_factor: %s" % options.expand_factor)
print(" inflate_factor: %s" % options.inflate_factor)
print(" mult factor: %s" % options.mult_factor)
print(" max loops: %s\n" % options.max_loop)

def get_options():
usage = "usage: %prog [options] <input_matrix>"
Expand Down Expand Up @@ -144,7 +144,7 @@ def get_graph(csv_filename):
M = []
for r in open(csv_filename):
r = r.strip().split(",")
M.append( map( lambda x: float(x.strip()), r))
M.append(list(map(lambda x: float(x.strip()), r)))

G = nx.from_numpy_matrix(np.matrix(M))
return np.array(M), G
Expand All @@ -155,29 +155,29 @@ def clusters_to_output(clusters, options):
for k, v in clusters.items():
f.write("%s|%s\n" % (k, ", ".join(map(str, v)) ))
f.close()
else:
print "Clusters:"
else:
print("Clusters:")
for k, v in clusters.items():
print k, v
print('{}, {}'.format(k, v))

if __name__ == '__main__':

options, filename = get_options()
print_info(options)
M, G = get_graph(filename)

print " number of nodes: %s\n" % M.shape[0]
print(" number of nodes: %s\n" % M.shape[0])

print time.time(), "evaluating clusters..."
print("{}: {}".format(time.time(), "evaluating clusters..."))
M, clusters = networkx_mcl(G, expand_factor = options.expand_factor,
inflate_factor = options.inflate_factor,
max_loop = options.max_loop,
mult_factor = options.mult_factor)
print time.time(), "done\n"
print("{}: {}".format(time.time(), "done\n"))

clusters_to_output(clusters, options)

if options.draw:
print time.time(), "drawing..."
print("{}: {}".format(time.time(), "drawing..."))
draw(G, M, clusters)
print time.time(), "done"
print("{}: {}".format(time.time(), "done"))
2 changes: 1 addition & 1 deletion mcl/mcl_clustering_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest
import numpy as np
from mcl_clustering import *
from .mcl_clustering import *
import logging

#TODO: improveme
Expand Down
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
name='MCL_Markov_Cluster',
version='0.3',
description='Markov Cluster algorithm implementation',
url = 'https://github.com/koteth/python_mcl',
url = 'https://github.com/koteth/python_mcl',
scripts = [
'mcl/mcl_clustering.py'
],
install_requires = ['numpy', 'networkx'],
keywords = "MCL markov clustering graph",
classifiers=[
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
],
author='Gabriele Lami',
packages=['mcl'],
)

0 comments on commit 01e8687

Please sign in to comment.