Skip to content

Commit a9164ca

Browse files
committed
final script for novartispdx and some changes to calc_pdx_metrics.py
Changes to calc_pdx_metrics.py include adding flexibility for `study` and `source` instead of being hard coded to MPNST. Added an if statement around the final touches to combos dataset, because if there is no drug data for the combo drugs, errors arise. Moved writing combos to csv to be inside this if statement.
1 parent 9d36112 commit a9164ca

4 files changed

Lines changed: 25 additions & 29 deletions

File tree

build/novartispdx/01-samples-novartispdx.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def get_complete_novartispdx_sample_sheet(synObject):
4444
print("Logging into Synapse")
4545
PAT = args.token
4646
synObject = synapseclient.login(authToken=PAT)
47-
4847
samplesheet = get_complete_novartispdx_sample_sheet(synObject)
4948

5049
if (args.prevSamples):

build/novartispdx/04-experiments-novartispdx.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def get_novartis_pdx_experiments_file(synObject, samples_df):
2020
novartispdx_curvefile['treatment']=novartispdx_curvefile['treatment'].str.replace('untreated', 'control')
2121
novartispdx_curvefile['experiment'] = novartispdx_curvefile.groupby(['model_id']).ngroup()+1
2222
# remove triple combination(s)
23-
novartispdx_curvefile = novartispdx_curvefile[~novartispdx_curvefile['treatment'].str.contains(r'\+.*\+')]
23+
novartispdx_curvefile = novartispdx_curvefile[~novartispdx_curvefile['treatment'].str.contains(r'\+')]
2424
# remove dose information appended to some drugs in the treatment column and include in dose colum
2525
druganddose = novartispdx_curvefile['treatment'].str.split('-', expand=True)
2626
druganddose = druganddose.rename({0: 'treatment', 1:'dose'}, axis=1)
@@ -39,12 +39,9 @@ def get_novartis_pdx_experiments_file(synObject, samples_df):
3939
#merge on drug names done in calc_pdx_metrics.py
4040
#final_w_drugIDs = finaldf.merge(drug_df, how='left',right_on='chem_name', left_on="treatment")
4141
final_allIDs = nomissingcontrols.merge(samples_df, how='left', right_on='common_name', left_on='model_id')
42-
print(final_allIDs.head)
4342
final_allIDs = final_allIDs.drop('model_id', axis=1)
4443
finalDF = final_allIDs.rename({'improve_sample_id':'model_id'}, axis=1)
45-
print(finalDF.head)
4644
finalcurvefile = finalDF[['model_id', 'time', 'volume', 'treatment', 'experiment', 'dose']]
47-
print(finalcurvefile.head)
4845
return finalcurvefile
4946

5047

@@ -59,7 +56,6 @@ def get_novartis_pdx_experiments_file(synObject, samples_df):
5956
print("Logging into Synapse")
6057
PAT = args.token
6158
synObject = synapseclient.login(authToken=PAT)
62-
#drug_df = pd.read_csv(args.drugfile, sep='\t')
6359
samples_df = pd.read_csv(args.curSampleFile)
6460

6561
doseresponse_data = get_novartis_pdx_experiments_file(synObject, samples_df)

build/novartispdx/build_experiments.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
#python3 04-experiments-novartispdx.py --token $SYNAPSE_AUTH_TOKEN
33

44
python3 -m novartispdx.04-experiments-novartispdx --token $SYNAPSE_AUTH_TOKEN -o ~/Projects/CoderData/dev-environment/novartispdx/novartispdx_curvedata.tsv
5-
python3 utils/calc_pdx_metrics.py /tmp/novartispdx_curvedata.tsv --drugfile=/tmp/novartispdx_drugs.tsv --outprefix=/tmp/novartispdx
5+
python3 utils/calc_pdx_metrics.py /tmp/novartispdx_curvedata.tsv --drugfile=/tmp/novartispdx_drugs.tsv --outprefix=/tmp/novartispdx --study='Novartis PDX Gao etal 2015' --source='Synapse'

build/utils/calc_pdx_metrics.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +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('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)
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)
193193
if time_normalize:
194194
auc = auc/np.max(time)
195195
return {"metric": "auc", "value": auc, 'time':np.max(time)}
@@ -292,7 +292,7 @@ def lmm(time, volume, treatment, drug_name):
292292
#interaction_term = 'time:exp_type'
293293
# if interaction_term in fit.params:
294294
# time_coef_value = fit.params['time']
295-
print(fit.params)
295+
#print(fit.params)
296296
i_coef_value = fit.params['time:exp_type[T.'+drug_name+']']
297297
#i_coef_value = fit.params['time:exp_type['+drug_name+']']
298298
# else:
@@ -312,6 +312,8 @@ def main():
312312
parser.add_argument('curvefile')
313313
parser.add_argument('--drugfile')
314314
parser.add_argument('--outprefix',default='/tmp/')
315+
parser.add_argument('--study')
316+
parser.add_argument('--source')
315317

316318
args = parser.parse_args()
317319

@@ -325,22 +327,21 @@ def main():
325327
expsing = expsing.dropna()
326328

327329
# source improve_sample_id improve_drug_id study time time_unit dose_response_metric dose_response_value
328-
329-
combos[['drug1','drug2']]=combos.drug.str.split('+',expand=True)
330-
print('COMBOS ARE: ')
331-
print(combos[['drug1', 'drug2']])
332-
combos = combos.rename({'metric':'drug_combination_metric','value':'drug_combination_value','sample':'improve_sample_id'},axis=1).dropna()
333-
334-
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']]
335-
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']]
336-
print(expcomb[['improve_drug_1', 'improve_drug_2']])
337-
expcomb[['source']]='Synapse'
338-
expcomb[['study']]='MPNST PDX in vivo'
339-
340-
expsing[['source']]='Synapse'
341-
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
342343
expsing.to_csv(args.outprefix+'_experiments.tsv',index=False, sep="\t")
343-
expcomb.to_csv(args.outprefix+'_combinations.tsv',index=False, sep="\t")
344+
#expcomb.to_csv(args.outprefix+'_combinations.tsv',index=False, sep="\t")
344345

345346

346347

0 commit comments

Comments
 (0)