-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to sodar core v1 (#1973)
- Loading branch information
Showing
14 changed files
with
317 additions
and
230 deletions.
There are no files selected for viewing
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
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
19 changes: 0 additions & 19 deletions
19
backend/maintenance/management/commands/create_variant_summary.py
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
backend/maintenance/management/commands/drop_variant_summary.py
This file was deleted.
Oops, something went wrong.
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
102 changes: 102 additions & 0 deletions
102
backend/variants/migrations/0110_drop_variant_summary.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,102 @@ | ||
# Generated by Django 4.2.16 on 2024-10-09 13:00 | ||
|
||
from django.db import connection | ||
from django.db import migrations, utils | ||
from django.db.migrations.recorder import MigrationRecorder | ||
|
||
def is_migration_applied(app_name, migration_name): | ||
recorder = MigrationRecorder(connection) | ||
try: | ||
return recorder.migration_qs.filter(app=app_name, name=migration_name).exists() | ||
except utils.ProgrammingError: | ||
return False # migration table does not exist yet | ||
|
||
if not is_migration_applied('projectroles', '0001_initial'): | ||
run_before = [] # fresh installation, will run projectroles squashed migrations | ||
elif is_migration_applied('projectroles', '0032_alter_appsetting_value'): | ||
run_before = [] # critical projectroles migration already applied | ||
else: | ||
# We will not execute the squashed projectroles migration 0001..0032 and the | ||
# projectroles migration 0032 has not been applied yet. | ||
run_before = [ | ||
("projectroles", "0032_alter_appsetting_value"), | ||
] | ||
|
||
|
||
SQL_OUTER = r""" | ||
DROP MATERIALIZED VIEW IF EXISTS variants_smallvariantsummary; | ||
CREATE MATERIALIZED VIEW variants_smallvariantsummary | ||
AS | ||
%s | ||
WITH NO DATA; | ||
CREATE UNIQUE INDEX variants_smallvariantsummary_id ON variants_smallvariantsummary(id); | ||
CREATE INDEX variants_smallvariantsummary_coord ON variants_smallvariantsummary( | ||
release, chromosome, start, "end", bin, reference, alternative | ||
); | ||
""" | ||
|
||
|
||
SQL_INNER = r""" | ||
WITH excluded_case_ids AS ( | ||
SELECT DISTINCT variants_case.id AS case_id | ||
FROM variants_case | ||
JOIN projectroles_project ON variants_case.project_id = projectroles_project.id | ||
JOIN projectroles_appsetting ON | ||
projectroles_project.id = projectroles_appsetting.project_id AND | ||
projectroles_appsetting.name = 'exclude_from_inhouse_db' AND | ||
projectroles_appsetting.value = '1' | ||
) | ||
SELECT | ||
row_number() OVER (PARTITION BY true) AS id, | ||
release, | ||
chromosome, | ||
start, | ||
"end", | ||
bin, | ||
reference, | ||
alternative, | ||
sum(num_hom_ref) AS count_hom_ref, | ||
sum(num_het) AS count_het, | ||
sum(num_hom_alt) AS count_hom_alt, | ||
sum(num_hemi_ref) AS count_hemi_ref, | ||
sum(num_hemi_alt) AS count_hemi_alt | ||
FROM ( | ||
SELECT DISTINCT | ||
variants.release, | ||
variants.chromosome, | ||
variants.start, | ||
variants."end", | ||
variants.bin, | ||
variants.reference, | ||
variants.alternative, | ||
variants.num_hom_ref, | ||
variants.num_het, | ||
variants.num_hom_alt, | ||
variants.num_hemi_ref, | ||
variants.num_hemi_alt, | ||
variants.case_id | ||
FROM variants_smallvariant AS variants | ||
WHERE NOT EXISTS (SELECT 1 from excluded_case_ids AS e WHERE e.case_id = variants.case_id) | ||
) AS variants_per_case | ||
GROUP BY (release, chromosome, start, "end", bin, reference, alternative) | ||
""" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("variants", "0109_alter_clearexpiredexportedfilesbgjob_bg_job_and_more"), | ||
] | ||
|
||
run_before = run_before | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
""" | ||
DROP MATERIALIZED VIEW IF EXISTS variants_smallvariantsummary; | ||
""", | ||
SQL_OUTER % SQL_INNER | ||
) | ||
] |
81 changes: 81 additions & 0 deletions
81
backend/variants/migrations/0111_create_variant_summary.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,81 @@ | ||
# Generated by Django 4.2.16 on 2024-10-09 13:00 | ||
|
||
from django.db import migrations | ||
|
||
|
||
SQL_OUTER = r""" | ||
DROP MATERIALIZED VIEW IF EXISTS variants_smallvariantsummary; | ||
CREATE MATERIALIZED VIEW variants_smallvariantsummary | ||
AS | ||
%s | ||
WITH NO DATA; | ||
CREATE UNIQUE INDEX variants_smallvariantsummary_id ON variants_smallvariantsummary(id); | ||
CREATE INDEX variants_smallvariantsummary_coord ON variants_smallvariantsummary( | ||
release, chromosome, start, "end", bin, reference, alternative | ||
); | ||
""" | ||
|
||
|
||
SQL_INNER = r""" | ||
WITH excluded_case_ids AS ( | ||
SELECT DISTINCT variants_case.id AS case_id | ||
FROM variants_case | ||
JOIN projectroles_project ON variants_case.project_id = projectroles_project.id | ||
JOIN projectroles_appsetting ON | ||
projectroles_project.id = projectroles_appsetting.project_id AND | ||
projectroles_appsetting.name = 'exclude_from_inhouse_db' AND | ||
projectroles_appsetting.value = '1' | ||
) | ||
SELECT | ||
row_number() OVER (PARTITION BY true) AS id, | ||
release, | ||
chromosome, | ||
start, | ||
"end", | ||
bin, | ||
reference, | ||
alternative, | ||
sum(num_hom_ref) AS count_hom_ref, | ||
sum(num_het) AS count_het, | ||
sum(num_hom_alt) AS count_hom_alt, | ||
sum(num_hemi_ref) AS count_hemi_ref, | ||
sum(num_hemi_alt) AS count_hemi_alt | ||
FROM ( | ||
SELECT DISTINCT | ||
variants.release, | ||
variants.chromosome, | ||
variants.start, | ||
variants."end", | ||
variants.bin, | ||
variants.reference, | ||
variants.alternative, | ||
variants.num_hom_ref, | ||
variants.num_het, | ||
variants.num_hom_alt, | ||
variants.num_hemi_ref, | ||
variants.num_hemi_alt, | ||
variants.case_id | ||
FROM variants_smallvariant AS variants | ||
WHERE NOT EXISTS (SELECT 1 from excluded_case_ids AS e WHERE e.case_id = variants.case_id) | ||
) AS variants_per_case | ||
GROUP BY (release, chromosome, start, "end", bin, reference, alternative) | ||
""" | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("variants", "0110_drop_variant_summary"), | ||
("projectroles", "0032_alter_appsetting_value"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
SQL_OUTER % SQL_INNER, | ||
""" | ||
DROP MATERIALIZED VIEW IF EXISTS variants_smallvariantsummary; | ||
""", | ||
) | ||
] |
Oops, something went wrong.