-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #1099 - store hgvs converter used during matching process (on t…
…op of note)
- Loading branch information
Showing
11 changed files
with
199 additions
and
46 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
classification/migrations/0145_importedalleleinfo_hgvs_converter_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2.10 on 2024-07-04 08:06 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('classification', '0144_one_off_populate_historical_resolved_variant_hgvsconverter_version'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='importedalleleinfo', | ||
name='hgvs_converter_version', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='classification.hgvsconverterversion'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
classification/migrations/0146_hgvsconverterversion_used_converter_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.10 on 2024-07-05 03:02 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('classification', '0145_importedalleleinfo_hgvs_converter_version'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='hgvsconverterversion', | ||
name='used_converter_type', | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
54 changes: 54 additions & 0 deletions
54
classification/migrations/0147_one_off_populate_hgvsconverterversion_used_converter_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Generated by Django 4.2.10 on 2024-07-05 03:02 | ||
|
||
from django.db import migrations | ||
from django.db.models import F, Q, Min | ||
|
||
from genes.hgvs import HGVSConverterType | ||
|
||
|
||
def _one_off_populate_hgvsconverterversion_used_converter_type(apps, schema_editor): | ||
HGVSConverterVersion = apps.get_model('classification', 'HGVSConverterVersion') | ||
ResolvedVariantInfo = apps.get_model('classification', 'ResolvedVariantInfo') | ||
ImportedAlleleInfo = apps.get_model('classification', 'ImportedAlleleInfo') | ||
|
||
internal_qs = HGVSConverterVersion.objects.filter(method__startswith='Internally converted') | ||
internal_qs.update(used_converter_type=F("hgvs_converter_type")) | ||
clingen_qs = HGVSConverterVersion.objects.filter(method__startswith='ClinGen Allele Registry') | ||
clingen_qs.update(used_converter_type=HGVSConverterType.CLINGEN_ALLELE_REGISTRY.name) | ||
|
||
for converter_type in HGVSConverterType: | ||
qs = HGVSConverterVersion.objects.filter(Q(method__startswith=str(converter_type)) | Q(method__startswith=converter_type.name)) | ||
qs.update(used_converter_type=converter_type.name) | ||
|
||
# Legacy ones were 'unknown tool...' - ok to have these as NULL | ||
|
||
# We should probably remove dupes too (not including method) | ||
unique_fields = ("hgvs_converter_type", "version", "used_converter_type", "code_git_hash") | ||
newest_hcvs = HGVSConverterVersion.objects.values(*unique_fields).annotate(first_id=Min('id')) | ||
newest_ids = set(newest_hcvs.values_list("first_id", flat=True)) | ||
|
||
# The only object that should have it now is ResolvedVariantInfo | ||
for hcvs in HGVSConverterVersion.objects.filter(pk__in=newest_ids): | ||
kwargs = { | ||
f"c_hgvs_converter_version__{field}": getattr(hcvs, field) for field in unique_fields | ||
} | ||
ResolvedVariantInfo.objects.filter(**kwargs).update(c_hgvs_converter_version=hcvs) | ||
|
||
if num := HGVSConverterVersion.objects.exclude(pk__in=newest_ids).delete(): | ||
print(f"Deleted {num} dupe HGVSConverterVersion objects") | ||
|
||
# Now we need to assign all AlleleInfo to hgvs_converter_version | ||
if legacy := HGVSConverterVersion.objects.filter(version__startswith='Legacy').first(): | ||
ImportedAlleleInfo.objects.all().update(hgvs_converter_version=legacy) | ||
|
||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('classification', '0146_hgvsconverterversion_used_converter_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(_one_off_populate_hgvsconverterversion_used_converter_type) | ||
] |
21 changes: 21 additions & 0 deletions
21
classification/migrations/0148_alter_hgvsconverterversion_unique_together_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 4.2.10 on 2024-07-05 06:46 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('classification', '0147_one_off_populate_hgvsconverterversion_used_converter_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='hgvsconverterversion', | ||
unique_together={('hgvs_converter_type', 'version', 'used_converter_type', 'code_git_hash')}, | ||
), | ||
migrations.RemoveField( | ||
model_name='hgvsconverterversion', | ||
name='method', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.