Mercurial > repos > bimib > cobraxy
comparison COBRAxy/utils/general_utils.py @ 415:4a248b45273c draft
Uploaded
| author | francesco_lapi |
|---|---|
| date | Mon, 08 Sep 2025 21:56:19 +0000 |
| parents | 5086145cfb96 |
| children | ed2c1f9e20ba |
comparison
equal
deleted
inserted
replaced
| 414:5086145cfb96 | 415:4a248b45273c |
|---|---|
| 776 # Seconda passata: aggiungi le reazioni | 776 # Seconda passata: aggiungi le reazioni |
| 777 reactions_added = 0 | 777 reactions_added = 0 |
| 778 reactions_skipped = 0 | 778 reactions_skipped = 0 |
| 779 | 779 |
| 780 for idx, row in df.iterrows(): | 780 for idx, row in df.iterrows(): |
| 781 | |
| 782 reaction_id = str(row['ReactionID']).strip() | |
| 783 reaction_formula = str(row['Reaction']).strip() | |
| 784 | |
| 785 # Salta reazioni senza formula | |
| 786 if not reaction_formula or reaction_formula == 'nan': | |
| 787 raise ValueError(f"Formula della reazione mancante {reaction_id}") | |
| 788 | |
| 789 # Crea la reazione | |
| 790 reaction = Reaction(reaction_id) | |
| 791 reaction.name = reaction_id | |
| 792 | |
| 793 # Imposta bounds | |
| 794 reaction.lower_bound = float(row['lower_bound']) if pd.notna(row['lower_bound']) else -1000.0 | |
| 795 reaction.upper_bound = float(row['upper_bound']) if pd.notna(row['upper_bound']) else 1000.0 | |
| 796 | |
| 797 # Aggiungi gene rule se presente | |
| 798 if pd.notna(row['Rule']) and str(row['Rule']).strip(): | |
| 799 reaction.gene_reaction_rule = str(row['Rule']).strip() | |
| 800 | |
| 801 # Parse della formula della reazione | |
| 781 try: | 802 try: |
| 782 reaction_id = str(row['ReactionID']).strip() | 803 parse_reaction_formula(reaction, reaction_formula, metabolites_dict) |
| 783 reaction_formula = str(row['Reaction']).strip() | 804 except Exception as e: |
| 784 | 805 print(f"Errore nel parsing della reazione {reaction_id}: {e}") |
| 785 # Salta reazioni senza formula | 806 reactions_skipped += 1 |
| 786 if not reaction_formula or reaction_formula == 'nan': | 807 continue |
| 787 raise ValueError(f"Formula della reazione mancante {reaction_id}") | 808 |
| 788 | 809 # Aggiungi la reazione al modello |
| 789 # Crea la reazione | 810 model.add_reactions([reaction]) |
| 790 reaction = Reaction(reaction_id) | 811 reactions_added += 1 |
| 791 reaction.name = reaction_id | |
| 792 | |
| 793 # Imposta bounds | |
| 794 reaction.lower_bound = float(row['lower_bound']) if pd.notna(row['lower_bound']) else -1000.0 | |
| 795 reaction.upper_bound = float(row['upper_bound']) if pd.notna(row['upper_bound']) else 1000.0 | |
| 796 | |
| 797 # Aggiungi gene rule se presente | |
| 798 if pd.notna(row['Rule']) and str(row['Rule']).strip(): | |
| 799 reaction.gene_reaction_rule = str(row['Rule']).strip() | |
| 800 | |
| 801 # Parse della formula della reazione | |
| 802 try: | |
| 803 parse_reaction_formula(reaction, reaction_formula, metabolites_dict) | |
| 804 except Exception as e: | |
| 805 print(f"Errore nel parsing della reazione {reaction_id}: {e}") | |
| 806 reactions_skipped += 1 | |
| 807 continue | |
| 808 | |
| 809 # Aggiungi la reazione al modello | |
| 810 model.add_reactions([reaction]) | |
| 811 reactions_added += 1 | |
| 812 | 812 |
| 813 | 813 |
| 814 print(f"Aggiunte {reactions_added} reazioni, saltate {reactions_skipped} reazioni") | 814 print(f"Aggiunte {reactions_added} reazioni, saltate {reactions_skipped} reazioni") |
| 815 | 815 |
| 816 # Imposta l'obiettivo di biomassa | 816 # Imposta l'obiettivo di biomassa |
