Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_to_bounds.py @ 64:b10da5046afd draft
Uploaded
author | luca_milaz |
---|---|
date | Sun, 13 Oct 2024 08:25:29 +0000 |
parents | 5302258f8262 |
children | 1f928ad6a87e |
comparison
equal
deleted
inserted
replaced
63:5302258f8262 | 64:b10da5046afd |
---|---|
121 for reaction in rxns_ids: | 121 for reaction in rxns_ids: |
122 if reaction in ras_row.index: | 122 if reaction in ras_row.index: |
123 scaling_factor = ras_row[reaction] | 123 scaling_factor = ras_row[reaction] |
124 lower_bound=model.reactions.get_by_id(reaction).lower_bound | 124 lower_bound=model.reactions.get_by_id(reaction).lower_bound |
125 upper_bound=model.reactions.get_by_id(reaction).upper_bound | 125 upper_bound=model.reactions.get_by_id(reaction).upper_bound |
126 warning("Reaction: "+reaction+" Lower Bound: "+str(lower_bound)+" Upper Bound: "+str(upper_bound)+" Scaling Factor: "+str(scaling_factor)) | 126 #warning("Reaction: "+reaction+" Lower Bound: "+str(lower_bound)+" Upper Bound: "+str(upper_bound)+" Scaling Factor: "+str(scaling_factor)) |
127 valMax=float((upper_bound)*scaling_factor) | 127 valMax=float((upper_bound)*scaling_factor) |
128 valMin=float((lower_bound)*scaling_factor) | 128 valMin=float((lower_bound)*scaling_factor) |
129 if upper_bound!=0 and lower_bound==0: | 129 if upper_bound!=0 and lower_bound==0: |
130 model.reactions.get_by_id(reaction).upper_bound=valMax | 130 model.reactions.get_by_id(reaction).upper_bound=valMax |
131 if upper_bound==0 and lower_bound!=0: | 131 if upper_bound==0 and lower_bound!=0: |
183 rxn = model.reactions.get_by_id(reaction) | 183 rxn = model.reactions.get_by_id(reaction) |
184 rxn.lower_bound = float(df_FVA.loc[reaction, "minimum"]) | 184 rxn.lower_bound = float(df_FVA.loc[reaction, "minimum"]) |
185 rxn.upper_bound = float(df_FVA.loc[reaction, "maximum"]) | 185 rxn.upper_bound = float(df_FVA.loc[reaction, "maximum"]) |
186 | 186 |
187 if ras is not None: | 187 if ras is not None: |
188 #Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) | 188 Parallel(n_jobs=cpu_count())(delayed(process_ras_cell)(cellName, ras_row, model, rxns_ids, output_folder) for cellName, ras_row in ras.iterrows()) |
189 for cellName, ras_row in ras.iterrows(): | 189 #for cellName, ras_row in ras.iterrows(): |
190 process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) | 190 #process_ras_cell(cellName, ras_row, model, rxns_ids, output_folder) |
191 else: | 191 else: |
192 model_new = model.copy() | 192 model_new = model.copy() |
193 apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids) | 193 apply_ras_bounds(model_new, pd.Series([1]*len(rxns_ids), index=rxns_ids), rxns_ids) |
194 bounds = pd.DataFrame([(rxn.lower_bound, rxn.upper_bound) for rxn in model_new.reactions], index=rxns_ids, columns=["lower_bound", "upper_bound"]) | 194 bounds = pd.DataFrame([(rxn.lower_bound, rxn.upper_bound) for rxn in model_new.reactions], index=rxns_ids, columns=["lower_bound", "upper_bound"]) |
195 bounds.to_csv(output_folder + "bounds.csv", sep='\t', index=True) | 195 bounds.to_csv(output_folder + "bounds.csv", sep='\t', index=True) |
231 for patient_id in ras.index: | 231 for patient_id in ras.index: |
232 class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name] | 232 class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name] |
233 | 233 |
234 | 234 |
235 # Concatenate all ras DataFrames into a single DataFrame | 235 # Concatenate all ras DataFrames into a single DataFrame |
236 ras_combined = pd.concat(ras_list, axis=1) | 236 ras_combined = pd.concat(ras_list, axis=0) |
237 # Normalize the RAS values by max RAS | 237 # Normalize the RAS values by max RAS |
238 ras_combined = ras_combined.div(ras_combined.max(axis=0)) | 238 ras_combined = ras_combined.div(ras_combined.max(axis=0)) |
239 ras_combined = ras_combined.fillna(0) | 239 ras_combined = ras_combined.fillna(0) |
240 | 240 |
241 | 241 |