Mercurial > repos > bimib > cobraxy
diff COBRAxy/flux_to_map.py @ 241:049aa0f4844f draft default tip
Uploaded
author | francesco_lapi |
---|---|
date | Mon, 13 Jan 2025 15:16:18 +0000 |
parents | 63f5078627a9 |
children |
line wrap: on
line diff
--- a/COBRAxy/flux_to_map.py Mon Jan 13 10:01:40 2025 +0000 +++ b/COBRAxy/flux_to_map.py Mon Jan 13 15:16:18 2025 +0000 @@ -842,24 +842,37 @@ if missing_reactions: sys.exit(f'Execution aborted: Missing required reactions {missing_reactions} in {datasetName}\n') + # Calculate new rows using safe division lact_glc = np.divide( - dataset.loc['EX_lac__L_e'], -dataset.loc['EX_glc__D_e'], - out=np.zeros_like(dataset.loc['EX_lac__L_e']), where=dataset.loc['EX_glc__D_e'] != 0 + np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), + np.clip(dataset.loc['EX_glc__D_e'].to_numpy(), a_min=None, a_max=0), + out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), # Prepara un array con NaN come output di default + where=dataset.loc['EX_glc__D_e'].to_numpy() != 0 # Condizione per evitare la divisione per zero ) lact_gln = np.divide( - dataset.loc['EX_lac__L_e'], -dataset.loc['EX_gln__L_e'], - out=np.zeros_like(dataset.loc['EX_lac__L_e']), where=dataset.loc['EX_gln__L_e'] != 0 + np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), + np.clip(dataset.loc['EX_gln__L_e'].to_numpy(), a_min=None, a_max=0), + out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), + where=dataset.loc['EX_gln__L_e'].to_numpy() != 0 + ) + lact_o2 = np.divide( + np.clip(dataset.loc['EX_lac__L_e'].to_numpy(), a_min=0, a_max=None), + np.clip(dataset.loc['EX_o2_e'].to_numpy(), a_min=None, a_max=0), + out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), + where=dataset.loc['EX_o2_e'].to_numpy() != 0 ) glu_gln = np.divide( - dataset.loc['EX_glu__L_e'], -dataset.loc['EX_gln__L_e'], - out=np.zeros_like(dataset.loc['EX_glu__L_e']), where=dataset.loc['EX_gln__L_e'] != 0 + dataset.loc['EX_glu__L_e'].to_numpy(), + np.clip(dataset.loc['EX_gln__L_e'].to_numpy(), a_min=None, a_max=0), + out=np.full_like(dataset.loc['EX_lac__L_e'].to_numpy(), np.nan), + where=dataset.loc['EX_gln__L_e'].to_numpy() != 0 ) # Create a DataFrame for the new rows new_rows = pd.DataFrame({ - dataset.index.name: ['LactGlc', 'LactGln', 'GluGln'], - **{col: [lact_glc[i], lact_gln[i], glu_gln[i]] for i, col in enumerate(dataset.columns)} + dataset.index.name: ['LactGlc', 'LactGln','LactO2', 'GluGln'], + **{col: [lact_glc[i], lact_gln[i],lact_o2[i], glu_gln[i]] for i, col in enumerate(dataset.columns)} }) # Reset the index of the original dataset and append new rows