def muscle(sequences=None, alignment_file=None, fasta=None,<EOL>fmt='<STR_LIT>', as_file=False, maxiters=None, diags=False,<EOL>gap_open=None, gap_extend=None, muscle_bin=None):
if sequences:<EOL><INDENT>fasta_string = _get_fasta_string(sequences)<EOL><DEDENT>elif fasta:<EOL><INDENT>fasta_string = open(fasta, '<STR_LIT:r>').read()<EOL><DEDENT>if muscle_bin is None:<EOL><INDENT>muscle_bin = os.path.join(BINARY_DIR, '<STR_LIT>'.format(platform.system().lower()))<EOL><DEDENT>aln_format = '<STR_LIT>'<EOL>if fmt == '<STR_LIT>':<EOL><INDENT>aln_format = '<STR_LIT>'<EOL><DEDENT>muscle_cline = '<STR_LIT>'.format(muscle_bin, aln_format)<EOL>if maxiters is not None:<EOL><INDENT>muscle_cline += '<STR_LIT>'.format(maxiters)<EOL><DEDENT>if diags:<EOL><INDENT>muscle_cline += '<STR_LIT>'<EOL><DEDENT>if all([gap_open is not None, gap_extend is not None]):<EOL><INDENT>muscle_cline += '<STR_LIT>'.format(gap_open, gap_extend)<EOL><DEDENT>muscle = sp.Popen(str(muscle_cline),<EOL>stdin=sp.PIPE,<EOL>stdout=sp.PIPE,<EOL>stderr=sp.PIPE,<EOL>universal_newlines=True,<EOL>shell=True)<EOL>if sys.version_info[<NUM_LIT:0>] > <NUM_LIT:2>:<EOL><INDENT>alignment = muscle.communicate(input=fasta_string)[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>alignment = unicode(muscle.communicate(input=fasta_string)[<NUM_LIT:0>], '<STR_LIT:utf-8>')<EOL><DEDENT>aln = AlignIO.read(StringIO(alignment), fmt)<EOL>if as_file:<EOL><INDENT>if not alignment_file:<EOL><INDENT>alignment_file = tempfile.NamedTemporaryFile().name<EOL><DEDENT>AlignIO.write(aln, alignment_file, fmt)<EOL>return alignment_file<EOL><DEDENT>return aln<EOL>
Performs multiple sequence alignment with MUSCLE.

Args:

    sequences (list): Sequences to be aligned. ``sequences`` can be one of four things:

        1. a FASTA-formatted string

        2. a list of BioPython ``SeqRecord`` objects

        3. a list of AbTools ``Sequence`` objects

        4. a list of lists/tuples, of the format ``[sequence_id, sequence]``

    alignment_file (str): Path for the output alignment file. If not supplied,
        a name will be generated using ``tempfile.NamedTemporaryFile()``.

    fasta (str): Path to a FASTA-formatted file of sequences. Used as an
        alternative to ``sequences`` when suppling a FASTA file.

    fmt (str): Format of the alignment. Options are 'fasta' and 'clustal'. Default
        is 'fasta'.

    threads (int): Number of threads (CPU cores) for MUSCLE to use. Default is ``-1``, which
        results in MUSCLE using all available cores.

    as_file (bool): If ``True``, returns a path to the alignment file. If ``False``,
        returns a BioPython ``MultipleSeqAlignment`` object (obtained by calling
        ``Bio.AlignIO.read()`` on the alignment file).

    maxiters (int): Passed directly to MUSCLE using the ``-maxiters`` flag.

    diags (int): Passed directly to MUSCLE using the ``-diags`` flag.

    gap_open (float): Passed directly to MUSCLE using the ``-gapopen`` flag. Ignored
        if ``gap_extend`` is not also provided.

    gap_extend (float): Passed directly to MUSCLE using the ``-gapextend`` flag. Ignored
        if ``gap_open`` is not also provided.

    muscle_bin (str): Path to MUSCLE executable. ``abutils`` includes built-in MUSCLE binaries
        for MacOS and Linux, however, if a different MUSCLE binary can be provided. Default is
        ``None``, which results in using the appropriate built-in MUSCLE binary.

Returns:

    Returns a BioPython ``MultipleSeqAlignment`` object, unless ``as_file`` is ``True``,
        in which case the path to the alignment file is returned.