Class: Bio::Meme::Mast

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/bio/appl/meme/mast.rb,
lib/bio/appl/meme/mast/report.rb

Overview

Description

Bio::Meme::Mast is a wrapper for searching a database using sequence motifs. The code will read options from a Hash and run the program. Parsing of the output is provided by Bio::Meme::Mast::Report. Before running, options and options must be set in the constructor or Mast.config(options = {})

Usage

mast = Mast.new('/path/to/mast')
or with options
mast = Mast.new('/path/to/mast', {:mfile => 'meme.out', :d => '/shared/db/nr'})

report = Mast::Report.new(mast.run)
report.each do |motif|
  puts motif.length
end

Defined Under Namespace

Classes: Report

Constant Summary collapse

DEFAULT_OPTIONS =
{
  # required
  :mfile => nil, 
  :d => nil,
  # optional 
  :stdin => nil, # may not work as expected
  :count => nil, 
  :alphabet => nil, 
  :stdout => true, 
  :text => false, 
  :sep => false, 
  :norc => false, 
  :dna => false, 
  :comp => false, 
  :rank => nil, 
  :smax => nil, 
  :ev => nil, 
  :mt => nil,
  :w => false, 
  :bfile => nil, 
  :seqp => false, 
  :mf => nil, 
  :df => nil, 
  :minseqs => nil, 
  :mev => nil, 
  :m => nil, 
  :diag => nil, 
  :best => false, 
  :remcorr => false, 
  :brief => false, 
  :b => false, 
  :nostatus => true, 
  :hit_list => true, 
}

Constants included from Command

Command::QUOTE_CHARS_WINDOWS, Command::UNESCAPABLE_CHARS, Command::UNSAFE_CHARS_UNIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Command

_call_command_popen_jruby19, _call_command_popen_ruby18, _call_command_popen_ruby19, call_command, call_command_fork, call_command_open3, call_command_popen, escape_shell, escape_shell_unix, escape_shell_windows, http_post, http_post_form, make_cgi_params, make_cgi_params_key_value, make_command_line, make_command_line_unix, make_command_line_windows, mktmpdir, new_http, new_https, post, post_form, query_command, query_command_fork, query_command_open3, query_command_popen, read_uri, remove_entry_secure, safe_command_line_array, start_http, start_http_uri

Constructor Details

#initialize(mast_location, options = {}) ⇒ Mast

Create a mast instance

m = Mast.new('/usr/local/bin/mast')

Arguments:

  • (required) mast_location: String

Raises

ArgumentError if mast program is not found

Returns

a Bio::Meme::Mast object



97
98
99
100
101
102
103
# File 'lib/bio/appl/meme/mast.rb', line 97

def initialize(mast_location, options = {})
  unless File.exist?(mast_location)
    raise ArgumentError.new("mast: command not found : #{mast_location}")
  end
  @binary = mast_location
  options.empty? ? config(DEFAULT_OPTIONS) : config(options)
end

Instance Attribute Details

#cmdObject (readonly)

The command line String to be executed



86
87
88
# File 'lib/bio/appl/meme/mast.rb', line 86

def cmd
  @cmd
end

#optionsObject

A Hash of options for Mast



48
49
50
# File 'lib/bio/appl/meme/mast.rb', line 48

def options
  @options
end

Instance Method Details

#check_optionsObject

Checks if input/database files exist and options are valid

Raises

ArgumentError if the motifs file does not exist

Raises

ArgumentError if the database file does not exist

Raises

ArgumentError if there is an invalid option

Raises:

  • (ArgumentError)


137
138
139
140
141
142
143
# File 'lib/bio/appl/meme/mast.rb', line 137

def check_options
  @options.each_key do |k|
    raise ArgumentError.new("Invalid option: #{k}") unless DEFAULT_OPTIONS.has_key?(k)
  end
  raise ArgumentError.new("Motif file not found: #{@options[:mfile]}") if @options[:mfile].nil? or !File.exist?(@options[:mfile])
  raise ArgumentError.new("Database not found: #{@options[:d]}") if @options[:d].nil? or !File.exist?(@options[:d])
end

#config(options) ⇒ Object

Builds the command line string any options passed in will be merged with DEFAULT_OPTIONS Mast usage: mast <mfile> <opts> <flags>

mast.config({:mfile => "meme.out", :d => "/path/to/fasta/db"})

Arguments:

  • (required) options: Hash (see DEFAULT_OPTIONS)

Returns

the command line string



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/bio/appl/meme/mast.rb', line 115

def config(options)
  @options = DEFAULT_OPTIONS.merge(options)
  mfile, opts, flags = String.new, String.new, String.new
  @options.each_pair do |opt, val|
    if val.nil? or val == false
      next
    elsif opt == :mfile
      mfile = val
    elsif val == true
      flags << " -#{opt}"
    else
      opts << " -#{opt} #{val}"
    end
  end
  @cmd = "#{@binary} #{mfile + opts + flags}"
end

#runObject

Run the mast program


Returns

Bio::Meme::Mast::Report object



149
150
151
152
153
# File 'lib/bio/appl/meme/mast.rb', line 149

def run
  check_options
  call_command(@cmd) {|io| @output = io.read }
  Report.new(@output)
end