Commit 5788ece5 authored by Fabien  MAREUIL's avatar Fabien MAREUIL
Browse files

update score and gradient color from knn distance

parent 32c95663
Pipeline #47312 passed with stages
in 21 minutes and 52 seconds
...@@ -160,9 +160,7 @@ ...@@ -160,9 +160,7 @@
</div> </div>
<div class="row text-justify ml-3 mr-3"> <div class="row text-justify ml-3 mr-3">
<div class="col-8 text-wrap"> <div class="col-8 text-wrap">
Gradient colors for table is based on maximum and minimum zscore in the matrix. Zscore is given when you mouseover a cavity name. Be carefull, if its value is greater Gradient colors for table is based on maximum and minimum score in the matrix. Score is given when you mouseover a cavity name.
than {{ avg_std|get_zscore_threshold|floatformat:2|intcomma }} (-2 x the standard deviation),
it should be interpreted with caution.
</div> </div>
<div class="col-4"> <div class="col-4">
<table class="gradiant"><tbody><tr> <table class="gradiant"><tbody><tr>
...@@ -287,7 +285,7 @@ ...@@ -287,7 +285,7 @@
<tr class="collapse out collapseme{{ chaincount }}_{{ cavcount }}" style="background-color:rgb({{ distance.distance|get_color:avg_std }})"> <tr class="collapse out collapseme{{ chaincount }}_{{ cavcount }}" style="background-color:rgb({{ distance.distance|get_color:avg_std }})">
<th class="zui-sticky-col text-nowrap"> <th class="zui-sticky-col text-nowrap">
<a title="{{ distance.distance|get_zscore:avg_std }}" target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?pdbsearch={{ distance.cavity2.chain.pdb.code }}">{{ distance.cavity2.chain.pdb.code }}</a> <a title="{{ distance.distance|get_zscore:avg_std|floatformat:3|intcomma }}" target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?pdbsearch={{ distance.cavity2.chain.pdb.code }}">{{ distance.cavity2.chain.pdb.code }}</a>
/ /
<span class="dropdown"> <span class="dropdown">
<button class="dropbtn btn-outline-secondary" data-toggle="dropdown" title="uniprot: {{ distance.cavity2.chain.protein.uniprot_id }}"> <button class="dropbtn btn-outline-secondary" data-toggle="dropdown" title="uniprot: {{ distance.cavity2.chain.protein.uniprot_id }}">
...@@ -352,7 +350,7 @@ ...@@ -352,7 +350,7 @@
{% elif cavity == distance.cavity2 %} {% elif cavity == distance.cavity2 %}
<tr class="collapse out collapseme{{ chaincount }}_{{ cavcount }}" style="background-color:rgb({{ distance.distance|get_color:avg_std }})"> <tr class="collapse out collapseme{{ chaincount }}_{{ cavcount }}" style="background-color:rgb({{ distance.distance|get_color:avg_std }})">
<th class="zui-sticky-col text-nowrap"> <th class="zui-sticky-col text-nowrap">
<a title="{{ distance.distance|get_zscore:avg_std }}" target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?pdbsearch={{ distance.cavity1.chain.pdb.code }}">{{ distance.cavity1.chain.pdb.code }}</a> <a title="{{ distance.distance|get_zscore:avg_std|floatformat:3|intcomma }}" target="_blank" rel="noopener noreferrer" href="{% url 'cavities' %}?pdbsearch={{ distance.cavity1.chain.pdb.code }}">{{ distance.cavity1.chain.pdb.code }}</a>
/ /
<span class="dropdown"> <span class="dropdown">
<button class="dropbtn btn-outline-secondary" data-toggle="dropdown" title="uniprot: {{ distance.cavity1.chain.protein.uniprot_id }}"> <button class="dropbtn btn-outline-secondary" data-toggle="dropdown" title="uniprot: {{ distance.cavity1.chain.protein.uniprot_id }}">
......
...@@ -235,18 +235,20 @@ def verbose_name(obj, field_name=None): ...@@ -235,18 +235,20 @@ def verbose_name(obj, field_name=None):
@register.filter @register.filter
def get_zscore(distance, avg_std): def get_zscore_old(distance, avg_std):
# DEPRECATED
return (distance - avg_std.average) / avg_std.std return (distance - avg_std.average) / avg_std.std
@register.filter @register.filter
def get_color(distance, avg_std): def get_color_old(distance, avg_std):
# DEPRECATED
zminimum = np.arctan(float((avg_std.minimum - avg_std.average) / avg_std.std)) zminimum = np.arctan(float((avg_std.minimum - avg_std.average) / avg_std.std))
zmaximum = np.arctan(float((avg_std.maximum - avg_std.average) / avg_std.std)) zmaximum = np.arctan(float((avg_std.maximum - avg_std.average) / avg_std.std))
value = np.arctan(float((distance - avg_std.average) / avg_std.std)) value = np.arctan(float((distance - avg_std.average) / avg_std.std))
ratio = 1 - (1 * (value - zminimum) / (zmaximum - zminimum)) ratio = 1 - (1 * (value - zminimum) / (zmaximum - zminimum))
hsl = ratio * 120 / 360 hsl = ratio * 120 / 360
rgb_color = colorsys.hls_to_rgb(hsl, 0.6, 0.4) rgb_color = colorsys.hls_to_rgb(hsl, 0.6, 0.3)
return "{}, {}, {}".format( return "{}, {}, {}".format(
rgb_color[0] * 255, rgb_color[1] * 255, rgb_color[2] * 255 rgb_color[0] * 255, rgb_color[1] * 255, rgb_color[2] * 255
) )
...@@ -254,10 +256,36 @@ def get_color(distance, avg_std): ...@@ -254,10 +256,36 @@ def get_color(distance, avg_std):
@register.filter @register.filter
def get_zscore_threshold(avg_std): def get_zscore_threshold(avg_std):
# DEPRECATED
return -2 * avg_std.std return -2 * avg_std.std
@register.filter
def get_zscore(distance, avg_std):
value_max = avg_std.average + (avg_std.average - avg_std.minimum)
if distance > value_max:
distance = value_max
score = (distance - avg_std.minimum) / (value_max - avg_std.minimum)
return score
@register.filter
def get_color(distance, avg_std):
value_max = avg_std.average + (avg_std.average - avg_std.minimum)
if distance > value_max:
distance = value_max
value = float((distance - avg_std.minimum) / (value_max - avg_std.minimum))
ratio = 1 - value
hsl = ratio * 120 / 360
rgb_color = colorsys.hls_to_rgb(hsl, 0.65, 0.7)
return "{}, {}, {}".format(
rgb_color[0] * 255, rgb_color[1] * 255, rgb_color[2] * 255
)
@register.filter @register.filter
def make_list(avg_std): def make_list(avg_std):
step = (avg_std.maximum - avg_std.minimum) / 25 gradient_max = avg_std.average + (avg_std.average - avg_std.minimum)
return np.arange(avg_std.minimum, avg_std.maximum + step, step) step = (gradient_max - avg_std.minimum) / 25
return np.arange(avg_std.minimum, gradient_max + step, step)
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