class Bio::Alignment::FactoryTemplate::Simple

Template class for alignment application factory. The program acts: input: stdin or file, format = fasta format output: stdout (parser should be specified by DEFAULT_PARSER)

Attributes

command[R]

Last command-line string. Returns nil or an array of String. Note that filenames described in the command-line may already be removed because these files may be temporary files.

data_stdout[RW]

Last output to the stdout.

exit_status[R]

Last exit status

options[RW]

options

output[R]

Last raw result of the program. Return a string (or nil).

program[RW]

program name

report[R]

Last result object performed by the factory.

Public Class Methods

new(program = self.class::DEFAULT_PROGRAM, options = []) click to toggle source

Creates a new alignment factory

     # File lib/bio/alignment.rb
2215 def initialize(program = self.class::DEFAULT_PROGRAM, options = [])
2216   @program = program
2217   @options = options
2218   @command = nil
2219   @output = nil
2220   @report = nil
2221   @exit_status = nil
2222   @data_stdout = nil
2223 end

Public Instance Methods

query(seqs) click to toggle source

Executes the program. If seqs is not nil, perform alignment for seqs. If seqs is nil, simply executes the program.

Compatibility note: When seqs is nil, returns true if the program exits normally, and returns false if the program exits abnormally.

     # File lib/bio/alignment.rb
2265 def query(seqs)
2266   if seqs then
2267     query_alignment(seqs)
2268   else
2269     exec_local(@options)
2270     @exit_status.exitstatus == 0 ? true : false
2271   end
2272 end
query_align(seqs) click to toggle source

alias of query_alignment.

Compatibility Note: query_align will renamed to query_alignment.

     # File lib/bio/alignment.rb
2286 def query_align(seqs)
2287   #warn 'query_align is renamed to query_alignment.'
2288   query_alignment(seqs)
2289 end
query_alignment(seqs) click to toggle source

Performs alignment for seqs. seqs should be Bio::Alignment or Array of sequences or nil.

     # File lib/bio/alignment.rb
2276 def query_alignment(seqs)
2277   unless seqs.respond_to?(:output_fasta) then
2278     seqs = Bio::Alignment.new(seqs)
2279   end
2280   query_string(seqs.output_fasta(:width => 70))
2281 end
query_by_filename(filename_in) click to toggle source

Performs alignment of sequences in the file named fn.

     # File lib/bio/alignment.rb
2299 def query_by_filename(filename_in)
2300   _query_local(filename_in, @options)
2301   @report
2302 end
query_string(str) click to toggle source

Performs alignment for str. The str should be a string that can be recognized by the program.

     # File lib/bio/alignment.rb
2293 def query_string(str)
2294   _query_string(str, @options)
2295   @report
2296 end
reset() click to toggle source

Clear the internal data and status, except program and options.

     # File lib/bio/alignment.rb
2250 def reset
2251   @command = nil
2252   @output = nil
2253   @report = nil
2254   @exit_status = nil
2255   @data_stdout = nil
2256 end

Private Instance Methods

_generate_options(infile, outfile, options) click to toggle source

generates options specifying input/output filename. nil for filename means stdin or stdout. options must not contain specify filenames. returns an array of string.

     # File lib/bio/alignment.rb
2326 def _generate_options(infile, outfile, options)
2327   options +
2328     (infile ? _option_input_file(infile) : _option_input_stdin) +
2329     (outfile ? _option_output_file(outfile) : _option_output_stdout)
2330 end
_option_input_file(fn) click to toggle source

generates options specifying input filename. returns an array of string

     # File lib/bio/alignment.rb
2334 def _option_input_file(fn)
2335   [ fn ]
2336 end
_option_input_stdin() click to toggle source

generates options specifying that input is taken from stdin. returns an array of string

     # File lib/bio/alignment.rb
2346 def _option_input_stdin
2347   []
2348 end
_option_output_file(fn) click to toggle source

generates options specifying output filename. returns an array of string

     # File lib/bio/alignment.rb
2340 def _option_output_file(fn)
2341   raise 'can not specify output file: always stdout'
2342 end
_option_output_stdout() click to toggle source

generates options specifying output to stdout. returns an array of string

     # File lib/bio/alignment.rb
2352 def _option_output_stdout
2353   []
2354 end
_prepare_tempfile(str = nil) click to toggle source

prepare temporary file

     # File lib/bio/alignment.rb
2315 def _prepare_tempfile(str = nil)
2316   tf_in = Tempfile.open(str ? 'alignment_i' : 'alignment_o')
2317   tf_in.print str if str
2318   tf_in.close(false)
2319   tf_in
2320 end
exec_local(opt, data_stdin = nil) click to toggle source

Executes a program in the local machine.

     # File lib/bio/alignment.rb
2306 def exec_local(opt, data_stdin = nil)
2307   @exit_status = nil
2308   @command = [ @program, *opt ]
2309   #STDERR.print "DEBUG: ", @command.join(" "), "\n"
2310   @data_stdout = Bio::Command.query_command(@command, data_stdin)
2311   @exit_status = $?
2312 end