Skip to content

Commit 509d4df

Browse files
alanbchristiekaliifAlan Christie
authored
Align 1247 with staging (#631)
* fix: updated crystalform site tag generation scheme * fix: update tag generation scheme * fix: remove version field from ComputedMolecule Field was added in error, explicit version tracking is not necessary * fix: forgot to stage migration file.. * fix: fix querysets in target_loader.py Came up with pose generation - SiteObservation querysets were called over the entire table not by the target they should have been associated with. * fix: add warning to logs about overwriting ComputedMolecule metadata * fix: add additional ccp4 files to download (issue 1448) * fix: updates to tag generation Changed how some of the tags are generated as per the comment here: m2ms/fragalysis-frontend#1482 (comment) * feat: added centroid_res field to CanonSite model Also, removed fetching centroid_res from CANON_SITES_FILE. Seems that now it's being added to meta_aligner.yaml, so reading an additional file is not necessary. I hope... * feat: added new fields to metadata.csv Experiment code and centroid res * feat: added tag aliases to metadata.csv * Copies Target proposals to new (RHS) Compounds (#629) * fix: Branch for project reference fix * fix: Projects copied from Target (during RHS cset-upload) * fix: Add save before copying projects * fix: Remove unnecessary save() * ci: Attempt to fix docker-compose problem * ci: Fix staging and production builds (docker compose) --------- Co-authored-by: Alan Christie <alan.christie@matildapeak.com> --------- Co-authored-by: Kalev Takkis <ktakkis@informaticsmatters.com> Co-authored-by: Alan Christie <alan.christie@matildapeak.com>
1 parent 96fb1cb commit 509d4df

8 files changed

+100
-40
lines changed

.github/workflows/build-dev.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,11 @@ jobs:
8585
with:
8686
context: .
8787
tags: ${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ env.GITHUB_REF_SLUG }}
88-
- name: Test
89-
run: >
90-
docker-compose -f docker-compose.test.yml up
91-
--build
92-
--exit-code-from tests
93-
--abort-on-container-exit
88+
- name: Test (docker compose)
89+
uses: hoverkraft-tech/compose-action@v2.0.1
90+
with:
91+
compose-file: ./docker-compose.test.yml
92+
up-flags: --build --exit-code-from tests --abort-on-container-exit
9493
env:
9594
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
9695
BE_IMAGE_TAG: ${{ env.GITHUB_REF_SLUG }}

.github/workflows/build-production.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,11 @@ jobs:
134134
tags: |
135135
${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ steps.vars.outputs.tag }}
136136
${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:stable
137-
- name: Test
138-
run: >
139-
docker-compose -f docker-compose.test.yml up
140-
--build
141-
--exit-code-from tests
142-
--abort-on-container-exit
137+
- name: Test (docker compose)
138+
uses: hoverkraft-tech/compose-action@v2.0.1
139+
with:
140+
compose-file: ./docker-compose.test.yml
141+
up-flags: --build --exit-code-from tests --abort-on-container-exit
143142
env:
144143
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
145144
BE_IMAGE_TAG: ${{ steps.vars.outputs.tag }}

.github/workflows/build-staging.yaml

+5-6
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ jobs:
154154
with:
155155
context: .
156156
tags: ${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ steps.vars.outputs.tag }}
157-
- name: Test
158-
run: >
159-
docker-compose -f docker-compose.test.yml up
160-
--build
161-
--exit-code-from tests
162-
--abort-on-container-exit
157+
- name: Test (docker compose)
158+
uses: hoverkraft-tech/compose-action@v2.0.1
159+
with:
160+
compose-file: ./docker-compose.test.yml
161+
up-flags: --build --exit-code-from tests --abort-on-container-exit
163162
env:
164163
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
165164
BE_IMAGE_TAG: ${{ steps.vars.outputs.tag }}

viewer/cset_upload.py

+13
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ def create_mol(self, inchi, target, name=None) -> Compound:
303303
for project in target.project_set.all():
304304
cpd.project_id.add(project)
305305
cpd.save()
306+
# This is a new compound.
307+
# We must now set relationships to the Proposal that it applies to.
308+
# We do this by copying the relationships from the Target.
309+
num_target_proposals = len(target.project_id.all())
310+
assert num_target_proposals > 0
311+
if num_target_proposals > 1:
312+
logger.warning(
313+
'Compound Target %s has more than one Proposal (%d)',
314+
target.title,
315+
num_target_proposals,
316+
)
317+
for project in target.project_set.all():
318+
cpd.project_id.add(project)
306319
except MultipleObjectsReturned as exc:
307320
# NB! when processing new uploads, Compound is always
308321
# fetched by inchi_key, so this shouldn't ever create

viewer/download_structures.py

+42-3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ def __init__(self, category):
104104
# fmt: on
105105

106106

107+
class UploadTagSubquery(Subquery):
108+
"""Annotate SiteObservation with tag of given category"""
109+
110+
def __init__(self, category):
111+
# fmt: off
112+
query = SiteObservationTag.objects.filter(
113+
pk=Subquery(
114+
SiteObvsSiteObservationTag.objects.filter(
115+
site_observation=OuterRef(OuterRef('pk')),
116+
site_obvs_tag__category=TagCategory.objects.get(
117+
category=category,
118+
),
119+
).values('site_obvs_tag')[:1]
120+
)
121+
).values('upload_name')[0:1]
122+
super().__init__(query)
123+
# fmt: on
124+
125+
107126
class CuratedTagSubquery(Exists):
108127
"""Annotate SiteObservation with tag of given category"""
109128

@@ -427,14 +446,34 @@ def _metadata_file_zip(ziparchive, target, site_observations):
427446
logger.info('+ Processing metadata')
428447

429448
annotations = {}
430-
values = ['code', 'longcode', 'cmpd__compound_code', 'smiles', 'downloaded']
431-
header = ['Code', 'Long code', 'Compound code', 'Smiles', 'Downloaded']
449+
values = [
450+
'code',
451+
'longcode',
452+
'experiment__code',
453+
'cmpd__compound_code',
454+
'smiles',
455+
'canon_site_conf__canon_site__centroid_res',
456+
'downloaded',
457+
]
458+
header = [
459+
'Code',
460+
'Long code',
461+
'Experiment code',
462+
'Compound code',
463+
'Smiles',
464+
'Centroid res',
465+
'Downloaded',
466+
]
432467

433468
for category in TagCategory.objects.filter(category__in=TAG_CATEGORIES):
434469
tag = f'tag_{category.category.lower()}'
470+
upload_tag = f'upload_tag_{category.category.lower()}'
435471
values.append(tag)
436-
header.append(category.category)
472+
header.append(f'{category.category} alias')
437473
annotations[tag] = TagSubquery(category.category)
474+
values.append(upload_tag)
475+
header.append(f'{category.category} upload name')
476+
annotations[upload_tag] = UploadTagSubquery(category.category)
438477

439478
pattern = re.compile(r'\W+') # non-alphanumeric characters
440479
for tag in SiteObservationTag.objects.filter(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.2.25 on 2024-07-29 12:50
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('viewer', '0059_remove_computedmolecule_version'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='canonsite',
15+
name='centroid_res',
16+
field=models.TextField(null=True),
17+
),
18+
]

viewer/models.py

+1
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ class CanonSite(Versionable, models.Model):
409409
canon_site_num = models.IntegerField(
410410
null=True, help_text="numeric canon site id (enumerated on creation)"
411411
)
412+
centroid_res = models.TextField(null=True)
412413

413414
objects = models.Manager()
414415
filter_manager = CanonSiteDataManager()

viewer/target_loader.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
# assemblies and xtalforms
5353
XTALFORMS_FILE = "assemblies.yaml"
5454

55-
# canon site tag names
56-
CANON_SITES_FILE = "canonical_sites.yaml"
57-
5855
# target name, nothing else
5956
CONFIG_FILE = "config*.yaml"
6057

@@ -1086,6 +1083,7 @@ def process_canon_site(
10861083
10871084
Incoming data format:
10881085
<id: str>:
1086+
centroid_res: <str>
10891087
conformer_site_ids: <array[str]>
10901088
global_reference_dtag: <str>
10911089
reference_conformer_site_id: <str>
@@ -1109,6 +1107,9 @@ def process_canon_site(
11091107
)
11101108

11111109
residues = extract(key="residues", return_type=list)
1110+
centroid_res = extract(key="centroid_res")
1111+
conf_sites_ids = extract(key="conformer_site_ids", return_type=list)
1112+
ref_conf_site_id = extract(key="reference_conformer_site_id")
11121113

11131114
fields = {
11141115
"name": canon_site_id,
@@ -1117,11 +1118,9 @@ def process_canon_site(
11171118

11181119
defaults = {
11191120
"residues": residues,
1121+
"centroid_res": centroid_res,
11201122
}
11211123

1122-
conf_sites_ids = extract(key="conformer_site_ids", return_type=list)
1123-
ref_conf_site_id = extract(key="reference_conformer_site_id")
1124-
11251124
index_data = {
11261125
"ref_conf_site": ref_conf_site_id,
11271126
"conformer_site_ids": conf_sites_ids,
@@ -1477,10 +1476,9 @@ def process_bundle(self):
14771476
config = self._load_yaml(config_file)
14781477
meta = self._load_yaml(Path(upload_dir).joinpath(METADATA_FILE))
14791478
xtalforms_yaml = self._load_yaml(Path(upload_dir).joinpath(XTALFORMS_FILE))
1480-
canon_sites_yaml = self._load_yaml(Path(upload_dir).joinpath(CANON_SITES_FILE))
14811479

14821480
# this is the last file to load. if any of the files missing, don't continue
1483-
if not any([meta, config, xtalforms_yaml, canon_sites_yaml]):
1481+
if not any([meta, config, xtalforms_yaml]):
14841482
msg = "Missing files in uploaded data, aborting"
14851483
raise FileNotFoundError(msg)
14861484

@@ -1795,16 +1793,12 @@ def process_bundle(self):
17951793

17961794
logger.debug("data read and processed, adding tags")
17971795

1798-
canon_name_tag_map = {
1799-
k: v["centroid_res"] if "centroid_res" in v.keys() else "UNDEFINED"
1800-
for k, v in canon_sites_yaml.items()
1801-
}
1802-
18031796
# tag site observations
18041797
cat_canon = TagCategory.objects.get(category="CanonSites")
18051798
for val in canon_site_objects.values(): # pylint: disable=no-member
18061799
prefix = val.instance.canon_site_num
1807-
tag = canon_name_tag_map.get(val.versioned_key, "UNDEFINED")
1800+
# tag = canon_name_tag_map.get(val.versioned_key, "UNDEFINED")
1801+
tag = val.versioned_key
18081802
so_list = SiteObservation.objects.filter(
18091803
canon_site_conf__canon_site=val.instance
18101804
)
@@ -1823,12 +1817,10 @@ def process_bundle(self):
18231817
f"{val.instance.canon_site.canon_site_num}"
18241818
+ f"{next(numerators[val.instance.canon_site.canon_site_num])}"
18251819
)
1826-
tag = val.instance.name.split('+')[0]
1820+
# tag = val.instance.name.split('+')[0]
1821+
tag = val.instance.name
18271822
so_list = [
1828-
site_observation_objects[k].instance
1829-
for k in val.index_data["members"]
1830-
# site_observations_versioned[k]
1831-
# for k in val.index_data["members"]
1823+
site_observation_objects[k].instance for k in val.index_data["members"]
18321824
]
18331825
self._tag_observations(
18341826
tag, prefix, category=cat_conf, site_observations=so_list, hidden=True

0 commit comments

Comments
 (0)