Commit 9c6afc33 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Merge branch 'async-near-cavities' into 'master'

Async near cavities

See merge request !45
parents ded0cb6d c1785783
Pipeline #84283 passed with stages
in 11 minutes and 12 seconds
$(document).ready(function(){
$(".asnyc-construction.now[data-cavity-id]").each(function () {
loadNearCavityRows($(this));
});
});
function loadNearCavityRows($row){
if($row.length==0)
return;
$row.addClass("loading");
$.ajax({
url: '/cavity/'+$row.data("cavityId")+'/near-cavities',
data: {'chaincount':$row.data("chaincount"), 'cavcount':$row.data("cavcount")},
success: function(data){
var $data=$(data);
if ($row.hasClass("show"))
$data.addClass("show");
$data.insertAfter($row);
$row.remove();
}
});
}
\ No newline at end of file
{% load customtags %}
{% load humanize %}
<tr XXXid="cavity_{{ cavity.id }}"
{%if near_cavity %}
class="collapse out collapseme{{ chaincount }}_{{ cavcount }}"
style="background-color:rgb({{ score|get_color }})"
{%else%}
class="table-light"
{%endif%}>
<th class="zui-sticky-col text-nowrap">
{%if not near_cavity %}
<i class="far fa-plus-square" style="cursor: pointer;" data-toggle="collapse" data-target=".collapseme{{ chaincount }}_{{ cavcount }}"
onclick="loadNearCavityRows($('.asnyc-construction[data-cavity-id={{ cavity.id }}]:not(loading)'));"></i>
{%endif%}
<a {%if score %} title="{{ score|floatformat:3|intcomma }}" {%endif%}
target="_blank"
rel="noopener noreferrer"
href="{% url 'cavities' %}?pdbsearch={{ cavity.chain.pdb.code }}">{{ cavity.chain.pdb.code }}</a>
/
<span class="dropdown">
<div class="dropbtn" data-toggle="dropdown" title="uniprot: {{ cavity.chain.protein.uniprot_id }}">
{{ cavity.chain.pdb_chain_id }} | {{ cavity.chain.protein.short_name }}
</div>
<div class="dropdown-content">
<a target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?uniprotid={{ cavity.chain.protein.uniprot_id }}">Query UniprotID in pockets</a>
<a target="_blank" rel="noopener noreferrer" href="{% url 'compound_list' %}?uniprot_id={{ cavity.chain.protein.uniprot_id }}">Query UniprotID as iPPI-DB target</a>
</div>
</span>
/
<span class="dropdown">
<div class="dropbtn" data-toggle="dropdown">
{{ cavity.cavity_number }}
</div>
<div class="dropdown-content">
<a target="_blank" rel="noopener noreferrer" href="{% url 'networks' %}?search={{ cavity|build_name }}"> Query pocket in pocketome</a>
</div>
</span>
::
{% if cavity.partner.ligand %}
<span class="dropdown">
<div class="dropbtn" data-toggle="dropdown" title="smiles: {{ cavity.partner.ligand.canonical_smile }}">
{{ cavity.partner.ligand.pdb_ligand_id }}_{{ cavity.partner.ligand.supplementary_id }}
</div>
<div class="dropdown-content">
<a target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?ligandcode={{ cavity.partner.ligand.pdb_ligand_id }}">Query ligand ID in pockets</a>
<a target="_blank" rel="noopener noreferrer" href="{% url 'compound_list' %}?similar_to=ECFP4:{{ cavity.partner.ligand.canonical_smile|urlencode }}">Query SMILES in iPPI-DB compounds</a>
</div>
</span>
{% else %}
<span class="dropdown">
<div class="dropbtn" data-toggle="dropdown" title="uniprot: {{ cavity.partner.chain.protein.uniprot_id }}">
{{ cavity.partner.chain.pdb_chain_id }} | {{ cavity.partner.chain.protein.short_name }}
</div>
<div class="dropdown-content">
<a target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?uniprotid={{ cavity.partner.chain.protein.uniprot_id }}">Query UniprotID in pockets</a>
<a target="_blank" rel="noopener noreferrer" href="{% url 'compound_list' %}?uniprot_id={{ cavity.partner.chain.protein.uniprot_id }}">Query UniprotID as iPPI-DB target</a>
</div>
</span>
{% endif %}
</th>
<td>{% if cavity.partner.ligand %}PL{% else %}HD{% endif %}</td>
<td>{{ cavity.volume|floatformat:0 }}</td>
<td>{{ cavity.npr1|floatformat:2 }}</td>
<td>{{ cavity.npr2|floatformat:2 }}</td>
<td>{{ cavity.asphericity|floatformat:2 }}</td>
<td>{{ cavity.eccentricity|floatformat:2 }}</td>
<td>{{ cavity.rgyr|floatformat:2 }}</td>
<td>{{ cavity.spherocityindex|floatformat:2 }}</td>
<td>{{ cavity.ca|floatformat:1 }}</td>
<td>{{ cavity.cz|floatformat:1 }}</td>
<td>{{ cavity.n|floatformat:1 }}</td>
<td>{{ cavity.o|floatformat:1 }}</td>
<td>{{ cavity.og|floatformat:1 }}</td>
<td>{{ cavity.nz|floatformat:1 }}</td>
<td>{{ cavity.od1|floatformat:1 }}</td>
<td>{{ cavity.du|floatformat:1 }}</td>
<td>{{ cavity.t40|floatformat:1 }}</td>
<td>{{ cavity.t40_50|floatformat:1 }}</td>
<td>{{ cavity.t50_60|floatformat:1 }}</td>
<td>{{ cavity.t60_70|floatformat:1 }}</td>
<td>{{ cavity.t70_80|floatformat:1 }}</td>
<td>{{ cavity.t80_90|floatformat:1 }}</td>
<td>{{ cavity.t90_100|floatformat:1 }}</td>
<td>{{ cavity.t100_110|floatformat:1 }}</td>
<td>{{ cavity.t110_120|floatformat:1 }}</td>
<td>{{ cavity.t120|floatformat:1 }}</td>
</tr>
\ No newline at end of file
{% load customtags %}
{% for distance in object.near_cavities %}
{% with distance.distance|get_zscore:avg_std as score %}
{% if object == distance.cavity1 %}
{% include "targetcentric_cavity_row.html" with chaincount=chaincount cavcount=cavcount cavity=distance.cavity2 score=score near_cavity=True %}
{% elif object == distance.cavity2 %}
{% include "targetcentric_cavity_row.html" with chaincount=chaincount cavcount=cavcount cavity=distance.cavity1 score=score near_cavity=True %}
{% endif %}
{%endwith%}
{% endfor %}
\ No newline at end of file
......@@ -74,6 +74,7 @@ urlpatterns = [
),
re_path(r"^targetcentric/$", views.PDBView.as_view(), name="cavities"),
re_path(r"^targetcentric/networks$", views.NetworkView.as_view(), name="networks"),
re_path(r"^cavity/(?P<pk>\d+)/near-cavities$", views.NearCavitiesHTMLFragmentView.as_view(), name="near_cavities"),
re_path(r"^api/", include(ROUTER.urls)),
re_path(r"^compounds/$", views.CompoundListView.as_view(), name="compound_list"),
re_path(
......
......@@ -11,7 +11,7 @@ iPPI-DB views
"""
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
from .targetcentric import PdbViewSet, DistanceViewSet, PDBView, NetworkView
from .targetcentric import PdbViewSet, DistanceViewSet, PDBView, NetworkView, NearCavitiesHTMLFragmentView
from .contribute import ippidb_wizard_view, ContributionDetailView
from .compound_query import (
CompoundListView,
......@@ -111,6 +111,7 @@ __all__ = [
PDBView,
get_output_job,
NetworkView,
NearCavitiesHTMLFragmentView,
get_json_network,
IppiDbCompoundSitemap,
IppiDbContributorsSitemap,
......
......@@ -4,7 +4,7 @@ iPPI-DB targetcentric views and related classes
from itertools import product
from functools import reduce
from operator import add
from django.views.generic import ListView
from django.views.generic import ListView, DetailView
from django.contrib import messages
from django.db.models import Case, When, Value, IntegerField, F, Q
from rest_framework import viewsets
......@@ -308,3 +308,16 @@ class NetworkView(ListView):
def get_queryset(self):
queryset = self.model.objects.all()
return queryset.order_by("number")
class NearCavitiesHTMLFragmentView(DetailView):
model = Cavity
template_name = "targetcentric_near_cavities.html"
def get_context_data(self, *, object_list=None, **kwargs):
return dict(
**super().get_context_data(**kwargs),
chaincount=self.request.GET.get('chaincount', '0'),
cavcount=self.request.GET.get('cavcount', '0'),
avg_std=MetaInformation.objects.first(),
)
import os
import subprocess
def get_db_ip():
result = subprocess.run(
[
"docker",
"ps",
"-f",
"name=%s" % get_guessed_container_name(),
"-q",
],
stdout=subprocess.PIPE,
)
ids = result.stdout.decode("utf-8").strip().split("\n")
if len(ids) > 1:
raise Exception("Can't find the DB, too much match")
if len(ids) == 0 or len(ids[0]) == 0:
result = subprocess.run(
[
"docker",
"ps",
"-f",
"name=_db",
"-q",
],
stdout=subprocess.PIPE,
)
ids = result.stdout.decode("utf-8").strip().split("\n")
if len(ids) > 1:
raise Exception(
"Can't find the DB, couldn't guess container name (tried '%s'), "
"and too much match with '_db'" % get_guessed_container_name()
)
if len(ids) == 0 or len(ids[0]) == 0:
raise Exception("Can't find the DB")
result = subprocess.run(
[
"docker",
"inspect",
"-f",
"'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'",
ids[0],
],
stdout=subprocess.PIPE,
)
return result.stdout.decode("utf-8").strip().replace("'", "")
def get_guessed_container_name():
return (
str(os.path.dirname(__file__).split(os.path.sep)[-2]).lower().replace("-", "")
+ "_db"
)
if __name__ == "__main__":
print(get_db_ip())
......@@ -17,6 +17,8 @@ from decouple import config
from django.utils.translation import gettext_lazy
from socket import gethostname, gethostbyname
from ippisite import db_finder
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PERSISTENT_DIR = os.path.join(BASE_DIR, 'persistent')
......@@ -122,13 +124,16 @@ if config("USE_SQLITE_AS_DB", default="False").upper() == "TRUE":
}
}
else:
POSTGRES_HOST = config("POSTGRES_HOST", '')
if not POSTGRES_HOST:
POSTGRES_HOST = db_finder.get_db_ip()
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": config("POSTGRES_DB"),
"USER": config("POSTGRES_USER"),
"PASSWORD": config("POSTGRES_PASSWORD"),
"HOST": config("POSTGRES_HOST"),
"HOST": POSTGRES_HOST,
"PORT": 5432,
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment