aboutsummaryrefslogtreecommitdiff
path: root/gn3/data_helpers.py
diff options
context:
space:
mode:
authorBonfaceKilz2021-10-26 08:48:30 +0300
committerGitHub2021-10-26 08:48:30 +0300
commit0cfff99e22155b6b15e23cbeff596f5f8f08709c (patch)
treec831f28534ebf6432972e107dbd6da5daef81088 /gn3/data_helpers.py
parent5440bfcd6940db08c4479a39ba66dbc802b2c426 (diff)
parentc13afb3af166d2b01e4f9fd9b09bb231f0a63cb1 (diff)
downloadgenenetwork3-0cfff99e22155b6b15e23cbeff596f5f8f08709c.tar.gz
Merge pull request #46 from genenetwork/partial-correlations
Partial correlations
Diffstat (limited to 'gn3/data_helpers.py')
-rw-r--r--gn3/data_helpers.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/gn3/data_helpers.py b/gn3/data_helpers.py
new file mode 100644
index 0000000..f0d971e
--- /dev/null
+++ b/gn3/data_helpers.py
@@ -0,0 +1,25 @@
+"""
+This module will hold generic functions that can operate on a wide-array of
+data structures.
+"""
+
+from math import ceil
+from functools import reduce
+from typing import Any, Tuple, Sequence
+
+def partition_all(num: int, items: Sequence[Any]) -> Tuple[Tuple[Any, ...], ...]:
+ """
+ Given a sequence `items`, return a new sequence of the same type as `items`
+ with the data partitioned into sections of `n` items per partition.
+
+ This is an approximation of clojure's `partition-all` function.
+ """
+ def __compute_start_stop__(acc, iteration):
+ start = iteration * num
+ return acc + ((start, start + num),)
+
+ iterations = range(ceil(len(items) / num))
+ return tuple([# type: ignore[misc]
+ tuple(items[start:stop]) for start, stop # type: ignore[has-type]
+ in reduce(
+ __compute_start_stop__, iterations, tuple())])