Class: Bio::Meme::Mast

Inherits:
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, 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

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



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

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



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

def cmd
  @cmd
end

#optionsObject

A Hash of options for Mast



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

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)


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

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



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

def config(options)
  @options = DEFAULT_OPTIONS.merge(options)
  mfile, opts, flags = "", "", ""
  @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



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

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