diff options
author | Frederick Muriuki Muriithi | 2021-10-19 09:16:38 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-10-19 09:16:38 +0300 |
commit | 3304fa682924b8f6bff5126ecf2fb58f4201b968 (patch) | |
tree | 7f9d097e0234b086533c2eb36c9d57e59d267949 /gn3 | |
parent | c5355c5db72fdec9e7e360ceec19d5d50d15ce00 (diff) | |
download | genenetwork3-3304fa682924b8f6bff5126ecf2fb58f4201b968.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.py | 16 |
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]))) |