def test_should_get_the_right_char_position_in_the_original_sequence(self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1'] problem.number_of_variables = 1 msa_1 = MSASolution(problem, msa=[('seq1', '-ABC')]) msa_2 = MSASolution(problem, msa=[('seq1', 'A--B-C')]) # check self.assertEqual( 0, msa_1.get_char_position_in_original_sequence(seq_index=0, position=1)) self.assertEqual(1, msa_1.get_char_position_in_original_sequence(0, 2)) self.assertEqual(2, msa_1.get_char_position_in_original_sequence(0, 3)) self.assertEqual(0, msa_2.get_char_position_in_original_sequence(0, 0)) self.assertEqual(1, msa_2.get_char_position_in_original_sequence(0, 3)) self.assertEqual(2, msa_2.get_char_position_in_original_sequence(0, 5))
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