def we_align(seqA, seqB, scorer=False, gap=-1): """ Carry out the traditional Waterman-Eggert algorithm. Parameters ---------- seqA, seqB : {str, list, tuple} The input strings. These should be iterables, so you can use tuples, lists, or strings. scorer : dict (default=False) If set to c{False} a scorer will automatically be calculated, otherwise, the scorer needs to be passed as a dictionary that covers all segment matches between the input strings. gap : int (default=-1) The gap penalty. Notes ----- The Waterman-Eggert algorithm (see :evobib:`Waterman1987`) returns *all* local matches between two sequences. Returns ------- alms : list A list consisting of tuples. Each tuple gives the alignment of one of the subsequences of the input sequences. Each tuple contains the aligned part of the first, the aligned part of the second sequence, and the score of the alignment. Examples -------- >>> seqA = 'fat cat' >>> setB = 'catfat' >>> we_align(seqA, seqB) [(['f', 'a', 't'], ['f', 'a', 't'], 3.0), (['c', 'a', 't'], ['c', 'a', 't'], 3.0)] """ # check whether the sequences are tuples if isinstance(seqA, (text_type, tuple)): seqA = list(seqA) seqB = list(seqB) elif not isinstance(seqA, list): raise ValueError("Input should be tuple, list, or string.") return malign.we_align(seqA, seqB, scorer or _get_scorer(seqA, seqB), gap)
def we_align(seqA, seqB, scorer=False, gap=-1): """ Carry out the traditional Waterman-Eggert algorithm. Parameters ---------- seqA, seqB : {str, list, tuple} The input strings. These should be iterables, so you can use tuples, lists, or strings. scorer : dict (default=False) If set to c{False} a scorer will automatically be calculated, otherwise, the scorer needs to be passed as a dictionary that covers all segment matches between the input strings. gap : int (default=-1) The gap penalty. Notes ----- The Waterman-Eggert algorithm (see :evobib:`Waterman1987`) returns *all* local matches between two sequences. Returns ------- alms : list A list consisting of tuples. Each tuple gives the alignment of one of the subsequences of the input sequences. Each tuple contains the aligned part of the first, the aligned part of the second sequence, and the score of the alignment. Examples -------- Align two sequences:: >>> seqA = 'fat cat' >>> seqB = 'catfat' >>> we_align(seqA, seqB) [(['f', 'a', 't'], ['f', 'a', 't'], 3.0), (['c', 'a', 't'], ['c', 'a', 't'], 3.0)] """ seqA, seqB = _as_lists(seqA, seqB) return malign.we_align(seqA, seqB, scorer or _get_scorer(seqA, seqB), gap)