diff options
| -rw-r--r-- | domagi/domagi.py | 12 | ||||
| -rw-r--r-- | tests/test_domagi.py | 17 |
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" |
