From ca80e1ec429adb65a59fcc8344350bfecfd38899 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Herv=C3=A9=20=20MENAGER?= <herve.menager@pasteur.fr>
Date: Sun, 8 Apr 2018 18:58:19 +0200
Subject: [PATCH] add "compound target family" to the LE-LLE plot

Former-commit-id: a8980972bc9fdf6728a1b910230b59734d4311ff
---
 ippisite/db.sqlite3.REMOVED.git-id            |  2 +-
 ippisite/ippidb/management/commands/lle_le.py |  3 +-
 ippisite/ippidb/models.py                     | 10 ++++++
 ippisite/ippidb/templates/compound_card.html  | 31 ++++++++++++++++---
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/ippisite/db.sqlite3.REMOVED.git-id b/ippisite/db.sqlite3.REMOVED.git-id
index 6947594a..5e100e09 100644
--- a/ippisite/db.sqlite3.REMOVED.git-id
+++ b/ippisite/db.sqlite3.REMOVED.git-id
@@ -1 +1 @@
-8e1155c407f37772a3cec105df9f551c3bbe8232
\ No newline at end of file
+484ef6ada16ce17d584108ab14d1ec6467385442
\ No newline at end of file
diff --git a/ippisite/ippidb/management/commands/lle_le.py b/ippisite/ippidb/management/commands/lle_le.py
index 6a0d08c8..2e04f1cf 100644
--- a/ippisite/ippidb/management/commands/lle_le.py
+++ b/ippisite/ippidb/management/commands/lle_le.py
@@ -17,9 +17,10 @@ class Command(BaseCommand):
         self.stdout.write(
             self.style.SUCCESS('Successfully flushed LE-LLE biplot data table'))
         for comp in Compound.objects.all():
+            print(comp.id)
             le = round(comp.le, 7)
             lle = round(comp.lle, 7)
-            le_lle_data.append({'x': le, 'y': lle, 'id': comp.id, 'family':'TBD'})
+            le_lle_data.append({'x': le, 'y': lle, 'id': comp.id, 'family_name': comp.best_activity_ppi_name})
         le_lle_json = json.dumps(le_lle_data, separators=(',',':'))
         new = LeLleBiplotData()
         new.le_lle_biplot_data = le_lle_json
diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py
index 0cc0f182..787862e2 100644
--- a/ippisite/ippidb/models.py
+++ b/ippisite/ippidb/models.py
@@ -422,6 +422,16 @@ class Compound(models.Model):
         """
         return float(self.compoundactivityresult_set.aggregate(Max('activity'))['activity__max'] - self.a_log_p)     
 
+    @property
+    def best_activity_ppi_name(self):
+        """
+        LE: Ligand Efficiency
+        """
+        best_activity = self.compoundactivityresult_set.aggregate(Max('activity'))['activity__max']
+        best_activity_car = self.compoundactivityresult_set.filter(activity=best_activity)[0]
+        ppi_name = best_activity_car.test_activity_description.ppi.name
+        return ppi_name
+
 class LeLleBiplotData(models.Model):
     le_lle_biplot_data = models.CharField('LE-LLE biplot JSON data', max_length=150000, blank=True, null=True)
 
diff --git a/ippisite/ippidb/templates/compound_card.html b/ippisite/ippidb/templates/compound_card.html
index 24f97c84..8ba957c4 100644
--- a/ippisite/ippidb/templates/compound_card.html
+++ b/ippisite/ippidb/templates/compound_card.html
@@ -154,18 +154,41 @@
             </div>
           </div>
           <div class="tab-pane fade" id="v-pills-pharmacology" role="tabpanel" aria-labelledby="v-pills-pharmacology-tab">
-             <div class="card col-sm-12 col-md-6">
+             <div class="card col-sm-12 col-md-12">
               <h5 class="card-header">Efficiencies: iPPI-DB biplot LE versus LLE</h5>
               <div class="card-body">
 
               <canvas id="le_lle_biplot"></canvas>
               <script>
+                var allData = {{ biplot_data | safe }};
+                var currentCompoundData = [];
+                var currentFamilyData = [];
+                var otherFamiliesData = [];
+                allData.forEach((item) => {
+                    if(item.id == {{ compound.id }}){
+                        currentCompoundData.push(item);
+                    }else if(item.family_name == '{{ compound.best_activity_ppi_name}}'){
+                        currentFamilyData.push(item);
+                    }else{
+                        otherFamiliesData.push(item)
+                    }
+                });
                 var scatterData = {
                 'datasets': [
                     { label: 'Other PPI families',
-                      borderColor: "rgba(211,211,211, 0.8)",
-                      backgroundColor: "rgba(211,211,211, 0.8)",
-                      data: {{ biplot_data | safe }}
+                      borderColor: "rgba(211,211,211, 0.5)",
+                      backgroundColor: "rgba(211,211,211, 0.5)",
+                      data: otherFamiliesData
+                    },
+                    { label: '{{ compound.best_activity_ppi_name}} family',
+                      borderColor: "rgba(54, 162, 235, 1)",
+                      backgroundColor: "rgba(54, 162, 235, 0.5)",
+                      data: currentFamilyData
+                    },
+                    { label: 'Compound',
+                      borderColor: "rgba(0, 17, 250, 1)",
+                      backgroundColor: "rgba(0, 17, 250, 0.5)",
+                      data: currentCompoundData
                     }
                 ]};
                 var ctx = document.getElementById('le_lle_biplot').getContext('2d');
-- 
GitLab