#NEWLINE# def doMultiple( options ) : #NEWLINE# #INDENT# first = True #NEWLINE# last_val = None #NEWLINE# ( headers , hists ) = ( [ ] , [ ] ) #NEWLINE# for line in sys . stdin : #NEWLINE# #INDENT# if ( line [ 0 ] == '#' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# data = line [ : ( - 1 ) ] . split ( '\t' ) #NEWLINE# if first : #NEWLINE# #INDENT# headers = data [ 1 : ] #NEWLINE# ncols = len ( headers ) #NEWLINE# first = False #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# val = data [ 0 ] #NEWLINE# if ( val != last_val ) : #NEWLINE# #INDENT# if ( last_val is not None ) : #NEWLINE# #INDENT# hists . append ( ( last_val , this_hist ) ) #NEWLINE# #UNINDENT# this_hist = ( [ 0 ] * ncols ) #NEWLINE# last_val = val #NEWLINE# #UNINDENT# for x in range ( ncols ) : #NEWLINE# #INDENT# this_hist [ x ] += int ( data [ ( this_hist + 1 ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( last_val is not None ) : #NEWLINE# #INDENT# hists . append ( ( last_val , this_hist ) ) #NEWLINE# #UNINDENT# if ( not headers ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# options . stdout . write ( ( 'value\ttotal\t%s\t%s\n' % ( '\t' . join ( headers ) , '\t' . join ( [ ( 'p%s' % x ) for x in headers ] ) ) ) ) #NEWLINE# ntotal = 0 #NEWLINE# hist = ( [ 0 ] * ncols ) #NEWLINE# for ( val , this_hist ) in hists : #NEWLINE# #INDENT# for x in range ( ncols ) : #NEWLINE# #INDENT# hist [ x ] += this_hist [ x ] #NEWLINE# #UNINDENT# ntotal += sum ( this_hist ) #NEWLINE# options . stdout . write ( ( '%s\t%i\t%s\t%s\n' % ( val , ntotal , '\t' . join ( [ ( '%i' % x ) for x in hist ] ) , '\t' . join ( [ ( '%f' % ( float ( x ) / ntotal ) ) for x in hist ] ) ) ) )