From 2864bf07f919dacc72b5df590b140881bbe8dc0c Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 2 Nov 2020 13:16:59 -0600 Subject: Changed correlation page logic to skip over traits that share fewer than 6 samples + traits that user doesn't have permission to access * wqflask/wqflask/correlation/show_corr_results.py - Moved the num_overlap check so that it never attempts to calculate the correlation if it's too low + checked if trait_object is None in the main loop (since it would be returned as None if the user doesn't have permissions --- wqflask/wqflask/correlation/show_corr_results.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/correlation/show_corr_results.py b/wqflask/wqflask/correlation/show_corr_results.py index e710bacd..4c2b64ba 100644 --- a/wqflask/wqflask/correlation/show_corr_results.py +++ b/wqflask/wqflask/correlation/show_corr_results.py @@ -184,6 +184,8 @@ class CorrelationResults(object): for _trait_counter, trait in enumerate(list(self.correlation_data.keys())[:self.return_number]): trait_object = create_trait(dataset=self.target_dataset, name=trait, get_qtl_info=True, get_sample_info=False) + if not trait_object: + continue if self.target_dataset.type == "ProbeSet" or self.target_dataset.type == "Geno": #ZS: Convert trait chromosome to an int for the location range option @@ -434,15 +436,15 @@ class CorrelationResults(object): self.this_trait_vals, target_vals, num_overlap = corr_result_helpers.normalize_values(self.this_trait_vals, target_vals) - #ZS: 2015 could add biweight correlation, see http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3465711/ - if self.corr_method == 'bicor': - sample_r, sample_p = do_bicor(self.this_trait_vals, target_vals) - elif self.corr_method == 'pearson': - sample_r, sample_p = scipy.stats.pearsonr(self.this_trait_vals, target_vals) - else: - sample_r, sample_p = scipy.stats.spearmanr(self.this_trait_vals, target_vals) - if num_overlap > 5: + #ZS: 2015 could add biweight correlation, see http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3465711/ + if self.corr_method == 'bicor': + sample_r, sample_p = do_bicor(self.this_trait_vals, target_vals) + elif self.corr_method == 'pearson': + sample_r, sample_p = scipy.stats.pearsonr(self.this_trait_vals, target_vals) + else: + sample_r, sample_p = scipy.stats.spearmanr(self.this_trait_vals, target_vals) + if numpy.isnan(sample_r): pass else: @@ -635,3 +637,4 @@ def get_header_fields(data_type, corr_method): 'Sample p(r)'] return header_fields + -- cgit v1.2.3 From 04e981ba202a6bd9d969c05855a33040928d15d0 Mon Sep 17 00:00:00 2001 From: zsloan Date: Mon, 2 Nov 2020 13:21:40 -0600 Subject: Created function for encoding the column value as bytes when fetching from the JSON-formatted string pulled from Redis (since this was needed after the Python 3 switchover) * wqflask/utility/redis_tools.py - Created function load_json_from_redis that encodes the key (column_value) when fetching a value from the JSON pulled from Redis --- wqflask/utility/redis_tools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'wqflask') diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py index d855a7fa..236cc755 100644 --- a/wqflask/utility/redis_tools.py +++ b/wqflask/utility/redis_tools.py @@ -25,6 +25,10 @@ def is_redis_available(): return True +def load_json_from_redis(item_list, column_value): + return json.loads(item_list[str.encode(column_value)]) + + def get_user_id(column_name, column_value): user_list = Redis.hgetall("users") key_list = [] @@ -46,7 +50,7 @@ def get_user_by_unique_column(column_name, column_value): if column_name in user_ob and user_ob[column_name] == column_value: item_details = user_ob else: - item_details = json.loads(user_list[column_value]) + item_details = load_json_from_redis(user_list, column_value) return item_details @@ -70,7 +74,7 @@ def get_users_like_unique_column(column_name, column_value): if column_value in user_ob[column_name]: matched_users.append(user_ob) else: - matched_users.append(json.loads(user_list[column_value])) + matched_users.append(load_json_from_redis(user_list, column_value)) return matched_users @@ -199,7 +203,7 @@ def get_groups_like_unique_column(column_name, column_value): if column_value in group_info[column_name]: matched_groups.append(group_info) else: - matched_groups.append(json.loads(group_list[column_value])) + matched_groups.append(load_json_from_redis(group_list, column_value)) return matched_groups -- cgit v1.2.3