Mercurial > repos > bimib > cobraxy
comparison COBRAxy/flux_to_map.py @ 241:049aa0f4844f draft
Uploaded
author | francesco_lapi |
---|---|
date | Mon, 13 Jan 2025 15:16:18 +0000 |
parents | 63f5078627a9 |
children | c6d78b0d324d |
comparison
equal
deleted
inserted
replaced
240:63f5078627a9 | 241:049aa0f4844f |
---|---|
840 missing_reactions = [reaction for reaction in required_reactions if reaction not in dataset.index] | 840 missing_reactions = [reaction for reaction in required_reactions if reaction not in dataset.index] |
841 | 841 |
842 if missing_reactions: | 842 if missing_reactions: |
843 sys.exit(f'Execution aborted: Missing required reactions {missing_reactions} in {datasetName}\n') | 843 sys.exit(f'Execution aborted: Missing required reactions {missing_reactions} in {datasetName}\n') |
844 | 844 |
845 | |
845 # Calculate new rows using safe division | 846 # Calculate new rows using safe division |
846 lact_glc = np.divide( | 847 lact_glc = np.divide( |
847 dataset.loc['EX_lac__L_e'], -dataset.loc['EX_glc__D_e'], | 848 np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), |
848 out=np.zeros_like(dataset.loc['EX_lac__L_e']), where=dataset.loc['EX_glc__D_e'] != 0 | 849 np.clip(dataset.loc['EX_glc__D_e'].to_numpy(), a_min=None, a_max=0), |
850 out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), # Prepara un array con NaN come output di default | |
851 where=dataset.loc['EX_glc__D_e'].to_numpy() != 0 # Condizione per evitare la divisione per zero | |
849 ) | 852 ) |
850 lact_gln = np.divide( | 853 lact_gln = np.divide( |
851 dataset.loc['EX_lac__L_e'], -dataset.loc['EX_gln__L_e'], | 854 np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), |
852 out=np.zeros_like(dataset.loc['EX_lac__L_e']), where=dataset.loc['EX_gln__L_e'] != 0 | 855 np.clip(dataset.loc['EX_gln__L_e'].to_numpy(), a_min=None, a_max=0), |
856 out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), | |
857 where=dataset.loc['EX_gln__L_e'].to_numpy() != 0 | |
858 ) | |
859 lact_o2 = np.divide( | |
860 np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), | |
861 np.clip(dataset.loc['EX_o2_e'].to_numpy(), a_min=None, a_max=0), | |
862 out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), | |
863 where=dataset.loc['EX_o2_e'].to_numpy() != 0 | |
853 ) | 864 ) |
854 glu_gln = np.divide( | 865 glu_gln = np.divide( |
855 dataset.loc['EX_glu__L_e'], -dataset.loc['EX_gln__L_e'], | 866 dataset.loc['EX_glu__L_e'].to_numpy(), |
856 out=np.zeros_like(dataset.loc['EX_glu__L_e']), where=dataset.loc['EX_gln__L_e'] != 0 | 867 np.clip(dataset.loc['EX_gln__L_e'].to_numpy(), a_min=None, a_max=0), |
868 out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), | |
869 where=dataset.loc['EX_gln__L_e'].to_numpy() != 0 | |
857 ) | 870 ) |
858 | 871 |
859 # Create a DataFrame for the new rows | 872 # Create a DataFrame for the new rows |
860 new_rows = pd.DataFrame({ | 873 new_rows = pd.DataFrame({ |
861 dataset.index.name: ['LactGlc', 'LactGln', 'GluGln'], | 874 dataset.index.name: ['LactGlc', 'LactGln','LactO2', 'GluGln'], |
862 **{col: [lact_glc[i], lact_gln[i], glu_gln[i]] for i, col in enumerate(dataset.columns)} | 875 **{col: [lact_glc[i], lact_gln[i],lact_o2[i], glu_gln[i]] for i, col in enumerate(dataset.columns)} |
863 }) | 876 }) |
864 | 877 |
865 # Reset the index of the original dataset and append new rows | 878 # Reset the index of the original dataset and append new rows |
866 dataset.reset_index(inplace=True) | 879 dataset.reset_index(inplace=True) |
867 dataset = pd.concat([dataset, new_rows], ignore_index=True) | 880 dataset = pd.concat([dataset, new_rows], ignore_index=True) |