From cfed08b9bc56ea8837b5f63194da142f148fdd4e Mon Sep 17 00:00:00 2001 From: AndiMajore <andi.majore@googlemail.com> Date: Fri, 5 May 2023 16:49:08 +0200 Subject: [PATCH] fixing drug-target-interaction update routine Former-commit-id: 0b2f1a7cbbc8478e6d464b65a75bfa2e799f9d05 [formerly 76c7bea1b462da0f1eebf7d16367320e3eeffa56] Former-commit-id: 009e32b1d3120a54f4088f5e073d264aa86ac29f --- .../management/commands/import_from_nedrex.py | 15 ++++++++++++--- scripts/docker-entrypoint.sh | 1 - 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/drugstone/management/commands/import_from_nedrex.py b/drugstone/management/commands/import_from_nedrex.py index a307523..642a330 100644 --- a/drugstone/management/commands/import_from_nedrex.py +++ b/drugstone/management/commands/import_from_nedrex.py @@ -103,7 +103,7 @@ class NedrexImporter: adjusted_name = name[:idx1 - 1].strip() if idx1 > 0 else '' if '=' in adjusted_name: idx2 = adjusted_name.index('=') - return adjusted_name[idx2+1:].strip() + return adjusted_name[idx2 + 1:].strip() return adjusted_name return name @@ -224,10 +224,11 @@ class NedrexImporter: self.cache.init_proteins() bulk = set() - existing = set() + delete = set() + existing = dict() if update: for edge in models.ProteinDrugInteraction.objects.filter(pdi_dataset=dataset): - existing.add(edge.__hash__()) + existing[edge.__hash__()] = edge source_datasets = dict() source_is_licenced = dict() @@ -248,6 +249,12 @@ class NedrexImporter: protein = self.cache.get_protein_by_uniprot(to_id(edge['targetDomainId'])) actions = json.dumps(edge['actions']) e = models.ProteinDrugInteraction(pdi_dataset=dataset, drug=drug, protein=protein, actions=actions) + if update and e.__hash__() in existing: + if existing[e.__hash__()] != e: + delete.add(existing[e.__hash__()]) + del existing[e.__hash__()] + else: + return if not update or e.__hash__() not in existing: bulk.add(e) for source in edge['dataSources']: @@ -260,6 +267,8 @@ class NedrexImporter: pass iter_edge_collection('drug_has_target', add_dpi) + for d in delete: + d.delete() models.ProteinDrugInteraction.objects.bulk_create(bulk) # new_datasets = [dataset].extend(source_datasets.values()) # DatasetLoader.remove_old_pdi_data(new_datasets, licenced) diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 4b187a4..079cbad 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -8,7 +8,6 @@ if [ -z "$DB_UPDATE_ON_START" ] || [ "$DB_UPDATE_ON_START" = "0" ] then echo "Update on startup disabled!" else - python3 manage.py populate_db --delete_model PDI python3 manage.py populate_db --update -a python3 manage.py make_graphs fi -- GitLab