From b0277ae1da434d81a744a87f4152e6d7852ee4ed Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 26 Aug 2026 02:50:29 +0100 Subject: Do not traverse graph when extracting segments in path range. --- doc/domagi-extract.dbk | 20 +++++++++----- domagi/domagi.py | 24 ++++++---------- domagi/extract-node-traversal.sql | 7 +++-- .../expected-output/test1-extract-path-7-10.gfa | 8 ++++++ .../expected-output/test1-extract-path-7-8.gfa | 4 +++ .../expected-output/test1-extract-path-7-9.gfa | 6 ++++ .../expected-output/test1-extract-path-8-10.gfa | 5 ++++ .../expected-output/test1-extract-path-8-9.gfa | 3 ++ tests/test_domagi.py | 32 ++++++++++++++++++++++ 9 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 test-data/expected-output/test1-extract-path-7-10.gfa create mode 100644 test-data/expected-output/test1-extract-path-7-8.gfa create mode 100644 test-data/expected-output/test1-extract-path-7-9.gfa create mode 100644 test-data/expected-output/test1-extract-path-8-10.gfa create mode 100644 test-data/expected-output/test1-extract-path-8-9.gfa diff --git a/doc/domagi-extract.dbk b/doc/domagi-extract.dbk index a2b7c6b..d20afd9 100644 --- a/doc/domagi-extract.dbk +++ b/doc/domagi-extract.dbk @@ -9,23 +9,29 @@ Options + + + + + Traverse the graph from a segment Segment name from which to begin the traversal - - - - Path range, in path[:pos1[-pos2]] format, from which to begin the traversal - The number of segments away from the initial segments to traverse - - + + + Extract segments in path range + + + + Extract segments in PATH_RANGE, specified in the path[:pos1[-pos2]] format. pos1 and pos2 are 0-based coordinates. The extracted segments include pos1 (inclusive) but not pos2 (exclusive). + diff --git a/domagi/domagi.py b/domagi/domagi.py index 2aba383..e2bf457 100644 --- a/domagi/domagi.py +++ b/domagi/domagi.py @@ -226,34 +226,27 @@ def depth(con, graph_depth_table, paths, bed_input, threads, progress): @click.option("-c", "--context-steps", "steps", type=click.INT, # TODO: Add default=0 - required=True, help="number of traversal steps") @common_options def extract(con, outfile, segment_name, path_range, steps, threads, progress): set_duckdb_threads(con, threads) with connect_duckdb(outfile, threads) as out_con: out_con.execute(read_sql("schema.sql")) - if segment_name: - con.execute(""" - CREATE TEMPORARY TABLE initial_segment AS - SELECT id FROM segment WHERE segment.name=? - """, - [segment_name]) - elif path_range: - # TODO: We're assuming the interval is [start, end) rather - # than [start, end]. But check what odgi does. + if path_range: + path, start, end = re.match(r"^([^:]*):(\d+)-(\d+)", path_range).groups() con.execute(""" - CREATE TEMPORARY TABLE initial_segment AS + CREATE TEMPORARY TABLE selected_segment AS SELECT segment_id AS id FROM path_segment INNER JOIN path ON path.id=path_segment.path_id - WHERE path.name=? AND start>=? AND start