Class: Genomer::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/genomer/plugin.rb

Overview

Superclass for genomer plugins which us the genomer plugin. This class implements the common API which plugins should use to interact with the genomer system

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments, flags) ⇒ Plugin

Initialize plugin with passed command line parameters.

This create a plugin instance with the command line arguments and instance set as instance variables. These command line arguments are passed by the Genomer::Runtime.

Parameters:

  • arguments (Array)

    List of command arguments

  • settings (Hash)

    Command line flags as :flag => value



71
72
73
74
75
76
77
78
79
# File 'lib/genomer/plugin.rb', line 71

def initialize(arguments,flags)
  @arguments = arguments
  @flags     = flags

  assembly = Pathname.new('assembly')
  @sequence_file   = assembly + 'sequence.fna'
  @scaffold_file   = assembly + 'scaffold.yml'
  @annotation_file = assembly + 'annotations.gff'
end

Instance Attribute Details

#annotation_fileObject (readonly)

Returns the value of attribute annotation_file.



61
62
63
# File 'lib/genomer/plugin.rb', line 61

def annotation_file
  @annotation_file
end

#argumentsArray (readonly)

Returns List of command line arguments.

Returns:

  • (Array)

    List of command line arguments



54
55
56
# File 'lib/genomer/plugin.rb', line 54

def arguments
  @arguments
end

#flagsHash (readonly)

Returns Command line flags as where --flag=value is :flag => value.

Returns:

  • (Hash)

    Command line flags as where --flag=value is :flag => value



57
58
59
# File 'lib/genomer/plugin.rb', line 57

def flags
  @flags
end

#scaffold_fileObject (readonly)

Returns the value of attribute scaffold_file.



60
61
62
# File 'lib/genomer/plugin.rb', line 60

def scaffold_file
  @scaffold_file
end

#sequence_fileObject (readonly)

Returns the value of attribute sequence_file.



59
60
61
# File 'lib/genomer/plugin.rb', line 59

def sequence_file
  @sequence_file
end

Class Method Details

.[](plugin) ⇒ Class

Return the corresponding class for this plugin name.

This method calls Kernel#require for the requested plugin by searching the available plugins for genomer-plugin-NAME. Where name is the passed string. The class for this plugin is then returned.

Parameters:

  • name (String)

    The name of plugin without the 'genomer-plugin-' prefix.

Returns:

  • (Class)

    The class for this genomer plugin.



17
18
19
20
21
# File 'lib/genomer/plugin.rb', line 17

def self.[](plugin)
  name = fetch(plugin).name
  require name
  Kernel.const_get(to_class_name(name))
end

.fetch(name) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/genomer/plugin.rb', line 23

def self.fetch(name)
  plugin = plugins.detect{|i| i.name == "genomer-plugin-#{name}" }
  unless plugin 
    error =  "Unknown command or plugin '#{name}.'\n"
    error << "run `genomer help` for a list of available commands\n"
    raise Genomer::Error, error
  end
  plugin
end

Instance Method Details

#annotations(options = {}) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/genomer/plugin.rb', line 89

def annotations(options = {})
  attns = Scaffolder::AnnotationLocator.new(
    scaffold_file,sequence_file,annotation_file)

  attns = attns.sort_by{|attn| [attn.start,attn.end] }

  if value = options[:reset]
    start = value.to_s =~ /^[-+]?[0-9]+$/ ? value.to_i : 1

    genes = attns.select{|i| i.feature == 'gene'}
    genes.each_with_index do |annotation,count|
      annotation.id.replace sprintf("%06d",count + start)
    end
  end

  if prefix = options[:prefix]
    genes = attns.select{|i| i.feature == 'gene'}
    genes.each{|attn| attn.id.insert(0,prefix) }
  end

  attns
end

#runString

This method should be overriden to perform this plugin's operation.

The run method is called on the plugin by Genomer::Runtime. This should be overridden in subclasses to perform the intended function. If an error is encountered raise a Genomer::Error with a description. This will be caught and the error message printed to the standard out.

subsequently output to the command line

Returns:

  • (String)

    The string output of this plugin. This is



121
122
# File 'lib/genomer/plugin.rb', line 121

def run
end

#scaffoldArray

The genome scaffold constructed from the files in the "ROOT/assembly/" directory.

Returns:

  • (Array)

    An array of Scaffolder::Region instances



84
85
86
87
# File 'lib/genomer/plugin.rb', line 84

def scaffold
  YAML::ENGINE.yamler = 'syck' if defined?(YAML::ENGINE) and Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('2.0.0')
  Scaffolder.new(YAML.load(File.read(scaffold_file)),sequence_file)
end