<s> '''<STR_LIT>''' <EOL> import sys <EOL> import re <EOL> import string <EOL> import os <EOL> import getopt <EOL> import time <EOL> import CGAT . Experiment as E <EOL> import CGAT . Histogram as Histogram <EOL> def main ( argv = None ) : <EOL> if argv == None : argv = sys . argv <EOL> parser = E . OptionParser ( version = "<STR_LIT>" , <EOL> usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , dest = "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT:-c>" , "<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:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT>" , action = "<STR_LIT>" , <EOL> choices = ( "<STR_LIT>" , ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( <EOL> nonull = None , <EOL> columns = [ <NUM_LIT:0> , ] , <EOL> empty_bins = True , <EOL> titles = False , <EOL> lower_limit = None , <EOL> upper_limit = None , <EOL> bin_size = None , <EOL> scale = None , <EOL> normalize = None , <EOL> append = [ ] , <EOL> cumulative = False , <EOL> reverse_cumulative = False ) <EOL> ( options , args ) = E . Start ( parser , argv = argv ) <EOL> if options . columns : <EOL> if options . columns != "<STR_LIT:all>" : <EOL> options . columns = [ int ( x ) - <NUM_LIT:1> for x in options . columns . split ( "<STR_LIT:U+002C>" ) ] <EOL> else : <EOL> options . columns . append ( <NUM_LIT:0> ) <EOL> histograms = [ ] <EOL> vals = [ ] <EOL> for x in options . columns : vals . append ( [ ] ) <EOL> lines = filter ( lambda x : x [ <NUM_LIT:0> ] < > "<STR_LIT:#>" , sys . stdin . readlines ( ) ) <EOL> ncols = len ( string . split ( lines [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] , "<STR_LIT:\t>" ) ) <EOL> if options . columns == "<STR_LIT:all>" : <EOL> options . columns = range ( ncols ) <EOL> for x in options . columns : vals . append ( [ ] ) <EOL> if options . titles : <EOL> data = lines [ <NUM_LIT:0> ] [ : - <NUM_LIT:1> ] . split ( "<STR_LIT:\t>" ) <EOL> del lines [ <NUM_LIT:0> ] <EOL> options . titles = map ( lambda x : data [ x ] , options . columns ) <EOL> for l in lines : <EOL> data = string . split ( l [ : - <NUM_LIT:1> ] , "<STR_LIT:\t>" ) <EOL> for x in range ( len ( options . columns ) ) : <EOL> try : <EOL> v = string . atof ( data [ options . columns [ x ] ] ) <EOL> except IndexError : <EOL> print "<STR_LIT>" , l [ : - <NUM_LIT:1> ] <EOL> continue <EOL> except ValueError : <EOL> continue <EOL> if options . scale : <EOL> v *= options . scale <EOL> if options . upper_limit != None and v > options . upper_limit : <EOL> v = options . upper_limit <EOL> if options . lower_limit != None and v < options . lower_limit : <EOL> v = options . lower_limit <EOL> vals [ x ] . append ( v ) <EOL> lines = None <EOL> hists = [ ] <EOL> titles = [ ] <EOL> for x in range ( len ( options . columns ) ) : <EOL> E . info ( "<STR_LIT>" % ( options . columns [ x ] , len ( vals [ x ] ) ) ) <EOL> if len ( vals [ x ] ) == <NUM_LIT:0> : continue <EOL> h = Histogram . Calculate ( vals [ x ] , no_empty_bins = options . empty_bins , increment = options . bin_size ) <EOL> if options . scale : h = Histogram . Scale ( h , <NUM_LIT:1.0> / options . scale ) <EOL> if options . normalize : h = Histogram . Normalize ( h ) <EOL> if options . cumulative : h = Histogram . Cumulate ( h ) <EOL> if options . reverse_cumulative : h = Histogram . Cumulate ( h , direction = <NUM_LIT:0> ) <EOL> hists . append ( h ) <EOL> for m in options . append : <EOL> if m == "<STR_LIT>" : <EOL> hists . append ( Histogram . Normalize ( h ) ) <EOL> if options . titles : <EOL> titles . append ( options . titles [ x ] ) <EOL> if titles : <EOL> options . stdout . write ( "<STR_LIT>" + "<STR_LIT:\t>" . join ( titles ) + "<STR_LIT:\n>" ) <EOL> if len ( hists ) == <NUM_LIT:1> : <EOL> Histogram . Print ( hists [ <NUM_LIT:0> ] , nonull = options . nonull ) <EOL> else : <EOL> combined_histogram = Histogram . Combine ( hists ) <EOL> Histogram . Print ( combined_histogram , nonull = options . nonull ) <EOL> E . Stop ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> sys . exit ( main ( sys . argv ) ) </s>
