Skip to content

Commit

Permalink
use multiprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Jan 24, 2025
1 parent 1bf74af commit 43ef6c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/jcvi/projects/sugarcane.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from dataclasses import dataclass
from enum import Enum
from itertools import combinations, groupby, product
from multiprocessing import Pool, cpu_count
from random import randint, random
from typing import Dict, List, Tuple
from uuid import uuid4
Expand Down Expand Up @@ -664,9 +665,9 @@ def simulate(args):

verbose = opts.verbose
N = opts.N
all_F1s, all_BC1s, all_BC2s, all_BC3s, all_BC4s = zip(
*[simulate_F1_to_BC4(SO, SS, mode, verbose) for _ in range(N)]
)
with Pool(cpu_count()) as pool:
results = pool.starmap(simulate_F1_to_BC4, [(SO, SS, mode, verbose)] * N)
all_F1s, all_BC1s, all_BC2s, all_BC3s, all_BC4s = zip(*results)

# Plotting
plot_summary(ax1, all_F1s)
Expand Down Expand Up @@ -1009,7 +1010,7 @@ def chromosome(args):
indir = f"simulations_{mode}"
genomes = []
for cross in CROSSES:
filename = op.join(indir, f"all_{cross}s")
filename = op.join(indir, f"all_{cross}")
with open(filename, encoding="utf-8") as fp:
for row in fp:
genome = Genome.from_str(row)
Expand Down

0 comments on commit 43ef6c9

Please sign in to comment.