Repository navigation
Description
1. What were you trying to do?
Surject a GAM file containing a single read. The alignment, dotplotted against CHM13, looks like
Note that all "legs" of the X can connect to each other, i.e. /, \, < are also possible alignment "shapes"
2. What did you want to happen?
Using --supplementary should allow the surjected alignment to be split up into two parts, aligned in opposite directions along approximately the same reference sequence. This would recapitulate what I see in the Giraffe alignments.
3. What actually happened?
The end of the read gets realigned to take a straight-line path instead of being split up to represent the U-turn path.
4. What data and command can the vg dev team use to make the problem happen?
- Read: sim_r10_HG002_1m.S46_75882.realigned.new.json
- Graph:
/private/groups/patenlab/anovak/projects/hprc/lr-giraffe/graphs/hprc-v2.1-mc-chm13-eval-sampled16o_fragmentlinked-for-real-r10y2025-HG002-full.gbz
Convert the JSON into a GAM: vg view -aJG sim_r10_HG002_1m.S46_75882.realigned.new.json > sim_r10_HG002_1m.S46_75882.realigned.new.gam
If you want to run the alignment too, this currently requires my "reversals" branch PR #4953. It aligns along the recombination#2#chrX#4 path which visits node 217495936 (in the middle of the X) in both directions.
ADAM_GRAPH=/private/groups/patenlab/anovak/projects/hprc/lr-giraffe/graphs/hprc-v2.1-mc-chm13-eval-sampled16o_fragmentlinked-for-real-r10y2025-HG002-full
REV_INDEX_PREFIX=/private/groups/patenlab/fokamoto/giraffe-loops/graph/hprc-v2.1-mc-chm13-eval-sampled16o_fragmentlinked-for-real-r10y2025-HG002-full.reversals
vg giraffe --gbz-name $ADAM_GRAPH.gbz -b r10 --threads 1 \
-G sim_r10_HG002_1m.S46_75882.realigned.new.gam \
--dist-name $ADAM_GRAPH.dist --minimizer-name $REV_INDEX_PREFIX.longread.withzip.min \
--zipcode-name $REV_INDEX_PREFIX.longread.zipcodes > sim_r10_HG002_1m.S46_75882.even_more_realigned.new.gam But for just the surjection
# Without supplementaries (no choice but to realign)
vg surject --read-length long -x $ADAM_GRAPH.gbz \
sim_r10_HG002_1m.S46_75882.realigned.new.gam > sim_r10_HG002_1m.S46_75882.realigned.new.nosup.gam
# With supplementaries (should split into two pieces)
vg surject --read-length long -x $ADAM_GRAPH.gbz \
--supplementary \
sim_r10_HG002_1m.S46_75882.realigned.new.gam > sim_r10_HG002_1m.S46_75882.realigned.new.withsup.gamThe start of the read gets realigned, while the end of the read stays in the exact same locations. The bug is that this happens even if supplementaries are requested.
vg filter --tsv-out nodes sim_r10_HG002_1m.S46_75882.realigned.new.gam | tr "," "\n" > original_alignment.nodes.txt
vg filter --tsv-out nodes sim_r10_HG002_1m.S46_75882.realigned.new.nosup.gam | tr "," "\n" > nosup_surject.nodes.txt
vg filter --tsv-out nodes sim_r10_HG002_1m.S46_75882.realigned.new.withsup.gam | tr "," "\n" > withsup_surject.nodes.txt
# These two are the same!
diff nosup_surject.nodes.txt withsup_surject.nodes.txt
# Start changes, end stays constant
diff --side-by-side original_alignment.nodes.txt nosup_surject.nodes.txt > orig_vs_nosup.txt5. What does running vg version say?
vg version v1.75.0-59-g18f9eb09e "Spike"
Compiled with g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 on Linux
Linked against libstd++ 20230528
Using HTSlib headers 101990, library 1.19.1-29-g3cfe8769
Built by fokamoto@mustard
Activity
adamnovak commentedon Jul 7, 2026
@eizengaj-roche You wrote the surject supplementary logic, right? Do you have any inklings as to why it might not be kicking in here?
jeizenga commentedon Jul 7, 2026
I'm having a hard time picturing what this sequence looks like, but maybe.
In general, I think the method that's implemented for getting supplementary alignments from big deletions is more compelling than for getting supplementary alignments from inverting motifs. The main reason is that, when dividing up the surject problem to align on either end of a deletion breakpoint, you can stay within one path-strand's surject routine. For inverting (or cross-chromosome) motifs, you also run awkwardly into the final surjection choice routine. The way surject was previously written was to expect that you produce one best surjection for each path strand, and then you choose the best path strand and move forward with it. The way I tried to work around this was to try to identify a "supplementary cover" consisting of path strands. Essentially, you try to find a set of path-strands whose collections of supplementary alignments collectively partition the read non-redundantly (this is roughly the same principal that is used to identify supplementary alignments in short-read giraffe). It looks to me like both strands align the full read, so one possibility is that the two strands' alignments are seen as redundant and therefore not a legitimate collection of supplementary alignments.
I don't necessarily think that this is the best formulation of the problem, so feel free to improve on it.
adamnovak commentedon Jul 13, 2026
Whatever's going on here is not as simple as
vg surjectnot being able to produce reverse-strand supplementary alignments.I set up a tiny GFA with an inversion of nodes 6 and 7, and mapped a read with the lead-up to the inversion and then the inversion. When surjecting the resulting graph alignment with
--supplementary, I managed to get the expected output of a primary alignment on the forward strand and a supplementary alignment on the reverse strand.adamnovak commentedon Jul 13, 2026
I could replicate this with (note that I'm breaking up the GFA nodes in autoindex):
You can also get that GAF using the reversals branch with:
This is about the same as the X except there are enough base differences that only the left half of the X shows up appreciably in chaining.
Next I have to dig into surject and try and see why it can't handle this. I could also try trimming down the graph further.
adamnovak commentedon Jul 14, 2026
OK, I've looked at the surject debug logs, and @jeizenga is right about what's happening here: we break the alignment into two problems of aligning to two different path-strand combinations, each of those produces a full-length alignment rather than softclipping, and we don't assemble a collection of supplementary alignments across those two path-strands and we just pick one alignment to win.
I think doing things that way makes sense for short-read alignments, but with long reads we might have e.g. a read that completely traverses an inverted region relative to the reference, or a full-length RNAseq read from an interchromosomal fusion between two paralogs that have better-than-a-softclip alignment scores. We want to be able to, at least as a mode if not by default, trust the graph alignment's idea of what pieces of the target reference path-strand set we should be visiting at any given point in the read.
I think the Right Way to do this would involve some high-level redesign of the surjector to not work within a single path-strand at a time, but instead to be trying to push the read onto the stick-forest graph of the target paths, with some transition cost for jumping from one place in there to another one suggested by the input graph-space alignment, which we can compare to the cost of aligning the rest of the tail right there. (If the graph alignment went through some off-target-reference material before reaching the target reference again, we'd need to do a new kind of DP problem, or at least fake it, to find out exactly where to put the cutover point and which read bases should belong to one supplementary alignment versus the other.) This all looks quite a lot like what @faithokamoto is working on with trying to build a DP problem in Giraffe that can produce supplementary graph alignments out of basically a
multipath_alignment_t, so we might be able to use the same code against that stick-forest graph. Alternately, we could adapt the existing spliced surjection logic here, with its concepts of colinearity graphs and friends (which I still haven't read through but look promising), but expand it to allow "splicing" together bits of multiple path-strands together when the graph alignment suggests it. This would probably be more total code, and still be somewhat duplicative of what Faith's trying to do, but would probably allow for changing current behavior less.Since I want to avoid bumping into Faith's work, I'm also thinking of doing this the Wrong Way: considering only single-path alignments, generate the alignments for the different path-strands as we do now, and then try to cut and paste them together into supplementary alignment sets if the result can get a higher overall score, with some cost for each cut. I think this would be fairly simple to implement to the point where it solves this case:
This approach would solve the problem we have now of only being able to combine alignments into supplementary sets when each has softclipped in the region the other covers, while being guided by the graph alignment and some transition cost and not just letting you combine anything with anything for free. But, it's layering on more passes and more code, and means we'd be computing and then throwing away a lot of base-level alignments. And once we had a unified approach to pulling supplementary sets out of a
multipath_alignment_tor something like it, we'd probably want to throw this away and use that instead.adamnovak commentedon Jul 23, 2026
I tried to try to do this in a
surject-supplementary-reversalbranch. But so far all I've managed to do is heavily refactor the guts of target path finding (introducing aSurjectionRecordto hold things that have been in big tuples), and also (basically separately) refactor supplementary finding so that it outputs its results in terms of alignments and not in terms of strands.I gave up on the idea of remembering cut-overs since I'm not sure we really need/want that. Shouldn't we be able to cut over anywhere? Also unless we jump right from one target path strand to another, it's hard to tell a cutover ought to exist.
I think that second part of what I did so far is necessary but not sufficient; I still need something that can figure out when alignments that substantially overlap (from dubious tail alignment) need to be cut apart with the pieces added to a supplementary cover. I don't want to go through all pairs of Alignments and separately all pairs of MultipathAlignments, but I'm not seeing a great way out of it.