Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align 1247 with staging #631

Merged
merged 18 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,11 @@ jobs:
with:
context: .
tags: ${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ env.GITHUB_REF_SLUG }}
- name: Test
run: >
docker-compose -f docker-compose.test.yml up
--build
--exit-code-from tests
--abort-on-container-exit
- name: Test (docker compose)
uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: ./docker-compose.test.yml
up-flags: --build --exit-code-from tests --abort-on-container-exit
env:
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
BE_IMAGE_TAG: ${{ env.GITHUB_REF_SLUG }}
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/build-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,11 @@ jobs:
tags: |
${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ steps.vars.outputs.tag }}
${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:stable
- name: Test
run: >
docker-compose -f docker-compose.test.yml up
--build
--exit-code-from tests
--abort-on-container-exit
- name: Test (docker compose)
uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: ./docker-compose.test.yml
up-flags: --build --exit-code-from tests --abort-on-container-exit
env:
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
BE_IMAGE_TAG: ${{ steps.vars.outputs.tag }}
Expand Down
11 changes: 5 additions & 6 deletions .github/workflows/build-staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ jobs:
with:
context: .
tags: ${{ steps.vars.outputs.BE_NAMESPACE }}/fragalysis-backend:${{ steps.vars.outputs.tag }}
- name: Test
run: >
docker-compose -f docker-compose.test.yml up
--build
--exit-code-from tests
--abort-on-container-exit
- name: Test (docker compose)
uses: hoverkraft-tech/compose-action@v2.0.1
with:
compose-file: ./docker-compose.test.yml
up-flags: --build --exit-code-from tests --abort-on-container-exit
env:
BE_NAMESPACE: ${{ steps.vars.outputs.BE_NAMESPACE }}
BE_IMAGE_TAG: ${{ steps.vars.outputs.tag }}
Expand Down
20 changes: 16 additions & 4 deletions viewer/cset_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ def create_mol(self, inchi, target, name=None) -> Compound:
current_identifier=name,
)
cpd.save()
# This is a new compound.
# We must now set relationships to the Proposal that it applies to.
# We do this by copying the relationships from the Target.
num_target_proposals = len(target.project_id.all())
assert num_target_proposals > 0
if num_target_proposals > 1:
logger.warning(
'Compound Target %s has more than one Proposal (%d)',
target.title,
num_target_proposals,
)
for project in target.project_set.all():
cpd.project_id.add(project)
except MultipleObjectsReturned as exc:
# NB! when processing new uploads, Compound is always
# fetched by inchi_key, so this shouldn't ever create
Expand Down Expand Up @@ -339,7 +352,6 @@ def set_mol(
smiles = Chem.MolToSmiles(mol)
inchi = Chem.inchi.MolToInchi(mol)
molecule_name = mol.GetProp('_Name')
version = mol.GetProp('version')

compound: Compound = self.create_mol(
inchi, compound_set.target, name=molecule_name
Expand Down Expand Up @@ -449,8 +461,9 @@ def set_mol(
existing_computed_molecules.append(k)

if len(existing_computed_molecules) == 1:
logger.info(
'Using existing ComputedMolecule %s', existing_computed_molecules[0]
logger.warning(
'Using existing ComputedMolecule %s and overwriting its metadata',
existing_computed_molecules[0],
)
computed_molecule = existing_computed_molecules[0]
elif len(existing_computed_molecules) > 1:
Expand Down Expand Up @@ -485,7 +498,6 @@ def set_mol(
computed_molecule.pdb = lhs_so
# TODO: this is wrong
computed_molecule.pdb_info = pdb_info
computed_molecule.version = version
# Extract possible reference URL and Rationale
# URLs have to be valid URLs and rationals must contain more than one word
ref_url: Optional[str] = (
Expand Down
76 changes: 73 additions & 3 deletions viewer/download_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ def __init__(self, category):
# fmt: on


class UploadTagSubquery(Subquery):
"""Annotate SiteObservation with tag of given category"""

def __init__(self, category):
# fmt: off
query = SiteObservationTag.objects.filter(
pk=Subquery(
SiteObvsSiteObservationTag.objects.filter(
site_observation=OuterRef(OuterRef('pk')),
site_obvs_tag__category=TagCategory.objects.get(
category=category,
),
).values('site_obvs_tag')[:1]
)
).values('upload_name')[0:1]
super().__init__(query)
# fmt: on


class CuratedTagSubquery(Exists):
"""Annotate SiteObservation with tag of given category"""

Expand Down Expand Up @@ -140,6 +159,10 @@ class ArchiveFile:
'ligand_pdb': {},
'ligand_mol': {},
'ligand_smiles': {},
# additional ccp4 files, issue 1448
'event_file_crystallographic': {},
'diff_file_crystallographic': {},
'sigmaa_file_crystallographic': {},
},
'molecules': {
'sdf_files': {},
Expand Down Expand Up @@ -423,14 +446,34 @@ def _metadata_file_zip(ziparchive, target, site_observations):
logger.info('+ Processing metadata')

annotations = {}
values = ['code', 'longcode', 'cmpd__compound_code', 'smiles', 'downloaded']
header = ['Code', 'Long code', 'Compound code', 'Smiles', 'Downloaded']
values = [
'code',
'longcode',
'experiment__code',
'cmpd__compound_code',
'smiles',
'canon_site_conf__canon_site__centroid_res',
'downloaded',
]
header = [
'Code',
'Long code',
'Experiment code',
'Compound code',
'Smiles',
'Centroid res',
'Downloaded',
]

for category in TagCategory.objects.filter(category__in=TAG_CATEGORIES):
tag = f'tag_{category.category.lower()}'
upload_tag = f'upload_tag_{category.category.lower()}'
values.append(tag)
header.append(category.category)
header.append(f'{category.category} alias')
annotations[tag] = TagSubquery(category.category)
values.append(upload_tag)
header.append(f'{category.category} upload name')
annotations[upload_tag] = UploadTagSubquery(category.category)

pattern = re.compile(r'\W+') # non-alphanumeric characters
for tag in SiteObservationTag.objects.filter(
Expand Down Expand Up @@ -812,6 +855,7 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
)
)
else:
# file not in upload
archive_path = str(apath.joinpath(param))

afile = [
Expand All @@ -820,12 +864,38 @@ def _create_structures_dict(site_obvs, protein_params, other_params):
archive_path=archive_path,
)
]

else:
logger.warning('Unexpected param: %s', param)
continue

zip_contents['proteins'][param][so.code] = afile

# add additional ccp4 files (issue 1448)
ccps = ('sigmaa_file', 'diff_file', 'event_file')
if param in ccps:
# these only come from siteobservation object
model_attr = getattr(so, param)
if model_attr and model_attr != 'None':
apath = Path('aligned_files').joinpath(so.code)
ccp_path = Path(model_attr.name)
path = ccp_path.parent.joinpath(
f'{ccp_path.stem}_crystallographic{ccp_path.suffix}'
)
archive_path = str(
apath.joinpath(path.parts[-1].replace(so.longcode, so.code))
)

afile = [
ArchiveFile(
path=str(path),
archive_path=archive_path,
)
]
zip_contents['proteins'][f'{param}_crystallographic'][
so.code
] = afile

zip_contents['molecules']['single_sdf_file'] = other_params['single_sdf_file']
zip_contents['molecules']['sdf_info'] = other_params['sdf_info']

Expand Down
17 changes: 17 additions & 0 deletions viewer/migrations/0059_remove_computedmolecule_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.25 on 2024-07-10 08:31

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('viewer', '0058_auto_20240614_1016'),
]

operations = [
migrations.RemoveField(
model_name='computedmolecule',
name='version',
),
]
18 changes: 18 additions & 0 deletions viewer/migrations/0060_canonsite_centroid_res.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.25 on 2024-07-29 12:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('viewer', '0059_remove_computedmolecule_version'),
]

operations = [
migrations.AddField(
model_name='canonsite',
name='centroid_res',
field=models.TextField(null=True),
),
]
2 changes: 1 addition & 1 deletion viewer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ class CanonSite(Versionable, models.Model):
canon_site_num = models.IntegerField(
null=True, help_text="numeric canon site id (enumerated on creation)"
)
centroid_res = models.TextField(null=True)

objects = models.Manager()
filter_manager = CanonSiteDataManager()
Expand Down Expand Up @@ -1027,7 +1028,6 @@ class ComputedMolecule(models.Model):
max_length=255,
help_text="Link to pdb file; user-uploaded pdb or pdb.experiment.pdb_info",
)
version = models.PositiveSmallIntegerField(null=False, default=1)

def __str__(self) -> str:
return f"{self.smiles}"
Expand Down
Loading
Loading