-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect-clusters.py
More file actions
executable file
·54 lines (34 loc) · 1.55 KB
/
select-clusters.py
File metadata and controls
executable file
·54 lines (34 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python2
import os
import sys
import zipcodetools
from optparse import OptionParser
###############################################################################
USAGE = """
python select-clusters.py --families <file of families to consider>
Clustertable is output from form-clusters-from-table.py
Find first point where >= cutoff % of zipcodes in rank [i, i+stepsize] merge into previous
zipcodes. That is, where cutoff % are not unique.
"""
parser = OptionParser(USAGE)
parser.add_option('--clustertable',dest='clusterTable', help = 'cluster table')
parser.add_option('--stepsize',dest='stepSize', type='int',default=1,help = 'step size')
parser.add_option('--cutoff',dest='cutOff', type='float',default=0.90,help = 'cutoff')
(options, args) = parser.parse_args()
if options.clusterTable is None:
parser.error('clusterTable not given')
###############################################################################
print 'input file',options.clusterTable
print 'step size',options.stepSize
print 'cutoff',options.cutOff
outFileName = options.clusterTable + '.sel.%i-%.2f.txt' % (options.stepSize,options.cutOff)
myData={}
myData['clusterTable'] = options.clusterTable
myData['stepSize'] = options.stepSize
myData['cutOff'] = options.cutOff
zipcodetools.select_clusters(myData)
print '%i selected zips written to %s' % (len(myData['selectedClusterList']),outFileName)
outFile = open(outFileName,'w')
for i in range(0,len(myData['selectedClusterList'])):
outFile.write('%i\t%s\n' % (i+1,myData['selectedClusterList'][i]))
outFile.close()