Skip to content
Snippets Groups Projects
Commit 6490a20b authored by Hartung, Michael's avatar Hartung, Michael
Browse files

Merge branch 'development' of...

Merge branch 'development' of gitlab.rrz.uni-hamburg.de:cosy-bio/drugst.one/backend into development


Former-commit-id: 733b561e
parents 96171739 e3395ded
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 ...@@ -21,7 +21,7 @@ COPY ./requirements.txt /usr/src/drugstone/requirements.txt
RUN pip install -r /usr/src/drugstone/requirements.txt RUN pip install -r /usr/src/drugstone/requirements.txt
COPY ./supervisord.conf /etc/supervisor/conf.d/supervisord.conf 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/ COPY . /usr/src/drugstone/
......
...@@ -33,7 +33,7 @@ services: ...@@ -33,7 +33,7 @@ services:
labels: labels:
- "com.centurylinklabs.watchtower.enable=true" - "com.centurylinklabs.watchtower.enable=true"
db: db:
image: postgres image: postgres:14
container_name: drugstone_postgres container_name: drugstone_postgres
restart: always restart: always
hostname: drugstone_postgres hostname: drugstone_postgres
......
...@@ -254,7 +254,7 @@ class Command(BaseCommand): ...@@ -254,7 +254,7 @@ class Command(BaseCommand):
if hash in uniq_combis: if hash in uniq_combis:
continue continue
uniq_combis.add(hash) 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]) parameter_combinations.append([ppi_ds, pdi_ds, identifier])
# close all database connections so subprocesses will create their own connections # 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 # this prevents the processes from running into problems because of using the same connection
......
...@@ -86,8 +86,8 @@ class Command(BaseCommand): ...@@ -86,8 +86,8 @@ class Command(BaseCommand):
def populate(kwargs): def populate(kwargs):
nedrex_api_url_unlicenced= "http://82.148.225.92:7123/" nedrex_api_url_unlicenced= "https://nedrex-api-open.zbh.uni-hamburg.de/"
nedrex_api_url_licenced = "http://82.148.225.92:8123/" nedrex_api_url_licenced = "https://nedrex-api-licenced.zbh.uni-hamburg.de/"
data_dir = kwargs['data_dir'] data_dir = kwargs['data_dir']
......
...@@ -18,7 +18,8 @@ from django.urls import path ...@@ -18,7 +18,8 @@ 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, TissueExpressionView, query_tissue_proteins, TaskView, \ 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 # cache time is 6 hours
urlpatterns = [ urlpatterns = [
...@@ -33,6 +34,7 @@ urlpatterns = [ ...@@ -33,6 +34,7 @@ urlpatterns = [
path('adjacent_drugs/', adjacent_drugs), path('adjacent_drugs/', adjacent_drugs),
path('adjacent_disorders/', adjacent_disorders), path('adjacent_disorders/', adjacent_disorders),
path('tissue_expression/', TissueExpressionView.as_view()), path('tissue_expression/', TissueExpressionView.as_view()),
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),
path('create_network', create_network), path('create_network', create_network),
......
...@@ -4,12 +4,13 @@ import string ...@@ -4,12 +4,13 @@ import string
import time import time
import uuid import uuid
from collections import defaultdict from collections import defaultdict
from functools import reduce
import pandas as pd import pandas as pd
import networkx as nx import networkx as nx
from django.http import HttpResponse from django.http import HttpResponse
from django.db.models import Q from django.db.models import Q, Max
from django.db import IntegrityError from django.db import IntegrityError
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from rest_framework.response import Response from rest_framework.response import Response
...@@ -415,18 +416,21 @@ def result_view(request) -> Response: ...@@ -415,18 +416,21 @@ def result_view(request) -> Response:
return Response(result) return Response(result)
else: else:
if view == 'proteins': if view == 'proteins':
proteins = list(
filter(lambda n: 'drugstone_type' in n and n['drugstone_type'] == 'protein', node_details.values()))
if fmt == 'csv': if fmt == 'csv':
items = [] items = []
for i in proteins: for i in proteins:
new_i = { new_i = {
'uniprot_ac': i['uniprot_ac'], 'id': i['id'],
'gene': i['symbol'], 'uniprot_ac': i['uniprot_ac'] if 'uniprot_ac' in i else [],
'name': i['protein_name'], 'gene': i['symbol'] if 'symbol' in i else [],
'ensg': i['ensg'], 'name': i['protein_name'] if 'protein_name' in i else [],
'entrez': i['entrez'], 'ensembl': i['ensg'] if 'ensg' in i else [],
'seed': is_seed[i[node_name_attribute]], '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'] new_i['score'] = i['score']
items.append(new_i) items.append(new_i)
else: else:
...@@ -468,11 +472,6 @@ def graph_export(request) -> Response: ...@@ -468,11 +472,6 @@ def graph_export(request) -> Response:
G = nx.Graph() G = nx.Graph()
node_map = dict() node_map = dict()
for node in nodes: 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 # networkx does not support datatypes such as lists or dicts
for key in list(node.keys()): for key in list(node.keys()):
if isinstance(node[key], list) or isinstance(node[key], dict): if isinstance(node[key], list) or isinstance(node[key], dict):
...@@ -507,7 +506,23 @@ def graph_export(request) -> Response: ...@@ -507,7 +506,23 @@ def graph_export(request) -> Response:
data = nx.generate_graphml(G) data = nx.generate_graphml(G)
response = HttpResponse(data, content_type='application/xml') response = HttpResponse(data, content_type='application/xml')
elif fmt == 'json': 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') response = HttpResponse(data, content_type='application/json')
elif fmt == 'csv': elif fmt == 'csv':
data = pd.DataFrame(nx.to_numpy_array(G), columns=G.nodes(), index=G.nodes()) data = pd.DataFrame(nx.to_numpy_array(G), columns=G.nodes(), index=G.nodes())
...@@ -612,6 +627,12 @@ def query_proteins(request) -> Response: ...@@ -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']) @api_view(['POST'])
def query_tissue_proteins(request) -> Response: def query_tissue_proteins(request) -> Response:
threshold = request.data['threshold'] threshold = request.data['threshold']
...@@ -632,6 +653,7 @@ class TissueView(APIView): ...@@ -632,6 +653,7 @@ class TissueView(APIView):
return Response(TissueSerializer(many=True).to_representation(tissues)) return Response(TissueSerializer(many=True).to_representation(tissues))
class TissueExpressionView(APIView): class TissueExpressionView(APIView):
""" """
Expression of host proteins in tissues. Expression of host proteins in tissues.
......
...@@ -4,7 +4,7 @@ python3 manage.py makemigrations drugstone ...@@ -4,7 +4,7 @@ python3 manage.py makemigrations drugstone
python3 manage.py migrate python3 manage.py migrate
python3 manage.py createfixtures python3 manage.py createfixtures
python3 manage.py cleanuptasks python3 manage.py cleanuptasks
python3 manage.py populate_db --update -a #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" /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