From b829bf6f5a26edaa57acde0c4a21e2c24d695e87 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 19 Oct 2021 09:16:38 +0300 Subject: 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. --- gn3/partial_correlations.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gn3/partial_correlations.py') 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]))) -- cgit v1.2.3