@@ -184,7 +184,12 @@ def AUC(time, volume, time_normalize=True):
184
184
dict: Dictionary containing the AUC value.
185
185
"""
186
186
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)
188
193
if time_normalize :
189
194
auc = auc / np .max (time )
190
195
return {"metric" : "auc" , "value" : auc , 'time' :np .max (time )}
@@ -270,10 +275,15 @@ def lmm(time, volume, treatment, drug_name):
270
275
raise ValueError ("These columns must be present: 'model_id', 'volume', 'time', 'exp_type'" )
271
276
272
277
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)
274
283
# Define the formula for mixed linear model
275
284
formula = 'log_volume ~ time*exp_type'
276
285
286
+ #print(data['exp_type'].cat.categories)
277
287
# Fit the model
278
288
model = mixedlm (formula , data , groups = data ['model_id' ])
279
289
fit = model .fit ()
@@ -284,6 +294,7 @@ def lmm(time, volume, treatment, drug_name):
284
294
# time_coef_value = fit.params['time']
285
295
#print(fit.params)
286
296
i_coef_value = fit .params ['time:exp_type[T.' + drug_name + ']' ]
297
+ #i_coef_value = fit.params['time:exp_type['+drug_name+']']
287
298
# else:
288
299
# coef_value = None # Handle the case when the interaction term is not present
289
300
@@ -301,6 +312,8 @@ def main():
301
312
parser .add_argument ('curvefile' )
302
313
parser .add_argument ('--drugfile' )
303
314
parser .add_argument ('--outprefix' ,default = '/tmp/' )
315
+ parser .add_argument ('--study' )
316
+ parser .add_argument ('--source' )
304
317
305
318
args = parser .parse_args ()
306
319
@@ -314,20 +327,21 @@ def main():
314
327
expsing = expsing .dropna ()
315
328
316
329
# 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
329
343
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")
331
345
332
346
333
347
@@ -341,21 +355,25 @@ def get_drug_stats(df, control='control'):
341
355
for name , group in tqdm (groups ):
342
356
# Each group contains multiple treatments and a control
343
357
drugs = set (group .treatment ) - set ([control ])
344
- print (name [0 ])
345
- print (drugs )
358
+ #print('line 355')
359
+ #print(name[0])
360
+ #print(drugs)
346
361
mod = list (set (group .model_id ))[0 ]
347
362
348
363
ctl_data = group [group .treatment == control ]
349
364
ctl_time = np .array (ctl_data .time )
350
365
ctl_volume = np .array (ctl_data .volume )
351
-
366
+ if (ctl_volume .shape [0 ] < 2 ):
367
+ continue
352
368
ctl_auc = AUC (ctl_time , ctl_volume )
353
369
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 )]
356
373
treat_time = np .array (d_data .time )
357
374
treat_volume = np .array (d_data .volume )
358
-
375
+ if (treat_volume .shape [0 ] < 2 ):
376
+ continue
359
377
# Get ABC for group
360
378
treat_auc = AUC (treat_time , treat_volume )
361
379
treat_abc = ABC (ctl_time , ctl_volume , treat_time , treat_volume )
@@ -368,6 +386,7 @@ def get_drug_stats(df, control='control'):
368
386
369
387
#llm
370
388
comb = pd .concat ([ctl_data , d_data ])
389
+ #print(comb)
371
390
lmm_res = lmm (comb .time , comb .volume , comb .treatment , d )
372
391
lmm_res .update ({'sample' : mod , 'drug' : d , 'time' : np .max (treat_time ), 'time_unit' : 'days' })
373
392
if '+' in d :
0 commit comments