Example #1
0
def BLAST(seq, seqs, evalue=10):
    lib_dir = temp('blast-' + str(id(seqs)))
    res_file = temp('blast-' + str(id(seqs)), str(id(seq)))

    dbtype = 'nucl' if isinstance(seqs[0], NASeq) else 'prot'
    seqtype = 'nucl' if isinstance(seq, NASeq) else 'prot'

    if not op.exists(op.join(lib_dir, seqs.get_file('fa') + '.phr')) \
      and not op.exists(op.join(lib_dir, seqs.get_file('fa') + '.nhr')):
        c = [[app('BLAST','makeblastdb'),'-in',seqs.get_file('fa'),'-out',lib_dir,'-parse_seqids','-dbtype',dbtype]]
    else:
        c = []

    if dbtype == 'nucl' and seqtype == 'nucl':
        blprog = 'blastn'  # TBLASTX
    elif dbtype == 'nucl' and seqtype == 'prot':
        blprog = 'blastx'
    elif dbtype == 'prot' and seqtype == 'nucl':
        blprog = 'tblastn'
    elif dbtype == 'prot' and seqtype == 'prot':
        blprog = 'blastp'  # PSIBLAST, PHIBLAST

    c += [[app('BLAST',blprog),'-db',lib_dir,'-query',seq.get_file('fa'),'-outfmt','"6 sseqid"','-out',res_file+'-out','-evalue',str(evalue)]]
    c += [[app('BLAST','blastdbcmd'),'-db',lib_dir,'-entry_batch',res_file+'-out','-out',res_file+'.fa']]
    run(c)

    return SeqList(open(res_file + '.fa', 'r'))
Example #2
0
    def get_file(self, frmt="fa", fdir=None):
        """
        Write my sequences to disk in a file *seqs-######* in the
        directory *fdir* making sure they're in a format specified by the list "frmt"
        and return a FileSeqList.

        Useful for quickly getting a file in the correct format to
        pass onto an external program.

        Parameters:
            frmt (str): a file type (e.g. FASTA, FASTQ, etc)
                (default: FASTA)
            fdir (str): a directory to save the file in
                (default: the temp directory)
        Returns:
            the file name of the saved sequences
        """
        from ochre.External.External import temp

        if isinstance(frmt, str):
            frmt = (frmt,)

        fname = "seqs-" + str(id(self)) + "." + frmt[0]
        if fdir is None:
            file_name = temp(fname)
        else:
            file_name = os.path.join(fdir, fname)

        self.write(file_name, frmt[0])
        return file_name