def calculate_m(self, current_segment): results = dict() for neighbor in self.hypercube.backward_neighbors(current_segment): # calculate M + S for each neighbor M = neighbor.get_distance() indices_changed = Hypercube.compare_indices(current_segment.index, neighbor.index) sequence = list() for i in range(0, len(indices_changed)): if indices_changed[i]: sequence.append(self.hypercube.sequences[i][current_segment.index[i]]) else: sequence.append('-') result = (M + self.calculate_s(sequence), neighbor.index) if result[0] not in results: results[result[0]] = list() results[result[0]].append(result[1]) else: results[result[0]].append(result[1]) if len(results) <= 0: return None max_result = max(results.keys()) backtrack_index = results[max_result] return (max_result, backtrack_index)
def generate_output(self, traceback_path): output_sequences = list() while len(output_sequences) < self.hypercube.dimension_count: output_sequences.append(list()) sequence_indices = list(self.hypercube.dimensions) previous_step = traceback_path[0] for current_step in traceback_path[1:]: indices_changed = Hypercube.compare_indices(previous_step, current_step) previous_step = tuple(current_step) for i in range(0, len(indices_changed)): if indices_changed[i]: sequence_indices[i] -= 1 if sequence_indices[i] >= 0: output_sequences[i].insert(0, self.hypercube.sequences[i][sequence_indices[i]]) else: output_sequences[i].insert(0, '-') else: output_sequences[i].insert(0, '-') return output_sequences