diff --git a/src/biomarkers/serializers.py b/src/biomarkers/serializers.py index a66be68b..d0f8fc7c 100644 --- a/src/biomarkers/serializers.py +++ b/src/biomarkers/serializers.py @@ -1,4 +1,5 @@ from rest_framework import serializers +from genes.serializers import GeneGEMWithType from user_files.models_choices import MoleculeType from .models import Biomarker, MRNAIdentifier, MethylationIdentifier, CNAIdentifier, MiRNAIdentifier, MoleculeIdentifier from tags.serializers import TagSerializer @@ -164,5 +165,14 @@ def get_was_already_used(ins: Biomarker) -> bool: This avoids the user to edit a Biomarker that was already used and generate inconsistencies. """ return ins.was_already_used + + +class BiomarkerFromCorrelationAnalysisSerializer(serializers.Serializer): + """ + Serializer for BiomarkerFromCorrelationAnalysis, including correlation analysis ID, gene GEM list, and correlation threshold. + """ + correlation_analysis_id = serializers.IntegerField() + gene_gem_list = GeneGEMWithType(many=True, required=False) + correlation_threshold = serializers.IntegerField(required=False) diff --git a/src/biomarkers/urls.py b/src/biomarkers/urls.py index c13293d6..06ee0197 100644 --- a/src/biomarkers/urls.py +++ b/src/biomarkers/urls.py @@ -18,4 +18,5 @@ path('methylation-sites', views.MethylationSites.as_view(), name='methylation_sites'), path('methylation-sites-finder', views.MethylationSites.as_view(), name='methylation_sites_finder'), path('biomarker-molecules', views.BiomarkerMolecules.as_view(), name='biomarker_molecules'), + path('biomarker-correlation-api', views.BiomarkerCorrelationAPIView.as_view(), name='biomarker_correlation_api'), ] diff --git a/src/biomarkers/views.py b/src/biomarkers/views.py index f31a09b0..c78b8ef4 100644 --- a/src/biomarkers/views.py +++ b/src/biomarkers/views.py @@ -10,15 +10,17 @@ from rest_framework.request import Request from rest_framework.response import Response from rest_framework.views import APIView +from api_service.models import Experiment from api_service.mrna_service import global_mrna_service from biomarkers.models import Biomarker, BiomarkerState, BiomarkerOrigin, MoleculeIdentifier -from biomarkers.serializers import BiomarkerSerializer, MoleculeIdentifierSerializer, \ +from biomarkers.serializers import BiomarkerFromCorrelationAnalysisSerializer, BiomarkerSerializer, MoleculeIdentifierSerializer, \ BiomarkerSimpleSerializer, BiomarkerSimpleUpdateSerializer from common.pagination import StandardResultsSetPagination from common.response import generate_json_response_or_404 from django.db.models import QuerySet, Q + class BiomarkerList(generics.ListAPIView): """REST endpoint: list for Biomarker model""" @@ -276,3 +278,22 @@ def get_queryset(self): filter_backends = [filters.OrderingFilter, filters.SearchFilter, DjangoFilterBackend] search_fields = ['identifier'] ordering_fields = ['identifier'] + + +class BiomarkerCorrelationAPIView(APIView): + """Validates the request data and retrieves the corresponding experiment.""" + + def post(self, request, *args, **kwargs): + # Instantiate the serializer with the received data + serializer = BiomarkerFromCorrelationAnalysisSerializer(data=request.data) + + # Validate the data (returns a 400 error if the structure is incorrect) + serializer.is_valid(raise_exception=True) + validated_data = serializer.validated_data + + # Here the Biomarker is created validating which parameters were sent from the frontend + cor_analysis = get_object_or_404(Experiment, pk=validated_data['correlation_analysis_id']) + + return Response({ + "ok": True, + }) \ No newline at end of file diff --git a/src/genes/serializers.py b/src/genes/serializers.py index c0dac294..b11a9b5a 100644 --- a/src/genes/serializers.py +++ b/src/genes/serializers.py @@ -7,3 +7,9 @@ class GeneForResultTableSerializer(serializers.ModelSerializer): class Meta: model = Gene fields = ['type', 'chromosome', 'start', 'end', 'description'] + +class GeneGEMWithType(serializers.Serializer): + """Serializer for GeneGEMWithType""" + id = serializers.IntegerField() + molecule_type = serializers.IntegerField() +