Skip to content

Commit

Permalink
Contig stitcher: implement Frankenstein cut_reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Nov 6, 2023
1 parent 928da70 commit d132607
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 14 additions & 1 deletion micall/core/contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class FrankensteinContig(AlignedContig):
Yet its .seq string looks like a real contig. """

def __init__(self, parts: List[GenotypedContig]):
assert len(parts) > 0, "Empty Frankensteins do not exist"

self.parts = [subpart for part in parts for subpart in
(part.parts if isinstance(part, FrankensteinContig) else [part])]

Expand All @@ -75,6 +77,17 @@ def seq(self):
return ''.join(map(lambda part: part.seq, self.parts))


def cut_reference(self, cut_point: float) -> Tuple['AlignedContig', 'AlignedContig']:
last_part = self.parts[-1]
left_parts = self.parts[-1:]

Check warning on line 82 in micall/core/contig_stitcher.py

View check run for this annotation

Codecov / codecov/patch

micall/core/contig_stitcher.py#L81-L82

Added lines #L81 - L82 were not covered by tests

left_remainder, left_overlap = left.cut_reference(right.alignment.r_st - 0.5)
right_overlap, right_remainder = right.cut_reference(left.alignment.r_ei + 0.5)

Check warning on line 85 in micall/core/contig_stitcher.py

View check run for this annotation

Codecov / codecov/patch

micall/core/contig_stitcher.py#L84-L85

Added lines #L84 - L85 were not covered by tests

alignment_left, alignment_right = self.alignment.cut_reference(cut_point)
return (AlignedContig(self.contig, alignment_left),

Check warning on line 88 in micall/core/contig_stitcher.py

View check run for this annotation

Codecov / codecov/patch

micall/core/contig_stitcher.py#L87-L88

Added lines #L87 - L88 were not covered by tests
AlignedContig(self.contig, alignment_right))


def align_to_reference(contig: GenotypedContig):
aligner = Aligner(seq=contig.ref_seq, preset='map-ont')
Expand All @@ -87,7 +100,7 @@ def align_to_reference(contig: GenotypedContig):
return AlignedContig(contig=contig, alignment=single_cigar_hit)


def align_equal(seq1, seq2) -> Tuple[str, str]:
def align_equal(seq1: str, seq2: str) -> Tuple[str, str]:
gap_open_penalty = 15
gap_extend_penalty = 3
use_terminal_gap_penalty = 1
Expand Down
9 changes: 7 additions & 2 deletions micall/tests/test_contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,10 @@ def test_3():
]

result = list(stitch_contigs(contigs))
assert 100 == sum(len(x.seq) for x in result)
assert result[0].contig.name == 'a+overlap(a,b)+b'
assert len(result) == 1

result = result[0]

assert 100 == len(result.seq)
assert result.seq == 'A' * 50 + 'C' * 50
assert result.contig.name == 'a+overlap(a,b)+b'

0 comments on commit d132607

Please sign in to comment.