diff --git a/Dockerfile b/Dockerfile index eb9ebfffb77c09b84161efdf55f95991221d3c07..6abc552ed463399196d426fb23663921f759c811 100755 --- a/Dockerfile +++ b/Dockerfile @@ -21,7 +21,7 @@ COPY ./requirements.txt /usr/src/drugstone/requirements.txt RUN pip install -r /usr/src/drugstone/requirements.txt COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf -RUN pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple nedrex==0.1.4 +RUN pip install nedrex COPY . /usr/src/drugstone/ diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml index cb01d8975c389a6f3d57b3e3046e6ab395d7b833..8de915488bad2a74c95f9e4f9d61a38c59ae8cbf 100755 --- a/docker-compose-prod.yml +++ b/docker-compose-prod.yml @@ -33,7 +33,7 @@ services: labels: - "com.centurylinklabs.watchtower.enable=true" db: - image: postgres + image: postgres:14 container_name: drugstone_postgres restart: always hostname: drugstone_postgres diff --git a/drugstone/management/commands/make_graphs.py b/drugstone/management/commands/make_graphs.py index 5a1f6ecdb01ccf9277f8ca70ca2322b1dd398dff..1a13741dc17a9d1bab5ef5bb6634580924e86baf 100755 --- a/drugstone/management/commands/make_graphs.py +++ b/drugstone/management/commands/make_graphs.py @@ -254,7 +254,7 @@ class Command(BaseCommand): if hash in uniq_combis: continue uniq_combis.add(hash) - for identifier in ['ensg', 'symbol', 'ensembl', 'uniprot']: + for identifier in ['ensg', 'symbol', 'entrez', 'uniprot']: parameter_combinations.append([ppi_ds, pdi_ds, identifier]) # close all database connections so subprocesses will create their own connections # this prevents the processes from running into problems because of using the same connection diff --git a/drugstone/management/commands/populate_db.py b/drugstone/management/commands/populate_db.py index 429cf6fc97b2fbc0ba07ec9b1051188b227ae9c0..94f64ce26a18c2afff81b2c5ef2e754a40f8aa25 100755 --- a/drugstone/management/commands/populate_db.py +++ b/drugstone/management/commands/populate_db.py @@ -86,8 +86,8 @@ class Command(BaseCommand): def populate(kwargs): - nedrex_api_url_unlicenced= "http://82.148.225.92:7123/" - nedrex_api_url_licenced = "http://82.148.225.92:8123/" + nedrex_api_url_unlicenced= "https://nedrex-api-open.zbh.uni-hamburg.de/" + nedrex_api_url_licenced = "https://nedrex-api-licenced.zbh.uni-hamburg.de/" data_dir = kwargs['data_dir'] diff --git a/drugstone/urls.py b/drugstone/urls.py index a2e5786b93670d486a922e0bd03c6d703c85b12a..886dbdd75f3ba34cc6fe475760096a12eee94879 100755 --- a/drugstone/urls.py +++ b/drugstone/urls.py @@ -18,7 +18,8 @@ from django.urls import path from drugstone.views import map_nodes, tasks_view, result_view, \ graph_export, TissueView, TissueExpressionView, 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 # cache time is 6 hours urlpatterns = [ @@ -33,6 +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('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 b2ef1ea245a923e0cf3d469d3245fe723a539bc4..57597b8f88d88aff18f9ce37951af149431edeac 100755 --- a/drugstone/views.py +++ b/drugstone/views.py @@ -4,12 +4,13 @@ import string import time import uuid from collections import defaultdict +from functools import reduce import pandas as pd import networkx as nx from django.http import HttpResponse -from django.db.models import Q +from django.db.models import Q, Max from django.db import IntegrityError from rest_framework.decorators import api_view from rest_framework.response import Response @@ -415,18 +416,21 @@ def result_view(request) -> Response: return Response(result) else: if view == 'proteins': + proteins = list( + filter(lambda n: 'drugstone_type' in n and n['drugstone_type'] == 'protein', node_details.values())) if fmt == 'csv': items = [] for i in proteins: new_i = { - 'uniprot_ac': i['uniprot_ac'], - 'gene': i['symbol'], - 'name': i['protein_name'], - 'ensg': i['ensg'], - 'entrez': i['entrez'], - 'seed': is_seed[i[node_name_attribute]], + 'id': i['id'], + 'uniprot_ac': i['uniprot_ac'] if 'uniprot_ac' in i else [], + 'gene': i['symbol'] if 'symbol' in i else [], + 'name': i['protein_name'] if 'protein_name' in i else [], + 'ensembl': i['ensg'] if 'ensg' in i else [], + 'entrez': i['entrez'] if 'entrez' in i else [], + 'seed': is_seed[i['id']], } - if i.get('score'): + if 'score' in i: new_i['score'] = i['score'] items.append(new_i) else: @@ -468,11 +472,6 @@ def graph_export(request) -> Response: G = nx.Graph() node_map = dict() for node in nodes: - # drugstone_id is not interesting outside of drugstone - # try: - # del node['drugstone_id'] - # except KeyError: - # pass # networkx does not support datatypes such as lists or dicts for key in list(node.keys()): if isinstance(node[key], list) or isinstance(node[key], dict): @@ -507,7 +506,23 @@ def graph_export(request) -> Response: data = nx.generate_graphml(G) response = HttpResponse(data, content_type='application/xml') elif fmt == 'json': - data = json.dumps(nx.readwrite.json_graph.node_link_data(G)) + data = nx.readwrite.json_graph.node_link_data(G) + del data['graph'] + del data['multigraph'] + remove_node_properties = ['color', 'shape', 'border_width', 'group_name', 'border_width_selected', 'shadow', + 'group_id', 'drugstone_type', 'font'] + remove_edge_properties = ['group_name', 'color', 'dashes', 'shadow', 'id'] + for node in data['nodes']: + for prop in remove_node_properties: + if prop in node: + del node[prop] + for edge in data['links']: + for prop in remove_edge_properties: + if prop in edge: + del edge[prop] + data["edges"] = data.pop("links") + data = json.dumps(data) + data = data.replace('"{', '{').replace('}"', '}').replace('"[', '[').replace(']"', ']').replace('\\"', '"') response = HttpResponse(data, content_type='application/json') elif fmt == 'csv': data = pd.DataFrame(nx.to_numpy_array(G), columns=G.nodes(), index=G.nodes()) @@ -612,6 +627,12 @@ 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'))}) + + @api_view(['POST']) def query_tissue_proteins(request) -> Response: threshold = request.data['threshold'] @@ -632,6 +653,7 @@ class TissueView(APIView): return Response(TissueSerializer(many=True).to_representation(tissues)) + class TissueExpressionView(APIView): """ Expression of host proteins in tissues. diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh index 43bf32df3da5898d25d96f8abd734edf4872ea3c..3c90d86f54ec7daebdfb9694939d1038ed24857c 100755 --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -4,7 +4,7 @@ python3 manage.py makemigrations drugstone python3 manage.py migrate python3 manage.py createfixtures python3 manage.py cleanuptasks -python3 manage.py populate_db --update -a +#python3 manage.py populate_db --update -a python3 manage.py make_graphs /usr/bin/supervisord -c "/etc/supervisor/conf.d/supervisord.conf"