-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels_add.py
More file actions
executable file
·265 lines (203 loc) · 8.88 KB
/
models_add.py
File metadata and controls
executable file
·265 lines (203 loc) · 8.88 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/env python
import logging
from os.path import splitext
import numpy as np
from semnet.writer import createOutput
from semnet import utils
################################################################################
# Add genes to the network
################################################################################
# Add genes downstream of nodes
def add_genes_ds_beta(path, newgene, args):
""" Iterate through beta matrix and place new genes downstream of each beta. """
# Initialize default values
path.reinit()
# Expand gamma and beta to account for new isoforms
for iso in range(0, newgene.count):
path.expand_beta()
path.expand_gamma()
# Make copy of oiriginal for iterating
_yvar = list(path.yvar)
# Append new gene to yvar
path.yvar.append(newgene.name)
# Iterate through BETA matrix and output all possible models
index = 0
for gene in _yvar:
# How many isoforms does the current gene have
isoCnt = utils.isoCount(gene)
# Create slice index of bottom 'newgene.count' rows of beta and
# alterating columns of beta
bSlice = np.s_[-newgene.count:, index:index+isoCnt]
model_type = "Adding Genes Downstream of Beta:\n {0} -> {1}".format(gene, newgene.name)
path.beta[bSlice] = 1
createOutput(path, model_type, args)
path.beta[bSlice] = 0
path.count_increment()
index += isoCnt
def add_genes_ds_gamma(path, newgene, args):
""" Iterate through gamma matrix and place new genes downstream of each gamma. """
# Initialize default values
path.reinit()
# Expand gamma and beta to account for new isoforms
for iso in range(0, newgene.count):
path.expand_beta()
path.expand_gamma()
# Append new gene to yvar
path.yvar.append(newgene.name)
# Iterate through GAMMA matrix and output all possible models
index = 0
for gene in path.xvar:
# How many isoforms does the current gene have
isoCnt = utils.isoCount(gene)
# Create slice index of bottom 'newgene.count' rows of gamma and
# alternating columns of gamma
gSlice = np.s_[-newgene.count:, index:index+isoCnt]
model_type = "Adding Genes Downstream of Gamma:\n {0} -> {1}".format(gene, newgene.name)
path.gamma[gSlice] = 1
createOutput(path, model_type, args)
path.gamma[gSlice] = 0
path.count_increment()
index += isoCnt
# Add genes upstream of nodes
def add_genes_above_beta(path, newgene, args):
""" Iterate through gamma matrix and place new genes upstream of betas. """
# Initialize default values
path.reinit()
# Expand matrices GAMMA and PHI matrices
for iso in range(0, newgene.count):
path.expand_gamma(axis=1) # Add column not row
path.expand_phi()
# Append new gene to yvar
path.xvar.append(newgene.name)
index = 0
for gene in path.yvar:
# How many isoforms does the current gene have
isoCnt = utils.isoCount(gene)
# Create slice index of right most 'newgene.count' columns of gamma and
# alterating rows of gamma
gSlice = np.s_[index:index+isoCnt, -newgene.count:]
model_type = "Adding Genes Upstream of beta:\n {1} -> {0}".format(gene, newgene.name)
path.gamma[gSlice] = 1
createOutput(path, model_type, args)
path.gamma[gSlice] = 0
path.count_increment()
index += isoCnt
def add_genes_above_gamma(path, newgene, args):
""" Iterate through gamma matrix and place new genes upstream of gammas. """
# Initialize default values
path.reinit()
# Make copy of oiriginal for iterating
_xvar = list(path.xvar)
for gene in _xvar:
# How many isoforms does the current gene have
isoCnt = utils.isoCount(gene)
# Convert the current exogenous gene to an enogenous gene
path.convert_ExogToEndog(gene)
# Append new gene to xvar
path.xvar.append(newgene.name)
# Expand gamma and phi matrices for my new gene
for iso in range(0, newgene.count):
path.expand_gamma(axis=1) # Add column not row
path.expand_phi()
# Create slice index of right most 'newgene.count' columns of gamma and
# the bottom 'isoCnt' rows of gamma.
gSlice = np.s_[-isoCnt:, -newgene.count:]
model_type = "Adding Genes Upstream of Gamma:\n {1} -> {0}".format(gene, newgene.name)
path.gamma[gSlice] = 1
createOutput(path, model_type, args)
path.count_increment()
# Reset I need to move different exogenous genes
path.reinit()
# Add genes between connected nodes
def add_genes_bt_beta(path, newgene, args):
""" Iterate through beta matrix and add genes between two betas. """
# Initialize default values again
path.reinit()
# Expand gamma and beta to account for new isoforms
for iso in range(0, newgene.count):
path.expand_beta()
path.expand_gamma()
# Make copy of oiriginal for iterating
_yvar = list(path.yvar)
# Append new gene to yvar
path.yvar.append(newgene.name)
# Iterate through BETA matrix and add genes between betas
cIndex = 0
for col in _yvar:
# How many isoforms does the current column have
colCnt = utils.isoCount(col)
rIndex = 0
for row in _yvar:
# A gene cannot act on itself, so skip when row=col
if col == row:
continue
# How many isoforms does the current row have
rowCnt = utils.isoCount(row)
# Zero slice, is the current location in Beta, if there are 1s
# there I will turn them 0
zSlice = np.s_[rIndex:rIndex+rowCnt, cIndex:cIndex+colCnt]
# Target slice, is the bottom 'newgene.count' rows, that will get turned 1
# showing that current 'col' is acting on the newgene
tSlice = np.s_[-newgene.count:, cIndex:cIndex+colCnt]
# Source slice, is the right most 'newgene.count' cols, that will get turned 1
# showing that newgene is acting on the current row
sSlice = np.s_[rIndex:rIndex+rowCnt, -newgene.count:]
# If there was a previous interaction (i.e. 1) then make models
if np.all(path.beta[zSlice]):
model_type = "Adding Genes Between Betas:\n {0} -> {2} -> {1}".format(col, row, newgene.name)
path.beta[zSlice] = 0
path.beta[tSlice] = 1
path.beta[sSlice] = 1
createOutput(path, model_type, args)
path.beta[zSlice] = 1
path.beta[tSlice] = 0
path.beta[sSlice] = 0
path.count_increment()
rIndex += rowCnt
cIndex += colCnt
def add_genes_bt_gamma_beta(path, newgene, args):
""" Iterate through gamma matrix and place new genes between gamma and ds beta. """
# Initialize default values again
path.reinit()
# Expand gamma and beta to account for new isoforms
for iso in range(0, newgene.count):
path.expand_beta()
path.expand_gamma()
# Make copy of oiriginal for iterating
_yvar = list(path.yvar)
# Add newGene to yvar because they are new endogenous genes
path.yvar.append(newgene.name)
# Iterate through each row of GAMMA matrix and place new gene in between
# gamma and beta
cIndex = 0
for col in path.xvar:
# How many isoforms does the current column have
colCnt = utils.isoCount(col)
rIndex = 0
for row in _yvar:
# How many isoforms does the current row have
rowCnt = utils.isoCount(row)
# Zero slice, is the current location in Gamma, if there are 1s
# there I will turn them 0
zSlice = np.s_[rIndex:rIndex+rowCnt, cIndex:cIndex+colCnt]
# Target slice, is the bottom 'newgene.count' rows in GAMMA, that
# will get turned 1 showing that current 'col' is acting on the
# newgene
tSlice = np.s_[-newgene.count:, cIndex:cIndex+colCnt]
# Source slice, is the right most 'newgene.count' cols in BETA,
# that will get turned 1 showing that newgene is acting on the
# current row
sSlice = np.s_[rIndex:rIndex+rowCnt, -newgene.count:]
# If there was a previous interaction (i.e. 1) then make models
if np.all(path.gamma[zSlice]):
model_type = "Adding Genes Between Gamma and Beta:\n {0} -> {2} -> {1}".format(col, row, newgene.name)
path.gamma[zSlice] = 0
path.gamma[tSlice] = 1
path.beta[sSlice] = 1
createOutput(path, model_type, args)
path.gamma[zSlice] = 1
path.gamma[tSlice] = 0
path.beta[sSlice] = 0
path.count_increment()
rIndex += rowCnt
cIndex += colCnt