diff --git a/README.md b/README.md index 57b87a01..e3a41b99 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@

# 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/). diff --git a/main.py b/main.py index 1fef7b62..d6b41aa4 100644 --- a/main.py +++ b/main.py @@ -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.') @@ -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.') diff --git a/refinegems/growth.py b/refinegems/growth.py index 903d52fb..43e48365 100644 --- a/refinegems/growth.py +++ b/refinegems/growth.py @@ -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 diff --git a/refinegems/investigate.py b/refinegems/investigate.py index fd863997..74433779 100644 --- a/refinegems/investigate.py +++ b/refinegems/investigate.py @@ -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) diff --git a/refinegems/io.py b/refinegems/io.py index 6b5c4534..5571cbe8 100644 --- a/refinegems/io.py +++ b/refinegems/io.py @@ -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' @@ -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 @@ -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): diff --git a/setup.py b/setup.py index 2422d5db..acea2b0f 100644 --- a/setup.py +++ b/setup.py @@ -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,