Skip to content

Commit

Permalink
DEV: ruff formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
YapengLang committed Nov 8, 2024
1 parent d6a9f4d commit be41b43
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/piqtree2/iqtree/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _parse_lie_model(
tree.params[lie_model_name]["model_parameters"] = model_parameters


def _tree_equal(node1:PhyloNode, node2:PhyloNode)->bool:
def _tree_equal(node1: PhyloNode, node2: PhyloNode) -> bool:
children_group1 = node1.children
children_group2 = node2.children

Expand Down
9 changes: 6 additions & 3 deletions src/piqtree2/model/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@ def available_models(model_type: str | None = None) -> _Table:
template = "Available {}substitution models"
if model_type == "dna":
table = make_table(
data=_make_models(DnaModel), title=template.format("nucleotide "),
data=_make_models(DnaModel),
title=template.format("nucleotide "),
)
elif model_type == "protein":
table = make_table(
data=_make_models(AaModel), title=template.format("protein "),
data=_make_models(AaModel),
title=template.format("protein "),
)
else:
table = make_table(
data=_make_models(SubstitutionModel), title=template.format(""),
data=_make_models(SubstitutionModel),
title=template.format(""),
)

return table
Expand Down
29 changes: 21 additions & 8 deletions tests/test_iqtree/test_tree_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,24 @@ def test_non_lie_dna_model_motif_absent(
non_lie_dna_with_rate_model: dict[str, Any],
) -> None:
non_lie_dna_with_rate_model["ModelDNA"].pop("state_freq")
with pytest.raises(ParseIqTreeError, match=re.escape("IQ-TREE output malformated, motif parameters not found.")):
with pytest.raises(
ParseIqTreeError,
match=re.escape("IQ-TREE output malformated, motif parameters not found."),
):
_ = _process_tree_yaml(non_lie_dna_with_rate_model, ["a", "b", "c", "d"])


def test_non_lie_dna_model_rate_absent(
non_lie_dna_with_rate_model: dict[str, Any],
) -> None:
non_lie_dna_with_rate_model["ModelDNA"].pop("rates")
with pytest.raises(ParseIqTreeError,match=re.escape("IQ-TREE output malformated, rate parameters not found.")):
with pytest.raises(
ParseIqTreeError,
match=re.escape("IQ-TREE output malformated, rate parameters not found."),
):
_ = _process_tree_yaml(non_lie_dna_with_rate_model, ["a", "b", "c", "d"])



def test_lie_dna_model(
lie_dna_model: dict[str, Any],
) -> None:
Expand All @@ -215,14 +220,22 @@ def test_lie_dna_model_motif_absent(
lie_dna_model: dict[str, Any],
) -> None:
lie_dna_model["ModelLieMarkovRY2.2b"].pop("state_freq")
with pytest.raises(ParseIqTreeError, match=re.escape("IQ-TREE output malformated, motif parameters not found.")):
with pytest.raises(
ParseIqTreeError,
match=re.escape("IQ-TREE output malformated, motif parameters not found."),
):
_ = _process_tree_yaml(lie_dna_model, ["a", "b", "c", "d"])


@pytest.mark.parametrize(("candidate", "expected"), [("((a:1.0,b:0.9),c:0.8);", True),
("((a:0.9,b:0.9),c:0.8);", False),
("((a:1.0,c:0.8),b:0.9);", False)])
def test_tree_equal(candidate:str, expected:bool) -> None:
@pytest.mark.parametrize(
("candidate", "expected"),
[
("((a:1.0,b:0.9),c:0.8);", True),
("((a:0.9,b:0.9),c:0.8);", False),
("((a:1.0,c:0.8),b:0.9);", False),
],
)
def test_tree_equal(candidate: str, expected: bool) -> None:
tree = make_tree("((a:1.0,b:0.9),c:0.8);")
candidate = make_tree(candidate)
assert _tree_equal(tree, candidate) == expected
3 changes: 2 additions & 1 deletion tests/test_model/test_substitution_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def test_model_type(
],
)
def test_get_substitution_model(
substitution_model: SubstitutionModel | str, iqtree_str: str,
substitution_model: SubstitutionModel | str,
iqtree_str: str,
) -> None:
out = get_substitution_model(substitution_model)
assert isinstance(out, SubstitutionModel)
Expand Down

0 comments on commit be41b43

Please sign in to comment.