<s> '''<STR_LIT>''' <EOL> import sys <EOL> import string <EOL> import re <EOL> import optparse <EOL> USAGE = """<STR_LIT>""" <EOL> import CGAT . Experiment as Experiment <EOL> import CGAT . Stats as Stats <EOL> import CGAT . CSV as CSV <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> parser = optparse . OptionParser ( version = "<STR_LIT>" , usage = globals ( ) [ "<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 ( min_length = <NUM_LIT:0> , <EOL> filename_graph = None ) <EOL> ( options , args ) = Experiment . Start ( parser , add_csv_options = True ) <EOL> tests = ( ( '<STR_LIT:none>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:none>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:none>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:none>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:none>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:all>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:all>' ) , <EOL> ( '<STR_LIT:none>' , '<STR_LIT:all>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:all>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:all>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:all>' ) , <EOL> ) <EOL> map_model2params = { <EOL> '<STR_LIT:none>' : <NUM_LIT:8> , <EOL> '<STR_LIT>' : <NUM_LIT:7> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT:all>' : <NUM_LIT:4> } <EOL> reader = CSV . DictReader ( sys . stdin , <EOL> dialect = options . csv_dialect ) <EOL> stats = { } <EOL> options . stdout . write ( "<STR_LIT:id>" ) <EOL> for a , b in tests : <EOL> options . stdout . write ( "<STR_LIT>" % ( a , b , a , b ) ) <EOL> stats [ ( a , b ) ] = <NUM_LIT:0> <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> ninput , noutput , nskipped , nerrors , ntests = <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> <EOL> for row in reader : <EOL> ninput += <NUM_LIT:1> <EOL> if int ( row [ '<STR_LIT>' ] ) <= options . min_length or int ( row [ '<STR_LIT>' ] ) <= options . min_length : <EOL> nskipped += <NUM_LIT:1> <EOL> continue <EOL> options . stdout . write ( row [ '<STR_LIT:id>' ] ) <EOL> for a , b in tests : <EOL> ntests += <NUM_LIT:1> <EOL> lnl_complex = float ( row [ '<STR_LIT>' % a ] ) <EOL> lnl_simple = float ( row [ '<STR_LIT>' % b ] ) <EOL> df_complex = map_model2params [ a ] <EOL> df_simple = map_model2params [ b ] <EOL> if options . loglevel >= <NUM_LIT:3> : <EOL> options . stdlog . write ( "<STR_LIT>" % ( a , <EOL> lnl_complex , df_complex , <EOL> b , lnl_simple , <EOL> df_simple ) ) <EOL> if lnl_complex < lnl_simple : <EOL> nerrors += <NUM_LIT:1> <EOL> options . stdout . write ( "<STR_LIT>" ) <EOL> continue <EOL> lrt = Stats . doLogLikelihoodTest ( lnl_complex , df_complex , lnl_simple , df_simple ) <EOL> if lrt . mPassed : stats [ ( a , b ) ] += <NUM_LIT:1> <EOL> options . stdout . write ( "<STR_LIT>" % ( <EOL> Stats . getSignificance ( lrt . mProbability ) , <EOL> lrt . mProbability ) ) <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> noutput += <NUM_LIT:1> <EOL> options . stdout . write ( "<STR_LIT>" ) <EOL> for a , b in tests : <EOL> options . stdout . write ( "<STR_LIT>" % ( stats [ ( a , b ) ] , <NUM_LIT> * stats [ ( a , b ) ] / noutput ) ) <EOL> options . stdout . write ( "<STR_LIT:\n>" ) <EOL> if options . filename_graph : <EOL> outfile = open ( options . filename_graph , '<STR_LIT:w>' ) <EOL> for a , b in tests : <EOL> outfile . write ( "<STR_LIT>" % ( a , b , stats [ ( a , b ) ] , <NUM_LIT> * stats [ ( a , b ) ] / noutput ) ) <EOL> outfile . close ( ) <EOL> options . stdout . write ( "<STR_LIT>" % ( ninput , noutput , nskipped , ntests , nerrors ) ) <EOL> Experiment . Stop ( ) </s>
