Skip to content
Snippets Groups Projects
Commit d17d283f authored by Maier, Andreas's avatar Maier, Andreas
Browse files

Merge branch 'production' into 'development'

Production

See merge request !2
parents c1d7e66b aa61a9c7
No related branches found
No related tags found
No related merge requests found
......@@ -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/
......
......@@ -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
......
......@@ -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
......
......@@ -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']
......
......@@ -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),
......
......@@ -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.
......
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment