Class: Bio::Blast

Inherits:
Object show all
Defined in:
lib/bio/appl/blast.rb,
lib/bio/io/fastacmd.rb,
lib/bio/appl/blast/rexml.rb,
lib/bio/appl/blast/report.rb,
lib/bio/appl/bl2seq/report.rb,
lib/bio/appl/blast/format0.rb,
lib/bio/appl/blast/format8.rb,
lib/bio/appl/blast/wublast.rb,
lib/bio/appl/blast/rpsblast.rb,
lib/bio/appl/blast/xmlparser.rb

Overview

Description

The Bio::Blast class contains methods for running local or remote BLAST searches, as well as for parsing of the output of such BLASTs (i.e. the BLAST reports). For more information on similarity searches and the BLAST program, see www.ncbi.nlm.nih.gov/Education/BLASTinfo/similarity.html.

Usage

require 'bio'

# To run an actual BLAST analysis:
#   1. create a BLAST factory
remote_blast_factory = Bio::Blast.remote('blastp', 'SWISS',
                                         '-e 0.0001', 'genomenet')
#or:
local_blast_factory = Bio::Blast.local('blastn','/path/to/db')

#   2. run the actual BLAST by querying the factory
report = remote_blast_factory.query(sequence_text)

# Then, to parse the report, see Bio::Blast::Report

Available databases for Bio::Blast.remote

----------+-------+---------------------------------------------------
 program  | query | db (supported in GenomeNet)
----------+-------+---------------------------------------------------
 blastp   | AA    | nr-aa, genes, vgenes.pep, swissprot, swissprot-upd,
----------+-------+ pir, prf, pdbstr
 blastx   | NA    | 
----------+-------+---------------------------------------------------
 blastn   | NA    | nr-nt, genbank-nonst, gbnonst-upd, dbest, dbgss,
----------+-------+ htgs, dbsts, embl-nonst, embnonst-upd, epd,
 tblastn  | AA    | genes-nt, genome, vgenes.nuc
----------+-------+---------------------------------------------------

See also

  • Bio::Blast::Report

  • Bio::Blast::Report::Hit

  • Bio::Blast::Report::Hsp

References

Defined Under Namespace

Modules: Default, RPSBlast, WU Classes: Bl2seq, Fastacmd, Report

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program, db, opt = [], server = 'local') ⇒ Blast

Creates a Bio::Blast factory object.

To run any BLAST searches, a factory has to be created that describes a certain BLAST pipeline: the program to use, the database to search, any options and the server to use. E.g.

blast_factory = Bio::Blast.new('blastn','dbsts', '-e 0.0001 -r 4', 'genomenet')

Arguments:

  • program (required): ‘blastn’, ‘blastp’, ‘blastx’, ‘tblastn’ or ‘tblastx’

  • db (required): name of the (local or remote) database

  • options: blastall options \

(see www.genome.jp/dbget-bin/show_man?blast2)

  • server: server to use (e.g. ‘genomenet’; DEFAULT = ‘local’)

Returns

Bio::Blast factory object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/bio/appl/blast.rb', line 174

def initialize(program, db, opt = [], server = 'local')
  @program  = program
  @db       = db
  @server   = server

  @blastall = 'blastall'
  @matrix   = nil
  @filter   = nil

  @output   = ''
  @parser   = nil
  @format   = 0

  set_options(opt)
end

Instance Attribute Details

#blastallObject

Full path for blastall. (default: ‘blastall’).



137
138
139
# File 'lib/bio/appl/blast.rb', line 137

def blastall
  @blastall
end

#dbObject

Database name (-d option for blastall)



128
129
130
# File 'lib/bio/appl/blast.rb', line 128

def db
  @db
end

#filterObject

Filter option for blastall -F (T or F).



143
144
145
# File 'lib/bio/appl/blast.rb', line 143

def filter
  @filter
end

#formatObject (readonly)

Output report format for blastall -m

0, pairwise; 1; 2; 3; 4; 5; 6; 7, XML Blast outpu;, 8, tabular; 9, tabular with comment lines; 10, ASN text; 11, ASN binery [intege].



152
153
154
# File 'lib/bio/appl/blast.rb', line 152

def format
  @format
end

#matrixObject

Substitution matrix for blastall -M



140
141
142
# File 'lib/bio/appl/blast.rb', line 140

def matrix
  @matrix
end

#optionsObject

Options for blastall



131
132
133
# File 'lib/bio/appl/blast.rb', line 131

def options
  @options
end

#outputObject (readonly)

Returns a String containing blast execution output in as is the Bio::Blast#format.



146
147
148
# File 'lib/bio/appl/blast.rb', line 146

def output
  @output
end

#parser=(value) ⇒ Object (writeonly)

to change :xmlparser, :rexml, :tab



155
156
157
# File 'lib/bio/appl/blast.rb', line 155

def parser=(value)
  @parser = value
end

#programObject

Program name (-p option for blastall): blastp, blastn, blastx, tblastn or tblastx



125
126
127
# File 'lib/bio/appl/blast.rb', line 125

def program
  @program
end

#serverObject

Server to submit the BLASTs to



134
135
136
# File 'lib/bio/appl/blast.rb', line 134

def server
  @server
end

Class Method Details

.local(program, db, option = '') ⇒ Object

This is a shortcut for Bio::Blast.new:

Bio::Blast.local(program, database, options)

is equivalent to

Bio::Blast.new(program, database, options, 'local')

Arguments:

  • program (required): ‘blastn’, ‘blastp’, ‘blastx’, ‘tblastn’ or ‘tblastx’

  • db (required): name of the local database

  • options: blastall options \

(see www.genome.jp/dbget-bin/show_man?blast2)

Returns

Bio::Blast factory object



88
89
90
# File 'lib/bio/appl/blast.rb', line 88

def self.local(program, db, option = '')
  self.new(program, db, option, 'local')
end

.remote(program, db, option = '', server = 'genomenet') ⇒ Object

Bio::Blast.remote does exactly the same as Bio::Blast.new, but sets the remote server ‘genomenet’ as its default.


Arguments:

  • program (required): ‘blastn’, ‘blastp’, ‘blastx’, ‘tblastn’ or ‘tblastx’

  • db (required): name of the remote database

  • options: blastall options \

(see www.genome.jp/dbget-bin/show_man?blast2)

  • server: server to use (DEFAULT = ‘genomenet’)

Returns

Bio::Blast factory object



102
103
104
# File 'lib/bio/appl/blast.rb', line 102

def self.remote(program, db, option = '', server = 'genomenet')
  self.new(program, db, option, server)
end

.reports(input, parser = nil) ⇒ Object

the method Bio::Blast.report is moved from bio/appl/blast/report.rb. only for xml format



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/bio/appl/blast.rb', line 108

def self.reports(input, parser = nil)
  ary = []
  input.each("</BlastOutput>\n") do |xml|
    xml.sub!(/[^<]*(<?)/, '\1') # skip before <?xml> tag
    next if xml.empty?          # skip trailing no hits
    if block_given?
      yield Report.new(xml, parser)
    else
      ary << Report.new(xml, parser)
    end
  end
  return ary
end

Instance Method Details

#optionObject

Returns options of blastall



206
207
208
209
# File 'lib/bio/appl/blast.rb', line 206

def option
  # backward compatibility
  Bio::Command.make_command_line(@options)
end

#option=(str) ⇒ Object

Set options for blastall



212
213
214
215
# File 'lib/bio/appl/blast.rb', line 212

def option=(str)
  # backward compatibility
  @options = Shellwords.shellwords(str)
end

#query(query) ⇒ Object

This method submits a sequence to a BLAST factory, which performs the actual BLAST.

fasta_sequences = Bio::FlatFile.open(Bio::FastaFormat, 'my_sequences.fa')
report = blast_factory.query(fasta_sequences)

Arguments:

  • query (required): single- or multiple-FASTA formatted sequence(s)

Returns

a Bio::Blast::Report object



201
202
203
# File 'lib/bio/appl/blast.rb', line 201

def query(query)
  return self.send("exec_#{@server}", query.to_s)
end