def find_cutting_points_in_first_parent(self, solution: MSASolution, position: int) -> list: """ Find the real cutting points in a solution. If the column is a gap then the next non-gap symbol must be found """ positions = [-1 for _ in range(solution.number_of_variables)] for i in range(solution.number_of_variables): if solution.is_gap_char_at_sequence(i, position): positions[i] = solution.get_next_char_position_after_gap( i, position) else: positions[i] = position return positions
def __find_symbol_position_in_original_sequence(self, solution: MSASolution, seq_index: int, position: int): """ Given a symbol position, finds the corresponding position of the symbol in the original sequence if gaps are not taken into account. If the symbol is a gap the returned value is -1 """ if position > solution.get_length_of_alignment(): raise Exception( 'Position {0} is larger than the sequence size {1}'.format( position, solution.get_length_of_alignment())) if not solution.is_gap_char_at_sequence(seq_index, position): symbol_position = solution.get_char_position_in_original_sequence( seq_index, position) else: position = solution.get_next_char_position_after_gap( seq_index, position) if position < 0: symbol_position = -1 else: symbol_position = solution.get_char_position_in_original_sequence( seq_index, position) return symbol_position
def test_should_get_next_char_position_after_gap(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2'] problem.number_of_variables = 2 msa_1 = MSASolution(problem, msa=[('seq1', '-ABC'), ('seq2', 'AB-C')]) problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa_2 = MSASolution(problem, msa=[('seq1', 'A--BC')]) msa_extra_gaps = MSASolution(problem, msa=[('seq1', '---A---BC--D---')]) # check self.assertEqual( 1, msa_1.get_next_char_position_after_gap(seq_index=0, gap_position=0)) self.assertEqual( 3, msa_1.get_next_char_position_after_gap(seq_index=1, gap_position=2)) self.assertEqual( 3, msa_2.get_next_char_position_after_gap(seq_index=0, gap_position=1)) self.assertEqual( 3, msa_2.get_next_char_position_after_gap(seq_index=0, gap_position=2)) self.assertEqual( 3, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=0)) self.assertEqual( 3, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=1)) self.assertEqual( 7, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=4)) self.assertEqual( 7, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=6)) self.assertEqual( 11, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=9)) self.assertEqual( 11, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=10)) self.assertEqual( -1, msa_extra_gaps.get_next_char_position_after_gap(seq_index=0, gap_position=12))