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

docs: add verbose arg to QueryCollection class #267

Merged
merged 3 commits into from Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions deeprankcore/query.py
Expand Up @@ -142,13 +142,17 @@ def __init__(self):
self.cpu_count = None
self.ids_count = {}

def add(self, query: Query):
def add(self, query: Query, verbose: bool = False):
""" Adds new query to the collection of all generated queries.
Args:
query (Query): must be a Query object, either ProteinProteinInterfaceResidueQuery or SingleResidueVariantAtomicQuery.
verbose: bool for logging query ids added, defaults to False.
"""
query_id = query.get_query_id()

if verbose:
_log.info(f'Adding query with ID {query_id}.')

if query_id not in self.ids_count:
self.ids_count[query_id] = 1
else:
Expand Down Expand Up @@ -181,8 +185,12 @@ def _process_one_query(
self,
prefix: str,
feature_names: List[str],
verbose: bool,
query: Query):

if verbose:
_log.info(f'\nProcess query with process ID {os.getpid()}.')

# because only one process may access an hdf5 file at the time:
output_path = f"{prefix}-{os.getpid()}.hdf5"

Expand All @@ -196,12 +204,13 @@ def _process_one_query(
_log.error(e)
_log.warning(f'Query {query.get_query_id()}\'s graph was not saved in the hdf5 file; check the query\'s files')

def process(
def process( # pylint: disable=too-many-arguments
self,
prefix: Optional[str] = None,
feature_modules: List[ModuleType] = None,
cpu_count: Optional[int] = None,
combine_output: bool = True,
verbose: bool = False
) -> List[str]:

"""
Expand All @@ -220,6 +229,8 @@ def process(

combine_output: boolean for combining the hdf5 files generated by the processes.
By default, the hdf5 files generated are combined into one, and then deleted.

verbose: bool for logging query ids processed, defaults to False.
"""

if cpu_count is None:
Expand All @@ -245,7 +256,7 @@ def process(

_log.info('Creating pool function to process the queries...')
pool_function = partial(self._process_one_query, prefix,
feature_names)
feature_names, verbose)

with Pool(self.cpu_count) as pool:
_log.info('Starting pooling...\n')
Expand Down