Package rdkit :: Package ML :: Package Data :: Module FindQuantBounds

[hide private]
[frames] | no frames]

# Source Code for Module rdkit.ML.Data.FindQuantBounds

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