def align(self, hard_region1, hard_region2): len1 = align_util.get_character_lengths(hard_region1) number_of_soft_regions1 = len(hard_region1) len2 = align_util.get_character_lengths(hard_region2) number_of_soft_regions2 = len(hard_region2) if (self.alignment_type == 'original'): alignment = self._seq_align(len1, len2, number_of_soft_regions1, number_of_soft_regions2) elif (self.alignment_type == 'extended'): alignment = self._seq_align_extended(len1, len2, number_of_soft_regions1, number_of_soft_regions2) if (self.output_format == 'text_tuples'): (output_alignment, indices_mapping) = \ align_util.convert_bead_to_tuples(alignment, hard_region1, hard_region2) if (self.print_flag): align_util.print_alignment_text_mapping(output_alignment) elif (self.output_format == 'index_tuples'): (text_mapping, output_alignment) = \ align_util.convert_bead_to_tuples(alignment, hard_region1, hard_region2) if (self.print_flag): align_util.print_alignment_index_mapping(output_alignment) else: # the Gale-Church alignment "bead" objects - a dictionary of objects output_alignment = alignment if (self.print_flag): align_util.print_alignments(output_alignment, hard_region1, hard_region2) return output_alignment
def align(self, hard_region1, hard_region2): len1 = align_util.get_character_lengths(hard_region1) number_of_soft_regions1 = len(hard_region1) len2 = align_util.get_character_lengths(hard_region2) number_of_soft_regions2 = len(hard_region2) if (self.alignment_type == 'original'): alignment = self._seq_align(len1, len2, number_of_soft_regions1, number_of_soft_regions2) elif (self.alignment_type == 'extended'): alignment = self._seq_align_extended(len1, len2, number_of_soft_regions1, number_of_soft_regions2) if (self.output_format == 'text_tuples'): (output_alignment, indices_mapping) = \ align_util.convert_bead_to_tuples(alignment, hard_region1, hard_region2) if (self.print_flag): align_util.print_alignment_text_mapping(output_alignment) elif (self.output_format == 'index_tuples'): (text_mapping, output_alignment) = \ align_util.convert_bead_to_tuples(alignment, hard_region1, hard_region2) if (self.print_flag): align_util.print_alignment_index_mapping(output_alignment) else: # the Gale-Church alignment "bead" objects - a dictionary of objects output_alignment = alignment if (self.print_flag): align_util.print_alignments(output_alignment, hard_region1, hard_region2) return output_alignment
def recursive_align(self, source, target, alignments): """ Apply L{self.align()} to the elements of the C{source} and C{target} texts in a top-down manner @rtype: C{list} of I{alignments} """ standard_alignment = self.align(source, target) alignments.append(standard_alignment) alignment_mapping = None if (self.output_format == 'text_tuples'): alignment_mapping = standard_alignment import align_util if (self.output_format == 'bead_objects'): (alignment_mapping, alignment_mapping_indices) = align_util.convert_bead_to_tuples(standard_alignment, source, target) for entry in alignment_mapping: source_list = [item for item in entry[0]] target_list = [item for item in entry[1]] if len(source_list) == 0 or len(target_list) == 0: break if not(isinstance(source_list[0], list)) or not(isinstance(target_list[0], list)): break lower_align = self.recursive_align(source_list, target_list, alignments) return alignments