phylogenetics/tools/blast.py
def local_blast(df,db,blast_program="blastp",
                 keep_tmp=False,
                 hitlist_size=100,
                 e_value_cutoff=0.01,
                 gapcosts=(11,1),
                 **kwargs):
    """
    Perform a blast query using sequences in the data frame against the subject
    database.
    """

    recognized_functions = {"blastp":apps.NcbiblastpCommandline,
                            "blastn":apps.NcbiblastnCommandline,
                            "blastx":apps.NcbiblastxCommandline,
                            "tblastn":apps.NcbitblastnCommandline,
                            "tblastx":apps.NcbitblastxCommandline,
                            "psiblast":apps.NcbipsiblastCommandline,
                            "rpsblast":apps.NcbirpsblastCommandline,
                            "rpstblastn":apps.NcbirpstblastnCommandline,
                            "deltablast":apps.NcbideltablastCommandline}

    try:
        _local_blast = recognized_functions[blast_program]
    except KeyError:
        err = "\nblast_program '{}' not recognized.\n\nAllowed programs:\n".format(blast_program)
        for k in recognized_functions.keys():
            err += "    {}\n".format(k)
        raise ValueError(err)

    gaps = '{} {}'.format(*gapcosts)

    # make a 10-character random string for temporary files
    tmp_file_root = "".join([random.choice(string.ascii_letters) for i in range(10)])
    input_file = "{}_blast_in.fasta".format(tmp_file_root)
    out_file = "{}_blast_out.xml".format(tmp_file_root)

    # Write data frame to fasta file
    phy.seqio.write.to_fasta(df,id_col="uid",filename=input_file)

    _local_blast(query=input_file,
                 cmd=blast_program,
                 db=db,
                 out=out_file,
                 outfmt=5,
                 max_target_seqs=hitlist_size,
                 threshold=e_value_cutoff,
                 gapopen=gapcosts[0],
                 gapextend=gapcosts[1],
                 **kwargs)()

    out_df = phy.read_blast_xml(out_file)

    if not keep_tmp:
        os.remove(input_file)
        os.remove(out_file)

    return out_df

    Perform a blast query using sequences in the data frame against the subject
    database.
    
Perform a blast query using sequences in the data frame against the subject
database.
Perform a blast query using sequences in the data frame against the subject database .
def local_blast(df,db,blast_program="blastp",
                 keep_tmp=False,
                 hitlist_size=100,
                 e_value_cutoff=0.01,
                 gapcosts=(11,1),
                 **kwargs):
    recognized_functions = {"blastp":apps.NcbiblastpCommandline,
                            "blastn":apps.NcbiblastnCommandline,
                            "blastx":apps.NcbiblastxCommandline,
                            "tblastn":apps.NcbitblastnCommandline,
                            "tblastx":apps.NcbitblastxCommandline,
                            "psiblast":apps.NcbipsiblastCommandline,
                            "rpsblast":apps.NcbirpsblastCommandline,
                            "rpstblastn":apps.NcbirpstblastnCommandline,
                            "deltablast":apps.NcbideltablastCommandline}
    try:
        _local_blast = recognized_functions[blast_program]
    except KeyError:
        err = "\nblast_program '{}' not recognized.\n\nAllowed programs:\n".format(blast_program)
        for k in recognized_functions.keys():
            err += "    {}\n".format(k)
        raise ValueError(err)
    gaps = '{} {}'.format(*gapcosts)
    tmp_file_root = "".join([random.choice(string.ascii_letters) for i in range(10)])
    input_file = "{}_blast_in.fasta".format(tmp_file_root)
    out_file = "{}_blast_out.xml".format(tmp_file_root)
    phy.seqio.write.to_fasta(df,id_col="uid",filename=input_file)
    _local_blast(query=input_file,
                 cmd=blast_program,
                 db=db,
                 out=out_file,
                 outfmt=5,
                 max_target_seqs=hitlist_size,
                 threshold=e_value_cutoff,
                 gapopen=gapcosts[0],
                 gapextend=gapcosts[1],
                 **kwargs)()
    out_df = phy.read_blast_xml(out_file)
    if not keep_tmp:
        os.remove(input_file)
        os.remove(out_file)
    return out_df
def local_blast ( df , db , blast_program = "blastp" , keep_tmp = False , hitlist_size = 100 , e_value_cutoff = 0.01 , gapcosts = ( 11 , 1 ) , ** kwargs ) : recognized_functions = { "blastp" : apps . NcbiblastpCommandline , "blastn" : apps . NcbiblastnCommandline , "blastx" : apps . NcbiblastxCommandline , "tblastn" : apps . NcbitblastnCommandline , "tblastx" : apps . NcbitblastxCommandline , "psiblast" : apps . NcbipsiblastCommandline , "rpsblast" : apps . NcbirpsblastCommandline , "rpstblastn" : apps . NcbirpstblastnCommandline , "deltablast" : apps . NcbideltablastCommandline } try : _local_blast = recognized_functions [ blast_program ] except KeyError : err = "\nblast_program '{}' not recognized.\n\nAllowed programs:\n" . format ( blast_program ) for k in recognized_functions . keys ( ) : err += "    {}\n" . format ( k ) raise ValueError ( err ) gaps = '{} {}' . format ( * gapcosts ) tmp_file_root = "" . join ( [ random . choice ( string . ascii_letters ) for i in range ( 10 ) ] ) input_file = "{}_blast_in.fasta" . format ( tmp_file_root ) out_file = "{}_blast_out.xml" . format ( tmp_file_root ) phy . seqio . write . to_fasta ( df , id_col = "uid" , filename = input_file ) _local_blast ( query = input_file , cmd = blast_program , db = db , out = out_file , outfmt = 5 , max_target_seqs = hitlist_size , threshold = e_value_cutoff , gapopen = gapcosts [ 0 ] , gapextend = gapcosts [ 1 ] , ** kwargs ) ( ) out_df = phy . read_blast_xml ( out_file ) if not keep_tmp : os . remove ( input_file ) os . remove ( out_file ) return out_df
Perform a blast query using sequences in the data frame against the subject
database.
Perform a blast query using sequences in the data frame against the subject database .
"""
    Perform a blast query using sequences in the data frame against the subject
    database.
    """ # make a 10-character random string for temporary files # Write data frame to fasta file
df
db
blast_program
keep_tmp
hitlist_size
e_value_cutoff
gapcosts