import sys
dfh=open(sys.argv[1],'r')
rfh=open(sys.argv[1]+'_30CpG_ANOVA_DMR.txt','w')
rfh.write(dfh.readline().rstrip()+'\t'+'_ANOVA_pvalue\n')
import scipy.stats as stats
indices=[]
temp_datas=[]
for i in range(0,14):
	temp_datas.append([])
for i in dfh:
	line=i.split()
	index=line[0]
	if 'NA' not in i:
		data=map(lambda x:float(x.split('(')[0]),line[1:])
		map(lambda x,y:x.append(y),temp_datas,data)
		indices.append(index)
		if len(indices)==30 and int(indices[-1].split('_')[0])-int(indices[0].split('_')[0])<1000000:
			anova=stats.f_oneway(temp_datas[0],temp_datas[1],temp_datas[2],temp_datas[3],temp_datas[4],temp_datas[5],temp_datas[6],temp_datas[7],temp_datas[8],temp_datas[9],temp_datas[10],temp_datas[11],temp_datas[12],temp_datas[13])
			scores=map(lambda x:str(sum(x)/len(x)),temp_datas)
			rfh.write(indices[0]+'&'+indices[-1]+'\t'+'\t'.join(map(lambda x:str(sum(x)/len(x)),temp_datas))+'\t'+str(anova[1])+'\n')
		if len(indices)==30:
			del indices[0]
			for i in range(0,14):
				temp_datas[i]=temp_datas[i][1:]
