Skip to content

Commit

Permalink
update cli validations & test config path
Browse files Browse the repository at this point in the history
  • Loading branch information
CatarinaCarolina committed Nov 22, 2024
1 parent 66fcfca commit c564dc7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 48 deletions.
4 changes: 2 additions & 2 deletions big_scape/cli/cli_common_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def common_all(fn):
help=(
"Prints more detailed information of each step in the analysis, "
"output all kinds of logs, including debugging log info, and writes to logfile. "
"Toggle to activate."
"Toggle to activate. Disclaimer: developed in linux, might not work as well in macOS."
),
),
click.option(
Expand Down Expand Up @@ -260,7 +260,7 @@ def common_cluster_query(fn):
"Alignment mode for each pair of gene clusters. global: the whole list of domains of "
"each BGC record is compared; local: Seeds the subset of the domains used to calculate "
"distance by trying to find the longest slice of common domain content (Longest Common "
"Subcluster, LCS) between both records, then extends each side (see --extension-strategy). "
"Subcluster, LCS) between both records, then extends each side (see --extend-strategy). "
"glocal: Starts with performing local, but domain selection is then extended to the "
"shortest upstream/downstream arms in a compared record pair. "
"auto: use glocal when at least one of the BGCs in each pair has the contig_edge annotation "
Expand Down
76 changes: 38 additions & 38 deletions big_scape/cli/cli_validations.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ def validate_output_paths(ctx) -> None:

timestamp = time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime())

if "db_path" in ctx.obj and ctx.obj["db_path"] is None:
db_path = ctx.obj["output_dir"] / Path(f"{ctx.obj['output_dir'].name}.db")
ctx.obj["db_path"] = db_path
if "db-path" in ctx.obj and ctx.obj["db-path"] is None:
db_path = ctx.obj["output-dir"] / Path(f"{ctx.obj['output-dir'].name}.db")
ctx.obj["db-path"] = db_path

if "log_path" in ctx.obj and ctx.obj["log_path"] is None:
if "log-path" in ctx.obj and ctx.obj["log-path"] is None:
log_filename = timestamp + ".log"
log_path = ctx.obj["output_dir"] / Path(log_filename)
ctx.obj["log_path"] = log_path
log_path = ctx.obj["output-dir"] / Path(log_filename)
ctx.obj["log-path"] = log_path

if "profile_path" in ctx.obj and ctx.obj["profile_path"] is None:
if "profile-path" in ctx.obj and ctx.obj["profile-path"] is None:
profile_filename = timestamp + ".profile"
profile_path = ctx.obj["output_dir"] / Path(profile_filename)
ctx.obj["profile_path"] = profile_path
profile_path = ctx.obj["output-dir"] / Path(profile_filename)
ctx.obj["profile-path"] = profile_path

return None

Expand All @@ -139,13 +139,13 @@ def validate_output_paths(ctx) -> None:
def validate_disk_only(ctx) -> None:
"""Checks if the database storage/dumping modes that were set are compatible"""

if not ("no_db_dump" in ctx.obj and "disk_only" in ctx.obj):
if not ("no-db-dump" in ctx.obj and "disk-only" in ctx.obj):
raise RuntimeError(
"Something went wrong with the database storage/dumping mode parameters. "
"Please contact the developers."
)

if ctx.obj["no_db_dump"] and ctx.obj["disk_only"]:
if ctx.obj["no-db-dump"] and ctx.obj["disk-only"]:
logging.error(
"You have selected both --no-db-dump and --disk-only. Please select only one"
)
Expand Down Expand Up @@ -244,9 +244,9 @@ def validate_includelist(ctx, param, domain_includelist_path):
return None

if not domain_includelist_path.exists():
logging.error("domain_includelist file does not exist!")
logging.error("domain-includelist file does not exist!")
raise InvalidArgumentError(
"--domain_includelist_all/any_path", domain_includelist_path
"--domain-includelist-all/any-path", domain_includelist_path
)

with domain_includelist_path.open(encoding="utf-8") as domain_includelist_file:
Expand Down Expand Up @@ -286,7 +286,7 @@ def validate_includelist_all(ctx, param, domain_includelist_all_path) -> None:

pfams = validate_includelist(ctx, param, domain_includelist_all_path)

ctx.params["domain_includelist_all"] = pfams
ctx.params["domain-includelist-all"] = pfams

return None

Expand All @@ -301,7 +301,7 @@ def validate_includelist_any(ctx, param, domain_includelist_any_path) -> None:

pfams = validate_includelist(ctx, param, domain_includelist_any_path)

ctx.params["domain_includelist_any"] = pfams
ctx.params["domain-includelist-any"] = pfams

return None

Expand All @@ -316,13 +316,13 @@ def validate_binning_cluster_workflow(ctx) -> None:

# --legacy_weights needs a classification method

if ctx.obj["legacy_weights"] and not ctx.obj["classify"]:
if ctx.obj["legacy-weights"] and not ctx.obj["classify"]:
logging.error(
"You have selected --legacy_weights but no classification method. "
"You have selected --legacy-weights but no classification method. "
"Please select any --classify method"
)
raise click.UsageError(
"You have selected --legacy_weights but no classification method. "
"You have selected --legacy-weights but no classification method. "
"Please select any --classify method"
)

Expand All @@ -343,18 +343,18 @@ def validate_binning_cluster_workflow(ctx) -> None:
# --classify legacy turns on --legacy_weights

if ctx.obj["classify"] == bs_enums.CLASSIFY_MODE.LEGACY:
ctx.obj["legacy_weights"] = True
ctx.obj["legacy-weights"] = True

# --hybrids_off needs --classify

if ctx.obj["hybrids_off"]:
if ctx.obj["hybrids-off"]:
if not (ctx.obj["classify"]):
logging.error(
"You have selected --hybrids_off but no classification method. "
"You have selected --hybrids-off but no classification method. "
"Please select any --classify method"
)
raise click.UsageError(
"You have selected --hybrids_off but no classification method. "
"You have selected --hybrids-off but no classification method. "
"Please select any --classify method"
)

Expand All @@ -366,11 +366,11 @@ def validate_binning_query_workflow(ctx) -> None:

if ctx.obj["legacy_weights"] and not ctx.obj["classify"]:
logging.error(
"You have selected --legacy_weights but no classification method. "
"You have selected --legacy-weights but no classification method. "
"Please select any --classify method, or remove this parameter"
)
raise click.UsageError(
"You have selected --legacy_weights but no classification method. "
"You have selected --legacy-weights but no classification method. "
"Please select any --classify method, or remove this parameter"
)

Expand All @@ -379,14 +379,14 @@ def validate_pfam_path(ctx) -> None:
"""Validates whether a BiG-SCAPE db exists when pfam_path is not provided,
which requires already processed gbk files and hence a DB in output"""

if ctx.obj["pfam_path"] is None and ctx.obj["db_path"] is None:
if ctx.obj["pfam-path"] is None and ctx.obj["db-path"] is None:
logging.error(
"Missing option '-p/--pfam_path'."
"Missing option '-p/--pfam-path'."
"BiG-SCAPE database not provided, a pfam file is "
"required in order to detect domains."
)
raise click.UsageError(
"Missing option '-p/--pfam_path'."
"Missing option '-p/--pfam-path'."
"BiG-SCAPE database not provided, a pfam file is "
"required in order to detect domains."
)
Expand All @@ -396,26 +396,26 @@ def validate_domain_include_list(ctx) -> None:
"""Raise an error if both domain includelists are given at the same time"""

if (
ctx.obj["domain_includelist_all_path"]
and ctx.obj["domain_includelist_any_path"]
ctx.obj["domain-includelist-all-path"]
and ctx.obj["domain-includelist-any-path"]
):
logging.error(
"You have selected both all and any domain_includelist options. "
"You have selected both all and any domain-includelist options. "
"Please select only one of the two at a time."
)
raise click.UsageError(
"You have selected both all and any domain_includelist options. "
"You have selected both all and any domain-includelist options. "
"Please select only one of the two at a time."
)


def validate_record_type(ctx, _, record_type) -> Optional[bs_enums.genbank.RECORD_TYPE]:
"""Validates whether a region_type is provided when running classify"""
"""Validates whether a record-type is provided when running classify"""
valid_types = {mode.value: mode for mode in bs_enums.genbank.RECORD_TYPE}

if record_type not in valid_types:
logging.error("Provided --record_type is invalid")
raise click.UsageError("Provided --record_type in invalid")
logging.error("Provided --record-type is invalid")
raise click.UsageError("Provided --record-type in invalid")

return valid_types[record_type]

Expand All @@ -425,16 +425,16 @@ def validate_query_record(ctx) -> None:
with a given record type"""

if (
ctx.obj["query_record_number"] is None
and ctx.obj["record_type"] != bs_enums.genbank.RECORD_TYPE.REGION
ctx.obj["query-record-number"] is None
and ctx.obj["record-type"] != bs_enums.genbank.RECORD_TYPE.REGION
):
logging.error(
"Missing option '--query_record_number'."
"Missing option '--query-record-number'."
"A query record number is required when running query mode with "
"a record type other than 'region'."
)
raise click.UsageError(
"Missing option '--query_record_number'."
"Missing option '--query-record-number'."
"A query record number is required when running query mode with "
"a record type other than 'region'."
)
Expand Down
16 changes: 8 additions & 8 deletions test/integration/test_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def test_generate_and_save_edges_workflow(self):
"legacy_weights": True,
"record_type": bs_enums.RECORD_TYPE.REGION,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

gbks = [
Expand Down Expand Up @@ -655,7 +655,7 @@ def test_calculate_distances_mix(self):
"legacy_weights": True,
"record_type": bs_enums.RECORD_TYPE.REGION,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

gbks = [create_mock_gbk_hsp(i, bs_enums.SOURCE_TYPE.QUERY) for i in range(3)]
Expand Down Expand Up @@ -873,7 +873,7 @@ def test_calculate_distances_legacy_classify(self):
"record_type": bs_enums.RECORD_TYPE.REGION,
"hybrids_off": False,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

pks_gbks = [
Expand Down Expand Up @@ -924,7 +924,7 @@ def test_calculate_distances_legacy_classify(self):
"record_type": bs_enums.RECORD_TYPE.REGION,
"hybrids_off": True,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

# bin 1 PKSI 3 pairs -> those were already in db
Expand Down Expand Up @@ -952,7 +952,7 @@ def test_calculate_distances_classify(self):
"record_type": bs_enums.RECORD_TYPE.REGION,
"hybrids_off": True,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

pks_gbks = [
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def test_calculate_distances_classify(self):
"record_type": bs_enums.RECORD_TYPE.REGION,
"hybrids_off": False,
"cores": 1,
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

bs_classify.calculate_distances_classify(run, list_bgc_records)
Expand Down Expand Up @@ -1484,7 +1484,7 @@ def test_generate_bins_query_workflow(self):
"classify": bs_enums.CLASSIFY_MODE.CLASS,
"propagate": True,
"gcf_cutoffs": [0.1, 0.7],
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

query_record, list_bgc_records = create_mock_query_dataset(run)
Expand Down Expand Up @@ -1624,7 +1624,7 @@ def test_calculate_distances_query(self):
"propagate": True,
"run_id": 1,
"gcf_cutoffs": [0.1, 0.8],
"config_file_path": Path("config.yml"),
"config_file_path": Path("big_scape/config.yml"),
}

query_record, list_bgc_records = create_mock_query_dataset(run)
Expand Down

0 comments on commit c564dc7

Please sign in to comment.