Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove entity descriptor fields #1327

Merged
merged 4 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Added

Changed
-------
- **BACKWARD INCOMPATIBLE:** Require Resolwe 39.x
- Rewrite ``expression-aggregator`` process to Python and make it
compatible with the new annotation model

Expand Down
72 changes: 0 additions & 72 deletions resolwe_bio/extensions.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,10 @@
"""Resolwe-bio extensions of Resolwe core."""

from django.db.models import Q
from django_filters import rest_framework as filters

from resolwe.composer import composer


class ExtendedCollectionFilter:
"""Collection filter extension."""

descriptor__general__species = filters.CharFilter(
field_name="entity__descriptor__general__species",
lookup_expr="icontains",
distinct=True,
)
tissue_type = filters.CharFilter(method="_filter_by_tissue")
treatment = filters.CharFilter(method="_filter_by_treatment")
outcome_is_defined = filters.CharFilter(method="_filter_by_outcome")

def _filter_by_multiple_fields(self, queryset, fields, value):
"""Filter by any of the given fields.

Return exactly those objects, who icontain `value` in at least one of
`fields`.
"""

query = Q()
for field in fields:
query |= Q(**{field + "__icontains": value})

return queryset.filter(query).distinct()

def _filter_by_tissue(self, queryset, name, value):
locations = [
"entity__descriptor__general__organ",
"entity__descriptor__general__biosample_source",
"entity__descriptor__disease_information__organ_part",
"entity__descriptor__disease_information__biopsy_site",
"entity__descriptor__pathological_information__organ_part",
"entity__descriptor__pathological_information__biopsy_site",
]
return self._filter_by_multiple_fields(queryset, locations, value)

def _filter_by_treatment(self, queryset, name, value):
locations = [
"entity__descriptor__general__biosample_treatment",
"entity__descriptor__treatment_type__drug",
"entity__descriptor__immuno_oncology_treatment_type__io_drug",
]
return self._filter_by_multiple_fields(queryset, locations, value)

def _filter_by_outcome(self, queryset, name, value):
locations = [
"entity__descriptor__response_and_survival_analysis__clinical_benefit",
"entity__descriptor__response_and_survival_analysis__confirmed_bor",
"entity__descriptor__response_and_survival_analysis__unconfirmed_bor",
"entity__descriptor__response_and_survival_analysis__pfs",
"entity__descriptor__response_and_survival_analysis__os",
"entity__descriptor__response_and_survival_analysis__dfs",
"entity__descriptor__response_and_survival_analysis__ttp",
]
return self._filter_by_multiple_fields(queryset, locations, value)


class ExtendedDataFilter:
"""Data filter extensions."""

Expand All @@ -81,18 +23,4 @@ def filter_output_icontains(self, queryset, name, value):
species = filters.CharFilter(method="filter_output_icontains")


class ExtendedEntityFilter:
"""Data filter extensions."""

def filter_species(self, queryset, name, value):
"""Filter queryset by genome build."""
return queryset.filter(descriptor__general__species__icontains=value)

species = filters.CharFilter(method="filter_species")


composer.add_extension(
"resolwe.flow.filters.CollectionFilter", ExtendedCollectionFilter
)
composer.add_extension("resolwe.flow.filters.DataFilter", ExtendedDataFilter)
composer.add_extension("resolwe.flow.filters.EntityFilter", ExtendedEntityFilter)
3 changes: 3 additions & 0 deletions resolwe_bio/migrations/0001_squashed_0015_sample_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def load_relation_types(apps, schema_editor):

class Migration(migrations.Migration):
initial = True
dependencies = [
("flow", "0021_annotationvalue_modified"),
]

operations = [
migrations.RunPython(load_relation_types),
Expand Down
31 changes: 31 additions & 0 deletions resolwe_bio/migrations/0005_remove_descriptor_indices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 3.2.12 on 2022-03-06 22:34
import os

from django.db import connection, migrations


def load_sql(apps, schema_editor):
file_names = [
"remove_resolwe_indexes.sql",
]
with connection.cursor() as c:
for file_name in file_names:
file_path = os.path.join(os.path.dirname(__file__), file_name)
with open(file_path) as fh:
sql_statement = fh.read()
c.execute(sql_statement)


class Migration(migrations.Migration):
dependencies = [
("resolwe_bio", "0004_merge_fastq_type"),
("flow", "0021_annotationvalue_modified"),
]

run_before = [
("flow", "0023_remove_entity_descriptor_and_more"),
]

operations = [
migrations.RunPython(load_sql),
]
30 changes: 30 additions & 0 deletions resolwe_bio/migrations/remove_resolwe_indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- Delete indexes related to the entity descriptor field that has been removed.
DROP INDEX IF EXISTS idx_entity_descriptor_sample_label_trgm,
idx_entity_descriptor_subject_id_trgm,
idx_entity_descriptor_batch,
idx_entity_descriptor_group,
idx_entity_descriptor_disease_type_trgm,
idx_entity_descriptor_disease_status,
idx_entity_descriptor_io_drug,
idx_entity_descriptor_io_treatment,
idx_entity_descriptor_confirmed_bor,
idx_entity_descriptor_pfs_event,
idx_entity_descriptor_description_trgm,
idx_entity_descriptor_biosample_source_trgm,
idx_entity_descriptor_biosample_treatment_trgm,
idx_entity_descriptor__general__organ,
idx_entity_descriptor__general__biosample_source,
idx_entity_descriptor__disease_information__organ_part,
idx_entity_descriptor__disease_information__biopsy_site,
idx_entity_descriptor__pathological_information__organ_part,
idx_entity_descriptor__pathological_information__biopsy_site,
idx_entity_descriptor__general__biosample_treatment,
idx_entity_descriptor__treatment_type__drug,
idx_entity_descriptor__immuno_oncology_treatment_type__io_drug,
idx_entity_descriptor__response_and_survival_analysis__clinical_benefit,
idx_entity_descriptor__response_and_survival_analysis__confirmed_bor,
idx_entity_descriptor__response_and_survival_analysis__unconfirmed_bor,
idx_entity_descriptor__response_and_survival_analysis__pfs,
idx_entity_descriptor__response_and_survival_analysis__os,
idx_entity_descriptor__response_and_survival_analysis__dfs,
idx_entity_descriptor__response_and_survival_analysis__ttp;
33 changes: 0 additions & 33 deletions resolwe_bio/migrations/resolwe_indexes.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,3 @@ CREATE OR REPLACE FUNCTION data_biut()
RETURN NEW;
END;
$$;

-- Add resolwe-bio specific fields to Entity search.
CREATE OR REPLACE FUNCTION generate_resolwe_bio_entity_search(entity flow_entity)
RETURNS tsvector
LANGUAGE plpgsql
AS $$
DECLARE
search tsvector;
BEGIN
SELECT
-- Species.
setweight(to_tsvector('simple', COALESCE(entity.descriptor->'general'->>'species', '')), 'A')
INTO search;

RETURN search;
END;
$$;

CREATE OR REPLACE FUNCTION entity_biut()
RETURNS TRIGGER
LANGUAGE plpgsql
AS $$
BEGIN
SELECT generate_resolwe_entity_search(NEW) || generate_resolwe_bio_entity_search(NEW)
INTO NEW.search;

IF NEW.search IS NULL THEN
RAISE WARNING 'Search index for entity (id: %) is NULL.', NEW.id;
END IF;

RETURN NEW;
END;
$$;
2 changes: 0 additions & 2 deletions resolwe_bio/tests/processes/test_chipseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ def set_sample_name(data, sample_name):
contributor=self.contributor,
type="data:chipseq:callpeak:macs2:",
entity_type="sample",
entity_descriptor_schema="sample",
input_schema=[
{
"name": "src",
Expand Down Expand Up @@ -679,7 +678,6 @@ def set_sample_name(data, sample_name):
contributor=self.contributor,
type="data:chipseq:callpeak:macs14:",
entity_type="sample",
entity_descriptor_schema="sample",
input_schema=[
{
"name": "src",
Expand Down
2 changes: 0 additions & 2 deletions resolwe_bio/tests/processes/test_diff_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def test_deseq2_nanostring(self):
contributor=self.contributor,
type="data:expression:nanostring:",
entity_type="sample",
entity_descriptor_schema="sample",
data_name="{{ src.file }}",
input_schema=[
{
Expand Down Expand Up @@ -311,7 +310,6 @@ def test_de_microarray(self):
contributor=self.contributor,
type="data:expression:microarray:",
entity_type="sample",
entity_descriptor_schema="sample",
data_name="{{ name }}",
input_schema=[
{
Expand Down
6 changes: 0 additions & 6 deletions resolwe_bio/tests/processes/test_support_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ def test_archive_samples_exp(self):
requirements={"expression-engine": "jinja"},
data_name="Upload expression into exp output field",
entity_type="sample",
entity_descriptor_schema="sample",
input_schema=[
{
"name": "exp",
Expand Down Expand Up @@ -545,7 +544,6 @@ def set_sample_name(data, sample_name):
},
},
entity_type="sample",
entity_descriptor_schema="sample",
contributor=self.contributor,
type="data:wgbs:bsrate:",
input_schema=[
Expand Down Expand Up @@ -617,7 +615,6 @@ def set_sample_name(data, sample_name):
},
},
entity_type="sample",
entity_descriptor_schema="sample",
contributor=self.contributor,
type="data:alignment:bam:walt:",
input_schema=[
Expand Down Expand Up @@ -685,7 +682,6 @@ def set_sample_name(data, sample_name):
},
},
entity_type="sample",
entity_descriptor_schema="sample",
contributor=self.contributor,
type="data:chipqc:",
input_schema=[
Expand Down Expand Up @@ -747,7 +743,6 @@ def set_sample_name(data, sample_name):
},
},
entity_type="sample",
entity_descriptor_schema="sample",
contributor=self.contributor,
type="data:chipseq:callpeak:macs2:",
input_schema=[
Expand Down Expand Up @@ -834,7 +829,6 @@ def set_sample_name(data, sample_name):
},
},
entity_type="sample",
entity_descriptor_schema="sample",
contributor=self.contributor,
type="data:nanostring:rcc:",
input_schema=[
Expand Down
2 changes: 0 additions & 2 deletions resolwe_bio/tests/processes/test_wgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def test_gatk_genomicsdb(self):
contributor=self.contributor,
type="data:variants:gvcf:",
entity_type="sample",
entity_descriptor_schema="sample",
data_name="{{ gvcf.file }}",
input_schema=[
{
Expand Down Expand Up @@ -310,7 +309,6 @@ def test_gatk_genotypegvcfs(self):
contributor=self.contributor,
type="data:variants:gvcf:",
entity_type="sample",
entity_descriptor_schema="sample",
data_name="{{ gvcf.file }}",
input_schema=[
{
Expand Down
Loading