Skip to content

Commit

Permalink
feat: upgrade to sodar core v1 (#1973)
Browse files Browse the repository at this point in the history
  • Loading branch information
stolpeo committed Oct 9, 2024
1 parent 85aac5f commit 92fddf6
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 230 deletions.
2 changes: 1 addition & 1 deletion backend/cases_import/models/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def __init__(self, project: Project):
def _build_fs_options(self, project: Project) -> FileSystemOptions:
"""Build `FileSystemOptions` from project settings."""
app_settings = AppSettingAPI()
kwargs = {"app_name": "cases_import", "project": project}
kwargs = {"plugin_name": "cases_import", "project": project}

path = app_settings.get(setting_name="import_data_path", **kwargs) or None
if not path:
Expand Down
2 changes: 1 addition & 1 deletion backend/cases_import/tests/test_models_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _setUpExecutor(self, action, fac_kwargs=None):

app_settings = AppSettingAPI()
app_settings.set(
app_name="cases_import",
plugin_name="cases_import",
setting_name="import_data_protocol",
value="file",
project=self.project,
Expand Down
2 changes: 1 addition & 1 deletion backend/cases_qc/tests/test_views_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _setUpExecutor(self, fac_kwargs: typing.Dict[str, str]):

app_settings = AppSettingAPI()
app_settings.set(
app_name="cases_import",
plugin_name="cases_import",
setting_name="import_data_protocol",
value="file",
project=self.project,
Expand Down
7 changes: 5 additions & 2 deletions backend/genepanels/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def __init__(self, *args, **kwargs):
self.fields["genes"] = self._build_genes_field()

def _build_genes_field(self):
rows = [entry.symbol for entry in self.instance.genepanelentry_set.all()]
initial_value = "\n".join(rows)
if self.instance.pk:
rows = [entry.symbol for entry in self.instance.genepanelentry_set.all()]
initial_value = "\n".join(rows)
else:
initial_value = ""
return forms.CharField(
label="Genes",
widget=forms.Textarea,
Expand Down
6 changes: 4 additions & 2 deletions backend/genepanels/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_create(self):

def test_get_absolute_url(self):
category = GenePanelCategoryFactory()
self.assertEqual(category.get_absolute_url(), f"/genepanels/category/{category.sodar_uuid}")
self.assertEqual(
category.get_absolute_url(), f"/genepanels/category/{category.sodar_uuid}/"
)

def test_str(self):
category = GenePanelCategoryFactory()
Expand All @@ -46,7 +48,7 @@ def test_create(self):

def test_get_absolute_url(self):
panel = GenePanelFactory()
self.assertEqual(panel.get_absolute_url(), f"/genepanels/panel/{panel.sodar_uuid}")
self.assertEqual(panel.get_absolute_url(), f"/genepanels/panel/{panel.sodar_uuid}/")

def test_get_hgnc_list(self):
panel = GenePanelFactory()
Expand Down
19 changes: 0 additions & 19 deletions backend/maintenance/management/commands/create_variant_summary.py

This file was deleted.

19 changes: 0 additions & 19 deletions backend/maintenance/management/commands/drop_variant_summary.py

This file was deleted.

2 changes: 1 addition & 1 deletion backend/seqmeta/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_create(self):

def test_get_absolute_url(self):
kit = EnrichmentKitFactory()
self.assertEqual(kit.get_absolute_url(), f"/seqmeta/enrichmentkit/{kit.sodar_uuid}")
self.assertEqual(kit.get_absolute_url(), f"/seqmeta/enrichmentkit/{kit.sodar_uuid}/")

def test_str(self):
kit = EnrichmentKitFactory()
Expand Down
2 changes: 1 addition & 1 deletion backend/varannos/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_create(self):

def test_get_absolute_url(self):
obj = VarAnnoSetFactory()
self.assertEqual(obj.get_absolute_url(), f"/varannos/varannoset/details/{obj.sodar_uuid}")
self.assertEqual(obj.get_absolute_url(), f"/varannos/varannoset/details/{obj.sodar_uuid}/")

def test_days_since_modification(self):
with freeze_time((datetime.now() - timedelta(days=10)).strftime("%Y-%m-%d")):
Expand Down
2 changes: 1 addition & 1 deletion backend/varfish/users/management/commands/initdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def _create_project(
for setting_name, value in setting_value.items():
if project_settings.get(setting_name) != value:
app_settings.set(
app_name="cases_import",
plugin_name="cases_import",
setting_name=setting_name,
value=value,
project=project,
Expand Down
102 changes: 102 additions & 0 deletions backend/variants/migrations/0110_drop_variant_summary.py
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 backend/variants/migrations/0111_create_variant_summary.py
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;
""",
)
]
Loading

0 comments on commit 92fddf6

Please sign in to comment.