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 2 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 _transformer(p, weight1, weight2):
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this might be better named _balance_transform

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, that might be more informative. Updated

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(_transformer, 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(_transformer, 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
Binary file added tests/data/CN.mm9.10000kb.test_sampled.cool
Copy link
Member

Choose a reason for hiding this comment

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

seems that a few deletable test files got added to the PR @Yaoyx

Copy link
Collaborator Author

@Yaoyx Yaoyx Oct 10, 2024

Choose a reason for hiding this comment

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

Files have been removed

Binary file not shown.
Binary file added tests/data/CN.mm9.1000kb.test_sampled.cool
Binary file not shown.
Binary file added tests/data/test_coverage.cool
Binary file not shown.
Binary file added tests/test_chr2chr1_reordered_inverted.cool
Binary file not shown.
Binary file added tests/test_chrom1_reordered.cool
Binary file not shown.
Binary file added tests/test_chrom1_reordered_inverted.cool
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,4 +732,4 @@ def test_diagsum_from_array():
exp = _diagsum_symm_dense(ar, bad_bins=list(range(3, 5)))
exp1 = diagsum_from_array(ar, ignore_diags=0)
exp1["balanced.avg"] = exp1["balanced.sum"] / exp1["n_valid"]
assert np.allclose(exp, exp1["balanced.avg"].values, equal_nan=True)
assert np.allclose(exp, exp1["balanced.avg"].values, equal_nan=True)
Binary file added tests/test_not_reordered.cool
Binary file not shown.
Loading