about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-08-15 01:49:20 +0100
committerArun Isaac2026-08-15 20:53:16 +0100
commitd9701953f6c755afea218bf10064e794a1167242 (patch)
tree8e5a4e38196786d163c9063ccf6051d3b68de217
parent2e6709e22b940c7ea9a89c8e4330582c97aa81d8 (diff)
downloaddomagi-d9701953f6c755afea218bf10064e794a1167242.tar.gz
domagi-d9701953f6c755afea218bf10064e794a1167242.tar.lz
domagi-d9701953f6c755afea218bf10064e794a1167242.zip
Error out if user-specified path does not exist.
-rw-r--r--domagi/domagi.py12
-rw-r--r--tests/test_domagi.py17
2 files changed, 29 insertions, 0 deletions
diff --git a/domagi/domagi.py b/domagi/domagi.py
index 77d28b9..adf3844 100644
--- a/domagi/domagi.py
+++ b/domagi/domagi.py
@@ -50,6 +50,16 @@ def set_duckdb_threads(con, threads):
     if threads:
         con.execute(f"SET threads TO {threads}")
 
+def assert_paths_exist(con, paths):
+    non_existent_paths = [path for path, in con.execute("""
+    SELECT UNNEST(?)
+    EXCEPT
+    SELECT name FROM path
+    """,
+    [paths]).fetchall()]
+    if non_existent_paths:
+        sys.exit(f"Paths {non_existent_paths} not found")
+
 @contextmanager
 def connect_duckdb(path, threads):
     with duckdb.connect(path) as con:
@@ -134,6 +144,7 @@ def crush(con, outfile, threads):
 @common_options
 def depth(con, graph_depth_table, paths, bed_input, threads):
     set_duckdb_threads(con, threads)
+    assert_paths_exist(con, paths)
     # With the -d flag, print the depth and unique depth of every
     # node.
     if graph_depth_table:
@@ -276,6 +287,7 @@ def overlap(con, paths, paths_file, threads):
     set_duckdb_threads(con, threads)
     if paths_file:
         paths = [line.rstrip() for line in paths_file.readlines()]
+    assert_paths_exist(con, paths)
     (con.execute(read_sql("overlap.sql"), [paths])
      .fetchdf()
      .to_csv(sys.stdout, sep="\t", index=False))
diff --git a/tests/test_domagi.py b/tests/test_domagi.py
index 757d1ec..3f63550 100644
--- a/tests/test_domagi.py
+++ b/tests/test_domagi.py
@@ -316,3 +316,20 @@ def test_domagi_view(tmp_path, test_data_file):
     assert result.exit_code == 0
     with open(test_data_file) as expected:
         assert_gfa_equal(expected, io.StringIO(result.stdout))
+
+def test_error_on_missing_paths(tmp_path):
+    test_data_file = Path("test-data/test1.gfa")
+    duckdb_path = tmp_path / f"{test_data_file.stem}.db"
+    runner = CliRunner()
+    result = runner.invoke(main, ["build",
+                                  "--gfa", test_data_file,
+                                  "--out", duckdb_path])
+    assert result.exit_code == 0
+    result = runner.invoke(main, ["depth",
+                                  "--db", duckdb_path,
+                                  "--path", "xx"])
+    assert result.exit_code == 1 and result.output == "Paths ['xx'] not found\n"
+    result = runner.invoke(main, ["overlap",
+                                  "--db", duckdb_path,
+                                  "--path", "xx"])
+    assert result.exit_code == 1 and result.output == "Paths ['xx'] not found\n"