import numpy as np
from decimal import *
from scipy.stats.stats import pearsonr
ifile = open('/home/scottn/sixmercounts.csv')
counts = np.genfromtxt(ifile, delimiter=',', dtype=np.int64, names=None)
mfile = open('/home/scottn/runwithgemma/mouse.pheno')
phen = np.genfromtxt(mfile, delimiter=',', dtype=None, names=None)
phenotype = []
for x in phen:
	phenotype.append(x[1])
sfile = open('/home/scottn/sixmerlist.csv')
sixes = np.genfromtxt(sfile, delimiter=',', dtype=None, names=None)
sixmers = []
for x in sixes:
	sixmers.append(x[0])
print('All files parsed')
#output = [['sixmer','correl','pval']]
output = []
n = len(counts)
#n = 50
for i in range(0, n):
	(c, p) = pearsonr(list(counts[i]), phenotype)
	output.append([sixmers[i], c, p])
ofile = open('/home/scottn/pearsoncorrelmotifcount.csv', 'w+')
for row in output:
	ofile.write(','.join([str(x) for x in row])+'\n')
ofile.close()
ifile.close()
mfile.close()
sfile.close()
