From 3393ad5f802fbe26914361006d995c03026caf69 Mon Sep 17 00:00:00 2001 From: Arjan Draisma Date: Wed, 29 May 2024 18:34:45 +0200 Subject: [PATCH 1/2] add temporary root dir --- big_scape/cli/constants.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/big_scape/cli/constants.py b/big_scape/cli/constants.py index dbb85066..4a1b71bb 100644 --- a/big_scape/cli/constants.py +++ b/big_scape/cli/constants.py @@ -1,6 +1,12 @@ """Contains constant values""" -DB_SCHEMA_PATH = "big_scape/data/schema.sql" +from sys import argv +from pathlib import Path + +# TODO: this almost certainly will break when packaging +ROOT_DIR = Path(argv[0]).parent + +DB_SCHEMA_PATH = ROOT_DIR / "big_scape/data/schema.sql" # TODO: add comments with notes as in BS1 # TODO: move to config file From ff33f472b20854850b58c982a78c3b09b22e8ba5 Mon Sep 17 00:00:00 2001 From: Arjan Draisma Date: Wed, 29 May 2024 21:48:29 +0200 Subject: [PATCH 2/2] fix root dir --- big_scape/cli/cli_common_options.py | 5 +++-- big_scape/output/legacy_output.py | 17 +++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/big_scape/cli/cli_common_options.py b/big_scape/cli/cli_common_options.py index 60fb279e..bf6df711 100644 --- a/big_scape/cli/cli_common_options.py +++ b/big_scape/cli/cli_common_options.py @@ -18,6 +18,7 @@ validate_classify, validate_output_dir, ) +from .constants import ROOT_DIR def common_all(fn): @@ -35,9 +36,9 @@ def common_all(fn): type=click.Path( exists=True, dir_okay=False, file_okay=True, path_type=Path ), - default="./config.ini", + default=ROOT_DIR / "config.ini", help="Path to BiG-SCAPE config file, which stores values for a " - "series of advanced use parameters. (default: ./config.ini).", + "series of advanced use parameters. (default: [BiG-SCAPE directory]/config.ini).", ), # diagnostic parameters click.option( diff --git a/big_scape/output/legacy_output.py b/big_scape/output/legacy_output.py index cb9514f3..c18bf3d2 100644 --- a/big_scape/output/legacy_output.py +++ b/big_scape/output/legacy_output.py @@ -21,6 +21,7 @@ from big_scape.enums import SOURCE_TYPE from big_scape.trees import generate_newick_tree from big_scape.comparison import get_record_category +from big_scape.cli.constants import ROOT_DIR import big_scape.network.network as bs_network import big_scape.network.utility as bs_network_utility @@ -34,7 +35,7 @@ def copy_base_output_templates(output_dir: Path): output_dir (Path): main output directory """ - template_root = Path("big_scape/output/html_template") + template_root = ROOT_DIR / Path("big_scape/output/html_template") template_dir = template_root / "output" # copy html content @@ -65,7 +66,7 @@ def prepare_cutoff_folders(output_dir: Path, label: str, cutoff: float) -> None: cutoff_network_path.mkdir(exist_ok=True) cutoff_files_path.mkdir(exist_ok=True) - template_root = Path("big_scape/output/html_template") + template_root = ROOT_DIR / Path("big_scape/output/html_template") overview_template = template_root / "overview_html" # copy overview html @@ -100,7 +101,7 @@ def prepare_pair_generator_folders( tree_path.mkdir(exist_ok=True) - template_root = Path("big_scape/output/html_template") + template_root = ROOT_DIR / Path("big_scape/output/html_template") pair_generator_template = template_root / "index_html" shutil.copy( @@ -118,7 +119,7 @@ def generate_pfams_js(output_dir: Path, pfam_info: list[tuple[str, str, str]]) - """ # gather color information - pfam_colors_file_path = Path("big_scape/output/domain_colors.tsv") + pfam_colors_file_path = ROOT_DIR / Path("big_scape/output/domain_colors.tsv") # make accession to color dictionary pfam_colors_dict = {} @@ -224,9 +225,7 @@ def generate_run_data_js( "classify": ( "Legacy Groups" if run["legacy_classify"] - else run["classify"].name.title() - if run["classify"] - else "Not Classify" + else run["classify"].name.title() if run["classify"] else "Not Classify" ), "weights": "Legacy Weights" if run["legacy_weights"] else "Mix", "alignment_mode": run["alignment_mode"].name.title(), @@ -1699,9 +1698,7 @@ def write_full_network_file(run: dict, all_bgc_records: list[BGCRecord]) -> None write_network_file(full_network_file_path, edgelist) -def get_full_network_edgelist( - run: dict, all_bgc_records: list -) -> set[ +def get_full_network_edgelist(run: dict, all_bgc_records: list) -> set[ tuple[ str, str,