scaffolder-tools 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +23 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +38 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/bin/scaffolder +14 -0
- data/features/help.feature +79 -0
- data/features/sequence.feature +157 -0
- data/features/step_definitions/scaffolder-tools.rb +4 -0
- data/features/support/env.rb +15 -0
- data/features/validate.feature +245 -0
- data/lib/scaffolder/binary_helper.rb +30 -0
- data/lib/scaffolder/tool/help.rb +57 -0
- data/lib/scaffolder/tool/sequence.rb +34 -0
- data/lib/scaffolder/tool/validate.rb +51 -0
- data/lib/scaffolder/tool.rb +44 -0
- data/lib/scaffolder/tool_index.rb +50 -0
- data/man/scaffolder-help.1.ronn +23 -0
- data/man/scaffolder-sequence.1.ronn +48 -0
- data/man/scaffolder-validate.1.ronn +28 -0
- data/scaffolder-tools.gemspec +125 -0
- data/spec/scaffolder/binary_helper_spec.rb +71 -0
- data/spec/scaffolder/tool/help_spec.rb +127 -0
- data/spec/scaffolder/tool/sequence_spec.rb +41 -0
- data/spec/scaffolder/tool/validate_spec.rb +167 -0
- data/spec/scaffolder/tool_index_spec.rb +49 -0
- data/spec/scaffolder/tool_spec.rb +147 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/exit_code_matcher.rb +26 -0
- metadata +330 -0
| @@ -0,0 +1,57 @@ | |
| 1 | 
            +
            require 'scaffolder/tool'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Scaffolder::Tool::Help < Scaffolder::Tool
         | 
| 4 | 
            +
              include Scaffolder::ToolIndex
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def self.description
         | 
| 7 | 
            +
                "Help information for scaffolder commands"
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def execute
         | 
| 11 | 
            +
                raise_for_unknown(@settings[:unknown_tool]) if @settings[:unknown_tool]
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                tool = settings.rest.first
         | 
| 14 | 
            +
                if tool
         | 
| 15 | 
            +
                  raise_for_unknown(tool) unless tool_exists?(tool)
         | 
| 16 | 
            +
                  man settings.rest.first
         | 
| 17 | 
            +
                elsif @settings[:version]
         | 
| 18 | 
            +
                  return version
         | 
| 19 | 
            +
                else
         | 
| 20 | 
            +
                  return help
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              private
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              def raise_for_unknown(command)
         | 
| 27 | 
            +
                msg = "Unknown command '#{command}'.\nSee 'scaffolder help'."
         | 
| 28 | 
            +
                raise ArgumentError.new(msg)
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              def version
         | 
| 32 | 
            +
                ver = File.read(File.join(%W|#{File.dirname(__FILE__)} .. .. .. VERSION|)).strip
         | 
| 33 | 
            +
                "scaffolder tool version #{ver}"
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def help
         | 
| 37 | 
            +
                string = <<-MSG.gsub(/^ {6}/, '')
         | 
| 38 | 
            +
                  usage: scaffolder [--version] COMMAND scaffold-file sequence-file
         | 
| 39 | 
            +
                  [options]
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  Commands:
         | 
| 42 | 
            +
                MSG
         | 
| 43 | 
            +
                [:help,:sequence,:validate].each do |name|
         | 
| 44 | 
            +
                  string << "  "
         | 
| 45 | 
            +
                  string << name.to_s.ljust(12)
         | 
| 46 | 
            +
                  string << tools[name].description + "\n"
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
                string
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              def man(tool)
         | 
| 52 | 
            +
                man_page = File.join(
         | 
| 53 | 
            +
                  %W|#{File.dirname(__FILE__)} .. .. .. man scaffolder-#{tool}.1.ronn|)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                Kernel.system("ronn -m #{File.expand_path(man_page)}")
         | 
| 56 | 
            +
              end
         | 
| 57 | 
            +
            end
         | 
| @@ -0,0 +1,34 @@ | |
| 1 | 
            +
            require 'yaml'
         | 
| 2 | 
            +
            require 'digest/sha1'
         | 
| 3 | 
            +
            require 'scaffolder'
         | 
| 4 | 
            +
            require 'scaffolder/tool'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class Scaffolder::Tool::Sequence < Scaffolder::Tool
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def self.description
         | 
| 9 | 
            +
                "Generate the fasta output for the scaffold"
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              def execute
         | 
| 13 | 
            +
                s = sequence(scaffold)
         | 
| 14 | 
            +
                Bio::Sequence.new(s).output(:fasta,:header => header(s,@settings))
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def sequence(scaffold)
         | 
| 20 | 
            +
                sequence = scaffold.inject(String.new) do |string,entry|
         | 
| 21 | 
            +
                  string << entry.sequence
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              def header(sequence,opts={})
         | 
| 26 | 
            +
                header = String.new
         | 
| 27 | 
            +
                header << opts[:definition] + " " if opts[:definition]
         | 
| 28 | 
            +
                unless opts[:no] && opts[:no][:sequence] && opts[:no][:sequence][:hash]
         | 
| 29 | 
            +
                  header << Digest::SHA1.hexdigest(sequence)
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
                header
         | 
| 32 | 
            +
              end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            end
         | 
| @@ -0,0 +1,51 @@ | |
| 1 | 
            +
            require 'yaml'
         | 
| 2 | 
            +
            require 'scaffolder'
         | 
| 3 | 
            +
            require 'scaffolder/tool'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            class Scaffolder::Tool::Validate < Scaffolder::Tool
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              def self.description
         | 
| 8 | 
            +
                "Validate scaffold for overlapping inserts"
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              def execute
         | 
| 12 | 
            +
                bad_sequences = errors
         | 
| 13 | 
            +
                return if bad_sequences.empty?
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                output = bad_sequences.inject(Array.new) do |array, sequence|
         | 
| 16 | 
            +
                  self.class.sequence_errors(sequence).each do |overlaps|
         | 
| 17 | 
            +
                    array << {'sequence-insert-overlap' => {
         | 
| 18 | 
            +
                      'source' => sequence.source,
         | 
| 19 | 
            +
                      'inserts' => overlaps.map do |overlap|
         | 
| 20 | 
            +
                        {'open'  => overlap.open,
         | 
| 21 | 
            +
                        'close'  => overlap.close,
         | 
| 22 | 
            +
                        'source' => overlap.source}
         | 
| 23 | 
            +
                      end
         | 
| 24 | 
            +
                    }}
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                  array
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                YAML.dump(output)
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def errors
         | 
| 33 | 
            +
                sequences = scaffold.select{|i| i.entry_type == :sequence}
         | 
| 34 | 
            +
                sequences.reject{|i| self.class.sequence_errors(i).empty? }
         | 
| 35 | 
            +
              end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
              def self.inserts_overlap?(a,b)
         | 
| 38 | 
            +
                ! (a.position.to_a & b.position.to_a).empty?
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              def self.sequence_errors(sequence)
         | 
| 42 | 
            +
                sequence.inserts.inject(Array.new) do |errors,a|
         | 
| 43 | 
            +
                  sequence.inserts.each do |b|
         | 
| 44 | 
            +
                    next if a.equal?(b)
         | 
| 45 | 
            +
                    errors << [a,b].sort if inserts_overlap?(a,b)
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
                  errors
         | 
| 48 | 
            +
                end.uniq
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            require 'scaffolder'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class Scaffolder::Tool
         | 
| 4 | 
            +
              require 'scaffolder/tool_index'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              attr :scaffold_file
         | 
| 7 | 
            +
              attr :sequence_file
         | 
| 8 | 
            +
              attr :settings
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def initialize(settings)
         | 
| 11 | 
            +
                @scaffold_file = settings.rest.first
         | 
| 12 | 
            +
                @sequence_file = settings.rest.last
         | 
| 13 | 
            +
                @settings = settings
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              def run(out=STDOUT,err=STDERR)
         | 
| 17 | 
            +
                begin
         | 
| 18 | 
            +
                  message = execute
         | 
| 19 | 
            +
                rescue Exception => e
         | 
| 20 | 
            +
                  err.puts("Error. #{e.message}")
         | 
| 21 | 
            +
                  exit(1)
         | 
| 22 | 
            +
                else
         | 
| 23 | 
            +
                  out.puts(message) if message
         | 
| 24 | 
            +
                  exit(0)
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
              def scaffold
         | 
| 29 | 
            +
                {:Scaffold => @scaffold_file, :Sequence => @sequence_file}.each do |name,file|
         | 
| 30 | 
            +
                  unless File.exists?(file)
         | 
| 31 | 
            +
                    raise ArgumentError.new("#{name} file not found: #{file}")
         | 
| 32 | 
            +
                  end
         | 
| 33 | 
            +
                  if File.size(file) == 0
         | 
| 34 | 
            +
                    raise ArgumentError.new("#{name} file is empty: #{file}")
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                Scaffolder.new(YAML.load(File.read(@scaffold_file)),@sequence_file)
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              Dir["#{File.dirname(__FILE__)}/tool/*.rb"].each do |f|
         | 
| 42 | 
            +
                require File.expand_path(f)
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            require 'scaffolder'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module Scaffolder::ToolIndex
         | 
| 4 | 
            +
              require 'scaffolder/tool'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def get_tool(name)
         | 
| 7 | 
            +
                tools[normalise(name)]
         | 
| 8 | 
            +
              end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              def tool_exists?(name)
         | 
| 11 | 
            +
                ! get_tool(name).nil?
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              def [](type)
         | 
| 15 | 
            +
                if tool_exists?(type)
         | 
| 16 | 
            +
                  get_tool(type)
         | 
| 17 | 
            +
                else
         | 
| 18 | 
            +
                  Scaffolder::Tool::Help
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              def determine_tool(settings)
         | 
| 23 | 
            +
                type = settings.rest.shift
         | 
| 24 | 
            +
                tool_class = self[type]
         | 
| 25 | 
            +
                settings[:unknown_tool] = type unless (tool_exists?(type) or type.nil?)
         | 
| 26 | 
            +
                [tool_class,settings]
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              private
         | 
| 30 | 
            +
             | 
| 31 | 
            +
              def tool_classes
         | 
| 32 | 
            +
                Scaffolder::Tool.constants.inject(Array.new) do |array,constant|
         | 
| 33 | 
            +
                  clss = Scaffolder::Tool.const_get(constant)
         | 
| 34 | 
            +
                  array << clss if clss.superclass == Scaffolder::Tool
         | 
| 35 | 
            +
                  array
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              def tools
         | 
| 40 | 
            +
                tool_classes.inject(Hash.new) do |hash,clss|
         | 
| 41 | 
            +
                  hash[clss.to_s.split('::').last.downcase.to_sym] = clss
         | 
| 42 | 
            +
                  hash
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
              def normalise(name)
         | 
| 47 | 
            +
                name.to_s.downcase.to_sym if name
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            scaffolder-help(1) -- display help information about scaffolder commands
         | 
| 2 | 
            +
            ========================================================================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## SYNOPSIS
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            `scaffolder help` [COMMAND]
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## DESCRIPTION
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            When run with no options **scaffolder-help** returns a list of available
         | 
| 11 | 
            +
            commands. When run with a scaffolder command name the corresponding man page is
         | 
| 12 | 
            +
            shown.
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            ## BUGS
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            **Scaffolder-help** is written in Ruby and depends on the scaffolder, BioRuby,
         | 
| 17 | 
            +
            configliere and ronn gems. See the Gemfile in the scaffolder-tools gem install
         | 
| 18 | 
            +
            directory for version details.
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ## COPYRIGHT
         | 
| 21 | 
            +
             | 
| 22 | 
            +
            **Scaffolder** is Copyright (C) 2010 Michael Barton
         | 
| 23 | 
            +
            <http://michaelbarton.me.uk>
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            scaffolder-sequence(1) -- assemble yaml scaffold file into fasta sequence
         | 
| 2 | 
            +
            =========================================================================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## SYNOPSIS
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            `scaffolder sequence` [<options>...] <scaffold-file> <sequence-file>
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## DESCRIPTION
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            **Scaffolder-sequence** assembles a single fasta nucleotide sequence from the
         | 
| 11 | 
            +
            sequences and coordinates specified in the **scaffold-file**.
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            ## FILES
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            **Scaffolder-sequence** requires two files to create a fasta assembly. The
         | 
| 16 | 
            +
            **scaffold-file** specifies the positions of individual contigs in the scaffold
         | 
| 17 | 
            +
            assembly. The **sequence-file** contains the corresponding fasta sequences of
         | 
| 18 | 
            +
            each contig specified in the scaffold file.
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            ## OPTIONS
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              * `--definition`=[<definition>]:
         | 
| 23 | 
            +
                Fasta definition line added at the top of the assembled sequence. The
         | 
| 24 | 
            +
                default is to use the SHA1 hash of the sequence as the definition.
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              * `--no-sequence-hash`:
         | 
| 27 | 
            +
                Do not append the SHA1 hash of the assembled sequence to the definition
         | 
| 28 | 
            +
                line.
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            ## EXAMPLES
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            Assemble sequence using a scaffold file and fasta formatted set of contigs.
         | 
| 33 | 
            +
            Pipe the assembly into another file.
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                $ scaffolder-sequence scaffold.yml contigs.fna > assembly.fna
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## BUGS
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            ## BUGS
         | 
| 40 | 
            +
             | 
| 41 | 
            +
            **Scaffolder-sequence** is written in Ruby and depends on the scaffolder,
         | 
| 42 | 
            +
            BioRuby, configliere and ronn gems. See the Gemfile in the scaffolder-tools gem
         | 
| 43 | 
            +
            install directory for version details.
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            ## COPYRIGHT
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            **Scaffolder** is Copyright (C) 2010 Michael Barton
         | 
| 48 | 
            +
            <http://michaelbarton.me.uk>
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            scaffolder-validate(1) -- Test scaffold for overlapping inserts
         | 
| 2 | 
            +
            ===============================================================
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## SYNOPSIS
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            `scaffolder validate` <scaffolder-file> <sequence-file>
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## DESCRIPTION
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            **Scaffolder-validate** examines the **scaffolder-file** to detect overlapping
         | 
| 11 | 
            +
            sequence inserts. Overlapping sequence inserts may lead to unexpected sequence
         | 
| 12 | 
            +
            output in generated scaffold sequence and should be avoided.  A list of any
         | 
| 13 | 
            +
            overlapping inserts is returned in a yaml format.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            ## EXAMPLES
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ scaffolder-validate scaffold.yml sequences.fna > overlapping_inserts.yml
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            ## BUGS
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            **Scaffolder-validate** is written in Ruby and depends on the scaffolder,
         | 
| 22 | 
            +
            BioRuby, configliere and ronn gems. See the Gemfile in the scaffolder-tools gem
         | 
| 23 | 
            +
            install directory for version details.
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## COPYRIGHT
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            **Scaffolder** is Copyright (C) 2010 Michael Barton
         | 
| 28 | 
            +
            <http://michaelbarton.me.uk>
         | 
| @@ -0,0 +1,125 @@ | |
| 1 | 
            +
            # Generated by jeweler
         | 
| 2 | 
            +
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 | 
            +
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |s|
         | 
| 7 | 
            +
              s.name = %q{scaffolder-tools}
         | 
| 8 | 
            +
              s.version = "0.1.0"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 | 
            +
              s.authors = ["Michael Barton"]
         | 
| 12 | 
            +
              s.date = %q{2011-01-04}
         | 
| 13 | 
            +
              s.default_executable = %q{scaffolder}
         | 
| 14 | 
            +
              s.description = %q{Binary to use with scaffolder genome scaffolds}
         | 
| 15 | 
            +
              s.email = %q{mail@michaelbarton.me.uk}
         | 
| 16 | 
            +
              s.executables = ["scaffolder"]
         | 
| 17 | 
            +
              s.extra_rdoc_files = [
         | 
| 18 | 
            +
                "LICENSE.txt",
         | 
| 19 | 
            +
                "README.rdoc"
         | 
| 20 | 
            +
              ]
         | 
| 21 | 
            +
              s.files = [
         | 
| 22 | 
            +
                ".document",
         | 
| 23 | 
            +
                ".rspec",
         | 
| 24 | 
            +
                "Gemfile",
         | 
| 25 | 
            +
                "LICENSE.txt",
         | 
| 26 | 
            +
                "README.rdoc",
         | 
| 27 | 
            +
                "Rakefile",
         | 
| 28 | 
            +
                "VERSION",
         | 
| 29 | 
            +
                "bin/scaffolder",
         | 
| 30 | 
            +
                "features/help.feature",
         | 
| 31 | 
            +
                "features/sequence.feature",
         | 
| 32 | 
            +
                "features/step_definitions/scaffolder-tools.rb",
         | 
| 33 | 
            +
                "features/support/env.rb",
         | 
| 34 | 
            +
                "features/validate.feature",
         | 
| 35 | 
            +
                "lib/scaffolder/binary_helper.rb",
         | 
| 36 | 
            +
                "lib/scaffolder/tool.rb",
         | 
| 37 | 
            +
                "lib/scaffolder/tool/help.rb",
         | 
| 38 | 
            +
                "lib/scaffolder/tool/sequence.rb",
         | 
| 39 | 
            +
                "lib/scaffolder/tool/validate.rb",
         | 
| 40 | 
            +
                "lib/scaffolder/tool_index.rb",
         | 
| 41 | 
            +
                "man/scaffolder-help.1.ronn",
         | 
| 42 | 
            +
                "man/scaffolder-sequence.1.ronn",
         | 
| 43 | 
            +
                "man/scaffolder-validate.1.ronn",
         | 
| 44 | 
            +
                "scaffolder-tools.gemspec",
         | 
| 45 | 
            +
                "spec/scaffolder/binary_helper_spec.rb",
         | 
| 46 | 
            +
                "spec/scaffolder/tool/help_spec.rb",
         | 
| 47 | 
            +
                "spec/scaffolder/tool/sequence_spec.rb",
         | 
| 48 | 
            +
                "spec/scaffolder/tool/validate_spec.rb",
         | 
| 49 | 
            +
                "spec/scaffolder/tool_index_spec.rb",
         | 
| 50 | 
            +
                "spec/scaffolder/tool_spec.rb",
         | 
| 51 | 
            +
                "spec/spec_helper.rb",
         | 
| 52 | 
            +
                "spec/support/exit_code_matcher.rb"
         | 
| 53 | 
            +
              ]
         | 
| 54 | 
            +
              s.homepage = %q{http://github.com/michaelbarton/scaffolder-tools}
         | 
| 55 | 
            +
              s.licenses = ["MIT"]
         | 
| 56 | 
            +
              s.require_paths = ["lib"]
         | 
| 57 | 
            +
              s.rubygems_version = %q{1.3.7}
         | 
| 58 | 
            +
              s.summary = %q{Tools for manipulating genome scaffolds}
         | 
| 59 | 
            +
              s.test_files = [
         | 
| 60 | 
            +
                "spec/scaffolder/binary_helper_spec.rb",
         | 
| 61 | 
            +
                "spec/scaffolder/tool/help_spec.rb",
         | 
| 62 | 
            +
                "spec/scaffolder/tool/sequence_spec.rb",
         | 
| 63 | 
            +
                "spec/scaffolder/tool/validate_spec.rb",
         | 
| 64 | 
            +
                "spec/scaffolder/tool_index_spec.rb",
         | 
| 65 | 
            +
                "spec/scaffolder/tool_spec.rb",
         | 
| 66 | 
            +
                "spec/spec_helper.rb",
         | 
| 67 | 
            +
                "spec/support/exit_code_matcher.rb"
         | 
| 68 | 
            +
              ]
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              if s.respond_to? :specification_version then
         | 
| 71 | 
            +
                current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
         | 
| 72 | 
            +
                s.specification_version = 3
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
         | 
| 75 | 
            +
                  s.add_runtime_dependency(%q<configliere>, ["~> 0.1"])
         | 
| 76 | 
            +
                  s.add_runtime_dependency(%q<bio>, ["~> 1.4"])
         | 
| 77 | 
            +
                  s.add_runtime_dependency(%q<scaffolder>, ["~> 0.4"])
         | 
| 78 | 
            +
                  s.add_runtime_dependency(%q<ronn>, ["~> 0.7"])
         | 
| 79 | 
            +
                  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 80 | 
            +
                  s.add_development_dependency(%q<jeweler>, ["~> 1.5"])
         | 
| 81 | 
            +
                  s.add_development_dependency(%q<gherkin>, ["~> 2.3.3"])
         | 
| 82 | 
            +
                  s.add_development_dependency(%q<rspec>, ["~> 2.4"])
         | 
| 83 | 
            +
                  s.add_development_dependency(%q<cucumber>, ["~> 0.10"])
         | 
| 84 | 
            +
                  s.add_development_dependency(%q<fakefs>, ["~> 0.2"])
         | 
| 85 | 
            +
                  s.add_development_dependency(%q<aruba>, ["~> 0.2"])
         | 
| 86 | 
            +
                  s.add_development_dependency(%q<mocha>, ["~> 0.9"])
         | 
| 87 | 
            +
                  s.add_development_dependency(%q<hashie>, ["~> 0.4"])
         | 
| 88 | 
            +
                  s.add_development_dependency(%q<yard>, ["~> 0.6"])
         | 
| 89 | 
            +
                  s.add_development_dependency(%q<scaffolder-test-helpers>, ["~> 0.1"])
         | 
| 90 | 
            +
                else
         | 
| 91 | 
            +
                  s.add_dependency(%q<configliere>, ["~> 0.1"])
         | 
| 92 | 
            +
                  s.add_dependency(%q<bio>, ["~> 1.4"])
         | 
| 93 | 
            +
                  s.add_dependency(%q<scaffolder>, ["~> 0.4"])
         | 
| 94 | 
            +
                  s.add_dependency(%q<ronn>, ["~> 0.7"])
         | 
| 95 | 
            +
                  s.add_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 96 | 
            +
                  s.add_dependency(%q<jeweler>, ["~> 1.5"])
         | 
| 97 | 
            +
                  s.add_dependency(%q<gherkin>, ["~> 2.3.3"])
         | 
| 98 | 
            +
                  s.add_dependency(%q<rspec>, ["~> 2.4"])
         | 
| 99 | 
            +
                  s.add_dependency(%q<cucumber>, ["~> 0.10"])
         | 
| 100 | 
            +
                  s.add_dependency(%q<fakefs>, ["~> 0.2"])
         | 
| 101 | 
            +
                  s.add_dependency(%q<aruba>, ["~> 0.2"])
         | 
| 102 | 
            +
                  s.add_dependency(%q<mocha>, ["~> 0.9"])
         | 
| 103 | 
            +
                  s.add_dependency(%q<hashie>, ["~> 0.4"])
         | 
| 104 | 
            +
                  s.add_dependency(%q<yard>, ["~> 0.6"])
         | 
| 105 | 
            +
                  s.add_dependency(%q<scaffolder-test-helpers>, ["~> 0.1"])
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
              else
         | 
| 108 | 
            +
                s.add_dependency(%q<configliere>, ["~> 0.1"])
         | 
| 109 | 
            +
                s.add_dependency(%q<bio>, ["~> 1.4"])
         | 
| 110 | 
            +
                s.add_dependency(%q<scaffolder>, ["~> 0.4"])
         | 
| 111 | 
            +
                s.add_dependency(%q<ronn>, ["~> 0.7"])
         | 
| 112 | 
            +
                s.add_dependency(%q<bundler>, ["~> 1.0"])
         | 
| 113 | 
            +
                s.add_dependency(%q<jeweler>, ["~> 1.5"])
         | 
| 114 | 
            +
                s.add_dependency(%q<gherkin>, ["~> 2.3.3"])
         | 
| 115 | 
            +
                s.add_dependency(%q<rspec>, ["~> 2.4"])
         | 
| 116 | 
            +
                s.add_dependency(%q<cucumber>, ["~> 0.10"])
         | 
| 117 | 
            +
                s.add_dependency(%q<fakefs>, ["~> 0.2"])
         | 
| 118 | 
            +
                s.add_dependency(%q<aruba>, ["~> 0.2"])
         | 
| 119 | 
            +
                s.add_dependency(%q<mocha>, ["~> 0.9"])
         | 
| 120 | 
            +
                s.add_dependency(%q<hashie>, ["~> 0.4"])
         | 
| 121 | 
            +
                s.add_dependency(%q<yard>, ["~> 0.6"])
         | 
| 122 | 
            +
                s.add_dependency(%q<scaffolder-test-helpers>, ["~> 0.1"])
         | 
| 123 | 
            +
              end
         | 
| 124 | 
            +
            end
         | 
| 125 | 
            +
             | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            require File.join(File.dirname(__FILE__),'..','spec_helper')
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Scaffolder::BinaryHelper do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              before(:each) do
         | 
| 6 | 
            +
                @help_tool = Scaffolder::Tool::Help
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                @tool_class = Class.new(Scaffolder::Tool)
         | 
| 9 | 
            +
                @tool_name = 'type'
         | 
| 10 | 
            +
                Scaffolder::Tool.const_set(@tool_name.capitalize,@tool_class)
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                @args = OpenStruct.new({ :rest => %W|#{@tool_name} arg1 arg2| })
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              after(:each) do
         | 
| 16 | 
            +
                Scaffolder::Tool.send(:remove_const,'Type')
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              subject do
         | 
| 20 | 
            +
                object = Object.new
         | 
| 21 | 
            +
                object.extend described_class
         | 
| 22 | 
            +
                object
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              describe "select_tool method" do
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                it "should return corresponding tool subclass when requested by name" do
         | 
| 28 | 
            +
                  subject[@tool_name].should == @tool_class
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                it "should return the help tool when passed an unknown name" do
         | 
| 32 | 
            +
                  subject['unknown-tool'].should == @help_tool
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                it "should return the help tool when passed nil" do
         | 
| 36 | 
            +
                  subject[nil].should == @help_tool
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              it "should fetch the right tool class when requested" do
         | 
| 42 | 
            +
                tool, args = subject.determine_tool(@args)
         | 
| 43 | 
            +
                tool.should == @tool_class
         | 
| 44 | 
            +
                args.rest.should == @args.rest[-2..-1]
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              it "should fetch the help tool class when no arguments passed" do
         | 
| 48 | 
            +
                no_args = Hash.new
         | 
| 49 | 
            +
                no_args.expects(:rest).returns([])
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                expected = no_args.clone
         | 
| 52 | 
            +
                expected[:empty_args] = true
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                tool, args = subject.determine_tool(no_args)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                tool.should == @help_tool
         | 
| 57 | 
            +
                args.should == expected
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
              it "should fetch the help tool class when an invalid argument is passed" do
         | 
| 61 | 
            +
                args = Hash.new
         | 
| 62 | 
            +
                args.expects(:rest).returns(['unknown-tool'])
         | 
| 63 | 
            +
                updated_args = args.clone
         | 
| 64 | 
            +
                updated_args[:unknown_tool] = 'unknown-tool'
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                tool, args = subject.determine_tool(args)
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                tool.should == @help_tool
         | 
| 69 | 
            +
                args.should == updated_args
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
            end
         | 
| @@ -0,0 +1,127 @@ | |
| 1 | 
            +
            require File.expand_path(File.join(File.dirname(__FILE__),'..','..','spec_helper'))
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Scaffolder::Tool::Help do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              it "should inherit from Scaffolder::Tool" do
         | 
| 6 | 
            +
                described_class.superclass.should == Scaffolder::Tool
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it "should return the description of the tool" do
         | 
| 10 | 
            +
                desc = "Help information for scaffolder commands"
         | 
| 11 | 
            +
                described_class.description.should == desc
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              USAGE = <<-MSG.gsub(/^ {6}/, '')
         | 
| 15 | 
            +
                  usage: scaffolder [--version] COMMAND scaffold-file sequence-file
         | 
| 16 | 
            +
                  [options]
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  Commands:
         | 
| 19 | 
            +
                MSG
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              before(:each) do
         | 
| 22 | 
            +
                @settings = Hash.new
         | 
| 23 | 
            +
                @settings.stubs(:rest).returns([])
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              describe "execution with no command and the version argument" do
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                subject do
         | 
| 29 | 
            +
                  @settings[:version] = true
         | 
| 30 | 
            +
                  @settings[:empty_args] = true
         | 
| 31 | 
            +
                  described_class.new(@settings)
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                it "should not raise an error" do
         | 
| 35 | 
            +
                  lambda{ subject.execute }.should_not raise_error
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                it "should return the version number" do
         | 
| 39 | 
            +
                  version = File.read('VERSION').strip
         | 
| 40 | 
            +
                  subject.execute.should == "scaffolder tool version " + version
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              describe "execution with no command" do
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                subject do
         | 
| 48 | 
            +
                  @settings[:empty_args] = true
         | 
| 49 | 
            +
                  described_class.new(@settings)
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                it "should not raise an error" do
         | 
| 53 | 
            +
                  lambda{ subject.execute }.should_not raise_error
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it "should contain the usage information" do
         | 
| 57 | 
            +
                  subject.execute.should include(USAGE)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                it "should contain each tool information" do
         | 
| 61 | 
            +
                  tool_subclasses.each do |cls|
         | 
| 62 | 
            +
                    subject.execute.should include(cls.description)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              describe "execution with an invalid command arguments" do
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                subject do
         | 
| 71 | 
            +
                  @settings[:unknown_tool] = 'unknown_command'
         | 
| 72 | 
            +
                  described_class.new(@settings)
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                it "should raise an error" do
         | 
| 76 | 
            +
                  lambda{ subject.execute }.should(raise_error(ArgumentError,
         | 
| 77 | 
            +
                    "Unknown command 'unknown_command'.\nSee 'scaffolder help'."))
         | 
| 78 | 
            +
                end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              describe "execution with the name of a scaffolder tool command" do
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                before(:each) do
         | 
| 85 | 
            +
                  @tool = Class.new(Scaffolder::Tool)
         | 
| 86 | 
            +
                  described_class.superclass.const_set('Fake',@tool)
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                  @man_dir = File.join(%W|#{File.dirname(__FILE__)} .. .. .. man| )
         | 
| 89 | 
            +
                  @fake_man = File.join(@man_dir,'scaffolder-fake.1.ronn')
         | 
| 90 | 
            +
                end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                after(:each) do
         | 
| 93 | 
            +
                  described_class.superclass.send(:remove_const,'Fake')
         | 
| 94 | 
            +
                end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                subject do
         | 
| 97 | 
            +
                  @settings.stubs(:rest).returns(['fake'])
         | 
| 98 | 
            +
                  described_class.new(@settings)
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                it "should not raise an error" do
         | 
| 102 | 
            +
                  Kernel.stubs(:system).with("ronn -m #{File.expand_path(@fake_man)}")
         | 
| 103 | 
            +
                  lambda{ subject.execute }.should_not raise_error
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
                it "should call ronn on the command line with the man file location" do
         | 
| 107 | 
            +
                  Kernel.expects(:system).with("ronn -m #{File.expand_path(@fake_man)}")
         | 
| 108 | 
            +
                  subject.execute
         | 
| 109 | 
            +
                end
         | 
| 110 | 
            +
             | 
| 111 | 
            +
              end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
              describe "execution with the name of a unknown command" do
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                subject do
         | 
| 116 | 
            +
                  @settings.stubs(:rest).returns(['fake'])
         | 
| 117 | 
            +
                  described_class.new(@settings)
         | 
| 118 | 
            +
                end
         | 
| 119 | 
            +
             | 
| 120 | 
            +
                it "should raise an error" do
         | 
| 121 | 
            +
                  lambda{ subject.execute }.should(raise_error(ArgumentError,
         | 
| 122 | 
            +
                    "Unknown command 'fake'.\nSee 'scaffolder help'."))
         | 
| 123 | 
            +
                end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
              end
         | 
| 126 | 
            +
             | 
| 127 | 
            +
            end
         |