aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-08-03 12:48:27 +0300
committerFrederick Muriuki Muriithi2022-08-03 12:48:27 +0300
commit85a6b9e556bd3f0d289ad01e56d6c0267431aa65 (patch)
treed66d44a0ce2f47995283791baa98fc563985c65a
parent6b11a267084c131ac7e1be76c4eb602996fd829e (diff)
downloadgenenetwork3-85a6b9e556bd3f0d289ad01e56d6c0267431aa65.tar.gz
Refactor: Remove unnecessary iterations and name
* remove extra iteration that is unnecessary * remove unnecessary variables
-rw-r--r--gn3/computations/rust_correlation.py24
1 files changed, 10 insertions, 14 deletions
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],