import numpy as np
from StringIO import StringIO
def waldtest(istr, alpha=.05, ostr=None):
	if ostr == None:
		ostr = istr
	ostr1 = ostr+'.uncor'
	ostr2 = ostr+'.corr'
	ifile = open(istr)
	ofile1 = open(ostr1, 'w+')
	ofile2 = open(ostr2, 'w+')
	source = np.genfromtxt(ifile, delimiter='\t', names=True, dtype=None)
	output1 = []
	output2 = []
	k = len(source)
	alphacorr = 1 - (1 - alpha)**(1/k)
	for row in source:
		if row[8] < alpha:
			output1.append(row)
			if row[8] < alphacorr:
				output2.append(row)
	for row in output1:
		ofile1.write('\t'.join([str(x) for x in row])+'\n')
	for row in output2:
		ofile2.write('\t'.join([str(x) for x in row])+'\n')
	ofile1.close()
	ofile2.close()
	ifile.close()