def test_should_is_gap_at_char_sequence_raise_exception_if_position_is_negative( self): # setup problem = MSA(score_list=[]) problem.identifiers = ['seq1', 'seq2', 'seq3'] problem.number_of_variables = 3 msa = MSASolution(problem, msa=[('seq1', '--AA-'), ('seq2', '--AA-'), ('seq3', '--AA-')]) # check self.assertTrue(msa.is_gap_char_at_sequence(0, 0)) self.assertTrue(msa.is_gap_char_at_sequence(0, 1)) self.assertTrue(msa.is_gap_char_at_sequence(1, 4)) self.assertTrue(msa.is_gap_char_at_sequence(2, 1)) with self.assertRaises(Exception): msa.is_gap_char_at_sequence(0, -1)
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