class Genomer::Runtime

Constants

MESSAGES

Attributes

arguments[R]
command[R]
flags[R]

Public Class Methods

new(settings) click to toggle source
# File lib/genomer/runtime.rb, line 36
def initialize(settings)
  @command   = settings.rest.shift
  @arguments = settings.rest
  @flags     = settings
end

Public Instance Methods

execute!() click to toggle source
# File lib/genomer/runtime.rb, line 42
def execute!
  return message :output, :version if flags[:version]

  if genomer_project?
    case command
    when nil    then message :output, :simple_help
    when "help" then help
    when "init" then message :error, :init_again
    when "man"  then man
    else             run_plugin
    end
  else
    case command
    when "init" then init
    else             message :output, :not_project
    end
  end
end
genomer_project?() click to toggle source
# File lib/genomer/runtime.rb, line 146
def genomer_project?
  File.exists?('Gemfile')
end
groffed_man_file(original_man_file) click to toggle source
# File lib/genomer/runtime.rb, line 110
def groffed_man_file(original_man_file)
  converted_man = Tempfile.new("genome-manpage-")
  File.open(converted_man.path,'w') do |out|
    out.puts render_man(File.read(original_man_file))
  end
  converted_man
end
help() click to toggle source
# File lib/genomer/runtime.rb, line 61
  def help
    msg =<<-EOF
      genomer COMMAND [options]

      Available commands:
        init        Create a new genomer project
        man         View man page for the specified plugin
    EOF
    msg.unindent!

    if File.exists?('Gemfile')
      msg << Genomer::Plugin.plugins.inject(String.new) do |str,p|
        str << '  '
        str << p.name.gsub("genomer-plugin-","").ljust(12)
        str << p.summary
        str << "\n"
      end
    end
    msg.strip
  end
init() click to toggle source
# File lib/genomer/runtime.rb, line 118
def init
  project_name = arguments.first
  if File.exists?(project_name)
    raise Genomer::Error, "Directory '#{project_name}' already exists."
  end

  require 'genomer/files'

  Dir.mkdir project_name
  Dir.mkdir File.join(project_name,'assembly')

  File.open(File.join(project_name,'Gemfile'),'w') do |file|
    file.print Genomer::Files.gemfile
  end

  ['scaffold.yml','sequence.fna','annotations.gff'].each do |name|
    File.open(File.join(project_name,'assembly',name),'w') do |file|
      file.print Genomer::Files.send(name.gsub('.','_').to_sym)
    end
  end

  "Genomer project '#{project_name}' created.\n"
end
man() click to toggle source
# File lib/genomer/runtime.rb, line 82
def man
  if not arguments.empty?
    location = if arguments.first == 'init'
                 File.expand_path File.dirname(__FILE__) + '/../../man/genomer-init.1.ronn'
               else
                 man_file(arguments.clone)
               end

    unless File.exists?(location)
      raise Genomer::Error, "No manual entry for command '#{arguments.join(' ')}'"
    end

    Kernel.exec "man #{groffed_man_file(location).path}"
  else
    message :output, :man
  end
end
man_file(arguments) click to toggle source
# File lib/genomer/runtime.rb, line 100
def man_file(arguments)
  plugin = arguments.first
  page = arguments.unshift("genomer").join('-') << ".ronn"
  File.join(Genomer::Plugin.fetch(plugin).full_gem_path, 'man', page)
end
message(type,msg) click to toggle source
# File lib/genomer/runtime.rb, line 30
def message(type,msg)
  content = MESSAGES[type][msg]
  type == :error ? raise(Genomer::Error, content) : content
end
render_man(input) click to toggle source
# File lib/genomer/runtime.rb, line 106
def render_man(input)
  Md2Man::ENGINE.render input
end
run_plugin() click to toggle source
# File lib/genomer/runtime.rb, line 142
def run_plugin
  Genomer::Plugin[command].new(arguments,flags).run
end