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

Code cleanup for relecov_core #121

Merged
merged 15 commits into from
Jul 23, 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
95 changes: 37 additions & 58 deletions relecov_core/admin.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,10 @@
# Generic imports
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User

from relecov_core.models import (
BioinfoAnalysisValue,
BioinfoAnalysisField,
Classification,
Chromosome,
ConfigSetting,
Effect,
Error,
Gene,
Filter,
LineageFields,
LineageValues,
LineageInfo,
MetadataVisualization,
OrganismAnnotation,
Profile,
PropertyOptions,
PublicDatabaseFields,
PublicDatabaseValues,
PublicDatabaseType,
Sample,
SampleState,
Schema,
SchemaProperties,
TemporalSampleStorage,
Variant,
VariantInSample,
VariantAnnotation,
DateUpdateState,
)
# Local imports
import relecov_core.models


def custom_date_format(self):
Expand All @@ -41,7 +14,7 @@ def custom_date_format(self):


class ProfileInLine(admin.StackedInline):
model = Profile
model = relecov_core.models.Profile
can_delete = False
verbose_name_plural = "Profile"
fk_name = "user"
Expand Down Expand Up @@ -199,30 +172,36 @@ class MetadataVisualizationAdmin(admin.ModelAdmin):
# Register models
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
admin.site.register(ConfigSetting, ConfigSettingAdmin)
admin.site.register(Filter, FilterAdmin)
admin.site.register(Effect, EffectAdmin)
admin.site.register(Gene, GeneAdmin)
admin.site.register(Chromosome, ChromosomeAdmin)
admin.site.register(LineageFields, LineageFieldsAdmin)
admin.site.register(LineageValues, LineageValuesAdmin)
admin.site.register(Sample, SampleAdmin)
admin.site.register(SampleState, SampleStateAdmin)
admin.site.register(Variant, VariantAdmin)
admin.site.register(VariantInSample, VariantInSampleAdmin)
admin.site.register(VariantAnnotation, VariantAnnotationAdmin)
admin.site.register(Schema, SchemaAdmin)
admin.site.register(SchemaProperties, SchemaPropertiesAdmin)
admin.site.register(PropertyOptions, PropertyOptionsAdmin)
admin.site.register(PublicDatabaseType, PublicDatabaseTypeAdmin)
admin.site.register(PublicDatabaseFields, PublicDatabaseFieldsAdmin)
admin.site.register(PublicDatabaseValues, PublicDatabaseValuesAdmin)
admin.site.register(MetadataVisualization, MetadataVisualizationAdmin)
admin.site.register(BioinfoAnalysisField, BioinfoAnalysisFielddAdmin)
admin.site.register(BioinfoAnalysisValue, BioinfoAnalysisValueAdmin)
admin.site.register(Classification, ClassificationAdmin)
admin.site.register(TemporalSampleStorage, TemporalSampleStorageAdmin)
admin.site.register(Error, ErrorAdmin)
admin.site.register(DateUpdateState, DateUpdateStateAdmin)
admin.site.register(LineageInfo, LineageInfoAdmin)
admin.site.register(OrganismAnnotation, OrganismAnnotationAdmin)
admin.site.register(relecov_core.models.ConfigSetting, ConfigSettingAdmin)
admin.site.register(relecov_core.models.Filter, FilterAdmin)
admin.site.register(relecov_core.models.Effect, EffectAdmin)
admin.site.register(relecov_core.models.Gene, GeneAdmin)
admin.site.register(relecov_core.models.Chromosome, ChromosomeAdmin)
admin.site.register(relecov_core.models.LineageFields, LineageFieldsAdmin)
admin.site.register(relecov_core.models.LineageValues, LineageValuesAdmin)
admin.site.register(relecov_core.models.Sample, SampleAdmin)
admin.site.register(relecov_core.models.SampleState, SampleStateAdmin)
admin.site.register(relecov_core.models.Variant, VariantAdmin)
admin.site.register(relecov_core.models.VariantInSample, VariantInSampleAdmin)
admin.site.register(relecov_core.models.VariantAnnotation, VariantAnnotationAdmin)
admin.site.register(relecov_core.models.Schema, SchemaAdmin)
admin.site.register(relecov_core.models.SchemaProperties, SchemaPropertiesAdmin)
admin.site.register(relecov_core.models.PropertyOptions, PropertyOptionsAdmin)
admin.site.register(relecov_core.models.PublicDatabaseType, PublicDatabaseTypeAdmin)
admin.site.register(relecov_core.models.PublicDatabaseFields, PublicDatabaseFieldsAdmin)
admin.site.register(relecov_core.models.PublicDatabaseValues, PublicDatabaseValuesAdmin)
admin.site.register(
relecov_core.models.MetadataVisualization, MetadataVisualizationAdmin
)
admin.site.register(
relecov_core.models.BioinfoAnalysisField, BioinfoAnalysisFielddAdmin
)
admin.site.register(relecov_core.models.BioinfoAnalysisValue, BioinfoAnalysisValueAdmin)
admin.site.register(relecov_core.models.Classification, ClassificationAdmin)
admin.site.register(
relecov_core.models.TemporalSampleStorage, TemporalSampleStorageAdmin
)
admin.site.register(relecov_core.models.Error, ErrorAdmin)
admin.site.register(relecov_core.models.DateUpdateState, DateUpdateStateAdmin)
admin.site.register(relecov_core.models.LineageInfo, LineageInfoAdmin)
admin.site.register(relecov_core.models.OrganismAnnotation, OrganismAnnotationAdmin)
1 change: 1 addition & 0 deletions relecov_core/api/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Generic imports
from django.apps import AppConfig


Expand Down
39 changes: 15 additions & 24 deletions relecov_core/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,86 +1,77 @@
# Generic imports
from rest_framework import serializers

from relecov_core.models import (
BioinfoAnalysisValue,
DateUpdateState,
Effect,
Filter,
LineageValues,
Sample,
Variant,
VariantAnnotation,
VariantInSample,
PublicDatabaseValues,
)
# Local imports
import relecov_core.models


class CreateBioinfoAnalysisValueSerializer(serializers.ModelSerializer):
class Meta:
model = BioinfoAnalysisValue
model = relecov_core.models.BioinfoAnalysisValue
fields = "__all__"


class CreateDateAfterChangeStateSerializer(serializers.ModelSerializer):
class Meta:
model = DateUpdateState
model = relecov_core.models.DateUpdateState
fields = "__all__"


class CreateSampleSerializer(serializers.ModelSerializer):
class Meta:
model = Sample
model = relecov_core.models.Sample
fields = "__all__"


class CreateEffectSerializer(serializers.ModelSerializer):
class Meta:
model = Effect
model = relecov_core.models.Effect
fields = "__all__"


class CreateErrorSerializer(serializers.ModelSerializer):
class Meta:
model = Sample
model = relecov_core.models.Sample
fields = "__all__"


class CreateVariantInSampleSerializer(serializers.ModelSerializer):
class Meta:
model = VariantInSample
model = relecov_core.models.VariantInSample
fields = "__all__"


class CreateVariantAnnotationSerializer(serializers.ModelSerializer):
class Meta:
model = VariantAnnotation
model = relecov_core.models.VariantAnnotation
fields = "__all__"


class CreateFilterSerializer(serializers.ModelSerializer):
class Meta:
model = Filter
model = relecov_core.models.Filter
fields = "__all__"


class CreateVariantSerializer(serializers.ModelSerializer):
class Meta:
model = Variant
model = relecov_core.models.Variant
fields = "__all__"


class CreateLineageValueSerializer(serializers.ModelSerializer):
class Meta:
model = LineageValues
model = relecov_core.models.LineageValues
fields = "__all__"


class CreatePublicDatabaseValueSerializer(serializers.ModelSerializer):
class Meta:
model = PublicDatabaseValues
model = relecov_core.models.PublicDatabaseValues
fields = "__all__"


class UpdateStateSampleSerializer(serializers.ModelSerializer):
class Meta:
model = Sample
model = relecov_core.models.Sample
fields = "__all__"
23 changes: 18 additions & 5 deletions relecov_core/api/urls.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Generic imports
from django.urls import path
from relecov_core.api import views

# Local imports
import relecov_core.api

app_name = "relecov_api"


urlpatterns = [
path(
"createBioinfoData", views.create_bioinfo_metadata, name="create_bioinfo_data"
"createBioinfoData",
relecov_core.api.views.create_bioinfo_metadata,
name="create_bioinfo_data",
),
path(
"createSampleData",
relecov_core.api.views.create_sample_data,
name="create_sample_data",
),
path(
"createVariantData",
relecov_core.api.views.create_variant_data,
name="create_variant_data",
),
path("createSampleData", views.create_sample_data, name="create_sample_data"),
path("createVariantData", views.create_variant_data, name="create_variant_data"),
path("updateState", views.update_state, name="update_state"),
path("updateState", relecov_core.api.views.update_state, name="update_state"),
]
6 changes: 0 additions & 6 deletions relecov_core/api/utils/analysis_handling.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
from relecov_core.models import (
BioinfoAnalysisField,
BioinfoAnalysisValue,
LineageFields,
Sample,
)

from relecov_core.core_config import (
ERROR_UNABLE_TO_STORE_IN_DATABASE,
)

from relecov_core.api.serializers import (
CreateBioinfoAnalysisValueSerializer,
CreateLineageValueSerializer,
)
# Local imports
import relecov_core.models
import relecov_core.api.serializers
import relecov_core.config


def split_bioinfo_data(data, schema_obj):
Expand All @@ -24,11 +13,11 @@ def split_bioinfo_data(data, schema_obj):
if field == "sequencing_sample_id":
split_data["sample"] = value
# if this field belongs to BioinfoAnalysisField table
if BioinfoAnalysisField.objects.filter(
if relecov_core.models.BioinfoAnalysisField.objects.filter(
schemaID=schema_obj, property_name__iexact=field
).exists():
split_data["bioinfo"][field] = value
elif LineageFields.objects.filter(
elif relecov_core.models.LineageFields.objects.filter(
schemaID=schema_obj, property_name__iexact=field
).exists():
split_data["lineage"][field] = value
Expand All @@ -38,21 +27,21 @@ def split_bioinfo_data(data, schema_obj):


def get_analysis_defined(s_obj):
return BioinfoAnalysisValue.objects.filter(
return relecov_core.models.BioinfoAnalysisValue.objects.filter(
bioinfo_analysis_fieldID__property_name="analysis_date", sample=s_obj
).values_list("value", flat=True)


def store_bioinfo_data(s_data, schema_obj):
"""Save the new field data in database"""
# schema_id = schema_obj.get_schema_id()
sample_obj = Sample.objects.filter(
sample_obj = relecov_core.models.Sample.objects.filter(
sequencing_sample_id__iexact=s_data["sample"]
).last()
# field to BioinfoAnalysisField table
for field, value in s_data["bioinfo"].items():
field_id = (
BioinfoAnalysisField.objects.filter(
relecov_core.models.BioinfoAnalysisField.objects.filter(
schemaID=schema_obj, property_name__iexact=field
)
.last()
Expand All @@ -63,26 +52,38 @@ def store_bioinfo_data(s_data, schema_obj):
"bioinfo_analysis_fieldID": field_id,
}

bio_value_serializer = CreateBioinfoAnalysisValueSerializer(data=data)
bio_value_serializer = (
relecov_core.api.serializers.CreateBioinfoAnalysisValueSerializer(data=data)
)
if not bio_value_serializer.is_valid():
return {"ERROR": str(field + " " + ERROR_UNABLE_TO_STORE_IN_DATABASE)}
return {
"ERROR": str(
field + " " + relecov_core.config.ERROR_UNABLE_TO_STORE_IN_DATABASE
)
}
bio_value_obj = bio_value_serializer.save()
sample_obj.bio_analysis_values.add(bio_value_obj)

# field to LineageFields table
for field, value in s_data["lineage"].items():
lineage_id = (
LineageFields.objects.filter(
relecov_core.models.LineageFields.objects.filter(
schemaID=schema_obj, property_name__iexact=field
)
.last()
.get_lineage_field_id()
)
data = {"value": value, "lineage_fieldID": lineage_id}
lineage_value_serializer = CreateLineageValueSerializer(data=data)
lineage_value_serializer = (
relecov_core.api.serializers.CreateLineageValueSerializer(data=data)
)

if not lineage_value_serializer.is_valid():
return {"ERROR": str(field + " " + ERROR_UNABLE_TO_STORE_IN_DATABASE)}
return {
"ERROR": str(
field + " " + relecov_core.config.ERROR_UNABLE_TO_STORE_IN_DATABASE
)
}
lineage_value_obj = lineage_value_serializer.save()
sample_obj.lineage_values.add(lineage_value_obj)

Expand Down
Loading
Loading