aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-10-18 05:47:45 +0300
committerFrederick Muriuki Muriithi2021-10-18 05:59:54 +0300
commit27cca4c118cba6a5f8e8b03d152070f83a44a9e5 (patch)
tree3c24dc254f0efd29f2fc9f5f7f064e7f31e48f05 /gn3
parent77099cac68e8f4792bf54d8e1f7ce6f315bedfa7 (diff)
downloadgenenetwork3-27cca4c118cba6a5f8e8b03d152070f83a44a9e5.tar.gz
Migrate `export_informative` function
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi * gn3/partial_correlations.py: Implement a mostly, bug-compatible `export_informative` function as part of migrating the partial correlations feature over to GN3 from GN1 * tests/unit/test_partial_correlations.py: Implement tests to ensure the code work in a similar manner as that one in GN1.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/partial_correlations.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/gn3/partial_correlations.py b/gn3/partial_correlations.py
new file mode 100644
index 0000000..8c37886
--- /dev/null
+++ b/gn3/partial_correlations.py
@@ -0,0 +1,32 @@
+"""
+This module deals with partial correlations.
+
+It is an attempt to migrate over the partial correlations feature from
+GeneNetwork1.
+"""
+
+from functools import reduce
+
+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()))