class Bio::Meme::Mast

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 #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

Constants

DEFAULT_OPTIONS

Attributes

cmd[R]

The command line String to be executed

options[RW]

A Hash of options for Mast

Public Class Methods

new(mast_location, options = {}) click to toggle source

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

# 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

Public Instance Methods

check_options() click to toggle source

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

# 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) click to toggle source

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:

Returns

the command line string

# 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
run() click to toggle source

Run the mast program


Returns

Bio::Meme::Mast::Report object

# File lib/bio/appl/meme/mast.rb, line 148
def run
  check_options
  call_command(@cmd) {|io| @output = io.read }
  Report.new(@output)
end