def mafft(sequences=None, alignment_file=None, fasta=None, fmt='<STR_LIT>', threads=-<NUM_LIT:1>, as_file=False,<EOL>reorder=True, print_stdout=False, print_stderr=False, mafft_bin=None):
if sequences:<EOL><INDENT>fasta_string = _get_fasta_string(sequences)<EOL>fasta_file = tempfile.NamedTemporaryFile(delete=False)<EOL>fasta_file.close()<EOL>ffile = fasta_file.name<EOL>with open(ffile, '<STR_LIT:w>') as f:<EOL><INDENT>f.write(fasta_string)<EOL><DEDENT><DEDENT>elif fasta:<EOL><INDENT>ffile = fasta<EOL><DEDENT>if alignment_file is None:<EOL><INDENT>alignment_file = tempfile.NamedTemporaryFile(delete=False).name<EOL><DEDENT>aln_format = '<STR_LIT>'<EOL>if fmt.lower() == '<STR_LIT>':<EOL><INDENT>aln_format = '<STR_LIT>'<EOL><DEDENT>if fmt.lower() == '<STR_LIT>':<EOL><INDENT>aln_format = '<STR_LIT>'<EOL><DEDENT>if reorder:<EOL><INDENT>aln_format += '<STR_LIT>'<EOL><DEDENT>if mafft_bin is None:<EOL><INDENT>mafft_bin = '<STR_LIT>'<EOL><DEDENT>mafft_cline = '<STR_LIT>'.format(mafft_bin, threads, aln_format, ffile, alignment_file)<EOL>mafft = sp.Popen(str(mafft_cline),<EOL>stdout=sp.PIPE,<EOL>stderr=sp.PIPE,<EOL>universal_newlines=True,<EOL>shell=True)<EOL>stdout, stderr = mafft.communicate()<EOL>if print_stdout:<EOL><INDENT>print(mafft_cline)<EOL>print(stdout)<EOL><DEDENT>if print_stderr:<EOL><INDENT>print(stderr)<EOL><DEDENT>os.unlink(ffile)<EOL>if os.stat(alignment_file).st_size == <NUM_LIT:0>:<EOL><INDENT>return None<EOL><DEDENT>if as_file:<EOL><INDENT>return alignment_file<EOL><DEDENT>aln = AlignIO.read(open(alignment_file), fmt)<EOL>os.unlink(alignment_file)<EOL>return aln<EOL>
Performs multiple sequence alignment with MAFFT.

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', 'phylip', and 'clustal'. Default
        is 'fasta'.

    threads (int): Number of threads for MAFFT to use. Default is ``-1``, which
        results in MAFFT using ``multiprocessing.cpu_count()`` threads.

    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).

    print_stdout (bool): If ``True``, prints MAFFT's standard output. Default is ``False``.

    print_stderr (bool): If ``True``, prints MAFFT's standard error. Default is ``False``.

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

Returns:

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