maboss 0.8.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
maboss/__init__.py ADDED
@@ -0,0 +1,25 @@
1
+ from .network import *
2
+ from .simulation import *
3
+ from .result import *
4
+ from .results import *
5
+ from .gsparser import load, loadBNet, loadSBML
6
+ from .server import MaBoSSClient
7
+ from .upp import UpdatePopulation
8
+ from .ensemble import EnsembleResult, Ensemble
9
+ import maboss.pipelines
10
+ from colomoto_jupyter import IN_IPYTHON
11
+ import colomoto.setup_helper
12
+ if IN_IPYTHON:
13
+ from colomoto_jupyter import jupyter_setup
14
+ from .widgets import *
15
+
16
+ import matplotlib.pyplot as plt
17
+ plt.ion()
18
+
19
+ jupyter_setup("mymodule",
20
+ label="MaBoSS",
21
+ color="green", # for menu and toolbar
22
+ menu=menu,
23
+ toolbar=toolbar,
24
+ js_api=js_api)
25
+
@@ -0,0 +1,70 @@
1
+ """
2
+ Class that contains the cMaBoSS simulation.
3
+ """
4
+ from .sbmlcmabossresult import SBMLCMaBoSSResult
5
+ from sys import stdout
6
+ class BNetSimulation(object):
7
+
8
+ def __init__(self, bnet, cfgs=None):
9
+
10
+ self.bnet = bnet
11
+ self.cfgs = cfgs
12
+
13
+ self.nb_nodes = self.count_nodes()
14
+ self.cmaboss = self.get_cmaboss()
15
+
16
+ if self.cfgs is None:
17
+ self.cmaboss_sim = self.cmaboss.MaBoSSSim(self.bnet)
18
+ else:
19
+ self.cmaboss_sim = self.cmaboss.MaBoSSSim(self.bnet, self.cfgs)
20
+
21
+ def count_nodes(self):
22
+
23
+ res = 0
24
+ with open(self.bnet, 'r') as f:
25
+ lines = f.readlines()
26
+ for line in lines:
27
+ if len(line) > 0 and "," in line and line.split(',')[0].strip() != "targets":
28
+ res += 1
29
+ return res
30
+
31
+ def print_bnd(self, out=stdout):
32
+ """Produce the content of the bnd file associated to the simulation."""
33
+ print(self.cmaboss_sim.str_bnd(), file=out)
34
+
35
+ def print_cfg(self, out=stdout):
36
+ """Produce the content of the cfg file associated to the simulation."""
37
+ print(self.cmaboss_sim.str_cfg(), file=out)
38
+
39
+ def get_cmaboss(self):
40
+
41
+ assert self.nb_nodes <= 1024, "Models with more than 1024 nodes are not compatible with this version of MaBoSS"
42
+
43
+ if self.nb_nodes <= 64:
44
+ return __import__("cmaboss")
45
+ elif self.nb_nodes <= 128:
46
+ return __import__("cmaboss_128n")
47
+ elif self.nb_nodes <= 256:
48
+ return __import__("cmaboss_256n")
49
+ elif self.nb_nodes <= 512:
50
+ return __import__("cmaboss_512n")
51
+ else:
52
+ return __import__("cmaboss_1024n")
53
+
54
+ def get_logical_rules(self):
55
+
56
+ out = self.cmaboss_sim.get_logical_rules()
57
+ rules = {}
58
+ for line in out.split("\n"):
59
+ if ":" in line:
60
+ node, rule = line.split(" : ", 1)
61
+ rules.update({node.strip(): rule.strip()})
62
+
63
+ return rules
64
+
65
+
66
+ def run(self, only_final_state=False):
67
+ return SBMLCMaBoSSResult(self, only_final_state)
68
+
69
+
70
+ __all__ = ["BNetSimulation"]
@@ -0,0 +1,103 @@
1
+ """
2
+ Class that contains the results of a MaBoSS simulation.
3
+ """
4
+
5
+ import pandas
6
+ import tempfile
7
+ import os
8
+ from .results.baseresult import BaseResult
9
+ from contextlib import ExitStack
10
+
11
+ class CMaBoSSResult(BaseResult):
12
+
13
+ def __init__(self, simul, workdir=None, overwrite=False, prefix="res", only_final_state=False):
14
+
15
+ self.simul = simul
16
+ self.output_nodes = simul.network.get_output()
17
+ self.only_final_state = only_final_state
18
+ BaseResult.__init__(self, simul, output_nodes=self.output_nodes)
19
+
20
+ cmaboss_module = simul.get_cmaboss()
21
+ cmaboss_sim = cmaboss_module.MaBoSSSim(
22
+ network_str=str(simul.network),
23
+ config_str=simul.str_cfg()
24
+ )
25
+
26
+ self.cmaboss_result = cmaboss_sim.run(self.only_final_state)
27
+
28
+ if workdir is not None:
29
+ if not os.path.exists(workdir):
30
+ os.makedirs(workdir)
31
+
32
+ self.cmaboss_result.display_run(os.path.join(workdir, "%s_run.txt" % prefix))
33
+
34
+ if self.only_final_state:
35
+ self.cmaboss_result.display_final_states(os.path.join(workdir, "%s_finalprob.csv" % prefix))
36
+ else:
37
+ self.cmaboss_result.display_probtraj(os.path.join(workdir, "%s_probtraj.csv" % prefix))
38
+ self.cmaboss_result.display_fp(os.path.join(workdir, "%s_fp.csv" % prefix))
39
+ self.cmaboss_result.display_statdist(os.path.join(workdir, "%s_statdist.csv" % prefix))
40
+
41
+
42
+
43
+ def get_last_states_probtraj(self):
44
+
45
+ raw_res = self.cmaboss_result.get_last_probtraj()
46
+ df = pandas.DataFrame(*raw_res)
47
+ return df
48
+
49
+ def get_states_probtraj(self, prob_cutoff=None):
50
+ if not self.only_final_state:
51
+
52
+ raw_res = self.cmaboss_result.get_probtraj()
53
+ df = pandas.DataFrame(*raw_res)
54
+ df.sort_index(axis=1, inplace=True)
55
+
56
+ if prob_cutoff is not None:
57
+ maxs = df.max(axis=0)
58
+ return df[maxs[maxs>prob_cutoff].index]
59
+
60
+ return df
61
+
62
+ def get_nodes_probtraj(self, nodes=None, prob_cutoff=None):
63
+ if not self.only_final_state:
64
+ raw_res = self.cmaboss_result.get_nodes_probtraj(nodes)
65
+ df = pandas.DataFrame(*raw_res)
66
+ df.sort_index(axis=1, inplace=True)
67
+
68
+ if prob_cutoff is not None:
69
+ maxs = df.max(axis=0)
70
+ return df[maxs[maxs>prob_cutoff].index]
71
+
72
+ return df
73
+
74
+ def get_last_nodes_probtraj(self, nodes=None):
75
+ raw_res = self.cmaboss_result.get_last_nodes_probtraj(nodes)
76
+ df = pandas.DataFrame(*raw_res)
77
+ df.sort_index(axis=0, inplace=True)
78
+
79
+ return df
80
+
81
+
82
+
83
+ def get_fptable(self):
84
+ if not self.only_final_state:
85
+ raw_res = self.cmaboss_result.get_fp_table()
86
+
87
+ df = pandas.DataFrame(["#%d" % fp for fp in sorted(raw_res.keys())], columns=["FP"])
88
+
89
+ df["Proba"] = [raw_res[fp][0] for fp in sorted(raw_res.keys())]
90
+ df["State"] = [raw_res[fp][1] for fp in sorted(raw_res.keys())]
91
+
92
+ raw_nodes = []
93
+ for node in self.simul.network.keys():
94
+ # df[node] = [1 if node in raw_res[fp][1].split(" -- ") else 0 for fp in sorted(raw_res.keys())]
95
+ raw_nodes.append([1 if node in raw_res[fp][1].split(" -- ") else 0 for fp in sorted(raw_res.keys())])
96
+
97
+ t_df = pandas.DataFrame(raw_nodes, index=list(self.simul.network.keys())).transpose()
98
+
99
+ return pandas.concat([df, t_df], axis=1)
100
+ # return df
101
+
102
+
103
+ __all__ = ["CMaBoSSResult"]
@@ -0,0 +1,90 @@
1
+ """
2
+ Class that contains the results of a MaBoSS simulation.
3
+ """
4
+
5
+ import pandas
6
+ import tempfile
7
+ import os
8
+ from .results.baseresult import BaseResult
9
+ from contextlib import ExitStack
10
+ from time import time
11
+ class CMaBoSSResult2(BaseResult):
12
+
13
+ def __init__(self, sim, workdir=None, only_final_state=False):
14
+
15
+ BaseResult.__init__(self, "some_path")
16
+ self.cmaboss_simulation = sim.cmaboss.MaBoSSSim(net=sim.cmaboss_net, cfg=sim.cmaboss_cfg)
17
+ self.cmaboss_result = self.cmaboss_simulation.run(only_last_state=only_final_state)
18
+
19
+ self.workdir = workdir
20
+ self.only_final_state = only_final_state
21
+
22
+ if workdir is not None:
23
+ if not os.path.exists(workdir):
24
+ os.makedirs(workdir)
25
+
26
+ self.cmaboss_result.display_run(os.path.join(workdir, "%s_run.txt" % prefix))
27
+
28
+ if self.only_final_state:
29
+ self.cmaboss_result.display_final_states(os.path.join(workdir, "%s_finalprob.csv" % prefix))
30
+ else:
31
+ self.cmaboss_result.display_probtraj(os.path.join(workdir, "%s_probtraj.csv" % prefix))
32
+ self.cmaboss_result.display_fp(os.path.join(workdir, "%s_fp.csv" % prefix))
33
+ self.cmaboss_result.display_statdist(os.path.join(workdir, "%s_statdist.csv" % prefix))
34
+
35
+
36
+ def get_last_states_probtraj(self):
37
+
38
+ raw_res = self.cmaboss_result.get_last_probtraj()
39
+ df = pandas.DataFrame(*raw_res)
40
+ return df
41
+
42
+ def get_states_probtraj(self, prob_cutoff=None):
43
+ if not self.only_final_state:
44
+
45
+ raw_res = self.cmaboss_result.get_probtraj()
46
+ df = pandas.DataFrame(*raw_res)
47
+ df.sort_index(axis=1, inplace=True)
48
+
49
+ if prob_cutoff is not None:
50
+ maxs = df.max(axis=0)
51
+ return df[maxs[maxs>prob_cutoff].index]
52
+
53
+ return df
54
+
55
+ def get_nodes_probtraj(self, prob_cutoff=None):
56
+ if not self.only_final_state:
57
+ raw_res = self.cmaboss_result.get_nodes_probtraj()
58
+ df = pandas.DataFrame(*raw_res)
59
+ df.sort_index(axis=1, inplace=True)
60
+
61
+ if prob_cutoff is not None:
62
+ maxs = df.max(axis=0)
63
+ return df[maxs[maxs>prob_cutoff].index]
64
+
65
+ return df
66
+
67
+ def get_last_nodes_probtraj(self):
68
+ raw_res = self.cmaboss_result.get_last_nodes_probtraj()
69
+ df = pandas.DataFrame(*raw_res)
70
+ df.sort_index(axis=0, inplace=True)
71
+
72
+ return df
73
+
74
+
75
+ def get_fptable(self):
76
+ if not self.only_final_state:
77
+ raw_res = self.cmaboss_result.get_fp_table()
78
+
79
+ df = pandas.DataFrame(["#%d" % fp for fp in sorted(raw_res.keys())], columns=["FP"])
80
+
81
+ df["Proba"] = [raw_res[fp][0] for fp in sorted(raw_res.keys())]
82
+ df["State"] = [raw_res[fp][1] for fp in sorted(raw_res.keys())]
83
+
84
+ for node in self.simul.network.keys():
85
+ df[node] = [1 if node in raw_res[fp][1].split(" -- ") else 0 for fp in sorted(raw_res.keys())]
86
+
87
+ return df
88
+
89
+
90
+ __all__ = ["CMaBoSSResult2"]
@@ -0,0 +1,53 @@
1
+ """
2
+ Class that contains the cMaBoSS simulation.
3
+ """
4
+ from .cmabossresult2 import CMaBoSSResult2
5
+
6
+ class CMaBoSSSimulation(object):
7
+
8
+ def __init__(self, bnd, cfgs):
9
+
10
+ self.bnd = bnd
11
+ self.cfgs = cfgs
12
+
13
+ self.nb_nodes = self.count_nodes()
14
+ self.cmaboss = self.get_cmaboss()
15
+
16
+ self.cmaboss_net = self.cmaboss.MaBoSSNet(self.bnd)
17
+ self.cmaboss_cfg = self.cmaboss.MaBoSSCfg(self.cmaboss_net, self.cfgs)
18
+ self.param = {'max_time': self.cmaboss_cfg.getMaxTime()}
19
+ self.network = {node: None for node in self.cmaboss_net.getListNodes()}
20
+
21
+ def count_nodes(self):
22
+
23
+ res = 0
24
+ with open(self.bnd, 'r') as f:
25
+ lines = f.readlines()
26
+ for line in lines:
27
+ if line.lower().startswith("node"):
28
+ res += 1
29
+ return res
30
+
31
+
32
+ def get_cmaboss(self):
33
+
34
+ assert self.nb_nodes <= 1024, "Models with more than 1024 nodes are not compatible with this version of MaBoSS"
35
+
36
+ if self.nb_nodes <= 64:
37
+ return __import__("cmaboss")
38
+ elif self.nb_nodes <= 128:
39
+ return __import__("cmaboss_128n")
40
+ elif self.nb_nodes <= 256:
41
+ return __import__("cmaboss_256n")
42
+ elif self.nb_nodes <= 512:
43
+ return __import__("cmaboss_512n")
44
+ else:
45
+ return __import__("cmaboss_1024n")
46
+
47
+ def run(self, workdir=None, only_final_state=False):
48
+ return CMaBoSSResult2(self, workdir, only_final_state)
49
+
50
+ def check(self):
51
+ return self.cmaboss.MaBoSSSim(net=self.cmaboss_net, cfg=self.cmaboss_cfg)
52
+
53
+ __all__ = ["CMaBoSSSimulation"]
@@ -0,0 +1,2 @@
1
+ from .result import EnsembleResult
2
+ from .ensemble import Ensemble