diff --git a/drugstone/urls.py b/drugstone/urls.py index 886dbdd75f3ba34cc6fe475760096a12eee94879..7e0d16a49c23fdbbccef3c1f1d6f39fe833eb162 100755 --- a/drugstone/urls.py +++ b/drugstone/urls.py @@ -34,7 +34,7 @@ urlpatterns = [ path('adjacent_drugs/', adjacent_drugs), path('adjacent_disorders/', adjacent_disorders), path('tissue_expression/', TissueExpressionView.as_view()), - path('tissue_max_expression/', get_max_tissue_expression()), + path('tissue_max_expression/', get_max_tissue_expression), path('tissues/', TissueView.as_view()), path('admin/', admin.site.urls), path('create_network', create_network), diff --git a/drugstone/views.py b/drugstone/views.py index 5ddea2f3fc451d33408945aa1b55861118b3f6dc..eb86c9de4af8be042065ba9e52f330465aee7ed8 100755 --- a/drugstone/views.py +++ b/drugstone/views.py @@ -630,7 +630,8 @@ def query_proteins(request) -> Response: @api_view(['GET']) def get_max_tissue_expression(request) -> Response: tissue = Tissue.objects.get(id=request.query_params.get('tissue')) - return Response({max: ExpressionLevel.objects.filter(tissue=tissue).aggregate(Max('expression_level'))}) + return Response({'max': ExpressionLevel.objects.filter(tissue=tissue).aggregate(Max('expression_level'))[ + 'expression_level__max']}) @api_view(['POST']) @@ -653,7 +654,6 @@ class TissueView(APIView): return Response(TissueSerializer(many=True).to_representation(tissues)) - class TissueExpressionView(APIView): """ Expression of host proteins in tissues. @@ -704,3 +704,50 @@ class TissueExpressionView(APIView): pt_expressions[ProteinSerializer().to_representation(protein)['drugstone_id']] = None return Response(pt_expressions) + + + def post(self, request) -> Response: + tissue = Tissue.objects.get(id=request.data.get('tissue')) + + if request.data.get('proteins'): + ids = json.loads(request.data.get('proteins')) + proteins = list(Protein.objects.filter(id__in=ids).all()) + elif request.data.get('token'): + proteins = [] + task = Task.objects.get(token=request.data['token']) + result = task_result(task) + network = result['network'] + node_attributes = result.get('node_attributes') + if not node_attributes: + node_attributes = {} + node_types = node_attributes.get('node_types') + if not node_types: + node_types = {} + parameters = json.loads(task.parameters) + seeds = parameters['seeds'] + nodes = network['nodes'] + for node in nodes + seeds: + node_type = node_types.get(node) + details = None + if node_type == 'protein': + if details: + proteins.append(details) + else: + try: + prot = Protein.objects.get(uniprot_code=node) + if prot not in proteins: + proteins.append(Protein.objects.get(uniprot_code=node)) + except Protein.DoesNotExist: + pass + + pt_expressions = {} + + for protein in proteins: + try: + expression_level = ExpressionLevel.objects.get(protein=protein, tissue=tissue) + pt_expressions[ + ProteinSerializer().to_representation(protein)['drugstone_id']] = expression_level.expression_level + except ExpressionLevel.DoesNotExist: + pt_expressions[ProteinSerializer().to_representation(protein)['drugstone_id']] = None + + return Response(pt_expressions) diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 3c90d86f54ec7daebdfb9694939d1038ed24857c..db7a2d39ad5d4040b6dd34294c675ea20ae7b9bf 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -5,6 +5,6 @@ python3 manage.py migrate python3 manage.py createfixtures python3 manage.py cleanuptasks #python3 manage.py populate_db --update -a -python3 manage.py make_graphs +#python3 manage.py make_graphs /usr/bin/supervisord -c "/etc/supervisor/conf.d/supervisord.conf"