forked from combogenomics/regtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
combineDists
executable file
·62 lines (48 loc) · 1.59 KB
/
combineDists
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import sys
import numpy as np
from scipy import stats
def getOptions():
import argparse
# create the top-level parser
description = ("Takes a bunch of distance matrices and outputs the average")
parser = argparse.ArgumentParser(description = description)
parser.add_argument('DIST_FILE', action='store', nargs='+',
help='Distant matrices')
parser.add_argument('-E', '--error', action="store_true",
default=False,
dest='error',
help='Compute the standard error of the values')
return parser.parse_args()
options = getOptions()
files = options.DIST_FILE
def readDist(infile):
b = True
d = {}
for l in open(infile):
s = l.rstrip().split('\t')
if b:
orgs = s[1:]
b = False
continue
o = s[0]
values = s[1:]
d[o] = d.get(o, {})
for x in orgs:
d[o][x] = float( values[orgs.index(x)] )
return d
d = {}
for f in files:
t = readDist(f)
for o in t:
d[o] = d.get(o, {})
for o1 in t[o]:
d[o][o1] = d[o].get(o1, [])
d[o][o1].append(t[o][o1])
orgs = set(d.keys())
print '\t'.join( [''] + sorted(orgs) )
for o in sorted(orgs):
if options.error:
print('\t'.join( [o] + [str(round(stats.sem(np.array(d[o][o1])),5)) if o1 in d[o] else '0' for o1 in sorted(orgs)] ))
else:
print('\t'.join( [o] + [str(round(np.array(d[o][o1]).mean(),5)) if o1 in d[o] else '0' for o1 in sorted(orgs)] ))