From 4a703ed803595ef6f0a2f7b792b771d982866b65 Mon Sep 17 00:00:00 2001 From: Kalev Takkis Date: Mon, 12 Feb 2024 13:03:08 +0000 Subject: [PATCH] Some changes to cset_upload.py to allow site observation short codes (#527) * stashing * fix: cset_upload.py updated to allow new-style site observation codes NB! this probably still won't work! I suspect the file I was given is broken and I cannot test it further --- viewer/cset_upload.py | 25 ++++++++++++++++--------- viewer/sdf_check.py | 8 +++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/viewer/cset_upload.py b/viewer/cset_upload.py index f1e84b6f..9cbeed32 100644 --- a/viewer/cset_upload.py +++ b/viewer/cset_upload.py @@ -198,9 +198,12 @@ def get_site_observation( zfile_hashvals=zfile_hashvals, ) else: - name = f'{compound_set.target.title}-{pdb_fn}' + name = pdb_fn try: - site_obvs = SiteObservation.objects.get(code__contains=name) + site_obvs = SiteObservation.objects.get( + code__contains=name, + experiment__experiment_upload__target__title=target, + ) except SiteObservation.DoesNotExist: # Initial SiteObservation lookup failed. logger.warning( @@ -210,7 +213,10 @@ def get_site_observation( ) # Try alternatives. # If all else fails then the site_obvs will be 'None' - qs = SiteObservation.objects.filter(code__contains=name) + qs = SiteObservation.objects.filter( + code__contains=name, + experiment__experiment_upload__target__title=target, + ) if qs.exists(): logger.info( 'Found SiteObservation containing name=%s qs=%s', @@ -219,7 +225,10 @@ def get_site_observation( ) else: alt_name = name.split(':')[0].split('_')[0] - qs = SiteObservation.objects.filter(code__contains=alt_name) + qs = SiteObservation.objects.filter( + code__contains=alt_name, + experiment__experiment_upload__target__title=target, + ) if qs.exists(): logger.info( 'Found SiteObservation containing alternative name=%s qs=%s', @@ -328,15 +337,13 @@ def set_mol( # try exact match first try: site_obvs = SiteObservation.objects.get( - code__contains=str(compound_set.target.title + '-' + i), + code=str(i), experiment__experiment_upload__target_id=compound_set.target, ) ref = site_obvs except SiteObservation.DoesNotExist: qs = SiteObservation.objects.filter( - code__contains=str( - compound_set.target.title + '-' + i.split(':')[0].split('_')[0] - ), + code=str(i.split(':')[0].split('_')[0]), experiment__experiment_upload__target_id=compound_set.target, ) if not qs.exists(): @@ -503,7 +510,7 @@ def set_descriptions( computed_set.save() description_dict = description_mol.GetPropsAsDict() - for key in list(description_dict.keys()): + for key in description_dict.keys(): if key in descriptions_needed and key not in [ 'ref_mols', 'ref_pdb', diff --git a/viewer/sdf_check.py b/viewer/sdf_check.py index 949f1001..411128e4 100755 --- a/viewer/sdf_check.py +++ b/viewer/sdf_check.py @@ -89,10 +89,12 @@ def check_refmol(mol, validate_dict, target=None): for ref_mol in ref_mols: ref_strip = ref_mol.strip() - query_string = f'{target}-' + ref_strip.split(':')[0].split('_')[0] - query = SiteObservation.objects.filter(code__contains=query_string) + query = SiteObservation.objects.filter( + code=ref_strip, + experiment__experiment_upload__target__title=target, + ) if len(query) == 0: - msg = f"No SiteObservation code contains '{query_string}'" + msg = f"No SiteObservation code contains '{ref_strip}'" validate_dict = add_warning( molecule_name=mol.GetProp('_Name'), field='ref_mol',