about summary refs log tree commit diff
diff options
context:
space:
mode:
authorzsloan2020-09-24 23:39:26 -0500
committerzsloan2020-09-24 23:39:26 -0500
commit0aa2d5271b703fd37fb9c6a7511ecfe551268d36 (patch)
treea68ee65cccb466438b70cf5e319c3cf8f7de25fd
parent194a53126f636ad845ca2423f3928170cdfb6a2f (diff)
downloadgenenetwork2-0aa2d5271b703fd37fb9c6a7511ecfe551268d36.tar.gz
Changed logic that defines the primary/other samplelists to be much more
efficient

* wqflask/wqflask/show_trait/show_trait.py - Add an "if" statement to
avoid unnecessarily running some code and changed a list to a set for
the purposes of searching if it contains an element
-rw-r--r--wqflask/wqflask/show_trait/show_trait.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py
index f1bd6f27..30b03e66 100644
--- a/wqflask/wqflask/show_trait/show_trait.py
+++ b/wqflask/wqflask/show_trait/show_trait.py
@@ -43,8 +43,6 @@ logger = getLogger(__name__ )
 class ShowTrait(object):
 
     def __init__(self, kw):
-        logger.debug("in ShowTrait, kw are:", kw)
-
         if 'trait_id' in kw and kw['dataset'] != "Temp":
             self.temp_trait = False
             self.trait_id = kw['trait_id']
@@ -152,6 +150,7 @@ class ShowTrait(object):
                 #self.nearest_marker1 = ""
                 #self.nearest_marker2 = ""
 
+
         self.make_sample_lists()
 
         self.qnorm_vals = quantile_normalize_vals(self.sample_groups)
@@ -397,6 +396,7 @@ class ShowTrait(object):
                                           return_results_menu_selected = return_results_menu_selected,)
 
     def make_sample_lists(self):
+
         all_samples_ordered = self.dataset.group.all_samples_ordered()
         
         parent_f1_samples = []
@@ -405,13 +405,18 @@ class ShowTrait(object):
 
         primary_sample_names = list(all_samples_ordered)
 
+
         if not self.temp_trait:
             other_sample_names = []
-            for sample in self.this_trait.data.keys():
-                if (self.this_trait.data[sample].name2 in primary_sample_names) and (self.this_trait.data[sample].name not in primary_sample_names):
-                    primary_sample_names.append(self.this_trait.data[sample].name)
-                    primary_sample_names.remove(self.this_trait.data[sample].name2)
-                elif sample not in all_samples_ordered:
+
+            for sample in self.this_trait.data:
+                if self.this_trait.data[sample].name2 != self.this_trait.data[sample].name:
+                    if (self.this_trait.data[sample].name2 in primary_sample_names) and (self.this_trait.data[sample].name not in primary_sample_names):
+                        primary_sample_names.append(self.this_trait.data[sample].name)
+                        primary_sample_names.remove(self.this_trait.data[sample].name2)
+
+                all_samples_set = set(all_samples_ordered)
+                if sample not in all_samples_set:
                     all_samples_ordered.append(sample)
                     other_sample_names.append(sample)
 
@@ -424,6 +429,7 @@ class ShowTrait(object):
                 primary_header = "%s Only" % (self.dataset.group.name)
             else:
                 primary_header = "Samples"
+
             primary_samples = SampleList(dataset = self.dataset,
                                             sample_names=primary_sample_names,
                                             this_trait=self.this_trait,
@@ -523,9 +529,7 @@ def get_z_scores(sample_groups):
 
 def get_nearest_marker(this_trait, this_db):
     this_chr = this_trait.locus_chr
-    logger.debug("this_chr:", this_chr)
     this_mb = this_trait.locus_mb
-    logger.debug("this_mb:", this_mb)
     #One option is to take flanking markers, another is to take the two (or one) closest
     query = """SELECT Geno.Name
                FROM Geno, GenoXRef, GenoFreeze
@@ -536,7 +540,6 @@ def get_nearest_marker(this_trait, this_db):
                ORDER BY ABS( Geno.Mb - {}) LIMIT 1""".format(this_chr, this_db.group.name+"Geno", this_mb)
     logger.sql(query)
     result = g.db.execute(query).fetchall()
-    logger.debug("result:", result)
 
     if result == []:
         return ""