@@ -378,18 +378,11 @@ def convert_masking(self, error_model: SequencingErrorModel):
378
378
379
379
self .reference_segment = Seq (modified_segment )
380
380
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 ):
388
382
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 ,
391
385
)
392
-
393
386
alignment = format_alignment (* raw_alignment [0 ], full_sequences = True ).split ()
394
387
aligned_template_seq = alignment [0 ]
395
388
aligned_mut_seq = alignment [- 2 ]
@@ -431,10 +424,24 @@ def make_cigar(self):
431
424
if cig_length == self .length :
432
425
break
433
426
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 )
434
438
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
+
438
445
439
446
# append the final section as we return
440
447
return cig_string + str (cig_count ) + curr_char
0 commit comments