-
Notifications
You must be signed in to change notification settings - Fork 15
Description
Hello @cdanielmachado, other developers and all in the community,
I am interested in performing analysis on my genome-scale community model, which I created using CarveMe. Specifically, I want to utilize some of the functions found in ReFramed, including the SteadyCom function. However, I am facing two main issues:
Lack of Documentation: I could not find much documentation on how to use the functions provided by ReFramed, including SteadyCom. Detailed examples and explanations would be extremely helpful.
KeyError: I keep encountering the following error when I attempt to run my analysis:
KeyError: 'community_biomass_dehalobacter_community_carveme'
Here is the code I am using:
import reframed
from reframed import load_cbmodel
from reframed.community.model import Community
from reframed.community.SteadyCom import SteadyCom
import pandas as pd
import matplotlib.pyplot as plt
# Path to the community model SBML file
community_model_path = "~/dehalobacter_community_carveme.xml"
# Load the community model
community_model = load_cbmodel(community_model_path)
# Initialize Community object with the loaded community model
community = Community("dehalobacter_community", [community_model])
# Define a new medium for the community in ReFramed format
new_medium_reframed = {
'EX_meoh_e': 10.0,
'EX_124triclbenz_e': 10.0,
'EX_co2_e': 50.0,
'EX_ca2_e': 1000,
'EX_fe2_e': 1000,
'EX_mobd_e': 1000,
'EX_thm_e': 0.1,
'EX_fol_e': 0.1,
'EX_cl_e': 1000.0,
'EX_fe3_e': 0.1,
'EX_h2_e': 1000.0,
'EX_h_e': 10,
'EX_h2o_e': 1000.0,
'EX_k_e': 1000.0,
'EX_mg2_e': 1000.0,
'EX_nh4_e': 1000,
'EX_pi_e': 1000.0,
'EX_so4_e': 1000.0,
'EX_mn2_e': 1000.0,
'EX_zn2_e': 1000.0,
'EX_cobalt2_e': 1000.0,
'EX_cu2_e': 1000.0,
'EX_h2s_e': 5.0,
}
# Update the community's medium
community.medium = new_medium_reframed
# Perform SteadyCom analysis
steadycom_result = SteadyCom(community)
# Extract and print results
print(steadycom_result)
# Convert SteadyCom results to DataFrame
df_steadycom = pd.DataFrame.from_dict(steadycom_result.values, orient='index', columns=['flux'])
df_steadycom.reset_index(inplace=True)
df_steadycom.columns = ['reaction', 'flux']
# Save SteadyCom results to CSV
df_steadycom.to_csv('dehalobacter_community_steadycom_results.csv', index=False)
# Plot SteadyCom results
plt.figure(figsize=(10, 6))
df_steadycom_sorted = df_steadycom.sort_values(by='flux', ascending=False).head(20) # Select top 20 reactions by flux
df_steadycom_sorted.plot(x='reaction', y='flux', kind='bar', legend=False, color='green')
plt.title('SteadyCom Analysis Results')
plt.ylabel('Flux')
plt.xlabel('Reaction')
plt.tight_layout()
plt.xticks(rotation=90)
plt.savefig('dehalobacter_community_steadycom_results.png')
plt.show()
It is odd that I get this KeyError since the model I have contains a biomass equation called "community_growth".
Could you please provide guidance on how to resolve the KeyError and any additional documentation or examples for using ReFramed's functions, particularly SteadyCom? I can also provide the genome-scale community model (GEM) file if needed.
Thank you for your assistance!