@@ -187,9 +187,9 @@ def AUC(time, volume, time_normalize=True):
187187 #print(time)
188188 if time_normalize :
189189 auc = auc / np .max (time )
190- return {"metric" : "auc" , "value" : auc }
190+ return {"metric" : "auc" , "value" : auc , 'time' : np . max ( time ) }
191191
192- def TGI (contr_volume , treat_volume ):
192+ def TGI (contr_volume , treat_volume , time ):
193193 """
194194 Computes the tumor growth inhibition (TGI) between two time-volume curves.
195195
@@ -207,7 +207,8 @@ def TGI(contr_volume, treat_volume):
207207 # Simulated batch response class object
208208 rtx = {
209209 "metric" : "TGI" ,
210- "value" : tgi
210+ "value" : tgi ,
211+ 'time' : np .max (time )
211212 }
212213 return rtx
213214
@@ -240,7 +241,7 @@ def ABC(contr_time=None, contr_volume=None, treat_time=None, treat_volume=None):
240241 tre = AUC (treat_time , treat_volume )
241242
242243 abc = con ['value' ] - tre ['value' ]
243- return {"metric" : "abc" , "value" : abc }#, "control": con, "treatment": tre}
244+ return {"metric" : "abc" , "value" : abc , 'time' : np . max ( treat_time ) }#, "control": con, "treatment": tre}
244245
245246
246247###LMM CODE
@@ -292,13 +293,14 @@ def lmm(time, volume, treatment, drug_name):
292293 'interaction_coef_value' : i_coef_value
293294 }
294295
295- return {'metric' : 'lmm' ,'value' : i_coef_value }
296+ return {'metric' : 'lmm' ,'value' : i_coef_value , 'time' : np . max ( time ) }
296297
297298def main ():
298299 parser = ArgumentParser ()
299300 ###read in file with model id, volume, time, condition
300301 parser .add_argument ('curvefile' )
301302 parser .add_argument ('--drugfile' )
303+ parser .add_argument ('--outprefix' ,default = '/tmp/' )
302304
303305 args = parser .parse_args ()
304306
@@ -308,8 +310,24 @@ def main():
308310 singles , combos = get_drug_stats (tab )
309311
310312 ##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' ]]
314+ expsing = expsing .dropna ()
315+
316+ combos [['drug1' ,'drug2' ]]= combos .drug .str .split ('+' ,expand = True )
317+ combos = combos .rename ({'metric' :'drug_combination_metric' ,'value' :'drug_combination_value' ,'sample' :'improve_sample_id' },axis = 1 ).dropna ()
318+
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+
322+ expcomb [['source' ]]= 'Synapse'
323+ expcomb [['study' ]]= 'MPNST PDX in vivo'
324+
325+ expsing [['source' ]]= 'Synapse'
326+ 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 )
311329
312- ##stats.to_csv('pdx_exp.tsv',sep='\t',index=False)
330+
313331
314332def get_drug_stats (df ,control = 'control' ):
315333 ##for each experiment, call group
@@ -341,24 +359,24 @@ def get_drug_stats(df,control='control'):
341359 treat_abc = ABC (ctl_time ,ctl_volume ,treat_time ,treat_volume )
342360 #print(f"AUC: {treat_auc}")
343361 #print(f"ABC: {treat_abc}")
344- treat_abc .update ({'sample' :mod ,'drug' :d })
362+ treat_abc .update ({'sample' :mod ,'drug' :d , 'time_unit' : 'days' })
345363 if '+' in d :
346364 combores .append (treat_abc )
347365 else :
348366 singleres .append (treat_abc )
349367 #lmm
350368 comb = pd .concat ([ctl_data ,d_data ])
351369 lmm_res = lmm (comb .time , comb .volume , comb .treatment ,d )
352- lmm_res .update ({'sample' :mod ,'drug' :d })
370+ lmm_res .update ({'sample' :mod ,'drug' :d , 'time_unit' : 'days' })
353371 #print(f"LMM: {lmm_res}")
354372 if '+' in d :
355- combores .append (lm_res )
373+ combores .append (lmm_res )
356374 else :
357- singleres .append (lm_res )
375+ singleres .append (lmm_res )
358376
359377 #get tgi for group
360- tg = TGI (ctl_volume ,treat_volume )
361- tg .update ({'sample' :mod ,'drug' :d })
378+ tg = TGI (ctl_volume ,treat_volume , treat_time )
379+ tg .update ({'sample' :mod ,'drug' :d , 'time_unit' : 'days' })
362380 #print(tg)
363381 if '+' in d :
364382 combores .append (tg )
@@ -368,13 +386,13 @@ def get_drug_stats(df,control='control'):
368386
369387 #get mRECIST for group
370388 mr = mrecist (treat_time ,treat_volume )
371- mr .update ({'sample' :mod ,'drug' :d })
389+ mr .update ({'sample' :mod ,'drug' :d , 'time_unit' : 'days' })
372390 if '+' in d :
373391 combores .append (mr )
374392 else :
375393 singleres .append (mr )
376394
377- sing = pd .DataFrame .from_records (singlres )
395+ sing = pd .DataFrame .from_records (singleres )
378396 comb = pd .DataFrame .from_records (combores )
379397 return sing ,comb
380398
0 commit comments