comparison chemfp_clustering/nxn_clustering.py @ 21:7c84cfa515e0

ChemicalToolBoX update.
author Bjoern Gruening <bjoern.gruening@gmail.com>
date Sat, 01 Jun 2013 20:03:04 +0200
parents 438bc12d591b
children 6c496b524b41
comparison
equal deleted inserted replaced
20:21d29a7f13d8 21:7c84cfa515e0
10 import os 10 import os
11 import chemfp 11 import chemfp
12 import scipy.cluster.hierarchy as hcluster 12 import scipy.cluster.hierarchy as hcluster
13 import pylab 13 import pylab
14 import numpy 14 import numpy
15 import tempfile
15 16
16 17
17 def distance_matrix(arena, tanimoto_threshold = 0.0): 18 def distance_matrix(arena, tanimoto_threshold = 0.0):
18 n = len(arena) 19 n = len(arena)
19 # Start off a similarity matrix with 1.0s along the diagonal 20 # Start off a similarity matrix with 1.0s along the diagonal
61 parser.add_argument('-p', '--processors', type=int, 62 parser.add_argument('-p', '--processors', type=int,
62 default=4) 63 default=4)
63 64
64 args = parser.parse_args() 65 args = parser.parse_args()
65 66
67 # make sure that the file ending is fps
68 temp_file = tempfile.NamedTemporaryFile()
69 temp_link = "%s.%s" % (temp_file.name, 'fps')
70 temp_file.close()
71 os.symlink(args.input_path, temp_link)
66 72
67 arena = chemfp.load_fingerprints( args.input_path ) 73 arena = chemfp.load_fingerprints( temp_link )
68 distances = distance_matrix( arena, args.tanimoto_threshold ) 74 distances = distance_matrix( arena, args.tanimoto_threshold )
69 linkage = hcluster.linkage( distances, method="single", metric="euclidean" ) 75 linkage = hcluster.linkage( distances, method="single", metric="euclidean" )
70 76
71 hcluster.dendrogram(linkage, labels=arena.ids) 77 hcluster.dendrogram(linkage, labels=arena.ids)
72 78