Skip to content

Commit aedd531

Browse files
authored
Update pool decorator, and multiprocessing (#539)
closes #535 #536 * 1. update pool_decorator * 2. convert lambda func to def func to avoid conflicts with pickle
1 parent ab97a04 commit aedd531

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

cooltools/api/dotfinder.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,9 @@ def cluster_filtering_hiccups(
12621262
# large helper functions wrapping smaller step-specific ones
12631263
####################################################################
12641264

1265+
def _compose_score_hist(tile, to_score, to_hist):
1266+
return to_hist(to_score(tile))
1267+
12651268
@pool_decorator
12661269
def scoring_and_histogramming_step(
12671270
clr,
@@ -1300,7 +1303,7 @@ def scoring_and_histogramming_step(
13001303
to_hist = partial(histogram_scored_pixels, kernels=kernels, ledges=ledges)
13011304

13021305
# compose scoring and histogramming together :
1303-
job = lambda tile: to_hist(to_score(tile))
1306+
job = partial(_compose_score_hist, to_score=to_score, to_hist=to_hist)
13041307

13051308
# standard multiprocessing implementation
13061309
if nproc > 1:
@@ -1388,7 +1391,7 @@ def scoring_and_extraction_step(
13881391
)
13891392

13901393
# compose scoring and histogramming together
1391-
job = lambda tile: to_extract(to_score(tile))
1394+
job = partial(_compose_score_hist, to_score=to_score, to_hist=to_extract)
13921395

13931396
# standard multiprocessing implementation
13941397
if nproc > 1:

cooltools/api/expected.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,10 @@ def per_region_smooth_cvd(
10351035
)
10361036

10371037
return cvd
1038+
1039+
def _balance_transform(p, weight1, weight2):
1040+
return p["count"] * p[weight1] * p[weight2]
1041+
10381042
# user-friendly wrapper for diagsum_symm and diagsum_pairwise - part of new "public" API
10391043
@pool_decorator
10401044
def expected_cis(
@@ -1179,7 +1183,7 @@ def expected_cis(
11791183
# define balanced data transform:
11801184
weight1 = clr_weight_name + "1"
11811185
weight2 = clr_weight_name + "2"
1182-
transforms = {"balanced": lambda p: p["count"] * p[weight1] * p[weight2]}
1186+
transforms = {"balanced": partial(_balance_transform, weight1=weight1, weight2=weight2)}
11831187
else:
11841188
raise ValueError(
11851189
"cooler is not balanced, or"
@@ -1317,8 +1321,7 @@ def expected_trans(
13171321
# define balanced data transform:
13181322
weight1 = clr_weight_name + "1"
13191323
weight2 = clr_weight_name + "2"
1320-
transforms = {"balanced": lambda p: p["count"] * p[weight1] * p[weight2]}
1321-
1324+
transforms = {"balanced": partial(_balance_transform, weight1=weight1, weight2=weight2)}
13221325
else:
13231326
raise ValueError(
13241327
"cooler is not balanced, or"

cooltools/lib/common.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
import bioframe
5-
from multiprocess import Pool
5+
from multiprocessing import Pool
66
from functools import wraps
77
import logging
88

@@ -526,7 +526,7 @@ def wrapper(*args, **kwargs):
526526
# If alternative or third party map functors are provided
527527
if "map_functor" in kwargs.keys():
528528
logging.info(f"using an alternative map functor: {kwargs['map_functor']}")
529-
return func(*args, **kwargs, map_functor=kwargs["map_functor"])
529+
return func(*args, **kwargs)
530530

531531
pool = None
532532
if "nproc" in kwargs.keys():

0 commit comments

Comments
 (0)