Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pool decorator, and multiprocessing #539

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cooltools/api/dotfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,9 @@ def cluster_filtering_hiccups(
# large helper functions wrapping smaller step-specific ones
####################################################################

def _compose_score_hist(tile, to_score, to_hist):
return to_hist(to_score(tile))

@pool_decorator
def scoring_and_histogramming_step(
clr,
Expand Down Expand Up @@ -1300,7 +1303,7 @@ def scoring_and_histogramming_step(
to_hist = partial(histogram_scored_pixels, kernels=kernels, ledges=ledges)

# compose scoring and histogramming together :
job = lambda tile: to_hist(to_score(tile))
job = partial(_compose_score_hist, to_score=to_score, to_hist=to_hist)

# standard multiprocessing implementation
if nproc > 1:
Expand Down Expand Up @@ -1388,7 +1391,7 @@ def scoring_and_extraction_step(
)

# compose scoring and histogramming together
job = lambda tile: to_extract(to_score(tile))
job = partial(_compose_score_hist, to_score=to_score, to_hist=to_extract)

# standard multiprocessing implementation
if nproc > 1:
Expand Down
9 changes: 6 additions & 3 deletions cooltools/api/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,10 @@ def per_region_smooth_cvd(
)

return cvd

def _balance_transform(p, weight1, weight2):
return p["count"] * p[weight1] * p[weight2]

# user-friendly wrapper for diagsum_symm and diagsum_pairwise - part of new "public" API
@pool_decorator
def expected_cis(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be useful to expose transforms in expected_cis? cc @sergpolly @nvictus

Expand Down Expand Up @@ -1179,7 +1183,7 @@ def expected_cis(
# define balanced data transform:
weight1 = clr_weight_name + "1"
weight2 = clr_weight_name + "2"
transforms = {"balanced": lambda p: p["count"] * p[weight1] * p[weight2]}
transforms = {"balanced": partial(_balance_transform, weight1=weight1, weight2=weight2)}
else:
raise ValueError(
"cooler is not balanced, or"
Expand Down Expand Up @@ -1317,8 +1321,7 @@ def expected_trans(
# define balanced data transform:
weight1 = clr_weight_name + "1"
weight2 = clr_weight_name + "2"
transforms = {"balanced": lambda p: p["count"] * p[weight1] * p[weight2]}

transforms = {"balanced": partial(_balance_transform, weight1=weight1, weight2=weight2)}
else:
raise ValueError(
"cooler is not balanced, or"
Expand Down
4 changes: 2 additions & 2 deletions cooltools/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import pandas as pd
import bioframe
from multiprocess import Pool
from multiprocessing import Pool
from functools import wraps
import logging

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

pool = None
if "nproc" in kwargs.keys():
Expand Down
Loading