Mercurial > repos > bimib > cobraxy
changeset 84:0446929eb06b draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 13 Oct 2024 11:06:47 +0000 |
parents | bfb17674d13b |
children | 7ffe9d0477cf |
files | COBRAxy/ras_to_bounds.py |
diffstat | 1 files changed, 13 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/COBRAxy/ras_to_bounds.py Sun Oct 13 11:05:23 2024 +0000 +++ b/COBRAxy/ras_to_bounds.py Sun Oct 13 11:06:47 2024 +0000 @@ -54,20 +54,20 @@ required = False, help = 'input ras') - parser.add_argument('-rn', '--names', - type=str, - help = 'ras class names') - parser.add_argument('-rs', '--ras_selector', required = True, type=utils.Bool("using_RAS"), help = 'ras selector') + + parser.add_argument('-c', '--classes', + type = str, + required = False, + help = 'input classes') parser.add_argument('-cc', '--cell_class', type = str, help = 'output of cell class') - ARGS = parser.parse_args() return ARGS @@ -128,7 +128,6 @@ scaling_factor = ras_row[reaction] lower_bound=model.reactions.get_by_id(reaction).lower_bound upper_bound=model.reactions.get_by_id(reaction).upper_bound - #warning("Reaction: "+reaction+" Lower Bound: "+str(lower_bound)+" Upper Bound: "+str(upper_bound)+" Scaling Factor: "+str(scaling_factor)) valMax=float((upper_bound)*scaling_factor) valMin=float((lower_bound)*scaling_factor) if upper_bound!=0 and lower_bound==0: @@ -191,8 +190,6 @@ if ras is not None: Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) - #for cellName, ras_row in ras.iterrows(): - #process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) else: model_new = model.copy() apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids) @@ -221,10 +218,10 @@ if(ARGS.ras_selector == True): ras_file_list = ARGS.input_ras.split(",") - ras_file_names = ARGS.names.split(",") - ras_class_names = [] - for file in ras_file_names: - ras_class_names.append(file.split(".")[0]) + if(len(ras_file_list)>1): + ras_class_names = [cls.strip() for cls in ARGS.classes.split(',')] + else: + ras_class_names = ["placeHolder"] ras_list = [] class_assignments = pd.DataFrame(columns=["Patient_ID", "Class"]) for ras_matrix, ras_class_name in zip(ras_file_list, ras_class_names): @@ -235,11 +232,10 @@ ras = ras.astype(float) ras_list.append(ras) for patient_id in ras.index: - class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name] - + class_assignments = class_assignments.append({"Patient_ID": patient_id, "Class": ras_class_name}, ignore_index=True) # Concatenate all ras DataFrames into a single DataFrame - ras_combined = pd.concat(ras_list, axis=0) + ras_combined = pd.concat(ras_list, axis=1) # Normalize the RAS values by max RAS ras_combined = ras_combined.div(ras_combined.max(axis=0)) ras_combined = ras_combined.fillna(0) @@ -265,7 +261,8 @@ if(ARGS.ras_selector == True): generate_bounds(model, medium, ras = ras_combined, output_folder=ARGS.output_folder) - class_assignments.to_csv(ARGS.cell_class, sep = '\t', index = False) + if(len(ras_list)>1): + class_assignments.to_csv(ARGS.cell_class, sep = '\t', index = False) else: generate_bounds(model, medium, output_folder=ARGS.output_folder)