@@ -310,91 +310,90 @@ def main():
310310 singles , combos = get_drug_stats (tab )
311311
312312 ##join with drug ids
313- expsing = singles .rename ({'drug' :'chem_name' ,'metric' :'drug_combination_metric ' ,'value' :'drug_combination_value ' ,'sample' :'improve_sample_id' },axis = 1 ).merge (drugs ,on = 'chem_name' ,how = 'left' )[['improve_drug_id' ,'improve_sample_id' ,'drug_combination_metric ' ,'drug_combination_value ' ]]
313+ expsing = singles .rename ({'drug' :'chem_name' ,'metric' :'dose_response_metric ' ,'value' :'dose_response_value ' ,'sample' :'improve_sample_id' },axis = 1 ).merge (drugs ,on = 'chem_name' ,how = 'left' )[['improve_drug_id' ,'improve_sample_id' ,'time_unit ' ,'time' , 'dose_response_metric' , 'dose_response_value ' ]]
314314 expsing = expsing .dropna ()
315+
316+ # source improve_sample_id improve_drug_id study time time_unit dose_response_metric dose_response_value
315317
316318 combos [['drug1' ,'drug2' ]]= combos .drug .str .split ('+' ,expand = True )
317319 combos = combos .rename ({'metric' :'drug_combination_metric' ,'value' :'drug_combination_value' ,'sample' :'improve_sample_id' },axis = 1 ).dropna ()
318320
319- 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' ,'drug_combination_metric' ,'drug_combination_value' ]]
320- 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' ,'drug_combination_metric' ,'drug_combination_value' ]]
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' ]]
321323
322324 expcomb [['source' ]]= 'Synapse'
323325 expcomb [['study' ]]= 'MPNST PDX in vivo'
324326
325327 expsing [['source' ]]= 'Synapse'
326328 expsing [['study' ]]= 'MPNST PDX in vivo'
327- expsing .to_csv (args .outprefix + '_experiments.csv ' ,index = False )
328- expcomb .to_csv (args .outprefix + '_combinations.csv ' ,index = False )
329+ expsing .to_csv (args .outprefix + '_experiments.tsv ' ,index = False , sep = " \t " )
330+ expcomb .to_csv (args .outprefix + '_combinations.tsv ' ,index = False , sep = " \t " )
329331
330332
331333
332- def get_drug_stats (df ,control = 'control' ):
334+ def get_drug_stats (df , control = 'control' ):
333335 ##for each experiment, call group
334- cols = ['experiment' ,'model_id' ]
336+ cols = ['experiment' , 'model_id' ]
335337 groups = df .groupby (cols )
336338 singleres = []
337339 combores = []
338340
339- for name ,group in tqdm (groups ):
340- #each group contains multiple treatments anda control
341- drugs = set (group .treatment )- set ([control ])
341+ for name , group in tqdm (groups ):
342+ # Each group contains multiple treatments and a control
343+ drugs = set (group .treatment ) - set ([control ])
342344 print (name [0 ])
343345 print (drugs )
344346 mod = list (set (group .model_id ))[0 ]
345- # print(set(group.model_id))
346- ctl_data = group [group .treatment == control ]
347+
348+ ctl_data = group [group .treatment == control ]
347349 ctl_time = np .array (ctl_data .time )
348350 ctl_volume = np .array (ctl_data .volume )
349351
350- ctl_auc = AUC (ctl_time ,ctl_volume )
352+ ctl_auc = AUC (ctl_time , ctl_volume )
351353 for d in drugs :
352354 print (d )
353- d_data = group [group .treatment == d ]
355+ d_data = group [group .treatment == d ]
354356 treat_time = np .array (d_data .time )
355357 treat_volume = np .array (d_data .volume )
356358
357- #get abc for group
358- treat_auc = AUC (treat_time ,treat_volume )
359- treat_abc = ABC (ctl_time ,ctl_volume ,treat_time ,treat_volume )
360- #print(f"AUC: {treat_auc}")
361- #print(f"ABC: {treat_abc}")
362- treat_abc .update ({'sample' :mod ,'drug' :d ,'time_unit' :'days' })
359+ # Get ABC for group
360+ treat_auc = AUC (treat_time , treat_volume )
361+ treat_abc = ABC (ctl_time , ctl_volume , treat_time , treat_volume )
362+ print (f"treat_time:, { treat_time } " )
363+ treat_abc .update ({'sample' : mod , 'drug' : d , 'time' : np .max (treat_time ), 'time_unit' : 'days' })
363364 if '+' in d :
364365 combores .append (treat_abc )
365366 else :
366367 singleres .append (treat_abc )
367- #lmm
368- comb = pd . concat ([ ctl_data , d_data ])
369- lmm_res = lmm ( comb . time , comb . volume , comb . treatment , d )
370- lmm_res . update ({ 'sample' : mod , 'drug' : d , 'time_unit' : 'days' } )
371- #print(f"LMM: {lmm_res}" )
368+
369+ #llm
370+ comb = pd . concat ([ ctl_data , d_data ] )
371+ lmm_res = lmm ( comb . time , comb . volume , comb . treatment , d )
372+ lmm_res . update ({ 'sample' : mod , 'drug' : d , 'time' : np . max ( treat_time ), 'time_unit' : 'days' } )
372373 if '+' in d :
373374 combores .append (lmm_res )
374375 else :
375376 singleres .append (lmm_res )
376377
377- #get tgi for group
378- tg = TGI (ctl_volume ,treat_volume ,treat_time )
379- tg .update ({'sample' :mod ,'drug' :d ,'time_unit' :'days' })
380- #print(tg)
378+ # Get TGI for group
379+ tg = TGI (ctl_volume , treat_volume , treat_time )
380+ tg .update ({'sample' : mod , 'drug' : d , 'time' : np .max (treat_time ), 'time_unit' : 'days' })
381381 if '+' in d :
382382 combores .append (tg )
383383 else :
384384 singleres .append (tg )
385385
386-
387- #get mRECIST for group
388- mr = mrecist (treat_time ,treat_volume )
389- mr .update ({'sample' :mod ,'drug' :d ,'time_unit' :'days' })
386+ # Get mRECIST for group
387+ mr = mrecist (treat_time , treat_volume )
388+ mr .update ({'sample' : mod , 'drug' : d , 'time' : np .max (treat_time ), 'time_unit' : 'days' })
390389 if '+' in d :
391390 combores .append (mr )
392391 else :
393392 singleres .append (mr )
394393
395394 sing = pd .DataFrame .from_records (singleres )
396395 comb = pd .DataFrame .from_records (combores )
397- return sing ,comb
396+ return sing , comb
398397
399398if __name__ == '__main__' :
400399 main ()
0 commit comments