aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-19 09:16:38 +0300
committerBonfaceKilz2021-10-19 16:33:32 +0300
commitb829bf6f5a26edaa57acde0c4a21e2c24d695e87 (patch)
tree3492b866fb05d2b1202216a8bb8f69c5e06dc2b5 /gn3
parenta44acad05fb286b9a2e797982d01841a1e817860 (diff)
downloadgenenetwork3-b829bf6f5a26edaa57acde0c4a21e2c24d695e87.tar.gz
Implement `dictify_by_samples`
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/partial_correlations.py: implement `dictify_by_samples` function * tests/unit/test_partial_correlations.py: implement tests for `dictify_by_samples` function Implement the `dictify_by_samples` function as a partial migration of the `web.webqtl.correlation.correlationFunction.fixStrains` function from GN1.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/partial_correlations.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/gn3/partial_correlations.py b/gn3/partial_correlations.py
index 99521c6..4db4807 100644
--- a/gn3/partial_correlations.py
+++ b/gn3/partial_correlations.py
@@ -44,3 +44,19 @@ def control_samples(controls: Sequence[dict], sampleslist: Sequence[str]):
),
[__process_control__(trait_data) for trait_data in controls],
(tuple(), tuple(), tuple(), tuple()))
+
+def dictify_by_samples(samples_vals_vars: Sequence[Sequence]) -> dict:
+ """
+ Build a sequence of dictionaries from a sequence of separate sequences of
+ samples, values and variances.
+
+ This is a partial migration of
+ `web.webqtl.correlation.correlationFunction.fixStrains` function in GN1.
+ This implementation extracts code that will find common use, and that will
+ find use in more than one place.
+ """
+ return tuple(
+ {
+ sample: {"sample_name": sample, "value": val, "variance": var}
+ for sample, val, var in zip(*trait_line)
+ } for trait_line in zip(*(samples_vals_vars[0:3])))