Skip to content

Commit b8b981e

Browse files
authored
Merge pull request #9 from Mye-InfoBank/5-updated-symbol-is-already-present-in-the-input-dataset
Fix conflict handling in apply
2 parents ba848dc + a74e5b5 commit b8b981e

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "hugo-unifier"
3-
version = "0.2.5"
3+
version = "0.2.6"
44
description = "Python package that can unify gene symbols across datasets based on the HUGO database."
55
readme = "README.md"
66
authors = [

src/hugo_unifier/apply_changes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def apply_changes(adata: ad.AnnData, df_changes: pd.DataFrame):
2323
symbol = row["symbol"]
2424
new_symbol = row["new"]
2525

26+
if action == "conflict":
27+
print(f"Conflict for {symbol} -> {new_symbol}")
28+
continue
29+
2630
assert (
2731
symbol in adata.var.index
2832
), f"Symbol {symbol} not found in AnnData object."

tests/test_cli.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,47 @@ def test_cli_apply_help():
5353
assert (
5454
"Apply changes to the input .h5ad file." in result.stdout
5555
), "Expected description for 'apply' command not found in output."
56+
57+
58+
def test_cli_full_pipeline(test_h5ad_paths, tmp_path):
59+
"""Test the full pipeline of the CLI."""
60+
get_dir = tmp_path / "get"
61+
get_dir.mkdir(parents=True, exist_ok=True)
62+
63+
cmd = ["hugo-unifier", "get", "--outdir", str(get_dir)]
64+
for input_file in test_h5ad_paths:
65+
cmd.extend(["--input", str(input_file)])
66+
67+
result = subprocess.run(cmd, capture_output=True, text=True)
68+
assert result.returncode == 0, f"Command failed with error: {result.stderr}"
69+
70+
apply_dir = tmp_path / "apply"
71+
apply_dir.mkdir(parents=True, exist_ok=True)
72+
73+
sample_to_apply = "uzzan"
74+
input_file = next(
75+
input_file
76+
for input_file in test_h5ad_paths
77+
if sample_to_apply in input_file.stem
78+
)
79+
80+
changes_file = get_dir / f"{sample_to_apply}.csv"
81+
assert changes_file.exists(), f"Changes file {changes_file} not found."
82+
83+
output_file = apply_dir / f"{sample_to_apply}.h5ad"
84+
assert not output_file.exists(), f"Output file {output_file} already exists."
85+
86+
cmd = [
87+
"hugo-unifier",
88+
"apply",
89+
"--input",
90+
str(input_file),
91+
"--changes",
92+
str(changes_file),
93+
"--output",
94+
str(output_file),
95+
]
96+
97+
result = subprocess.run(cmd, capture_output=True, text=True)
98+
assert result.returncode == 0, f"Command failed with error: {result.stderr}"
99+
assert output_file.exists(), f"Output file {output_file} not created."

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)