From 122305336cc92dff26f9cc25ada9770fc870b37b Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Wed, 17 Apr 2024 10:42:36 +0200 Subject: [PATCH 1/3] add default output path --- src/nplinker/defaults.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nplinker/defaults.py b/src/nplinker/defaults.py index 984c63a4..e9243454 100644 --- a/src/nplinker/defaults.py +++ b/src/nplinker/defaults.py @@ -19,3 +19,4 @@ ANTISMASH_DEFAULT_PATH: Path = config.root_dir / "antismash" BIGSCAPE_DEFAULT_PATH: Path = config.root_dir / "bigscape" BIGSCAPE_RUNNING_OUTPUT_PATH: Path = BIGSCAPE_DEFAULT_PATH / "bigscape_running_output" +OUTPUT_DEFAULT_PATH: Path = config.root_dir / "output" From 3a28faad8068a8fe368dd20d5c901dd5d16994ae Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Wed, 17 Apr 2024 11:05:09 +0200 Subject: [PATCH 2/3] use default output path for metcalf scoring --- src/nplinker/scoring/metcalf_scoring.py | 8 +++++--- tests/integration/test_nplinker_local.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nplinker/scoring/metcalf_scoring.py b/src/nplinker/scoring/metcalf_scoring.py index 30033499..adb47134 100644 --- a/src/nplinker/scoring/metcalf_scoring.py +++ b/src/nplinker/scoring/metcalf_scoring.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING import numpy as np import pandas as pd +from nplinker.defaults import OUTPUT_DEFAULT_PATH from nplinker.genomics import GCF from nplinker.logconfig import LogConfig from nplinker.metabolomics import MolecularFamily @@ -31,11 +32,13 @@ class MetcalfScoring(ScoringMethod): DATALINKS: The DataLinks object to use for scoring. LINKFINDER: The LinkFinder object to use for scoring. NAME: The name of the scoring method. This is set to 'metcalf'. + CACHE: The name of the cache file to use for storing the MetcalfScoring. """ DATALINKS = None LINKFINDER = None NAME = "metcalf" + CACHE = "cache_metcalf_scoring.pckl" def __init__(self, npl: NPLinker) -> None: """Create a MetcalfScoring object. @@ -69,9 +72,8 @@ def setup(npl: NPLinker): ) ) - cache_dir = os.path.join(npl.root_dir, "metcalf") - cache_file = os.path.join(cache_dir, "metcalf_scores.pckl") - os.makedirs(cache_dir, exist_ok=True) + OUTPUT_DEFAULT_PATH.mkdir(exist_ok=True) + cache_file = OUTPUT_DEFAULT_PATH / MetcalfScoring.CACHE # the metcalf preprocessing can take a long time for large datasets, so it's # better to cache as the data won't change unless the number of objects does diff --git a/tests/integration/test_nplinker_local.py b/tests/integration/test_nplinker_local.py index 3d8b4636..d2697479 100644 --- a/tests/integration/test_nplinker_local.py +++ b/tests/integration/test_nplinker_local.py @@ -27,7 +27,7 @@ def npl() -> NPLinker: npl.load_data() # remove cached score results before running tests root_dir = Path(npl.root_dir) - score_cache = root_dir / "metcalf" / "metcalf_scores.pckl" + score_cache = root_dir / "output" / "cache_metcalf_scoring.pckl" score_cache.unlink(missing_ok=True) return npl From e605d402db87e626dc06722441e092b321c45af1 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Wed, 17 Apr 2024 11:10:46 +0200 Subject: [PATCH 3/3] update docstrings and static typings --- src/nplinker/scoring/metcalf_scoring.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/nplinker/scoring/metcalf_scoring.py b/src/nplinker/scoring/metcalf_scoring.py index adb47134..c5558105 100644 --- a/src/nplinker/scoring/metcalf_scoring.py +++ b/src/nplinker/scoring/metcalf_scoring.py @@ -117,7 +117,8 @@ def setup(npl: NPLinker): # TODO CG: is it needed? remove it if not @property - def datalinks(self) -> DataLinks: + def datalinks(self) -> DataLinks | None: + """Get the DataLinks object used for scoring.""" return MetcalfScoring.DATALINKS def get_links( @@ -311,10 +312,12 @@ def _calc_standardised_score_gen( # TODO CG: refactor this method def format_data(self, data): + """Format the data for display.""" # for metcalf the data will just be a floating point value (i.e. the score) return f"{data:.4f}" # TODO CG: refactor this method def sort(self, objects, reverse=True): + """Sort the objects based on the score.""" # sort based on score return sorted(objects, key=lambda objlink: objlink[self], reverse=reverse)