In [43]:
import sys, getopt, math
import itertools as itt
from scipy.stats.stats import pearsonr
x2reps = ['xa1', 'xa2', 'xb1', 'xb2', 'xc1', 'xc2', 'xd1', 'xd2']
y2reps = ['ya1', 'ya2', 'yb1', 'yb2', 'yc1', 'yc2', 'yd1', 'yd2']
x3reps = ['xa1', 'xa2', 'xa3', 'xb1', 'xb2', 'xb3', 'xc1', 'xc2', 'xc3', 'xd1', 'xd2', 'xd3']
y3reps = ['ya1', 'ya2', 'ya3', 'yb1', 'yb2', 'yb3', 'yc1', 'yc2', 'yc3', 'yd1', 'yd2', 'yd3']
x4reps = ['xa1', 'xa2', 'xa3', 'xa4', 'xb1', 'xb2', 'xb3', 'xb4', 'xc1', 'xc2', 'xc3', 'xc4', 'xd1', 'xd2', 'xd3', 'xd4']
y4reps = ['ya1', 'ya2', 'ya3', 'ya4', 'yb1', 'yb2', 'yb3', 'yb4', 'yc1', 'yc2', 'yc3', 'yc4', 'yd1', 'yd2', 'yd3', 'yd4']
x23reps = ['xa1', 'xa2', 'xb1', 'xb2', 'xc1', 'xc2', 'xc3', 'xd1', 'xd2', 'xd3']
y23reps = ['ya1', 'ya2', 'yb1', 'yb2', 'yc1', 'yc2', 'yc3', 'yd1', 'yd2', 'yd3']
In [61]:
def parse_replicates(data_in, replicates):
group_data= []
#data_in = [array of ungrouped replicate data]
start = 0
end = replicates[0]
for i in range(0,len(replicates)):
group_data.append(data_in[start:end])
start = end
if i == len(replicates)-1:
end = end + replicates[i]
else:
end = end + replicates[i+1]
return group_data
In [62]:
x2parse = parse_replicates(x2reps, [2,2,2,2])
y2parse = parse_replicates(y2reps, [2,2,2,2])
x3parse = parse_replicates(x3reps, [3,3,3,3])
y3parse = parse_replicates(y3reps, [3,3,3,3])
x4parse = parse_replicates(x4reps, [4,4,4,4])
y4parse = parse_replicates(y4reps, [4,4,4,4])
x23parse = parse_replicates(x23reps, [2,2,3,3])
y23parse = parse_replicates(y23reps, [2,2,3,3])
x23parse
Out[62]:
In [110]:
def get_comb(x_in, y_in, xreps, yreps):
assert len(xreps) == len(yreps)
xparse = parse_replicates(x_in, xreps)
yparse = parse_replicates(y_in, yreps)
xperm = [list(itt.permutations(x, len(x))) for x in xparse]
yperm = [list(itt.permutations(y, len(y))) for y in yparse]
within = [[zip(j,k) for j,k in list(itt.product(x,y))[0:]] for x,y in zip(xperm,yperm)]
groups = []
for group in within:
groups.append(group)
betweens = list(itt.product(*groups))
return betweens
In [70]:
x2perm = [list(itt.permutations(x, len(x))) for x in x2parse]
y2perm = [list(itt.permutations(y, len(y))) for y in y2parse]
x3perm = [list(itt.permutations(x, len(x))) for x in x3parse]
y3perm = [list(itt.permutations(y, len(y))) for y in y3parse]
x4perm = [list(itt.permutations(x, len(x))) for x in x4parse]
y4perm = [list(itt.permutations(y, len(y))) for y in y4parse]
x23perm = [list(itt.permutations(x, len(x))) for x in x23parse]
y23perm = [list(itt.permutations(y, len(y))) for y in y23parse]
print len(x2perm[0])
print len(x3perm[0])
print len(x4perm[0])
print len(x23perm[2])
x23perm
Out[70]:
In [67]:
zip2reps = zip(x2perm, y2perm)
zip23reps = zip(x3perm, y23perm)
zip23reps
Out[67]:
In [36]:
product2reps = list(itt.product(x2reps, y2reps))
product2perms = list(itt.product(x2perm, y2perm))
print len(x2reps)
print len(product2reps)
print len(product2perms)
print product2reps
print product2perms
In [82]:
[[zip(j,k) for j,k in list(itt.product(x,y))[0:((len(x)+len(y))/2)]] for x,y in zip(x2perm,y2perm)]
Out[82]:
In [81]:
#[itt.product(x,y) for x,y in x2zip]
[[zip(j,k) for j,k in list(itt.product(x,y))[0:((len(x)+len(y))/2)]] for x,y in zip(x3perm,y23perm)]
Out[81]:
In [ ]:
comb2 = get_comb(x2reps, y2reps, [2,2,2,2], [2,2,2,2])
comb3 = get_comb(x3reps, y3reps, [3,3,3,3], [3,3,3,3])
comb4 = get_comb(x4reps, y4reps, [4,4,4,4], [4,4,4,4])
comb23 = get_comb(x23reps, y23reps, [2,2,3,3], [2,2,3,3])
comb323 = get_comb(x3reps, y23reps, [3,3,3,3], [2,2,3,3])
comb2
In [111]:
len(get_comb(x2reps, y2reps, [2,2,2,2], [2,2,2,2]))
Out[111]:
In [ ]: