-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathregStats
More file actions
executable file
·141 lines (118 loc) · 4.3 KB
/
Copy pathregStats
File metadata and controls
executable file
·141 lines (118 loc) · 4.3 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/python
import sys
import networkx as nx
import numpy as np
from regtools.regnet import *
def getOptions():
import argparse
# create the top-level parser
description = ("Statistics on pangenome scale regulatory networks")
parser = argparse.ArgumentParser(description = description)
parser.add_argument('GML_FILE', action='store',
help='Pangenome regulatory network')
parser.add_argument('-A', '--average', action="store_true",
default=False,
dest='average',
help='Average values (with mean absolute deviation)')
return parser.parse_args()
options = getOptions()
infile = options.GML_FILE
n = nx.read_gml(infile)
# Grep the orgs in the net
orgs = set()
for x in n:
for o in n.node[x]['orgs'].split():
orgs.add(o)
norg = len(orgs)
# Inspect the proportion of conserved and variable regulatory links
regulators = filter(lambda x: n.node[x]['kind'] == 'regulator', n.nodes())
reglinks = filter(lambda x: n[x[0]][x[1]]['kind'] == 'regulated',
n.edges())
v = set()
unattended = set()
for a, b in reglinks:
#rorgs = reg.union(prom).union(gene)
r = RegLink(n.node[a]['label'], n.node[b]['label'], norg)
# Number of orgs in which the regulator, the promoter and the gene are present
reg = set(n.node[a]['orgs'].split())
prom = set(n[a][b]['orgs'].split())
gene = set(n.node[b]['orgs'].split())
# Sanity check: promoter cannot be a superset of genes, only a subset
if prom.issuperset(gene) and not prom.issubset(gene):
raise ValueError('Found a regulator edge with more orgs than the regulated gene (%s --> %s)'%(a, b))
# r/p/g
plugged = 0
# Plug length
pluglen = []
# r/ /g
unplugged = 0
# /p/g
ready = 0
# / /g
notready = 0
# r/ /
absent = 0
# / /
missing = 0
for o in orgs:
if o in reg and o in prom and o in gene:
plugged += 1
# It is plugged, we want to know also the plug-length
# That is the number of downstream genes
pluglen.append( getPlugLen(n, b, o) )
elif o in reg and o not in prom and o in gene:
unplugged += 1
elif o not in reg and o in prom and o in gene:
ready += 1
elif o not in reg and o not in prom and o in gene:
notready += 1
elif o in reg and o not in prom and o not in gene:
absent += 1
elif o not in reg and o not in prom and o not in gene:
missing += 1
else:
print('Unattended case (%s --> %s // %s - %s - %s)'%(a, b,
o in reg,
o in prom,
o in gene))
unattended.add( (o in reg,
o in prom,
o in gene) )
r.plugged = float(plugged)/r.norgs
if len(pluglen) != 0:
r.pluglen = np.array(pluglen).mean()
r.unplugged = float(unplugged)/r.norgs
r.ready = float(ready)/r.norgs
r.notready = float(notready)/r.norgs
r.absent = float(absent)/r.norgs
r.missing = float(missing)/r.norgs
v.add( r )
if not options.average:
b = True
for r in v:
if b:
print('#' + r.header)
b = False
print(str(r))
#if len(unattended) > 0:
# for u in unattended:
# print(u)
else:
print('\t'.join( ('# links', 'Plugged', 'Unplugged', 'Ready', 'Not ready',
'Absent', 'Missing', 'Plug length') ))
print('\t'.join( [str(x) for x in (len(reglinks),
getMean(v, 'plugged'),
getMean(v, 'unplugged'),
getMean(v, 'ready'),
getMean(v, 'notready'),
getMean(v, 'absent'),
getMean(v, 'missing'),
getMean(v, 'pluglen')) ]))
print('\t'.join( [str(x) for x in (len(reglinks),
getMad(v, 'plugged'),
getMad(v, 'unplugged'),
getMad(v, 'ready'),
getMad(v, 'notready'),
getMad(v, 'absent'),
getMad(v, 'missing'),
getMad(v, 'pluglen')) ]))