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
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.
Last output to the stdout.
Last exit status
options
Last raw result of the program. Return a string (or nil).
program name
Last result object performed by the factory.
Public Class Methods
Creates a new alignment factory
# File lib/bio/alignment.rb, line 2221 def initialize(program = self.class::DEFAULT_PROGRAM, options = []) @program = program @options = options @command = nil @output = nil @report = nil @exit_status = nil @data_stdout = nil end
Public Instance Methods
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, line 2271 def query(seqs) if seqs then query_alignment(seqs) else exec_local(@options) @exit_status.exitstatus == 0 ? true : false end end
alias of query_alignment.
Compatibility Note: #query_align will renamed to query_alignment.
# File lib/bio/alignment.rb, line 2292 def query_align(seqs) #warn 'query_align is renamed to query_alignment.' query_alignment(seqs) end
Performs alignment for seqs. seqs
should be Bio::Alignment or Array of sequences or
nil.
# File lib/bio/alignment.rb, line 2282 def query_alignment(seqs) unless seqs.respond_to?(:output_fasta) then seqs = Bio::Alignment.new(seqs) end query_string(seqs.output_fasta(:width => 70)) end
Performs alignment of sequences in the file named fn
.
# File lib/bio/alignment.rb, line 2305 def query_by_filename(filename_in) _query_local(filename_in, @options) @report end
Performs alignment for str
. The str
should be a
string that can be recognized by the program.
# File lib/bio/alignment.rb, line 2299 def query_string(str) _query_string(str, @options) @report end
Clear the internal data and status, except program and options.
# File lib/bio/alignment.rb, line 2256 def reset @command = nil @output = nil @report = nil @exit_status = nil @data_stdout = nil end
Private Instance Methods
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, line 2332 def _generate_options(infile, outfile, options) options + (infile ? _option_input_file(infile) : _option_input_stdin) + (outfile ? _option_output_file(outfile) : _option_output_stdout) end
generates options specifying input filename. returns an array of string
# File lib/bio/alignment.rb, line 2340 def _option_input_file(fn) [ fn ] end
generates options specifying that input is taken from stdin. returns an array of string
# File lib/bio/alignment.rb, line 2352 def _option_input_stdin [] end
generates options specifying output filename. returns an array of string
# File lib/bio/alignment.rb, line 2346 def _option_output_file(fn) raise 'can not specify output file: always stdout' end
generates options specifying output to stdout. returns an array of string
# File lib/bio/alignment.rb, line 2358 def _option_output_stdout [] end
prepare temporary file
# File lib/bio/alignment.rb, line 2321 def _prepare_tempfile(str = nil) tf_in = Tempfile.open(str ? 'alignment_i' : 'alignment_o') tf_in.print str if str tf_in.close(false) tf_in end
Executes a program in the local machine.
# File lib/bio/alignment.rb, line 2312 def exec_local(opt, data_stdin = nil) @exit_status = nil @command = [ @program, *opt ] #STDERR.print "DEBUG: ", @command.join(" "), "\n" @data_stdout = Bio::Command.query_command(@command, data_stdin) @exit_status = $? end