Class: Genomer::Plugin
- Inherits:
-
Object
- Object
- Genomer::Plugin
- 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
-
#annotation_file ⇒ Object
readonly
Returns the value of attribute annotation_file.
-
#arguments ⇒ Array
readonly
List of command line arguments.
-
#flags ⇒ Hash
readonly
Command line flags as where --flag=value is :flag => value.
-
#scaffold_file ⇒ Object
readonly
Returns the value of attribute scaffold_file.
-
#sequence_file ⇒ Object
readonly
Returns the value of attribute sequence_file.
Class Method Summary collapse
-
.[](plugin) ⇒ Class
Return the corresponding class for this plugin name.
- .fetch(name) ⇒ Object
Instance Method Summary collapse
- #annotations(options = {}) ⇒ Object
-
#initialize(arguments, flags) ⇒ Plugin
constructor
Initialize plugin with passed command line parameters.
-
#run ⇒ String
This method should be overriden to perform this plugin's operation.
-
#scaffold ⇒ Array
The genome scaffold constructed from the files in the "ROOT/assembly/" directory.
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.
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_file ⇒ Object (readonly)
Returns the value of attribute annotation_file.
61 62 63 |
# File 'lib/genomer/plugin.rb', line 61 def annotation_file @annotation_file end |
#arguments ⇒ Array (readonly)
Returns List of command line arguments.
54 55 56 |
# File 'lib/genomer/plugin.rb', line 54 def arguments @arguments end |
#flags ⇒ Hash (readonly)
Returns 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_file ⇒ Object (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_file ⇒ Object (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.
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( = {}) attns = Scaffolder::AnnotationLocator.new( scaffold_file,sequence_file,annotation_file) attns = attns.sort_by{|attn| [attn.start,attn.end] } if value = [: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 = [:prefix] genes = attns.select{|i| i.feature == 'gene'} genes.each{|attn| attn.id.insert(0,prefix) } end attns end |
#run ⇒ String
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
121 122 |
# File 'lib/genomer/plugin.rb', line 121 def run end |
#scaffold ⇒ Array
The genome scaffold constructed from the files in the "ROOT/assembly/" directory.
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 |