Skip to content

Commit 2566b92

Browse files
committed
I think I worked through some bugs in alignments.
1 parent fc2aced commit 2566b92

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

neat/read_simulator/utils/read.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,11 @@ def convert_masking(self, error_model: SequencingErrorModel):
378378

379379
self.reference_segment = Seq(modified_segment)
380380

381-
def make_cigar(self):
382-
"""
383-
Aligns the reference and mutated sequences.
384-
"""
385-
386-
# These parameters were set to minimize breaks in the mutated sequence and find the best
387-
# alignment from there.
381+
def align_seqs(self, reverse: bool):
388382
raw_alignment = pairwise2.align.globalms(
389-
self.reference_segment, self.read_sequence, match=1, mismatch=-1, open=-0.5, extend=-0.1,
390-
penalize_extend_when_opening=True, one_alignment_only=True
383+
self.reference_segment, self.read_sequence, match=10, mismatch=-10, open=-20, extend=-10,
384+
penalize_extend_when_opening=True, one_alignment_only=True,
391385
)
392-
393386
alignment = format_alignment(*raw_alignment[0], full_sequences=True).split()
394387
aligned_template_seq = alignment[0]
395388
aligned_mut_seq = alignment[-2]
@@ -431,10 +424,24 @@ def make_cigar(self):
431424
if cig_length == self.length:
432425
break
433426

427+
return cig_string, cig_count, curr_char, cig_length
428+
429+
430+
def make_cigar(self):
431+
"""
432+
Aligns the reference and mutated sequences.
433+
"""
434+
# These parameters were set to minimize breaks in the mutated sequence and find the best
435+
# alignment from there.
436+
437+
cig_string, cig_count, curr_char, cig_length = self.align_seqs(False)
434438
if cig_length < self.length:
435-
# Note that samtools will throw an error if this happens. Maybe need to adjust alignment parameters.
436-
_LOG.error("Problem creating cigar string")
437-
sys.exit(1)
439+
_LOG.warning("Poor alignment, trying reversed")
440+
cig_string2, cig_count2, curr_char2, cig_length = self.align_seqs(True)
441+
if cig_length < self.length:
442+
_LOG.error("Alignment still not working")
443+
sys.exit(1)
444+
438445

439446
# append the final section as we return
440447
return cig_string + str(cig_count) + curr_char

0 commit comments

Comments
 (0)