#!/usr/bin/env python2.5

from BNfinder.data import dataset


if __name__=="__main__":
    import sys
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-c", "--cpd", dest="cpd",help="Input file with the conditional probability distributions gotten from bnfinder")
    parser.add_option("-d", "--data", dest="data",help="Input file with values of regulator variables.")
    
    parser.add_option("-m", "--ml", dest="ml",default=False,help="Should we output only the most likely value.")
    parser.add_option("-p", "--prob", dest="prob",type=int,help="Output the probability of given class value (for all nodes).")
    parser.add_option("-o", "--out", dest="out",default=sys.stdout,help="Output file.")
    
    (options, args) = parser.parse_args()

    if options.cpd==None or options.data==None:
        print "You must provide a cpd file and input data. Run bnc --help for more options."
    else:
        cpd=eval(open(options.cpd).read())
        d=dataset().fromNewFile(open(options.data),float_transform=None)
        if options.out!=sys.stdout:
            options.out=open(options.out,"w")
        d.classify(cpd,options.out,ML=options.ml,prob=options.prob,transformed=False)
