diff options
author | Frederick Muriuki Muriithi | 2021-10-18 12:27:32 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2021-10-18 12:27:32 +0300 |
commit | 94ca79045baf978d6aab964c7c70b84911c1124f (patch) | |
tree | 35627e25d9d7073c9c06258e3fafb114b69e9dd4 /gn3/db/traits.py | |
parent | 157df453cdb84591cb44af9f1d2677cd0b2c0380 (diff) | |
download | genenetwork3-94ca79045baf978d6aab964c7c70b84911c1124f.tar.gz |
Move `export_informative` function to `gn3.db.traits` module
Issue:
https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi
* gn3/db/traits.py: Move `export_informative` function here
* gn3/partial_correlations.py: Remove `export_informative` function
* tests/unit/db/test_traits.py: Move `export_informative` function tests here
* tests/unit/test_partial_correlations.py: Remove `export_informative`
function tests
The `export_informative` function relates more to the traits than to the
partial correlations, and could find use in more than just the partial
correlations stuff. This commit moves the function to the more
traits-specific `gn3.db.traits` module.
Diffstat (limited to 'gn3/db/traits.py')
-rw-r--r-- | gn3/db/traits.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gn3/db/traits.py b/gn3/db/traits.py index 1e29aff..1c6aaa7 100644 --- a/gn3/db/traits.py +++ b/gn3/db/traits.py @@ -743,3 +743,27 @@ def generate_traits_filename(base_path: str = TMPDIR): """Generate a unique filename for use with generated traits files.""" return "{}/traits_test_file_{}.txt".format( os.path.abspath(base_path), random_string(10)) + +def export_informative(trait_data: dict, inc_var: bool = False) -> tuple: + """ + Export informative strain + + This is a migration of the `exportInformative` function in + web/webqtl/base/webqtlTrait.py module in GeneNetwork1. + + There is a chance that the original implementation has a bug, especially + dealing with the `inc_var` value. It the `inc_var` value is meant to control + the inclusion of the `variance` value, then the current implementation, and + that one in GN1 have a bug. + """ + def __exporter__(acc, data_item): + if not inc_var or data_item["variance"] is not None: + return ( + acc[0] + (data_item["sample_name"],), + acc[1] + (data_item["value"],), + acc[2] + (data_item["variance"],)) + return acc + return reduce( + __exporter__, + filter(lambda td: td["value"] is not None, trait_data["data"].values()), + (tuple(), tuple(), tuple())) |