Skip to content

Commit

Permalink
fix: adding missing references to category presets (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jul 12, 2024
1 parent 36da785 commit ec715ce
Show file tree
Hide file tree
Showing 7 changed files with 673 additions and 15 deletions.
129 changes: 129 additions & 0 deletions backend/seqvars/migrations/0004_auto_20240712_1236.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Generated by Django 3.2.25 on 2024-07-12 12:36

import typing

import django.core.serializers.json
from django.db import migrations, models
import django.db.models.deletion
import django_pydantic_field.compat.django
import django_pydantic_field.fields

import seqvars.models


class Migration(migrations.Migration):

dependencies = [
("seqvars", "0003_seqvarsquerysettings_predefinedquery"),
]

operations = [
migrations.AddField(
model_name="seqvarsquerysettings",
name="clinvarpresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsclinvar",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="columnspresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetscolumns",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="consequencepresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsconsequence",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="frequencypresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsfrequency",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="genotypepresets",
field=django_pydantic_field.fields.PydanticSchemaField(
blank=True,
config=None,
default={"choice": None},
encoder=django.core.serializers.json.DjangoJSONEncoder,
null=True,
schema=django_pydantic_field.compat.django.GenericContainer(
typing.Union, (seqvars.models.SeqvarsGenotypePresets, type(None))
),
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="locuspresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetslocus",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="phenotypepriopresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsphenotypeprio",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="qualitypresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsquality",
),
),
migrations.AddField(
model_name="seqvarsquerysettings",
name="variantpriopresets",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
to="seqvars.seqvarsquerypresetsvariantprio",
),
),
migrations.AlterField(
model_name="seqvarspredefinedquery",
name="genotype",
field=django_pydantic_field.fields.PydanticSchemaField(
blank=True,
config=None,
default={"choice": None},
encoder=django.core.serializers.json.DjangoJSONEncoder,
null=True,
schema=django_pydantic_field.compat.django.GenericContainer(
typing.Union, (seqvars.models.SeqvarsGenotypePresets, type(None))
),
),
),
]
45 changes: 44 additions & 1 deletion backend/seqvars/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,10 @@ class SeqvarsPredefinedQuery(SeqvarsQueryPresetsBase):

#: The chosen genotype presets.
genotype = SchemaField(
schema=typing.Optional[SeqvarsGenotypePresets], default=SeqvarsGenotypePresets()
schema=typing.Optional[SeqvarsGenotypePresets],
default=SeqvarsGenotypePresets(),
null=True,
blank=True,
)

#: The chosen quality presets.
Expand Down Expand Up @@ -731,6 +734,46 @@ class SeqvarsQuerySettings(BaseModel):
SeqvarsPredefinedQuery, on_delete=models.PROTECT, null=True, blank=True
)

#: The chosen genotype presets.
genotypepresets = SchemaField(
schema=typing.Optional[SeqvarsGenotypePresets],
default=SeqvarsGenotypePresets(),
null=True,
blank=True,
)
#: The chosen quality presets.
qualitypresets = models.ForeignKey(
SeqvarsQueryPresetsQuality, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen frequency presets.
frequencypresets = models.ForeignKey(
SeqvarsQueryPresetsFrequency, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen consequence presets.
consequencepresets = models.ForeignKey(
SeqvarsQueryPresetsConsequence, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen locus presets.
locuspresets = models.ForeignKey(
SeqvarsQueryPresetsLocus, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen phenotype priorization presets.
phenotypepriopresets = models.ForeignKey(
SeqvarsQueryPresetsPhenotypePrio, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen variant priorization presets.
variantpriopresets = models.ForeignKey(
SeqvarsQueryPresetsVariantPrio, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen clinvar presets.
clinvarpresets = models.ForeignKey(
SeqvarsQueryPresetsClinvar, on_delete=models.SET_NULL, null=True, blank=True
)
#: The chosen columns presets.
columnspresets = models.ForeignKey(
SeqvarsQueryPresetsColumns, on_delete=models.SET_NULL, null=True, blank=True
)

def __str__(self):
return f"SeqvarsQuerySettings '{self.sodar_uuid}'"

Expand Down
127 changes: 126 additions & 1 deletion backend/seqvars/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import typing
from typing import Optional

from django_pydantic_field.rest_framework import SchemaField
Expand Down Expand Up @@ -410,7 +411,10 @@ class SeqvarsPredefinedQuerySerializer(QueryPresetsBaseSerializer):
included_in_sop = serializers.BooleanField(required=False, default=False)

genotype = SchemaField(
schema=Optional[SeqvarsGenotypePresets], default=SeqvarsGenotypePresets()
schema=Optional[SeqvarsGenotypePresets],
required=False,
allow_null=True,
default=None,
)

quality = serializers.SlugRelatedField(
Expand Down Expand Up @@ -772,6 +776,42 @@ class SeqvarsQuerySettingsSerializer(BaseModelSerializer):
#: Serialize ``predefinedquery`` as its ``sodar_uuid``.
predefinedquery = serializers.ReadOnlyField(source="predefinedquery.sodar_uuid")

#: Serialize ``genotypepresets`` as its ``sodar_uuid``.
genotypepresets = SchemaField(
schema=typing.Optional[SeqvarsGenotypePresets],
required=False,
allow_null=True,
default=None,
)
#: Serialize ``qualitypresets`` as its ``sodar_uuid``.
qualitypresets = serializers.ReadOnlyField(
source="qualitypresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``consequencepresets`` as its ``sodar_uuid``.
consequencepresets = serializers.ReadOnlyField(
source="consequencepresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``locuspresets`` as its ``sodar_uuid``.
locuspresets = serializers.ReadOnlyField(
source="locuspresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``frequencypresets`` as its ``sodar_uuid``.
frequencypresets = serializers.ReadOnlyField(
source="frequencypresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``phenotypepriopresets`` as its ``sodar_uuid``.
phenotypepriopresets = serializers.ReadOnlyField(
source="phenotypepriopresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``variantpriopresets`` as its ``sodar_uuid``.
variantpriopresets = serializers.ReadOnlyField(
source="variantpriopresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``clinvarpresets`` as its ``sodar_uuid``.
clinvarpresets = serializers.ReadOnlyField(
source="clinvarpresets.sodar_uuid", required=False, allow_null=True, default=None
)

#: Serialize ``genotype`` as its ``sodar_uuid``.
genotype = serializers.ReadOnlyField(source="genotype.sodar_uuid")
#: Serialize ``quality`` as its ``sodar_uuid``.
Expand Down Expand Up @@ -801,6 +841,14 @@ class Meta:
"session",
"presetssetversion",
"predefinedquery",
"genotypepresets",
"qualitypresets",
"consequencepresets",
"locuspresets",
"frequencypresets",
"phenotypepriopresets",
"variantpriopresets",
"clinvarpresets",
"genotype",
"quality",
"consequence",
Expand All @@ -822,6 +870,35 @@ class SeqvarsQuerySettingsDetailsSerializer(
owned category settings.
"""

#: Serialize ``qualitypresets`` as its ``sodar_uuid``.
qualitypresets = serializers.UUIDField(
source="qualitypresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``consequencepresets`` as its ``sodar_uuid``.
consequencepresets = serializers.UUIDField(
source="consequencepresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``locuspresets`` as its ``sodar_uuid``.
locuspresets = serializers.UUIDField(
source="locuspresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``frequencypresets`` as its ``sodar_uuid``.
frequencypresets = serializers.UUIDField(
source="frequencypresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``phenotypepriopresets`` as its ``sodar_uuid``.
phenotypepriopresets = serializers.UUIDField(
source="phenotypepriopresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``variantpriopresets`` as its ``sodar_uuid``.
variantpriopresets = serializers.UUIDField(
source="variantpriopresets.sodar_uuid", required=False, allow_null=True, default=None
)
#: Serialize ``clinvarpresets`` as its ``sodar_uuid``.
clinvarpresets = serializers.UUIDField(
source="clinvarpresets.sodar_uuid", required=False, allow_null=True, default=None
)

#: Nested serialization of the genotype settings.
genotype = SeqvarsQuerySettingsGenotypeSerializer()
#: Nested serialization of the quality settings.
Expand All @@ -839,6 +916,54 @@ class SeqvarsQuerySettingsDetailsSerializer(
#: Nested serialization of the clinvar settings.
clinvar = SeqvarsQuerySettingsClinvarSerializer()

def validate(self, data):
data = super().validate(data)

if "qualitypresets" in data:
qualitypresets_uuid = data.pop("qualitypresets")["sodar_uuid"]
if qualitypresets_uuid:
data["qualitypresets"] = SeqvarsQueryPresetsQuality.objects.get(
sodar_uuid=qualitypresets_uuid
)
if "consequencepresets" in data:
consequencepresets_uuid = data.pop("consequencepresets")["sodar_uuid"]
if consequencepresets_uuid:
data["consequencepresets"] = SeqvarsQueryPresetsConsequence.objects.get(
sodar_uuid=consequencepresets_uuid
)
if "locuspresets" in data:
locuspresets_uuid = data.pop("locuspresets")["sodar_uuid"]
if locuspresets_uuid:
data["locuspresets"] = SeqvarsQueryPresetsLocus.objects.get(
sodar_uuid=locuspresets_uuid
)
if "frequencypresets" in data:
frequencypresets_uuid = data.pop("frequencypresets")["sodar_uuid"]
if frequencypresets_uuid:
data["frequencypresets"] = SeqvarsQueryPresetsFrequency.objects.get(
sodar_uuid=frequencypresets_uuid
)
if "phenotypepriopresets" in data:
phenotypepriopresets_uuid = data.pop("phenotypepriopresets")["sodar_uuid"]
if phenotypepriopresets_uuid:
data["phenotypepriopresets"] = SeqvarsQueryPresetsPhenotypePrio.objects.get(
sodar_uuid=phenotypepriopresets_uuid
)
if "variantpriopresets" in data:
variantpriopresets_uuid = data.pop("variantpriopresets")["sodar_uuid"]
if variantpriopresets_uuid:
data["variantpriopresets"] = SeqvarsQueryPresetsVariantPrio.objects.get(
sodar_uuid=variantpriopresets_uuid
)
if "clinvarpresets" in data:
clinvarpresets_uuid = data.pop("clinvarpresets")["sodar_uuid"]
if clinvarpresets_uuid:
data["clinvarpresets"] = SeqvarsQueryPresetsClinvar.objects.get(
sodar_uuid=clinvarpresets_uuid
)

return data

class Meta:
model = SeqvarsQuerySettingsSerializer.Meta.model
fields = SeqvarsQuerySettingsSerializer.Meta.fields + [
Expand Down
Loading

0 comments on commit ec715ce

Please sign in to comment.