-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels_newlink.py
More file actions
executable file
·132 lines (105 loc) · 5.16 KB
/
models_newlink.py
File metadata and controls
executable file
·132 lines (105 loc) · 5.16 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
#!/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 additional links to existing genes in the network
################################################################################
def add_newlinks_beta_to_beta(path, args):
""" function to add new links to above all of the betas """
# Initialize default values
path.reinit()
# Iterate overall of the endogenous variables (cols of beta)
for index, gene in enumerate(path.yvar):
# Determine if gene has multiple isoforms
isoCnt = utils.isoCount(gene)
# Iterate over the the endogenous varaibles (rows of beta) and add link
# one at a time.
for row, target in enumerate(path.yvar):
# A gene cannot regulate itself in SEMs
if row != index:
# Determine if gene has multiple isoforms
tCnt = utils.isoCount(target)
# Skip when one gene is already regulating the other
if path.beta[row, index] == 0 and path.beta[index, row] == 0:
model_type = "Adding Newlinks Beta to Beta:\n {0} -> {1}".format(gene, target)
path.beta[row:row+tCnt, index:index+isoCnt] = 1
createOutput(path, model_type, args)
path.beta[row:row+tCnt, index:index+isoCnt] = 0
path.count_increment()
def add_newlinks_gamma_to_beta(path, args):
""" function to add new links to above all of the betas """
# Initialize default values
path.reinit()
# Iterate overall of the exogenous variables
for index, gene in enumerate(path.xvar):
# Determine if gene has multiple isoforms
isoCnt = utils.isoCount(gene)
# Iterate over the rows of gamma and add link one at a time. In other words,
# add new links to each of the endogenous variables.
for row, target in enumerate(path.yvar):
# Determine if gene has multiple isoforms
tCnt = utils.isoCount(target)
if path.gamma[row, index] == 0:
model_type = "Adding Newlinks Gamma to Beta:\n {0} -> {1}".format(gene, target)
path.gamma[row:row+tCnt, index:index+isoCnt] = 1
createOutput(path, model_type, args)
path.gamma[row:row+tCnt, index:index+isoCnt] = 0
path.count_increment()
def add_newlinks_beta_to_gamma(path, args):
""" function to add new links to above all of the betas """
# Initialize default values
path.reinit()
# make a copy of the yvar and xvar for iteration, because I am going to be
# messing with both lists
_yvar = list(path.yvar)
_xvar = list(path.xvar)
# Iterate over all exogenous variables (cols of gamma), turn them into an
# endogenous variable 1 at a time and then add all betas
for col, target in enumerate(_xvar):
# Determine if gene has multiple isoforms
tCnt = utils.isoCount(target)
# Convert exogenous varaible to an endogenous variable
path.convert_ExogToEndog(target)
# Now iterate over all endogenous variables (cols of beta)
for index, gene in enumerate(_yvar):
# Determine if gene has multiple isoforms
isoCnt = utils.isoCount(gene)
# Skip when one gene is already regulating the other
if path.beta[index, -1] == 0:
model_type = "Adding Newlinks Beta to Gamma :\n {0} -> {1}".format(gene, target)
path.beta[-tCnt:, index:index+isoCnt] = 1
createOutput(path, model_type, args)
path.beta[-tCnt:, index:index+isoCnt] = 0
path.count_increment()
# Initialize default values
path.reinit()
def add_newlinks_gamma_to_gamma(path, args):
""" function to add new links to above all of the betas """
# Initialize default values
path.reinit()
# make a copy of the yvar and xvar for iteration, because I am going to be
# messing with both lists
_xvar = list(path.xvar)
# Iterate over all exogenous variables (cols of gamma), turn them into an
# endogenous variable 1 at a time and then add all betas
for col, target in enumerate(_xvar):
# Determine if gene has multiple isoforms
tCnt = utils.isoCount(target)
# Convert exogenous varaible to an endogenous variable
path.convert_ExogToEndog(target)
# Now iterate over the new endogenous variable list (cols of gamma) and
# add links 1 at a time to gamma
for index, gene in enumerate(path.xvar):
model_type = "Adding Newlinks Gamma to Gamma :\n {0} -> {1}".format(gene, target)
# Determine if gene has multiple isoforms
isoCnt = utils.isoCount(gene)
# Skip when one gene is already regulating the other
path.gamma[-tCnt:, index:index+isoCnt] = 1
createOutput(path, model_type, args)
path.gamma[-tCnt:, index:index+isoCnt] = 0
path.count_increment()
# Initialize default values
path.reinit()