@@ -34,8 +34,8 @@ def baseline(signatures, phenotype, is_binary=False):
34
34
PC [PC < 0 ] = - 1
35
35
SC [pd .isnull (SC )] = 0
36
36
PC [pd .isnull (PC )] = 0
37
- C = SC .join (PC , how = "inner" )
38
- cosscores = pairwise_distances (C [signatures .columns ].T ,C [phenotype .columns ].T , metric = "cosine" )
37
+ C = SC .join (PC , how = "outer" ). fillna ( 0 )
38
+ cosscores = 1 - pairwise_distances (C [signatures .columns ].T ,C [phenotype .columns ].T , metric = "cosine" )
39
39
baseline_df = pd .DataFrame (cosscores , columns = ["Cosine Score" ], index = signatures .columns )
40
40
return baseline_df
41
41
@@ -94,13 +94,13 @@ def compute_metrics(rewards, ground_truth, K=[2,5,10], use_negative_class=False,
94
94
## DRUG SIMULATOR ##
95
95
######################
96
96
97
- def simulate (network_fname , targets , phenotypes , simu_params = {}, nbseed = 0 , quiet = False ):
97
+ def simulate (network_fname , targets , patients , score , simu_params = {}, nbseed = 0 , quiet = False ):
98
98
'''
99
99
Simulate and score the individual effects of drugs on patient phenotypes, compared to controls
100
100
@param\t network_fname\t Python character string: (relative) path to a network .BNET file
101
101
@param\t targets\t Pandas DataFrame: rows/[genes] x columns/[drugs to test] (either 1: active expression, -1: inactive expression, 0: undetermined expression)
102
- @param\t phenotypes \t Pandas DataFrame: rows/[genes+annotation patient/control ] x columns/[samples] (either 1: activatory, -1: inhibitory, 0: no regulation).
103
- The last line "annotation" is 1 (healthy sample) or 2 (patient sample).
102
+ @param\t patients \t Pandas DataFrame: rows/[genes] x columns/[samples] (either 1: activatory, -1: inhibitory, 0: no regulation).
103
+ @param \t score \t Python object: scoring of attractors
104
104
@param\t simu_params\t Python dictionary[default={}]: arguments to MPBN-SIM
105
105
@param\t nbseed\t Python integer[default=0]
106
106
@param\t quiet\t Python bool[default=False]
@@ -122,7 +122,7 @@ def simulate(network_fname, targets, phenotypes, simu_params={}, nbseed=0, quiet
122
122
dfdata = phenotypes .loc [list (set ([g for g in genes if (g in phenotypes .index )]))]
123
123
samples = phenotypes .loc ["annotation" ]
124
124
frontier = compute_frontier (dfdata , samples )
125
- patients = dfdata [[c for c in dfdata .columns if (phenotypes . loc [ "annotation" ] [c ]== 2 )]]
125
+ patients = dfdata [[c for c in dfdata .columns if (samples [c ]== 2 )]]
126
126
## 2. Compute one score per drug and per patients
127
127
if (simu_params .get ('thread_count' , 1 )== 1 ):
128
128
scores = [simulate_treatment (network_fname , targets .loc [[g for g in targets .index if (g in genes )]], frontier , patients [[Patient ]], simu_params , quiet = quiet ) for Patient in patients .columns ]
@@ -150,13 +150,13 @@ def compute_frontier(df, samples, nbseed=0, quiet=False):
150
150
print ("<NORD_DS> Accuracy of the model %.2f" % acc )
151
151
return model
152
152
153
- def compute_score (f , x0 , A , frontier , genes , nb_sims , experiments , repeat = 1 , exp_name = "" , quiet = False ):
153
+ def compute_score (f , x0 , A , score , genes , nb_sims , experiments , repeat = 1 , exp_name = "" , quiet = False ):
154
154
'''
155
155
Compute similarities between any attractor in WT and in mutants, weighted by their probabilities
156
156
@param\t f\t Boolean Network (MPBN) object: the mutated network
157
157
@param\t x0\t MPBN object: initial state
158
158
@param\t A\t Attractor list: list of attractors in mutant network
159
- @param\t frontier \t Python object: model to classify phenotypes
159
+ @param\t score \t Python object: scoring of attractors
160
160
@param\t genes\t Python character string list: list of genes in the model @frontier
161
161
@param\t nb_sims\t Python integer: number of iterations to compute the probabilities
162
162
@param\t experiments\t Python dictionary list: list of experiments (different rates/depths)
@@ -179,17 +179,17 @@ def compute_score(f, x0, A, frontier, genes, nb_sims, experiments, repeat=1, exp
179
179
probs = mpbn_sim .estimate_reachable_attractor_probabilities (f , x0 , A , nb_sims , depth (f , ** depth_args ), rates (f , ** rates_args ))
180
180
attrs = pd .DataFrame ({"MUT_%d" % ia : a for ia , a in enumerate (A )}).replace ("*" ,np .nan ).astype (float ).loc [genes ]
181
181
probs = np .array ([probs [ia ]/ 100. for ia in range (attrs .shape [1 ])])
182
- classification_attrs = ( frontier . predict ( attrs . values . T ) == 1 ). astype ( int ) #classifies into 1:control, 2:patient
182
+ classification_attrs = score ( attrs )
183
183
drug_score = probs .T .dot (classification_attrs )
184
184
d_scores .append (drug_score )
185
185
return np .mean (d_scores ) if (repeat > 1 ) else d_scores [0 ]
186
186
187
- def simulate_treatment (network_name , targets , frontier , state , simu_params = {}, quiet = False ):
187
+ def simulate_treatment (network_name , targets , score , state , simu_params = {}, quiet = False ):
188
188
'''
189
189
Compute the score assigned to a drug with targets in @targets[[drug]] in network
190
190
@param\t network_name\t Python character string: filename of the network in .bnet (needs to be pickable)
191
191
@param\t targets\t Pandas DataFrame: rows/[genes] x columns/[columns]
192
- @param\t frontier \t Python object: model to classify phenotypes
192
+ @param\t score \t Python object: scoring of attractors
193
193
@param\t state\t Pandas DataFrame: binary patient initial state rows/[genes] x columns/[values in {-1,0,1}]
194
194
@param\t simu_params\t Python dictionary[default={}]: arguments to MPBN-SIM
195
195
@param\t seednb\t Python integer[default=0]
0 commit comments