From c7980e0180515dcbc2f7a35eeaa3f717205d656d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20M=C3=A9nager?= <herve.menager@pasteur.fr>
Date: Thu, 24 Sep 2020 15:13:55 +0200
Subject: [PATCH] use best_activity to compute compound LE and LLE

thereby discarding Kd ratio, which isn't a
valid type activity to compute these

FIX #244
---
 ippisite/ippidb/models.py | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index 181f149b..3bb8468c 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -1556,11 +1556,6 @@ def update_compound_cached_properties(compounds_queryset=None):
         )
         c.save()
     compounds_queryset.update(
-        pubs=Subquery(
-            compounds_queryset.filter(id=OuterRef("id"))
-            .annotate(_pubs=Count("refcompoundbiblio", distinct=True))
-            .values("_pubs")[:1]
-        ),
         best_activity=Subquery(
             compounds_queryset.filter(id=OuterRef("id"))
             .annotate(
@@ -1571,11 +1566,18 @@ def update_compound_cached_properties(compounds_queryset=None):
             )
             .values("_best_activity")[:1]
         ),
+    )
+    compounds_queryset.update(
+        pubs=Subquery(
+            compounds_queryset.filter(id=OuterRef("id"))
+            .annotate(_pubs=Count("refcompoundbiblio", distinct=True))
+            .values("_pubs")[:1]
+        ),
         le=Subquery(
             compounds_queryset.filter(id=OuterRef("id"))
             .annotate(
                 _le=Cast(
-                    1.37 * Max("compoundactivityresult__activity") / F("nb_atom_non_h"),
+                    1.37 * F("best_activity") / F("nb_atom_non_h"),
                     FloatField(),
                 )
             )
@@ -1585,7 +1587,7 @@ def update_compound_cached_properties(compounds_queryset=None):
             compounds_queryset.filter(id=OuterRef("id"))
             .annotate(
                 _lle=Cast(
-                    Max("compoundactivityresult__activity") - F("a_log_p"), FloatField()
+                    F("best_activity") - F("a_log_p"), FloatField()
                 )
             )
             .values("_lle")[:1]
-- 
GitLab