Пример #1
0
def align_fasta(infname, outfname, debug=False):
    """
    Generate an alignment for the given fasta file.

    Args:
        infname (str): Path to fasta to be aligned.
        outfname (str): Path to output fasta to be
    """
    muscle_exec = {
        "Windows": "niclassify/bin/muscle3.8.31_i86win32.exe",
        "Linux": "niclassify/bin/muscle3.8.31_i86linux64",
        "Darwin": "niclassify/bin/muscle3.8.31_i86darwin64"
    }[PLATFORM]

    alignment_call = MuscleCommandline(os.path.realpath(
        os.path.join(MAIN_PATH, muscle_exec)),
                                       input=os.path.realpath(infname),
                                       out=os.path.realpath(outfname))

    print(alignment_call.__str__())

    if debug:
        subprocess.run(alignment_call.__str__(),
                       creationflags=subprocess.CREATE_NEW_CONSOLE,
                       shell=True)
    else:
        subprocess.run(alignment_call.__str__(), shell=True)

    r_script = os.path.realpath(
        os.path.join(MAIN_PATH, "niclassify/core/scripts/trim_alignment.R"))

    trim_call = [R_LOC, r_script, outfname, outfname]

    if debug:
        proc = subprocess.run(trim_call,
                              creationflags=subprocess.CREATE_NEW_CONSOLE,
                              env=os.environ.copy())
    else:
        proc = subprocess.run(trim_call, env=os.environ.copy())

    if os.stat(outfname).st_size == 0:
        raise ChildProcessError("Sequence Alignment Failed")

    if proc.returncode != 0:
        raise RScriptFailedError("R TrimAlignment failed")
Пример #2
0
def allign_fasta(filename = "filename", 
                 extension_in = ".fasta", 
                 extension_out = ".aln"):
    """
        This function requires MUSCLE from http://www.drive5.com/muscle. The
            main objective - read FASTA file with multiple records, find similar
            sequences, save alingment of similar sequences to "filename.aln".
        @param filename: FASTA file, which should be alligned.
        @param extension_in: FASTA file type end, could be .fa or similar.
        @param extension_out: Alignment file type: ".aln".
    """
    from Bio.Align.Applications import MuscleCommandline
    
    
    if filename == None:
        return False;
    
    if not os.path.exists(filename + extension_in):
        return False;   
        
    cline = MuscleCommandline(input=filename + extension_in, out=filename + extension_out);
    os.system(cline.__str__());
    return True;