Skip to content

Commit

Permalink
Bug fixes for dependencies #85
Browse files Browse the repository at this point in the history
minor bug fixes
  • Loading branch information
f3rryman committed Sep 27, 2023
1 parent 6e3edc2 commit cf8b6e7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</p>

# refineGEMs
`refineGEMs` is a python package inteded to help with the curation of genome-scale metabolic models (GEMS).
`refineGEMs` is a python package intended to help with the curation of genome-scale metabolic models (GEMS).

## Documentation
The docs can be found [here](https://refinegems.readthedocs.io/en/latest/).
Expand Down
13 changes: 9 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main(configpath=None):
if (config['single']):
try:
model_cobra, errors = cobra.io.sbml.validate_sbml_model(config['model'])
logging.info(errors)
#logging.info(errors)
except (OSError):
model_cobra = None
logging.info('No or no valid model given, please enter a valid path in the model field in the config file.')
Expand Down Expand Up @@ -162,14 +162,19 @@ def main(configpath=None):
if any(mods):
if config['model_out'] == 'stdout':
config['model_out'] = config['out_path'] + model_libsbml.getId() + '_modified_' + str(today) + '.xml'

rg.io.write_to_file(model_libsbml, config['model_out'])

try:
rg.io.write_to_file(model_libsbml, config['model_out'])
except (OSError) as e:
logging.info(e)
logging.info("Model could not be saved...")

if model_cobra is not None:
try:
model_cobra, errors = cobra.io.sbml.validate_sbml_model(config['model_out'])
logging.info(errors)
except (OSError):
except (OSError) as e:
logging.info(e)
model_cobra = None
logging.info('Model was invalidated during curation steps.')

Expand Down
2 changes: 1 addition & 1 deletion refinegems/growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def get_growth_selected_media(model: cobraModel, media: list[str], basis: str, a
growth_one = growth_one_medium_from_default(model, medium_df, anaerobic)
elif (basis == 'minimal_uptake'):
growth_one = growth_one_medium_from_minimal(model, medium_df, anaerobic)
growth = growth.append(growth_one, ignore_index=True)
growth = pd.concat([growth, growth_one], ignore_index=True) # pd.append is deprecated
return growth


Expand Down
2 changes: 1 addition & 1 deletion refinegems/investigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def get_egc(model: cobraModel) -> pd.DataFrame:
rxn = Reaction(row['type'])
rxn.name = 'Test ' + row['type'] + ' dissipation reaction'
rxn.add_metabolites(met_atp)
model.add_reaction(rxn)
model.add_reactions([rxn]) # add_reactions instead of add_reaction -> needs list of reactions
except(KeyError):
dissipation_rxns.drop(dissipation_rxns[dissipation_rxns['type'] == row['type']].index, inplace=True)

Expand Down
13 changes: 8 additions & 5 deletions refinegems/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def load_medium_from_db(mediumname: str) -> pd.DataFrame:
Returns:
pd.DataFrame: Table containing composition for one medium with metabs added as BiGG_EX exchange reactions
"""
medium_query = f"SELECT * FROM media m JOIN media_compositions mc ON m.id = mc.medium_id WHERE m.medium = '{mediumname}'"
medium_query = f"SELECT * FROM media m JOIN media_compositions mc ON m.id = mc.medium_id WHERE m.medium = '{mediumname}'"
medium = load_a_table_from_database(medium_query)
medium = medium[['medium', 'medium_description', 'BiGG', 'substance']]
medium['BiGG_R'] = 'R_EX_' + medium['BiGG'] + '_e'
Expand Down Expand Up @@ -168,7 +168,7 @@ def load_a_table_from_database(table_name_or_query: str) -> pd.DataFrame:
engine = sqlalchemy.create_engine(sqlalchemy_engine_input)
open_con = engine.connect()

db_table = pd.read_sql(table_name_or_query, open_con)
db_table = pd.read_sql(sqlalchemy.text(table_name_or_query), open_con)

open_con.close()
return db_table
Expand Down Expand Up @@ -220,9 +220,12 @@ def write_to_file(model: libModel, new_filename: str):
- model (libModel): Model loaded with libSBML
- new_filename (str): Filename|Path for modified model
"""
new_document = model.getSBMLDocument()
writeSBMLToFile(new_document, new_filename)
logging.info("Modified model written to " + new_filename)
try:
new_document = model.getSBMLDocument()
writeSBMLToFile(new_document, new_filename)
logging.info("Modified model written to " + new_filename)
except (OSError) as e:
print("Could not write to file. Wrong path?")


def write_report(dataframe: pd.DataFrame, filepath: str):
Expand Down
34 changes: 17 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@
url='https://github.com/draeger-lab/refinegems',
license='MIT',
packages=['refinegems'],
python_requires ='>=3.8, <3.10',
python_requires ='>=3.8, <3.11',
install_requires = [
"cobra==0.22.0",
"biopython==1.79",
"cobra>=0.26.0", # cobra changed model.add_reaction to model.add_reactions -> important in investigate.py
"biopython>=1.79",
"bioregistry",
"bioservices",
"importlib-resources<=5.13.0",
"memote==0.13.0",
"pandas==1.2.4",
"numpy==1.20.3",
"gffutils==0.10.1",
"markupsafe==2.0.1",
"depinfo==1.7.0",
"sortedcontainers==2.4.0",
"libchebipy==1.0.10",
"ratelimit==2.2.1",
"sqlalchemy==1.4.43",
"venn==0.1.3",
"ols-client==0.1.3",
"seaborn==0.12.2",
"click==8.1.3"
"memote>=0.13.0",
"pandas>=1.2.4",
"numpy>=1.20.3",
"gffutils>=0.10.1",
"markupsafe>=2.0.1",
"depinfo>=1.7.0",
"sortedcontainers>=2.4.0",
"libchebipy>=1.0.10",
"ratelimit>=2.2.1",
"sqlalchemy>=1.4.43",
"venn>=0.1.3",
"ols-client>=0.1.3",
"seaborn>=0.12.2",
"click>=8.1.3"
],
zip_safe=False,
include_package_data=True,
Expand Down

0 comments on commit cf8b6e7

Please sign in to comment.