Skip to content
Snippets Groups Projects
Commit 00d3f741 authored by Bienchen's avatar Bienchen
Browse files

Use reference DB info from JSON input

parent 743319e5
Branches
No related tags found
No related merge requests found
...@@ -364,38 +364,48 @@ def _cast_release_date(release_date): ...@@ -364,38 +364,48 @@ def _cast_release_date(release_date):
raise raise
def _cmp_ref_dbs(db_dct, db_objs):
"""Compare a reference DB dict to a list of ReferenceDatabase objects.
Note: does not check the DB name!"""
for obj in db_objs:
if db_dct["release_date"] != obj.release_date:
continue
if db_dct["version"] != obj.version:
continue
for url in db_dct["location_url"]:
if url == obj.url:
return True
return False
def _get_modelcif_ref_dbs(meta_json): def _get_modelcif_ref_dbs(meta_json):
"""Get sequence databases used for monomer features.""" """Get sequence databases used for monomer features."""
# vendor formatting for DB names/ URLs, extend on KeyError # vendor formatting for DB names/ URLs, extend on KeyError
# ToDo: adapt to new JSON input # ToDo: adapt to new JSON input
sdb_dct = {} # 'sequence database list', starts as dict sdb_lst = {} # 'sequence database list' starts as dict since we need to
# compare DBs between the different monomers.
i = 0
for data in meta_json.values(): for data in meta_json.values():
i += 1
for db_name, vdct in data["databases"].items(): for db_name, vdct in data["databases"].items():
if vdct["version"] == "NA":
vdct["version"] = None
vdct["release_date"] = _cast_release_date(vdct["release_date"]) vdct["release_date"] = _cast_release_date(vdct["release_date"])
# if DB already exists, check URL and version if db_name in sdb_lst:
if db_name in sdb_dct: if _cmp_ref_dbs(vdct, sdb_lst[db_name]):
# ToDo: switch URL to the actual URL read from JSON continue
if ( else:
sdb_dct[db_name].version != vdct["version"] sdb_lst[db_name] = []
or sdb_dct[db_name].url != vdct["location_url"][0] for url in vdct["location_url"]:
): sdb_lst[db_name].append(
raise RuntimeError( modelcif.ReferenceDatabase(
"Database versions or URLs differ for " db_name,
+ f"'{db_name}': '{sdb_dct[db_name].version}/ " url,
+ f"{sdb_dct[db_name].url}' vs. '{vdct['version']}/ " version=vdct["version"],
+ f"{vdct['location_url'][0]}'" release_date=vdct["release_date"],
) )
# ToDo: deal with DBs with multiple URLs )
sdb_dct[db_name] = modelcif.ReferenceDatabase(
db_name,
vdct["location_url"][0],
version=vdct["version"],
release_date=vdct["release_date"],
)
return sdb_dct.values() return [x for sublist in sdb_lst.values() for x in sublist]
def _store_as_modelcif( def _store_as_modelcif(
...@@ -472,7 +482,7 @@ def _store_as_modelcif( ...@@ -472,7 +482,7 @@ def _store_as_modelcif(
system.target_entities, system.target_entities,
model, model,
sw_dct, sw_dct,
# ToDo: _storte_as_modelcif should not use __meta__, __meta__ is # ToDo: _store_as_modelcif should not use __meta__, __meta__ is
# tool specific # tool specific
_get_modelcif_ref_dbs(data_json["__meta__"]), _get_modelcif_ref_dbs(data_json["__meta__"]),
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment