Skip to content

Commit

Permalink
Some changes to cset_upload.py to allow site observation short codes (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
kaliif authored Feb 12, 2024
1 parent ee98c09 commit 4a703ed
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
25 changes: 16 additions & 9 deletions viewer/cset_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 5 additions & 3 deletions viewer/sdf_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4a703ed

Please sign in to comment.