def _G_test(site_counts):
 from math import log
 G = 0
 tot = sum(site_counts)
 tot_syn = (site_counts[0] + site_counts[2])
 tot_non = (site_counts[1] + site_counts[3])
 tot_fix = sum(site_counts[:2])
 tot_poly = sum(site_counts[2:])
 exp = [((tot_fix * tot_syn) / tot), ((tot_fix * tot_non) / tot), ((tot_poly * tot_syn) / tot), ((tot_poly * tot_non) / tot)]
 for (obs, ex) in zip(site_counts, exp):
  G += (obs * log((obs / ex)))
 G *= 2
 return chisqprob(G, 1)

def _G_test ( site_counts ) : from math import log G = 0 tot = sum ( site_counts ) tot_syn = ( site_counts [ 0 ] + site_counts [ 2 ] ) tot_non = ( site_counts [ 1 ] + site_counts [ 3 ] ) tot_fix = sum ( site_counts [ : 2 ] ) tot_poly = sum ( site_counts [ 2 : ] ) exp = [ ( ( tot_fix * tot_syn ) / tot ) , ( ( tot_fix * tot_non ) / tot ) , ( ( tot_poly * tot_syn ) / tot ) , ( ( tot_poly * tot_non ) / tot ) ] for ( obs , ex ) in zip ( site_counts , exp ) : G += ( obs * log ( ( obs / ex ) ) ) G *= 2 return chisqprob ( G , 1 )
g test for 2x2 contingency table .