From 85a6b9e556bd3f0d289ad01e56d6c0267431aa65 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 3 Aug 2022 12:48:27 +0300 Subject: Refactor: Remove unnecessary iterations and name * remove extra iteration that is unnecessary * remove unnecessary variables --- gn3/computations/rust_correlation.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'gn3') diff --git a/gn3/computations/rust_correlation.py b/gn3/computations/rust_correlation.py index 5a79a40..276013a 100644 --- a/gn3/computations/rust_correlation.py +++ b/gn3/computations/rust_correlation.py @@ -78,25 +78,21 @@ def run_correlation(dataset, trait_vals: def parse_correlation_output(result_file: str, top_n: int = 500) -> list[dict]: """parse file output """ - - corr_results = [] - - with open(result_file, "r", encoding="utf-8") as file_reader: - - lines = [next(file_reader) for x in range(top_n)] - - for line in lines: - (trait_name, corr_coeff, - p_val, num_overlap) = line.rstrip().split(",") - corr_data = { + def __parse_line__(line): + (trait_name, corr_coeff, p_val, num_overlap) = line.rstrip().split(",") + return { + trait_name: { "num_overlap": num_overlap, "corr_coefficient": corr_coeff, "p_value": p_val - } + }} - corr_results.append({trait_name: corr_data}) + with open(result_file, "r", encoding="utf-8") as file_reader: + return [ + __parse_line__(line) + for idx, line in enumerate(file_reader) if idx < top_n] - return corr_results + return [] def get_samples(all_samples: dict[str, str], -- cgit v1.2.3