diff options
author | zsloan | 2021-05-25 20:49:48 +0000 |
---|---|---|
committer | zsloan | 2021-05-25 20:49:48 +0000 |
commit | 666494b49bef48a46145cf415262d532530aba46 (patch) | |
tree | 4f8dde2b5d72ace719cf7698ab1e9ac9b16b52ec | |
parent | 4d15c32e7d86885cffce1720db0df394bd6a02ff (diff) | |
download | genenetwork2-666494b49bef48a46145cf415262d532530aba46.tar.gz |
Fixed/shortened get_categorical_variables function and correctly pass them to show_trait template
-rw-r--r-- | wqflask/wqflask/show_trait/show_trait.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/wqflask/wqflask/show_trait/show_trait.py b/wqflask/wqflask/show_trait/show_trait.py index 837c7a54..a02da872 100644 --- a/wqflask/wqflask/show_trait/show_trait.py +++ b/wqflask/wqflask/show_trait/show_trait.py @@ -279,6 +279,8 @@ class ShowTrait: hddn['suggestive'] = 0 hddn['num_perm'] = 0 hddn['categorical_vars'] = "" + if categorical_var_list: + hddn['categorical_vars'] = ",".join(categorical_var_list) hddn['manhattan_plot'] = "" hddn['control_marker'] = "" if not self.temp_trait: @@ -684,23 +686,13 @@ def get_ncbi_summary(this_trait): return None -def get_categorical_variables(this_trait, sample_list): +def get_categorical_variables(this_trait, sample_list) -> list: categorical_var_list = [] if len(sample_list.attributes) > 0: for attribute in sample_list.attributes: - attribute_vals = [] - for sample_name in list(this_trait.data.keys()): - if sample_list.attributes[attribute].name in this_trait.data[sample_name].extra_attributes: - attribute_vals.append( - this_trait.data[sample_name].extra_attributes[sample_list.attributes[attribute].name]) - else: - attribute_vals.append("N/A") - num_distinct = len(set(attribute_vals)) - - if num_distinct < 10: - categorical_var_list.append( - sample_list.attributes[attribute].name) + if len(sample_list.attributes[attribute].distinct_values) < 10: + categorical_var_list.append(sample_list.attributes[attribute].name) return categorical_var_list |