From 586428723f40d929f3ef9402352378c6d6629841 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Fri, 28 Aug 2026 03:05:32 +0100 Subject: Bridge extracted subpaths. --- doc/domagi-extract.dbk | 5 +- domagi/domagi.py | 76 ++++++++++++++++------ .../expected-output/test-extract-path-bridge-0.gfa | 9 +++ .../expected-output/test-extract-path-bridge-1.gfa | 9 +++ .../expected-output/test-extract-path-bridge-2.gfa | 9 +++ .../expected-output/test-extract-path-bridge-3.gfa | 13 ++++ .../expected-output/test1-extract-bed-windows.gfa | 46 +++++++++++++ .../test1-extract-path-no-bridge-10-20.gfa | 9 --- .../expected-output/test2-extract-bed-windows.gfa | 12 ++++ .../expected-output/test3-extract-bed-windows.gfa | 13 ++++ test-data/test-extract-path-bridge.gfa | 18 +++++ tests/test_domagi.py | 28 ++++++-- 12 files changed, 211 insertions(+), 36 deletions(-) create mode 100644 test-data/expected-output/test-extract-path-bridge-0.gfa create mode 100644 test-data/expected-output/test-extract-path-bridge-1.gfa create mode 100644 test-data/expected-output/test-extract-path-bridge-2.gfa create mode 100644 test-data/expected-output/test-extract-path-bridge-3.gfa create mode 100644 test-data/expected-output/test1-extract-bed-windows.gfa delete mode 100644 test-data/expected-output/test1-extract-path-no-bridge-10-20.gfa create mode 100644 test-data/expected-output/test2-extract-bed-windows.gfa create mode 100644 test-data/expected-output/test3-extract-bed-windows.gfa create mode 100644 test-data/test-extract-path-bridge.gfa diff --git a/doc/domagi-extract.dbk b/doc/domagi-extract.dbk index 9671d33..736703d 100644 --- a/doc/domagi-extract.dbk +++ b/doc/domagi-extract.dbk @@ -35,7 +35,10 @@ - Bridge subpaths that are separated by less than DISTANCE. Default DISTANCE is 300000. This reduces the fragmentation of paths that are unspecified in the input path ranges. Set DISTANCE to 0 to disable bridging. + + Bridge subpaths that are separated by less than DISTANCE. Default DISTANCE is 300000. This reduces the fragmentation of paths that are unspecified in the input path ranges. Set DISTANCE to 0 to disable bridging. + In contrast to odgi, when bridging subpaths, domagi does not use the newly extracted segments to extend the subgraph further and recursively bridge more subpaths. + diff --git a/domagi/domagi.py b/domagi/domagi.py index f398926..a221a6b 100644 --- a/domagi/domagi.py +++ b/domagi/domagi.py @@ -254,44 +254,82 @@ def extract(con, outfile, segment_name, path_range, steps, max_distance_subpaths con.execute(f""" ATTACH '{outfile}' AS subset_db (READ_WRITE); - INSERT INTO subset_db.segment - SELECT segment.id, name, sequence FROM selected_segment - INNER JOIN segment ON segment.id=selected_segment.id; - - INSERT INTO subset_db.link - SELECT from_segment, from_orientation, to_segment, to_orientation - FROM selected_segment - INNER JOIN link ON from_segment=selected_segment.id; - CREATE TEMPORARY TABLE selected_path_segment AS - WITH selected_path_segment_with_gap_flag AS ( + WITH selected_path_segment_with_gap AS ( + -- Select path segments computing gaps within paths. + SELECT path_segment.path_id, + segment_id, + segment_orientation, + start, + "end", + start-LAG("end") OVER (PARTITION BY path_id ORDER BY start) AS gap + FROM path_segment + INNER JOIN selected_segment ON selected_segment.id=path_segment.segment_id), + gap AS ( + -- Find gaps within paths. + SELECT path_id, + LAG("end") OVER (PARTITION BY path_id ORDER BY start) AS start, + start AS "end" + FROM selected_path_segment_with_gap + QUALIFY gap<=?), + selected_path_segment_with_bridged_gaps AS ( + -- Find segments in gaps, and union them with already selected + -- segments. + SELECT path_segment.path_id, + segment_id, + segment_orientation, + path_segment.start, + path_segment.end + FROM path_segment + INNER JOIN gap + ON gap.path_id=path_segment.path_id + AND gap.start