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

include processes parameter in pynteny build #87

Merged
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
mt
  • Loading branch information
Robaina committed Mar 14, 2023
commit 3f87b8d234eeffa9a246a178ee585df28d66576f
7 changes: 5 additions & 2 deletions src/pynteny/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def annotate(
utils.parallelize_over_input_files(
wrappers.run_prodigal,
input_list=list(contigs_dir.iterdir()),
n_processes=processes,
processes=processes,
output_dir=prodigal_dir,
output_format="fasta",
metagenome=metagenome,
Expand Down Expand Up @@ -634,6 +634,7 @@ def build(
seq_prefix: str = None,
prepend_file_name: bool = False,
output_file: Path = None,
processes: int = None,
) -> LabelledFASTA:
"""Build database from data files.

Expand All @@ -643,6 +644,7 @@ def build(
prepend_file_name (bool, optional): whether to add file name as genome ID to
each record in the result merged fasta file.
output_file (Path, optional): path to output file. Defaults to None.
processes (int, optional): maximum number of threads. Defaults to all minus one.

Returns:
LabelledFASTA: object containing the labelled peptide database.
Expand All @@ -663,7 +665,8 @@ def build(
assembly_fasta = FASTA(self._data)
logger.info("Translating and annotating assembly data.")
labelled_database = GeneAnnotator(assembly_fasta).annotate(
output_file=output_file
output_file=output_file,
processes=processes,
)
elif self.is_gbk(self._data_files[0]):
logger.info("Parsing GenBank data.")
Expand Down
1 change: 1 addition & 0 deletions src/pynteny/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def build_database(args: Union[CommandArgs, ArgumentParser]) -> None:
database.build(
output_file=args.outfile,
prepend_file_name=prepend_file_name,
processes=args.processes,
)
logger.info("Database built successfully!")
logging.shutdown()
Expand Down
8 changes: 4 additions & 4 deletions src/pynteny/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def terminal_execute(


def parallelize_over_input_files(
callable, input_list: list, n_processes: int = None, **callable_kwargs
callable, input_list: list, processes: int = None, **callable_kwargs
) -> None:
"""Parallelize callable over a set of input objects using a pool
of workers. Inputs in input list are passed to the first argument
Expand All @@ -184,9 +184,9 @@ def parallelize_over_input_files(
n_processes (int, optional): maximum number of threads.
Defaults to all minus one.
"""
if n_processes is None:
n_processes = os.cpu_count - 1
p = Pool(processes=n_processes)
if processes is None:
processes = os.cpu_count - 1
p = Pool(processes=processes)
p.map(partial(callable, **callable_kwargs), input_list)
p.close()
p.join()
Expand Down