Skip to content

Commit

Permalink
remove pathos
Browse files Browse the repository at this point in the history
  • Loading branch information
Jianhua-Wang committed May 25, 2023
1 parent e5b6413 commit ee8a639
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 107 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## [0.3.2] - 2023-05-25

### Added

### Changed
- remove pathos
### Fixed


## [0.3.1] - 2023-05-25

### Added
Expand Down
58 changes: 44 additions & 14 deletions easyfinemap/easyfinemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import numpy as np
import pandas as pd
from pathos.pools import _ProcessPool as Pool
from concurrent.futures import ProcessPoolExecutor
from rich.progress import BarColumn, MofNCompleteColumn, Progress, TextColumn, TimeElapsedColumn
import tabix
import smunger as sg
Expand Down Expand Up @@ -689,6 +689,22 @@ def finemap_locus(
credible_set[ColName.LEAD_SNP] = lead_snp
return credible_set

def finemap_locus_parallel(self, kwargs):
"""
Perform finemapping for a locus in parallel.
Parameters
----------
kwargs : dict
Keyword arguments.
Returns
-------
pd.DataFrame
Finemapping results.
"""
return self.finemap_locus(**kwargs)

def finemap_all_loci(
self,
sumstats: pd.DataFrame,
Expand Down Expand Up @@ -771,21 +787,35 @@ def finemap_all_loci(
}
kwargs_list.append(kwargs)
ef = EasyFinemap()
output = []
with Progress(
TextColumn("{task.description}"),
BarColumn(),
MofNCompleteColumn(),
TimeElapsedColumn(),
auto_refresh=True,
) as progress:
with Pool(threads) as p:
task = progress.add_task("Perform Fine-mapping...", total=len(loci))
results = [p.apply_async(ef.finemap_locus, kwds=kwargs) for kwargs in kwargs_list]
for res in results:
# output = []
# with Progress(
# TextColumn("{task.description}"),
# BarColumn(),
# MofNCompleteColumn(),
# TimeElapsedColumn(),
# auto_refresh=True,
# ) as progress:
# with Pool(threads) as p:
# task = progress.add_task("Perform Fine-mapping...", total=len(loci))
# results = [p.apply_async(ef.finemap_locus, kwds=kwargs) for kwargs in kwargs_list]
# for res in results:
# progress.update(task, advance=1)
# progress.refresh()
# output.append(res.get())
with ProcessPoolExecutor(max_workers=threads) as executor:
output = []
with Progress(
TextColumn("{task.description}"),
BarColumn(),
MofNCompleteColumn(),
TimeElapsedColumn(),
auto_refresh=True,
) as progress:
task = progress.add_task("Perform Fine-mapping...", total=len(kwargs_list))
for _ in executor.map(ef.finemap_locus_parallel, kwargs_list):
progress.update(task, advance=1)
progress.refresh()
output.append(res.get())
output.append(_)
output_df = pd.concat(output, ignore_index=True)
if outfile:
output_df.to_csv(outfile, sep="\t", index=False, float_format="%0.6g")
Expand Down
2 changes: 1 addition & 1 deletion easyfinemap/loci.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def indep_snps_by_conditional(
BarColumn(),
MofNCompleteColumn(),
TimeElapsedColumn(),
auto_refresh=False,
auto_refresh=True,
) as progress:
task = progress.add_task("Run cojo-slct", total=len(args_list))
for _ in executor.map(loci.cojo_slct, *zip(*args_list)):
Expand Down
95 changes: 4 additions & 91 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ mkdocs-material-extensions = { version = "^1.1.1", optional = true }
pandas = "^1.5.2"
rich = "^13.3.1"
jupyter = { version = "^1.0.0", optional = true }
pathos = "^0.3.0"
smunger = "0.0.23"
rpy2 = "^3.5.10"

Expand Down

0 comments on commit ee8a639

Please sign in to comment.