Package: pyblast
Running NCBI BLAST manually is of course not rocket science, but this
module provides several benefits over doing so:Automatically runs a BLAST process for each CPU on the system;
achieves far better throughput than the-num_threadsoptionProvides an iterator API that emits native Python objects for each
BLAST resultas they’re produced, rather than at the endResultandHitobjects obviate the need for manually parsing
results; all values represented by their native Python types (e.g.Hit.evalueis afloat, etc)ExampleHere’s a simple example with comments hilighting some relevant
featuresimport pyblast

with open('data.fasta') as f:
    # Use the pyblast.blastx() iterator function
    for r in pyblast.blastx(f, db='/path/to/swissprot'):
        msg = 'query {} has {} hits'.format(r.query_id, len(r.hits))
        if r.hits:
            # Use Hit.evalue as a float for comparison
            min_evalue = sorted([h.evalue for h in r.hits])[0]
            msg += '; minimum evalue {:f}'.format(min_evalue)

        print msgThis will produce output like the followingquery M00181:167:000000000-A4VBV:1:1101:11880:1874 1:N:0:6 has 6 hits; minimum evalue 0.310000
query M00181:167:000000000-A4VBV:1:1101:17067:1875 1:N:0:6 has 14 hits; minimum evalue 0.200000
query M00181:167:000000000-A4VBV:1:1101:15039:1878 1:N:0:6 has 4 hits; minimum evalue 4.400000
query M00181:167:000000000-A4VBV:1:1101:17090:1895 1:N:0:6 has 6 hits; minimum evalue 1.700000
query M00181:167:000000000-A4VBV:1:1101:15843:1907 1:N:0:6 has 2 hits; minimum evalue 1.800000APIblastn(input_file, *args, **kwargs)Iterator to process the contents of the FASTAinput_fileusingblastn; yieldsResultobjects.The*argsand**kwargsarguments control howblastnis
invoked. The former are passed as options without values, while the
latter are passed as options with values. For example,blastn(some_file, 'ungapped',db='foo/bar')will runblastnwith the-ungapped-dbfoo/baroptions.In addition, the following keyword arguments are handled specially and
are not passed on to BLAST:pb_num_processes: number of BLAST processes to spawn; default issysconf(SC_NPROCESSORS_ONLN)pb_fields: iterable of field names to retrieve for each hit; default isDEFAULT_HIT_FIELDS. The list of valid field names (and their meanings) can be found in the*** Formatting optionssection ofblastn-help.blastp(input_file, *args, **kwargs)See documentation forblastn.blastx(input_file, *args, **kwargs)See documentation forblastn.ResultThe result of BLAST processing a single query sequence. The set of
attributes on this object are:id: identifier for the query sequence; can beNonedescription: textual description of the query sequence; can beNonehits: array ofHitobjectsHitA single sequence hit in aResultobject.The attributes of this object are the names of the fields requested of
BLAST. For example, ifblastnwas run withpb_fields=['qseqid',...]then one could access theqseqidvalue of theHitobjecthlike so:h.qseqid. Fields referenced that were not
requested of BLAST have aNonevalue.In addition, BLAST fields are converted to their native Python types.
For example,evaluefields are automatically converted to floating
point values.DEFAULT_HIT_FIELDSThe default fields returned for eachHitobject.VERSIONThe version ofpyblastthat’s being used. This can be used to more
easily than feature detection to determine what features of the module
are available.