about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2025-09-02 11:12:45 +0100
committerArun Isaac2025-09-02 11:27:49 +0100
commit5fb407f65c2714e589bb912c0f62cd79f7311a50 (patch)
treebacbea0690a433417f5425c134f92d0c3fc4e221
parentb300727c1881a591a24f39a3730810f93bd43245 (diff)
downloadpyhegp-5fb407f65c2714e589bb912c0f62cd79f7311a50.tar.gz
pyhegp-5fb407f65c2714e589bb912c0f62cd79f7311a50.tar.lz
pyhegp-5fb407f65c2714e589bb912c0f62cd79f7311a50.zip
Suffix CLI subcommand functions with _command.
We distinguish CLI subcommand functions using the _command suffix.
This way, we don't have to concoct weird names for the actual
workhorse functions.

To remain consistent, we also suffix _command to the command testing
functions.
-rw-r--r--pyhegp/pyhegp.py16
-rw-r--r--tests/test_pyhegp.py4
2 files changed, 10 insertions, 10 deletions
diff --git a/pyhegp/pyhegp.py b/pyhegp/pyhegp.py
index 4db76ea..e88ea8d 100644
--- a/pyhegp/pyhegp.py
+++ b/pyhegp/pyhegp.py
@@ -114,23 +114,23 @@ def encrypt_genotype(genotype, key, summary):
 def main():
     pass
 
-@main.command()
+@main.command("summary")
 @click.argument("genotype-file", type=click.File("r"))
 @click.option("--output", "-o", "summary_file",
               type=click.File("wb"),
               default="-",
               help="output file")
-def summary(genotype_file, summary_file):
+def summary_command(genotype_file, summary_file):
     write_summary(summary_file,
                   genotype_summary(read_genotype(genotype_file)))
 
-@main.command()
+@main.command("pool")
 @click.option("--output", "-o", "pooled_summary_file",
               type=click.File("wb"),
               default="-",
               help="output file")
 @click.argument("summary-files", type=click.File("rb"), nargs=-1)
-def pool(pooled_summary_file, summary_files):
+def pool_command(pooled_summary_file, summary_files):
     summaries = [read_summary(file) for file in summary_files]
     pooled_summary = pool_summaries(summaries)
     max_snps = max(len(summary.data) for summary in summaries)
@@ -139,13 +139,13 @@ def pool(pooled_summary_file, summary_files):
         print(f"Dropped {dropped_snps} SNP(s)")
     write_summary(pooled_summary_file, pooled_summary)
 
-@main.command()
+@main.command("encrypt")
 @click.argument("genotype-file", type=click.File("r"))
 @click.option("--summary", "-s", "summary_file", type=click.File("rb"),
               help="Summary statistics file")
 @click.option("--key", "-k", "key_file", type=click.File("w"),
               help="Output key")
-def encrypt(genotype_file, summary_file, key_file):
+def encrypt_command(genotype_file, summary_file, key_file):
     genotype = read_genotype(genotype_file)
     if summary_file:
         summary = read_summary(summary_file)
@@ -168,13 +168,13 @@ def encrypt(genotype_file, summary_file, key_file):
     with ciphertext_path.open("w") as ciphertext_file:
         write_genotype(ciphertext_file, encrypted_genotype)
 
-@main.command()
+@main.command("cat")
 @click.option("--output", "-o", "output_file",
               type=click.File("wb"),
               default="-",
               help="output file")
 @click.argument("ciphertext-files", type=click.File("rb"), nargs=-1)
-def cat(output_file, ciphertext_files):
+def cat_command(output_file, ciphertext_files):
     write_genotype(output_file,
                    pd.concat([read_genotype(file) for file in ciphertext_files]))
 
diff --git a/tests/test_pyhegp.py b/tests/test_pyhegp.py
index 0a62ad1..6200d0a 100644
--- a/tests/test_pyhegp.py
+++ b/tests/test_pyhegp.py
@@ -50,7 +50,7 @@ def test_pool_stats(pools):
             and pooled_stats.std == approx(np.std(combined_pool, axis=0, ddof=1),
                                            rel=1e-6))
 
-def test_encrypt(tmp_path):
+def test_encrypt_command(tmp_path):
     shutil.copy("test-data/encrypt-test-genotype.tsv", tmp_path)
     ciphertext = tmp_path / "encrypt-test-genotype.tsv.hegp"
     result = CliRunner().invoke(main, ["encrypt",
@@ -124,7 +124,7 @@ def test_conservation_of_solutions(genotype, phenotype):
             == np.linalg.solve(hegp_encrypt(genotype, key),
                                hegp_encrypt(phenotype, key)))
 
-def test_pool(tmp_path):
+def test_pool_command(tmp_path):
     columns = ["chromosome", "position", "reference", "mean", "std"]
     complete_summary = tmp_path / "complete-summary"
     result = CliRunner().invoke(main, ["pool",