Mercurial > repos > laurenmarazzi > netisce_test
comparison tools/myTools/bin/SFA_exp_attr.py @ 1:7e5c71b2e71f draft default tip
Uploaded
author | laurenmarazzi |
---|---|
date | Wed, 22 Dec 2021 16:00:34 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:f24d4892aaed | 1:7e5c71b2e71f |
---|---|
1 #!/usr/bin/env python3 | |
2 # ----------------------------------------------------------- | |
3 # SimulateAttractors.py | |
4 ## estimate experimental attractors | |
5 ## calculate the median of the resistant and vehicle attractors | |
6 #----------------------------------------------------------- | |
7 | |
8 | |
9 import os | |
10 import numpy as np | |
11 import pandas as pd | |
12 import networkx as nx | |
13 import random | |
14 import sfa | |
15 import csv | |
16 import sys | |
17 ########INPUTS############ | |
18 | |
19 fpath = os.path.join(sys.argv[1]) #location of networkfile | |
20 | |
21 samples=pd.read_csv(sys.argv[2],index_col = 0) ##expression values for data | |
22 | |
23 class ThreeNodeCascade(sfa.base.Data): | |
24 def __init__(self): | |
25 super().__init__() | |
26 self._abbr = "TNC" | |
27 self._name = "A simple three node cascade" | |
28 | |
29 signs = {'activates':1, 'inhibits':-1} | |
30 A, n2i, dg = sfa.read_sif(fpath, signs=signs, as_nx=True) | |
31 self._A = A | |
32 self._n2i = n2i | |
33 self._dg = dg | |
34 self._i2n = {idx: name for name, idx in n2i.items()} | |
35 | |
36 # end of def __init__ | |
37 # end of def class | |
38 | |
39 if __name__ == "__main__": | |
40 ## initalize parameters from SFA | |
41 data = ThreeNodeCascade() | |
42 algs = sfa.AlgorithmSet() | |
43 alg = algs.create('SP') | |
44 alg.data = data | |
45 alg.params.apply_weight_norm = True | |
46 alg.initialize() | |
47 alg.params.exsol_forbidden=True | |
48 alg.params.alpha=.9 | |
49 | |
50 netnodes= list(data.dg.nodes) #get network node names | |
51 samples=samples.loc[list(set(netnodes) & set(samples.index))] | |
52 n = data.dg.number_of_nodes() #the number of nodes | |
53 b = np.zeros((n,)) | |
54 | |
55 | |
56 | |
57 logss=pd.DataFrame(index=samples.columns,columns=netnodes,copy=True) | |
58 pi=[] | |
59 for name, item in samples.iteritems(): #for each experimental sample | |
60 enodes=item.index.tolist() | |
61 for node in enodes: # set initial state to sample norm exp value | |
62 b[data.n2i[node]]=float(str(item.loc[node])) | |
63 | |
64 x = alg.compute(b,pi) #Run SFA calculation | |
65 logss.loc[name,netnodes]=x[0] | |
66 logss=logss.astype(float).round(3) | |
67 #write out nondisc tables | |
68 logss.to_csv('attrs_exp.tsv', sep=' ',float_format='%.3f',index_label="name",chunksize=10000) |