Skip to content

Commit d348323

Browse files
Adding the accept_nonRNA and force_experiments features
1 parent 8637e15 commit d348323

File tree

13 files changed

+813
-257
lines changed

13 files changed

+813
-257
lines changed

notebooks/NORDic Network Identification (NI) Part I.ipynb

Lines changed: 207 additions & 36 deletions
Large diffs are not rendered by default.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from subprocess import check_call
99

1010
NAME = "NORDic"
11-
VERSION = "2.1.2"
11+
VERSION = "2.2.0"
1212

1313
setup(name=NAME,
1414
version=VERSION,

src/NORDic/NORDic_DR/functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import NORDic.NORDic_DR.bandits as bandits
88
import NORDic.NORDic_DR.utils as utils
99

10-
def adaptive_testing(network_name, signatures, targets, frontier, states, simu_params={}, bandit_args={},
10+
def adaptive_testing(network_name, signatures, targets, score, states, simu_params={}, bandit_args={},
1111
reward_fname=None, quiet=False):
1212
'''
1313
Perform adaptive testing and recommends most promising treatments (=maximizing score)
1414
@param\tnetwork_name\tPython character string: (relative) path to a network .BNET file
1515
@param\tsignatures\tPandas DataFrame: rows/[features] x columns/[drugs to test]
1616
@param\ttargets\tPandas DataFrame: rows/[genes] x columns/[drugs to test] (either 1: active expression, -1: inactive expression, 0: undetermined expression)
17-
@param\tfrontier\tPython object with a function "predict" that returns predictions (1: control, or 2: treated) on phenotypes
17+
@param\tscore\tPython object: scoring of attractors
1818
@param\tstates\tPandas DataFrame: rows/[gene] x columns/[patient samples] (either 1: activatory, -1: inhibitory, 0: no regulation).
1919
@param\tsimu_params\tPython dictionary[default={}]: arguments to MPBN-SIM
2020
@param\tbandit_params\tPython dictionary[default={}]: arguments to the bandit algorithms
@@ -42,7 +42,7 @@ def adaptive_testing(network_name, signatures, targets, frontier, states, simu_p
4242
"network_name": network_name,
4343
"reward_fname": reward_fname,
4444
"targets": targets,
45-
"frontier": frontier,
45+
"score": score,
4646
"states": states,
4747
"simu_params": simu_params,
4848
}
@@ -101,7 +101,7 @@ def reward(self, arm):
101101
if (not np.isnan(self.memoization[arm, patient])):
102102
return float(self.memoization[arm, patient])
103103
result = float(simulate_treatment(self.network_name, self.targets[[self.targets.columns[arm]]],
104-
self.frontier, self.states.iloc[:,patient],
104+
self.score, self.states.iloc[:,patient],
105105
self.simu_params, quiet=False)[0])
106106
self.memoization[arm, patient] = result
107107
return result

src/NORDic/NORDic_DS/functions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def baseline(signatures, phenotype, is_binary=False):
3434
PC[PC<0] = -1
3535
SC[pd.isnull(SC)] = 0
3636
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")
3939
baseline_df = pd.DataFrame(cosscores, columns=["Cosine Score"], index=signatures.columns)
4040
return baseline_df
4141

@@ -94,13 +94,13 @@ def compute_metrics(rewards, ground_truth, K=[2,5,10], use_negative_class=False,
9494
## DRUG SIMULATOR ##
9595
######################
9696

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):
9898
'''
9999
Simulate and score the individual effects of drugs on patient phenotypes, compared to controls
100100
@param\tnetwork_fname\tPython character string: (relative) path to a network .BNET file
101101
@param\ttargets\tPandas DataFrame: rows/[genes] x columns/[drugs to test] (either 1: active expression, -1: inactive expression, 0: undetermined expression)
102-
@param\tphenotypes\tPandas 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\tpatients\tPandas DataFrame: rows/[genes] x columns/[samples] (either 1: activatory, -1: inhibitory, 0: no regulation).
103+
@param\tscore\tPython object: scoring of attractors
104104
@param\tsimu_params\tPython dictionary[default={}]: arguments to MPBN-SIM
105105
@param\tnbseed\tPython integer[default=0]
106106
@param\tquiet\tPython bool[default=False]
@@ -122,7 +122,7 @@ def simulate(network_fname, targets, phenotypes, simu_params={}, nbseed=0, quiet
122122
dfdata = phenotypes.loc[list(set([g for g in genes if (g in phenotypes.index)]))]
123123
samples = phenotypes.loc["annotation"]
124124
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)]]
126126
## 2. Compute one score per drug and per patients
127127
if (simu_params.get('thread_count', 1)==1):
128128
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):
150150
print("<NORD_DS> Accuracy of the model %.2f" % acc)
151151
return model
152152

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):
154154
'''
155155
Compute similarities between any attractor in WT and in mutants, weighted by their probabilities
156156
@param\tf\tBoolean Network (MPBN) object: the mutated network
157157
@param\tx0\tMPBN object: initial state
158158
@param\tA\tAttractor list: list of attractors in mutant network
159-
@param\tfrontier\tPython object: model to classify phenotypes
159+
@param\tscore\tPython object: scoring of attractors
160160
@param\tgenes\tPython character string list: list of genes in the model @frontier
161161
@param\tnb_sims\tPython integer: number of iterations to compute the probabilities
162162
@param\texperiments\tPython 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
179179
probs = mpbn_sim.estimate_reachable_attractor_probabilities(f, x0, A, nb_sims, depth(f, **depth_args), rates(f, **rates_args))
180180
attrs = pd.DataFrame({"MUT_%d"%ia: a for ia, a in enumerate(A)}).replace("*",np.nan).astype(float).loc[genes]
181181
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)
183183
drug_score = probs.T.dot(classification_attrs)
184184
d_scores.append(drug_score)
185185
return np.mean(d_scores) if (repeat>1) else d_scores[0]
186186

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):
188188
'''
189189
Compute the score assigned to a drug with targets in @targets[[drug]] in network
190190
@param\tnetwork_name\tPython character string: filename of the network in .bnet (needs to be pickable)
191191
@param\ttargets\tPandas DataFrame: rows/[genes] x columns/[columns]
192-
@param\tfrontier\tPython object: model to classify phenotypes
192+
@param\tscore\tPython object: scoring of attractors
193193
@param\tstate\tPandas DataFrame: binary patient initial state rows/[genes] x columns/[values in {-1,0,1}]
194194
@param\tsimu_params\tPython dictionary[default={}]: arguments to MPBN-SIM
195195
@param\tseednb\tPython integer[default=0]

0 commit comments

Comments
 (0)