1
2
3
4
5 from __future__ import print_function
6
7 from rdkit.Dbase import DbConnection
8 from rdkit.ML.Data import Quantize
9
10
11 -def runIt(namesAndTypes, dbConnect, nBounds, resCol, typesToDo=['float']):
12 results = map(lambda x: x[0], dbConnect.GetColumns(namesAndTypes[resCol][0]))
13 nPossibleRes = max(results) + 1
14 for cName, cType in namesAndTypes:
15 if cType in typesToDo:
16 dList = map(lambda x: x[0], dbConnect.GetColumns(cName))
17 qDat = Quantize.FindVarMultQuantBounds(dList, nBounds, results, nPossibleRes)
18 print(cName, qDat)
19
20
22 import sys
23 msg = """
24 Usage: FindQuantBounds [-r res_col -n bounds_per_var -i] dbName tableName
25 Optional Arguments:
26 -r: specify the number of the result column
27 -n: specify the number of bounds to attempt to find for each variable
28 -i: also find vars for integer values
29 """
30 print(msg)
31 sys.exit(-1)
32
33
34 if __name__ == '__main__':
35 import sys
36 import getopt
37
38 try:
39 args, extras = getopt.getopt(sys.argv[1:], 'n:r:i')
40 except Exception:
41 Usage()
42
43 if len(extras) != 2:
44 Usage()
45
46 nBounds = 1
47 typesToDo = ['float']
48 includeInts = 0
49 resCol = -1
50 for arg, val in args:
51 if arg == '-i':
52 includeInts = 1
53 typesToDo.append('integer')
54 elif arg == '-n':
55 try:
56 nBounds = int(val)
57 except ValueError:
58 Usage()
59 elif arg == '-r':
60 try:
61 resCol = int(val)
62 except ValueError:
63 Usage()
64
65 dbName = extras[0]
66 tableName = extras[1]
67 dbConnect = DbConnection.DbConnect(dbName, tableName)
68 namesAndTypes = dbConnect.GetColumnNamesAndTypes()
69 runIt(namesAndTypes, dbConnect, nBounds, resCol, typesToDo)
70