Skip to content

Commit 0ec8ac1

Browse files
glennhickeyclaude
andcommitted
Add vg chunk -H to include haplotype paths in chunks
Since libbdsg 30c805e (Feb 2026), ReferencePathOverlay indexes only REFERENCE and GENERIC paths by default, and the chunker only copies paths the overlay has indexed. vg call and vg deconstruct were updated to opt back in for embedded haplotypes, but vg chunk was not, so chunks of .vg graphs silently lost their haplotype paths. Indexing haplotypes means building a full position index over every haplotype in the graph, which is too expensive to do by default on big graphs, so make it opt-in with -H/--haplotype-paths for any input, including GBZ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ce79f12 commit 0ec8ac1

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎src/subcommand/chunk_main.cpp‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ void help_chunk(char** argv) {
109109
<< " with haplotype frequencies for each chunk." << endl
110110
<< " --no-embedded-haplotypes don't load haplotypes from the graph. It is" << endl
111111
<< " possible to -T without any haplotypes available." << endl
112+
<< " -H, --haplotype-paths also include haplotype paths in graph chunks." << endl
113+
<< " Slow and memory-hungry on big graphs, since" << endl
114+
<< " every haplotype gets a position index." << endl
112115
<< " -f, --fully-contained only return GAM alignments that are" << endl
113116
<< " fully contained within chunk" << endl
114117
<< " -u, --cut-alignments cut alignments to be fully within the chunk" << endl
@@ -144,6 +147,7 @@ int main_chunk(int argc, char** argv) {
144147
string node_ranges_file;
145148
bool trace = false;
146149
bool no_embedded_haplotypes = false;
150+
bool haplotype_paths = false;
147151
bool fully_contained = false;
148152
bool cut_alignments = false;
149153
int n_chunks = 0;
@@ -187,6 +191,7 @@ int main_chunk(int argc, char** argv) {
187191
{"node-ranges", required_argument, 0, 'R'},
188192
{"trace", no_argument, 0, 'T'},
189193
{"no-embedded-haplotypes", no_argument, 0, OPT_NO_EMBEDDED_HAPLOTYPES},
194+
{"haplotype-paths", no_argument, 0, 'H'},
190195
{"fully-contained", no_argument, 0, 'f'},
191196
{"cut-alignments", no_argument, 0, 'u'},
192197
{"threads", required_argument, 0, 't'},
@@ -203,7 +208,7 @@ int main_chunk(int argc, char** argv) {
203208
};
204209

205210
int option_index = 0;
206-
c = getopt_long (argc, argv, "h?x:G:a:gFp:P:s:o:e:S:E:b:c:r:R:Tfut:n:l:m:CMO:",
211+
c = getopt_long (argc, argv, "h?x:G:a:gFp:P:s:o:e:S:E:b:c:r:R:THfut:n:l:m:CMO:",
207212
long_options, &option_index);
208213

209214

@@ -311,6 +316,10 @@ int main_chunk(int argc, char** argv) {
311316
no_embedded_haplotypes = true;
312317
break;
313318

319+
case 'H':
320+
haplotype_paths = true;
321+
break;
322+
314323
case 'f':
315324
fully_contained = true;
316325
break;
@@ -465,7 +474,10 @@ int main_chunk(int argc, char** argv) {
465474
}
466475

467476
path_handle_graph = vg::io::VPKG::load_one<PathHandleGraph>(xg_file);
468-
graph = overlay_helper.apply(path_handle_graph.get(), ensure_indexed);
477+
// The chunker only copies indexed paths into the chunks, so haplotypes
478+
// need to be indexed to come along. That builds a position index over
479+
// every haplotype in the graph, which is expensive on big graphs.
480+
graph = overlay_helper.apply(path_handle_graph.get(), haplotype_paths, ensure_indexed);
469481
}
470482

471483
// Now load the haplotype data

‎test/t/30_vg_chunk.t‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ BASH_TAP_ROOT=../deps/bash-tap
55

66
PATH=../bin:$PATH # for vg
77

8-
plan tests 42
8+
plan tests 46
99

1010
# Construct a graph with alt paths so we can make a GBWT and a GBZ
1111
vg construct -m 1000 -r small/x.fa -v small/x.vcf.gz -a >x.vg
@@ -138,8 +138,17 @@ vg chunk -x graph.gbz -p GRCh38#0#chr1:5-7 -c 1 >part.vg
138138
vg chunk -x part.vg -p GRCh38#0#chr1:5-7 -c 1 >subpart.vg
139139
is "$?" "0" "chunking the same base path range out of a chunk works"
140140
is "$(vg stats -l part.vg)" "$(vg stats -l subpart.vg)" "chunking the same base path range out of a chunk gets the same nodes"
141+
is "$(vg paths -L -H -x part.vg | wc -l)" "0" "chunking a GBZ leaves out haplotype paths by default"
142+
vg chunk -x graph.gbz -p GRCh38#0#chr1:5-7 -c 1 -H >part.vg
143+
is "$(vg paths -L -H -x part.vg | wc -l)" "3" "chunking a GBZ with -H keeps the haplotype paths"
141144

142-
rm -f graph.gbz part.vg subpart.vg log.txt
145+
vg convert -g graphs/gfa_with_reference.gfa >graph.vg
146+
vg chunk -x graph.vg -p GRCh38#0#chr1:5-7 -c 1 >part.vg
147+
is "$(vg paths -L -H -x part.vg | wc -l)" "0" "chunking a non-GBZ graph leaves out haplotype paths by default"
148+
vg chunk -x graph.vg -p GRCh38#0#chr1:5-7 -c 1 -H >part.vg
149+
is "$(vg paths -L -H -x part.vg | wc -l)" "3" "chunking a non-GBZ graph with -H keeps the haplotype paths"
150+
151+
rm -f graph.gbz graph.vg part.vg subpart.vg log.txt
143152

144153
# GBZ chunking
145154
vg gbwt --graph-name graph.gbz --set-reference sample --gfa-input graphs/components_walks.gfa

0 commit comments

Comments
 (0)