Mercurial > repos > bimib > cobraxy
comparison COBRAxy/ras_to_bounds.py @ 130:03bbbd9af67d draft
Uploaded
author | luca_milaz |
---|---|
date | Tue, 15 Oct 2024 18:31:34 +0000 |
parents | dfb6a1dc6dbc |
children | 63cb32c3d8b1 |
comparison
equal
deleted
inserted
replaced
129:dfb6a1dc6dbc | 130:03bbbd9af67d |
---|---|
178 # Set medium conditions | 178 # Set medium conditions |
179 for reaction, value in medium.items(): | 179 for reaction, value in medium.items(): |
180 if value is not None: | 180 if value is not None: |
181 model.reactions.get_by_id(reaction).lower_bound = -float(value) | 181 model.reactions.get_by_id(reaction).lower_bound = -float(value) |
182 | 182 |
183 | |
184 mediumRxns_ids = medium.keys() | |
185 | 183 |
186 # Perform Flux Variability Analysis (FVA) on this medium | 184 # Perform Flux Variability Analysis (FVA) on this medium |
187 df_FVA = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=0, processes=1).round(8) | 185 df_FVA = cobra.flux_analysis.flux_variability_analysis(model, fraction_of_optimum=0, processes=1).round(8) |
188 | 186 |
189 # Set FVA bounds | 187 # Set FVA bounds |
220 ARGS.output_folder = 'ras_to_bounds/' | 218 ARGS.output_folder = 'ras_to_bounds/' |
221 | 219 |
222 if(ARGS.ras_selector == True): | 220 if(ARGS.ras_selector == True): |
223 ras_file_list = ARGS.input_ras.split(",") | 221 ras_file_list = ARGS.input_ras.split(",") |
224 ras_file_names = ARGS.name.split(",") | 222 ras_file_names = ARGS.name.split(",") |
223 if len(ras_file_names) != len(set(ras_file_names)): | |
224 error_message = "Duplicated file names in the uploaded RAS matrices." | |
225 warning(error_message) | |
226 raise ValueError(error_message) | |
227 pass | |
225 ras_class_names = [] | 228 ras_class_names = [] |
226 for file in ras_file_names: | 229 for file in ras_file_names: |
227 ras_class_names.append(file.split(".")[0]) | 230 ras_class_names.append(file.split(".")[0]) |
228 ras_list = [] | 231 ras_list = [] |
229 class_assignments = pd.DataFrame(columns=["Patient_ID", "Class"]) | 232 class_assignments = pd.DataFrame(columns=["Patient_ID", "Class"]) |
231 ras = read_dataset(ras_matrix, "ras dataset") | 234 ras = read_dataset(ras_matrix, "ras dataset") |
232 ras.replace("None", None, inplace=True) | 235 ras.replace("None", None, inplace=True) |
233 ras.set_index("Reactions", drop=True, inplace=True) | 236 ras.set_index("Reactions", drop=True, inplace=True) |
234 ras = ras.T | 237 ras = ras.T |
235 ras = ras.astype(float) | 238 ras = ras.astype(float) |
239 #append class name to patient id (dataframe index) | |
240 ras.index = [f"{idx}_{ras_class_name}" for idx in ras.index] | |
236 ras_list.append(ras) | 241 ras_list.append(ras) |
237 for patient_id in ras.index: | 242 for patient_id in ras.index: |
238 class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name] | 243 class_assignments.loc[class_assignments.shape[0]] = [patient_id, ras_class_name] |
239 | 244 |
240 | 245 |