Skip to content
Snippets Groups Projects
Commit ac64a8ce authored by AndiMajore's avatar AndiMajore
Browse files

try to fix tissue expression route

Former-commit-id: ce36ed579d6db16b9325d3f75d2d3b9f8e5421ac [formerly 05ebeee6e00b7ee69d912087f4a128f32aec02da]
Former-commit-id: 62181610c82c73f04deaafdf23b67d14db0661c0
parent 1db389eb
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ from django.urls import path ...@@ -19,7 +19,7 @@ from django.urls import path
from drugstone.views import map_nodes, tasks_view, result_view, \ from drugstone.views import map_nodes, tasks_view, result_view, \
graph_export, TissueView, query_tissue_proteins, TaskView, \ graph_export, TissueView, query_tissue_proteins, TaskView, \
adjacent_drugs, adjacent_disorders, fetch_edges, create_network, load_network, get_license, get_datasets, \ adjacent_drugs, adjacent_disorders, fetch_edges, create_network, load_network, get_license, get_datasets, \
get_max_tissue_expression, get_tissue_expression get_max_tissue_expression
# cache time is 6 hours # cache time is 6 hours
urlpatterns = [ urlpatterns = [
...@@ -33,7 +33,7 @@ urlpatterns = [ ...@@ -33,7 +33,7 @@ urlpatterns = [
path('query_tissue_proteins/', query_tissue_proteins), path('query_tissue_proteins/', query_tissue_proteins),
path('adjacent_drugs/', adjacent_drugs), path('adjacent_drugs/', adjacent_drugs),
path('adjacent_disorders/', adjacent_disorders), path('adjacent_disorders/', adjacent_disorders),
path('tissue_expression/', get_tissue_expression), 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('tissues/', TissueView.as_view()),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
......
...@@ -653,49 +653,56 @@ class TissueView(APIView): ...@@ -653,49 +653,56 @@ class TissueView(APIView):
return Response(TissueSerializer(many=True).to_representation(tissues)) return Response(TissueSerializer(many=True).to_representation(tissues))
@api_view(['POST', 'GET']) class TissueExpressionView(APIView):
def get_tissue_expression(request) -> Response: """
tissue = Tissue.objects.get(id=request.query_params.get('tissue')) Expression of host proteins in tissues.
"""
if request.query_params.get('proteins'): def get(self, request) -> Response:
ids = json.loads(request.query_params.get('proteins')) return self.post(request)
proteins = list(Protein.objects.filter(id__in=ids).all())
elif request.query_params.get('token'): def post(self, request) -> Response:
proteins = [] tissue = Tissue.objects.get(id=request.data.get('tissue'))
task = Task.objects.get(token=request.query_params['token'])
result = task_result(task) if request.data.get('proteins'):
network = result['network'] ids = json.loads(request.data.get('proteins'))
node_attributes = result.get('node_attributes') proteins = list(Protein.objects.filter(id__in=ids).all())
if not node_attributes: elif request.data.get('token'):
node_attributes = {} proteins = []
node_types = node_attributes.get('node_types') task = Task.objects.get(token=request.data['token'])
if not node_types: result = task_result(task)
node_types = {} network = result['network']
parameters = json.loads(task.parameters) node_attributes = result.get('node_attributes')
seeds = parameters['seeds'] if not node_attributes:
nodes = network['nodes'] node_attributes = {}
for node in nodes + seeds: node_types = node_attributes.get('node_types')
node_type = node_types.get(node) if not node_types:
details = None node_types = {}
if node_type == 'protein': parameters = json.loads(task.parameters)
if details: seeds = parameters['seeds']
proteins.append(details) nodes = network['nodes']
else: for node in nodes + seeds:
try: node_type = node_types.get(node)
prot = Protein.objects.get(uniprot_code=node) details = None
if prot not in proteins: if node_type == 'protein':
proteins.append(Protein.objects.get(uniprot_code=node)) if details:
except Protein.DoesNotExist: proteins.append(details)
pass else:
try:
pt_expressions = {} prot = Protein.objects.get(uniprot_code=node)
if prot not in proteins:
for protein in proteins: proteins.append(Protein.objects.get(uniprot_code=node))
try: except Protein.DoesNotExist:
expression_level = ExpressionLevel.objects.get(protein=protein, tissue=tissue) pass
pt_expressions[
ProteinSerializer().to_representation(protein)['drugstone_id']] = expression_level.expression_level pt_expressions = {}
except ExpressionLevel.DoesNotExist:
pt_expressions[ProteinSerializer().to_representation(protein)['drugstone_id']] = None 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) return Response(pt_expressions)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment