Skip to content

Commit

Permalink
Contig stitcher: ensure the order of stitched contigs
Browse files Browse the repository at this point in the history
Instead of appending the newly stitched part to the end,
prepend it at the start.

This way we make sure that it will be processed on
the next loop cycle.
  • Loading branch information
Donaim committed Nov 6, 2023
1 parent 2e8c9f0 commit 34d2187
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions micall/core/contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,14 @@ def stitch_contigs(contigs: Iterable[GenotypedContig]):
stitched = yield from (x for x in aligned if not isinstance(x, AlignedContig))
aligned = [x for x in aligned if isinstance(x, AlignedContig)]

# Going left-to-right through aligned contigs.
aligned = list(sorted(aligned, key=lambda x: x.alignment.r_st))
while aligned:
# Going left-to-right through aligned parts.
current = min(aligned, key=lambda x: x.alignment.r_st)
aligned.remove(current)
current = aligned.pop(0)

# Filter out all contigs that are contained within the current one.
# TODO: actually filter out if covered by multiple contigs
# TODO: split contigs that have big gaps in them first, otherwise they will cover too much.
aligned = [x for x in aligned if not \
interval_contains((current.alignment.r_st, current.alignment.r_ei),
(x.alignment.r_st, x.alignment.r_ei))]
Expand All @@ -216,7 +217,7 @@ def stitch_contigs(contigs: Iterable[GenotypedContig]):
yield current
continue

# Get overlaping regions
# Replace two contigs by their stitched version, then loop with it.
new_contig = stitch_2_contigs(current, overlapping_contig)
aligned.remove(overlapping_contig)
aligned.append(new_contig)
aligned.insert(0, new_contig)

0 comments on commit 34d2187

Please sign in to comment.