Skip to content

Commit fca76bd

Browse files
committed
Fixed git issue. Adding pdx update from novartis and local change
1 parent b958e83 commit fca76bd

2 files changed

Lines changed: 46 additions & 25 deletions

File tree

build/mpnst/03_get_experiments.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ fwrite(pdx_data, file.path("/tmp", paste0(out_prefix, "_pdx_curve_data.tsv")), s
240240
message("Wrote PDX curve data")
241241

242242
system(sprintf(
243-
"/opt/venv/bin/python calc_pdx_metrics.py %s --drugfile %s --outprefix %s",
244-
paste0("/tmp/", out_prefix, "_pdx_curve_data.tsv"),
245-
drugfile,
246-
paste0("/tmp/", out_prefix, "_pdx")
243+
"/opt/venv/bin/python calc_pdx_metrics.py %s --drugfile %s --outprefix %s --source 'NF Data Portal' --study 'MPNST PDX'",
244+
paste0("/tmp/", out_prefix, "_pdx_curve_data.tsv"),
245+
drugfile,
246+
paste0("/tmp/", out_prefix, "_pdx")
247247
))
248248

249+
250+
249251
message("Wrote PDX experiments to ", "/tmp/", out_prefix, "_pdx_experiments.tsv and combinations")
250252

251253

build/utils/calc_pdx_metrics.py

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,12 @@ def AUC(time, volume, time_normalize=True):
184184
dict: Dictionary containing the AUC value.
185185
"""
186186
auc = trapz_auc(time, volume)
187-
#print(time)
187+
#print('at line 187')
188+
#print(time.shape)
189+
#print(time.dtype)
190+
#print(np.max(time.astype(int)))
191+
#print('auc is : ')
192+
#print(auc)
188193
if time_normalize:
189194
auc = auc/np.max(time)
190195
return {"metric": "auc", "value": auc, 'time':np.max(time)}
@@ -270,10 +275,15 @@ def lmm(time, volume, treatment, drug_name):
270275
raise ValueError("These columns must be present: 'model_id', 'volume', 'time', 'exp_type'")
271276

272277
data['log_volume'] = np.log(data['volume'])
273-
278+
#print('drug name is ' + drug_name)
279+
data['exp_type'] = data['exp_type'].astype('category')
280+
data['exp_type']=pd.Categorical(data['exp_type'],categories = ['control',drug_name], ordered=True)
281+
#print(data)
282+
#print(data['exp_type'].cat.categories)
274283
# Define the formula for mixed linear model
275284
formula = 'log_volume ~ time*exp_type'
276285

286+
#print(data['exp_type'].cat.categories)
277287
# Fit the model
278288
model = mixedlm(formula, data, groups=data['model_id'])
279289
fit = model.fit()
@@ -284,6 +294,7 @@ def lmm(time, volume, treatment, drug_name):
284294
# time_coef_value = fit.params['time']
285295
#print(fit.params)
286296
i_coef_value = fit.params['time:exp_type[T.'+drug_name+']']
297+
#i_coef_value = fit.params['time:exp_type['+drug_name+']']
287298
# else:
288299
# coef_value = None # Handle the case when the interaction term is not present
289300

@@ -301,6 +312,8 @@ def main():
301312
parser.add_argument('curvefile')
302313
parser.add_argument('--drugfile')
303314
parser.add_argument('--outprefix',default='/tmp/')
315+
parser.add_argument('--study')
316+
parser.add_argument('--source')
304317

305318
args = parser.parse_args()
306319

@@ -314,20 +327,21 @@ def main():
314327
expsing = expsing.dropna()
315328

316329
# source improve_sample_id improve_drug_id study time time_unit dose_response_metric dose_response_value
317-
318-
combos[['drug1','drug2']]=combos.drug.str.split('+',expand=True)
319-
combos = combos.rename({'metric':'drug_combination_metric','value':'drug_combination_value','sample':'improve_sample_id'},axis=1).dropna()
320-
321-
expcomb = combos.rename({'drug1':'chem_name'},axis=1).merge(drugs,on='chem_name',how='left').rename({'improve_drug_id':'improve_drug_1'},axis=1)[['improve_drug_1','drug2','improve_sample_id','time_unit','time','drug_combination_metric','drug_combination_value']]
322-
expcomb = expcomb.rename({'drug2':'chem_name'},axis=1).merge(drugs,on='chem_name',how='left').rename({'improve_drug_id':'improve_drug_2'},axis=1)[['improve_drug_1','improve_drug_2','improve_sample_id','time_unit','time','drug_combination_metric','drug_combination_value']]
323-
324-
expcomb[['source']]='Synapse'
325-
expcomb[['study']]='MPNST PDX in vivo'
326-
327-
expsing[['source']]='Synapse'
328-
expsing[['study']]='MPNST PDX in vivo'
330+
if combos.shape[0]> 0:
331+
combos[['drug1','drug2']]=combos['drug'].str.split('+',expand=True)
332+
333+
combos = combos.rename({'metric':'drug_combination_metric','value':'drug_combination_value','sample':'improve_sample_id'},axis=1).dropna()
334+
335+
expcomb = combos.rename({'drug1':'chem_name'},axis=1).merge(drugs,on='chem_name',how='left').rename({'improve_drug_id':'improve_drug_1'},axis=1)[['improve_drug_1','drug2','improve_sample_id','time_unit','time','drug_combination_metric','drug_combination_value']]
336+
expcomb = expcomb.rename({'drug2':'chem_name'},axis=1).merge(drugs,on='chem_name',how='left').rename({'improve_drug_id':'improve_drug_2'},axis=1)[['improve_drug_1','improve_drug_2','improve_sample_id','time_unit','time','drug_combination_metric','drug_combination_value']]
337+
expcomb[['source']]=args.source
338+
expcomb[['study']]=args.study
339+
expcomb.to_csv(args.outprefix+'_combinations.tsv',index=False, sep="\t")
340+
341+
expsing[['source']]=args.source
342+
expsing[['study']]=args.study
329343
expsing.to_csv(args.outprefix+'_experiments.tsv',index=False, sep="\t")
330-
expcomb.to_csv(args.outprefix+'_combinations.tsv',index=False, sep="\t")
344+
#expcomb.to_csv(args.outprefix+'_combinations.tsv',index=False, sep="\t")
331345

332346

333347

@@ -341,21 +355,25 @@ def get_drug_stats(df, control='control'):
341355
for name, group in tqdm(groups):
342356
# Each group contains multiple treatments and a control
343357
drugs = set(group.treatment) - set([control])
344-
print(name[0])
345-
print(drugs)
358+
#print('line 355')
359+
#print(name[0])
360+
#print(drugs)
346361
mod = list(set(group.model_id))[0]
347362

348363
ctl_data = group[group.treatment == control]
349364
ctl_time = np.array(ctl_data.time)
350365
ctl_volume = np.array(ctl_data.volume)
351-
366+
if (ctl_volume.shape[0] < 2):
367+
continue
352368
ctl_auc = AUC(ctl_time, ctl_volume)
353369
for d in drugs:
354-
print(d)
355-
d_data = group[group.treatment == d]
370+
#print('is our drug a string or dict?')
371+
#print(str(d))
372+
d_data = group[group.treatment == str(d)]
356373
treat_time = np.array(d_data.time)
357374
treat_volume = np.array(d_data.volume)
358-
375+
if (treat_volume.shape[0] < 2):
376+
continue
359377
# Get ABC for group
360378
treat_auc = AUC(treat_time, treat_volume)
361379
treat_abc = ABC(ctl_time, ctl_volume, treat_time, treat_volume)
@@ -368,6 +386,7 @@ def get_drug_stats(df, control='control'):
368386

369387
#llm
370388
comb = pd.concat([ctl_data, d_data])
389+
#print(comb)
371390
lmm_res = lmm(comb.time, comb.volume, comb.treatment, d)
372391
lmm_res.update({'sample': mod, 'drug': d, 'time': np.max(treat_time), 'time_unit': 'days'})
373392
if '+' in d:

0 commit comments

Comments
 (0)