def local_alignment(query, target=None, targets=None, match=<NUM_LIT:3>, mismatch=-<NUM_LIT:2>,<EOL>gap_open=-<NUM_LIT:5>, gap_extend=-<NUM_LIT:2>, matrix=None, aa=False, gap_open_penalty=None, gap_extend_penalty=None):
if aa and not matrix:<EOL><INDENT>err = '<STR_LIT>'<EOL>raise RuntimeError(err)<EOL><DEDENT>if not target and not targets:<EOL><INDENT>err = '<STR_LIT>'<EOL>raise RuntimeError(err)<EOL><DEDENT>if target:<EOL><INDENT>targets = [target, ]<EOL><DEDENT>if gap_open_penalty is not None:<EOL><INDENT>gap_open = -<NUM_LIT:1> * gap_open_penalty<EOL><DEDENT>if gap_extend_penalty is not None:<EOL><INDENT>gap_extend = -<NUM_LIT:1> * gap_extend_penalty<EOL><DEDENT>alignments = []<EOL>for t in targets:<EOL><INDENT>try:<EOL><INDENT>alignment = SSWAlignment(query=query,<EOL>target=t,<EOL>match=match,<EOL>mismatch=mismatch,<EOL>matrix=matrix,<EOL>gap_open=-<NUM_LIT:1> * gap_open,<EOL>gap_extend=-<NUM_LIT:1> * gap_extend,<EOL>aa=aa)<EOL>alignments.append(alignment)<EOL><DEDENT>except IndexError:<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if len(alignments) == <NUM_LIT:1>:<EOL><INDENT>return alignments[<NUM_LIT:0>]<EOL><DEDENT>return alignments<EOL>
Striped Smith-Waterman local pairwise alignment.

Args:

    query: Query sequence. ``query`` can be one of four things:

        1. a nucleotide or amino acid sequence, as a string

        2. a Biopython ``SeqRecord`` object

        3. an AbTools ``Sequence`` object

        4. a list/tuple of the format ``[seq_id, sequence]``

    target: A single target sequence. ``target`` can be anything that
        ``query`` accepts.

    targets (list): A list of target sequences, to be proccssed iteratively.
        Each element in the ``targets`` list can be anything accepted by
        ``query``.

    match (int): Match score. Should be a positive integer. Default is 3.

    mismatch (int): Mismatch score. Should be a negative integer. Default is -2.

    gap_open (int): Penalty for opening gaps. Should be a negative integer.
        Default is -5.

    gap_extend (int): Penalty for extending gaps. Should be a negative
        integer. Default is -2.

    matrix (str, dict): Alignment scoring matrix. Two options for passing the
        alignment matrix:

        - The name of a built-in matrix. Current options are ``blosum62`` and ``pam250``.

        - A nested dictionary, giving an alignment score for each residue pair. Should be formatted
          such that retrieving the alignment score for A and G is accomplished by::

            matrix['A']['G']

    aa (bool): Must be set to ``True`` if aligning amino acid sequences. Default
        is ``False``.

Returns:

    If a single target sequence is provided (via ``target``), a single ``SSWAlignment``
    object will be returned. If multiple target sequences are supplied (via ``targets``),
    a list of ``SSWAlignment`` objects will be returned.