Skip to content

Commit

Permalink
fix: properly representing recessive for genotypes (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jul 19, 2024
1 parent aced8af commit 8dbb5fb
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.25 on 2024-07-17 10:30

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("seqvars", "0004_auto_20240712_1236"),
]

operations = [
migrations.AddField(
model_name="seqvarsquerysettingsgenotype",
name="recessive_mode",
field=models.CharField(
choices=[
("disabled", "disabled"),
("comphet_recessive", "comphet_recessive"),
("homozygous_recessive", "homozygous_recessive"),
("recessive", "recessive"),
],
default="disabled",
max_length=128,
),
),
]
30 changes: 26 additions & 4 deletions backend/seqvars/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import typing
import uuid as uuid_object

import django
from django.contrib.auth import get_user_model
from django.db import models, transaction
from django_pydantic_field.v2.fields import PydanticSchemaField as SchemaField
Expand Down Expand Up @@ -796,12 +795,12 @@ class SeqvarsGenotypeChoice(str, Enum):
HET = "het"
#: Homozygous alternative genotype (or hemizygous alt for chrX / male).
HOM = "hom"
#: Non-heterozygous.
NON_HET = "non_het"
#: Non-homozygous.
NON_HOM = "non-hom"
NON_HOM = "non_hom"
#: Variant.
VARIANT = "variant"
#: Compound heterozygous index.
COMPHET_INDEX = "comphet_index"
#: Recessive index.
RECESSIVE_INDEX = "recessive_index"
#: Recessive parent.
Expand All @@ -819,6 +818,8 @@ class SeqvarsSampleGenotypeChoice(pydantic.BaseModel):
sample: str
#: The genotype.
genotype: SeqvarsGenotypeChoice
#: Include no-call genotype, will disable quality filter.
include_no_call: bool = False


class SeqvarsQuerySettingsGenotype(SeqvarsQuerySettingsCategoryBase):
Expand All @@ -829,6 +830,27 @@ class SeqvarsQuerySettingsGenotype(SeqvarsQuerySettingsCategoryBase):
SeqvarsQuerySettings, on_delete=models.CASCADE, related_name="genotype"
)

RECESSIVE_MODE_DISABLED = "disabled"
RECESSIVE_MODE_COMPHET_RECESSIVE = "comphet_recessive"
RECESSIVE_MODE_HOMOZYGOUS_RECESSIVE = "homozygous_recessive"
RECESSIVE_MODE_RECESSIVE = "recessive"

RECESSIVE_MODE_CHOICES = (
(RECESSIVE_MODE_DISABLED, RECESSIVE_MODE_DISABLED),
(RECESSIVE_MODE_COMPHET_RECESSIVE, RECESSIVE_MODE_COMPHET_RECESSIVE),
(RECESSIVE_MODE_HOMOZYGOUS_RECESSIVE, RECESSIVE_MODE_HOMOZYGOUS_RECESSIVE),
(RECESSIVE_MODE_RECESSIVE, RECESSIVE_MODE_RECESSIVE),
)

#: The recessive mode.
recessive_mode = models.CharField(
max_length=128,
choices=RECESSIVE_MODE_CHOICES,
default=RECESSIVE_MODE_DISABLED,
null=False,
blank=False,
)

#: Per-sample genotype choice.
sample_genotype_choices = SchemaField(schema=list[SeqvarsSampleGenotypeChoice], default=list)

Expand Down
11 changes: 10 additions & 1 deletion backend/seqvars/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,11 +663,20 @@ class Meta:
class SeqvarsQuerySettingsGenotypeSerializer(SeqvarsQuerySettingsBaseSerializer):
"""Serializer for ``QuerySettingsGenotype``."""

recessive_mode = serializers.ChoiceField(
choices=SeqvarsQuerySettingsGenotype.RECESSIVE_MODE_CHOICES,
default=SeqvarsQuerySettingsGenotype.RECESSIVE_MODE_DISABLED,
required=False,
)

sample_genotype_choices = SchemaField(schema=list[SeqvarsSampleGenotypeChoice], default=list)

class Meta:
model = SeqvarsQuerySettingsGenotype
fields = SeqvarsQuerySettingsBaseSerializer.Meta.fields + ["sample_genotype_choices"]
fields = SeqvarsQuerySettingsBaseSerializer.Meta.fields + [
"recessive_mode",
"sample_genotype_choices",
]
read_only_fields = fields


Expand Down
2 changes: 2 additions & 0 deletions backend/seqvars/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ class SeqvarsQuerySettingsGenotypeFactory(BaseModelFactory):
# ``QuerySettingsGenotype``.
querysettings = factory.SubFactory(SeqvarsQuerySettingsFactory, genotype=None)

recessive_mode = SeqvarsQuerySettingsGenotype.RECESSIVE_MODE_DISABLED

sample_genotype_choices = [SampleGenotypeChoiceFactory()]

class Meta:
Expand Down
19 changes: 17 additions & 2 deletions backend/seqvars/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
SeqvarsQuerySettingsVariantPrio,
SeqvarsResultRow,
SeqvarsResultSet,
SeqvarsSampleGenotypeChoice,
)
from seqvars.tests.factories import (
SampleGenotypeChoiceFactory,
Expand Down Expand Up @@ -71,16 +72,30 @@ def test_values(self):
"ref",
"het",
"hom",
"non-hom",
"non_het",
"non_hom",
"variant",
"comphet_index",
"recessive_index",
"recessive_parent",
],
SeqvarsGenotypeChoice.values(),
)


class TestSeqvarsSampleGenotypeChoice(TestCase):

def test_values(self):
self.assertEqual(
[
"disabled",
"comphet_recessive",
"homozygous_recessive",
"recessive",
],
SeqvarsSampleGenotypeChoice.values(),
)


class TestSeqvarsSampleGenotypeChoice(TestCase):

def test_values(self):
Expand Down
1 change: 1 addition & 0 deletions backend/seqvars/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,7 @@ def test_serialize_existing(self):
# QuerySettingsBase
"querysettings",
# GenotypeSettingsBase
"recessive_mode",
"sample_genotype_choices",
]
expected = model_to_dict(
Expand Down
23 changes: 21 additions & 2 deletions backend/varfish/tests/drf_openapi_schema/varfish_api_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7684,6 +7684,18 @@ components:
* `grch37` - GRCh37
* `grch38` - GRCh38
RecessiveModeEnum:
enum:
- disabled
- comphet_recessive
- homozygous_recessive
- recessive
type: string
description: |-
* `disabled` - disabled
* `comphet_recessive` - comphet_recessive
* `homozygous_recessive` - homozygous_recessive
* `recessive` - recessive
RegionCoverageStats:
description: Per-region QC stats for alignment.
properties:
Expand Down Expand Up @@ -8506,9 +8518,8 @@ components:
- ref
- het
- hom
- non-hom
- non_hom
- variant
- comphet_index
- recessive_index
- recessive_parent
title: SeqvarsGenotypeChoice
Expand Down Expand Up @@ -10109,6 +10120,10 @@ components:
type: string
format: uuid
readOnly: true
recessive_mode:
allOf:
- $ref: '#/components/schemas/RecessiveModeEnum'
default: disabled
sample_genotype_choices:
$ref: '#/components/schemas/SeqvarsSampleGenotypeChoiceList'
required:
Expand Down Expand Up @@ -10340,6 +10355,10 @@ components:
type: string
genotype:
$ref: '#/components/schemas/SeqvarsGenotypeChoice'
include_no_call:
default: false
title: Include No Call
type: boolean
required:
- sample
- genotype
Expand Down
2 changes: 1 addition & 1 deletion frontend/ext/reev-frontend-lib
24 changes: 23 additions & 1 deletion frontend/ext/varfish-api/src/lib/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4141,6 +4141,15 @@ export const $PatchedTargetBedFile = {
}
} as const;

export const $RecessiveModeEnum = {
enum: ['disabled', 'comphet_recessive', 'homozygous_recessive', 'recessive'],
type: 'string',
description: `* \`disabled\` - disabled
* \`comphet_recessive\` - comphet_recessive
* \`homozygous_recessive\` - homozygous_recessive
* \`recessive\` - recessive`
} as const;

export const $RegionCoverageStats = {
description: 'Per-region QC stats for alignment.',
properties: {
Expand Down Expand Up @@ -5119,7 +5128,7 @@ export const $SeqvarsColumnConfigList = {

export const $SeqvarsGenotypeChoice = {
description: 'Store genotype choice of a ``SampleGenotype``.',
enum: ['any', 'ref', 'het', 'hom', 'non-hom', 'variant', 'comphet_index', 'recessive_index', 'recessive_parent'],
enum: ['any', 'ref', 'het', 'hom', 'non_hom', 'variant', 'recessive_index', 'recessive_parent'],
title: 'SeqvarsGenotypeChoice',
type: 'string'
} as const;
Expand Down Expand Up @@ -7212,6 +7221,14 @@ export const $SeqvarsQuerySettingsGenotype = {
format: 'uuid',
readOnly: true
},
recessive_mode: {
allOf: [
{
'$ref': '#/components/schemas/RecessiveModeEnum'
}
],
default: 'disabled'
},
sample_genotype_choices: {
'$ref': '#/components/schemas/SeqvarsSampleGenotypeChoiceList'
}
Expand Down Expand Up @@ -7474,6 +7491,11 @@ export const $SeqvarsSampleGenotypeChoiceList = {
},
genotype: {
'$ref': '#/components/schemas/SeqvarsGenotypeChoice'
},
include_no_call: {
default: false,
title: 'Include No Call',
type: 'boolean'
}
},
required: ['sample', 'genotype'],
Expand Down
12 changes: 11 additions & 1 deletion frontend/ext/varfish-api/src/lib/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,14 @@ export type PatchedTargetBedFile = {
genome_release?: GenomeReleaseEnum;
};

/**
* * `disabled` - disabled
* * `comphet_recessive` - comphet_recessive
* * `homozygous_recessive` - homozygous_recessive
* * `recessive` - recessive
*/
export type RecessiveModeEnum = 'disabled' | 'comphet_recessive' | 'homozygous_recessive' | 'recessive';

/**
* Per-region QC stats for alignment.
*/
Expand Down Expand Up @@ -1592,7 +1600,7 @@ export type SeqvarsColumnConfigList = Array<{
/**
* Store genotype choice of a ``SampleGenotype``.
*/
export type SeqvarsGenotypeChoice = 'any' | 'ref' | 'het' | 'hom' | 'non-hom' | 'variant' | 'comphet_index' | 'recessive_index' | 'recessive_parent';
export type SeqvarsGenotypeChoice = 'any' | 'ref' | 'het' | 'hom' | 'non_hom' | 'variant' | 'recessive_index' | 'recessive_parent';

/**
* Presets value for the chosen genotype.
Expand Down Expand Up @@ -2102,6 +2110,7 @@ export type SeqvarsQuerySettingsGenotype = {
readonly date_created: string;
readonly date_modified: string;
readonly querysettings: string;
recessive_mode?: RecessiveModeEnum;
sample_genotype_choices?: SeqvarsSampleGenotypeChoiceList;
};

Expand Down Expand Up @@ -2194,6 +2203,7 @@ export type SeqvarsResultSet = {
export type SeqvarsSampleGenotypeChoiceList = Array<{
sample: string;
genotype: SeqvarsGenotypeChoice;
include_no_call?: boolean;
}>;

export type SeqvarsSampleQualityFilterList = Array<{
Expand Down

0 comments on commit 8dbb5fb

Please sign in to comment.