<s> '''<STR_LIT>''' <EOL> import sys <EOL> import math <EOL> import numpy <EOL> import CGAT . Experiment as E <EOL> import CGAT . IOTools as IOTools <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if argv is None : <EOL> argv = sys . argv <EOL> parser = E . OptionParser ( <EOL> version = "<STR_LIT>" , <EOL> usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> choices = ( "<STR_LIT>" , ) ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( <EOL> method = "<STR_LIT>" , <EOL> columns = "<STR_LIT:all>" , <EOL> headers = True , <EOL> xrange = None , <EOL> pseudocounts = <NUM_LIT:1> , <EOL> normalize = True , <EOL> number_format = "<STR_LIT>" <EOL> ) <EOL> ( options , args ) = E . Start ( parser , <EOL> add_pipe_options = True ) <EOL> if options . xrange : <EOL> options . xrange = map ( float , options . xrange . split ( "<STR_LIT:U+002C>" ) ) <EOL> data , legend = IOTools . readTable ( sys . stdin , <EOL> numeric_type = numpy . float32 , <EOL> take = options . columns , <EOL> headers = options . headers , <EOL> truncate = options . xrange ) <EOL> nrows , ncols = data . shape <EOL> for y in range ( <NUM_LIT:1> , ncols ) : <EOL> for x in range ( nrows ) : <EOL> data [ x , y ] = data [ x , y ] + float ( options . pseudocounts ) <EOL> if options . normalize : <EOL> t = numpy . sum ( data [ : , y ] ) <EOL> for x in range ( nrows ) : <EOL> data [ x , y ] = data [ x , y ] / t <EOL> for x in range ( <NUM_LIT:1> , len ( legend ) - <NUM_LIT:1> ) : <EOL> for y in range ( x + <NUM_LIT:1> , len ( legend ) ) : <EOL> if options . method == "<STR_LIT>" : <EOL> d1 = <NUM_LIT:0.0> <EOL> d2 = <NUM_LIT:0.0> <EOL> for bin in range ( nrows ) : <EOL> p = data [ bin , x ] <EOL> q = data [ bin , y ] <EOL> d1 += p * math . log ( p / q ) <EOL> d2 += q * math . log ( q / p ) <EOL> options . stdout . write ( "<STR_LIT>" % <EOL> ( legend [ x ] , legend [ y ] , <EOL> options . number_format % d1 ) ) <EOL> options . stdout . write ( "<STR_LIT>" % <EOL> ( legend [ y ] , legend [ x ] , <EOL> options . number_format % d2 ) ) <EOL> E . Stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv ) ) </s>
