Skip to content

Commit

Permalink
Merge pull request #2151 from merenlab/reaction-network-updates
Browse files Browse the repository at this point in the history
Reaction network updates
  • Loading branch information
semiller10 authored Oct 21, 2023
2 parents c221eac + 5bfd9f2 commit 8efdd13
Showing 4 changed files with 80 additions and 8 deletions.
16 changes: 10 additions & 6 deletions anvio/biochemistry/reactionnetwork.py
Original file line number Diff line number Diff line change
@@ -1080,7 +1080,7 @@ class KODatabase:
Unless an alternative directory is provided, the database is downloaded and set up in a
default anvi'o data directory, and loaded from this directory in network construction.
"""
default_dir = os.path.join(os.path.dirname(ANVIO_PATH), 'data/MISC/KEGG/KO_REACTION_NETWORK')
default_dir = os.path.join(os.path.dirname(ANVIO_PATH), 'data/misc/KEGG/KO_REACTION_NETWORK')
expected_files = ['ko_info.txt', 'ko_data.tsv']

def __init__(self, ko_dir: str = None) -> None:
@@ -1353,7 +1353,7 @@ class ModelSEEDDatabase:
By default, the database is loaded from a default directory of ModelSEED files unless an
alternative directory is provided.
"""
default_dir = os.path.join(os.path.dirname(ANVIO_PATH), 'data/MISC/ModelSEED')
default_dir = os.path.join(os.path.dirname(ANVIO_PATH), 'data/misc/MODELSEED')

# Compounds are identified as cytosolic or extracellular in ModelSEED reactions.
compartment_ids = {0: 'c', 1: 'e'}
@@ -2199,8 +2199,10 @@ def make_contigs_database_network(
f"Here are the unrecognized KO IDs from the contigs database: {', '.join(undefined_ko_ids)}"
)

self.run.info("Reference KEGG KO database directory", self.ko_dir, nl_before=1)
self.run.info("Reference ModelSEED database directory", self.modelseed_dir)
ko_dir = KODatabase.default_dir if self.ko_dir is None else self.ko_dir
modelseed_dir = ModelSEEDDatabase.default_dir if self.modelseed_dir is None else self.modelseed_dir
self.run.info("Reference KEGG KO database directory", ko_dir, nl_before=1)
self.run.info("Reference ModelSEED database directory", modelseed_dir)

if store:
if contigs_super.a_meta['reaction_network_ko_annotations_hash']:
@@ -2654,8 +2656,10 @@ def make_pangenomic_network(
f"from the pan database: {', '.join(undefined_ko_ids)}"
)

self.run.info("Reference KEGG KO database directory", self.ko_dir, nl_before=1)
self.run.info("Reference ModelSEED database directory", self.modelseed_dir)
ko_dir = KODatabase.default_dir if self.ko_dir is None else self.ko_dir
modelseed_dir = ModelSEEDDatabase.default_dir if self.modelseed_dir is None else self.modelseed_dir
self.run.info("Reference KEGG KO database directory", ko_dir, nl_before=1)
self.run.info("Reference ModelSEED database directory", modelseed_dir)

if store:
if pan_super.p_meta['reaction_network_ko_annotations_hash']:
69 changes: 69 additions & 0 deletions anvio/migrations/contigs/v21_to_v22.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env python
# -*- coding: utf-8

import sys
import argparse

import anvio.dbinfo as dbinfo
import anvio.terminal as terminal

from anvio.errors import ConfigError

current_version, next_version = [x[1:] for x in __name__.split('_to_')]

run = terminal.Run()
progress = terminal.Progress()

def migrate(db_path):
if db_path is None:
raise ConfigError("No database path is given.")

contigs_db_info = dbinfo.ContigsDBInfo(db_path)
if str(contigs_db_info.version) != current_version:
raise ConfigError(
f"The version of the provided contigs database is {contigs_db_info.version}, "
f"not the required version, {current_version}, so this script cannot upgrade the database.")

progress.new("Migrating")
progress.update("Adding any missing database metavariables")

self_table = contigs_db_info.get_self_table()
contigs_db = contigs_db_info.load_db()
for key in [
'reaction_network_ko_annotations_hash',
'reaction_network_kegg_database_release',
'reaction_network_modelseed_database_sha'
]:
if key not in self_table:
contigs_db.set_meta_value(key, None)

progress.update("Updating version")
contigs_db.remove_meta_key_value_pair('version')
contigs_db.set_version(next_version)

progress.update("Committing changes")
contigs_db.disconnect()

progress.end()

message = (
"Congratulations! Your contigs database is now version 22. This update fixes a bug that prevented "
"construction and storage of a metabolic reaction network in version 21 databases that were created "
"from scratch and not migrated from version 20. You can blame the author of this script for the "
"oversight responsible for the bug and this annoying migration. If the version 21 database was "
"created from scratch, then placeholders for three 'metavariables' should now have been added to the "
"database; if the version 21 database migrated from version 20, then nothing at all should have "
"changed in the database except the version number."
)
run.info_single(message, nl_after=1, nl_before=1, mc='green')

if __name__ == '__main__':
parser = argparse.ArgumentParser(description=f"A simple script to upgrade an anvi'o contigs database from version {current_version} to version {next_version}")
parser.add_argument("contigs_db", metavar="CONTIGS_DB", help=f"An anvi'o contigs database of version {current_version}")
args, unknown = parser.parse_known_args()

try:
migrate(args.contigs_db)
except ConfigError as e:
print(e)
sys.exit(-1)
1 change: 0 additions & 1 deletion anvio/migrations/pan/v16_to_v17.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
import anvio.dbinfo as dbinfo
import anvio.terminal as terminal

from anvio.dbinfo import PanDBInfo
from anvio.errors import ConfigError

run = terminal.Run()
2 changes: 1 addition & 1 deletion anvio/tables/__init__.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
__email__ = "a.murat.eren@gmail.com"


contigs_db_version = "21"
contigs_db_version = "22"
profile_db_version = "38"
genes_db_version = "6"
pan_db_version = "17"

0 comments on commit 8efdd13

Please sign in to comment.