Sha256: d67d42b5b8ce4415ade02c8484ae55a4cd24f75972a42e4d3c1345e878e59289

Contents?: true

Size: 952 Bytes

Versions: 1

Compression:

Stored size: 952 Bytes

Contents

require 'tempfile'
require 'bio'
require 'scaffolder'

module Scaffolder::Test
  module Helpers

    def write_sequence_file(entries,file = Tempfile.new("sequence").path)
      File.open(file,'w') do |tmp|
        make_sequence(entries).each do |entry|
          seq = Bio::Sequence.new(entry[:sequence])
          tmp.print(seq.output(:fasta,:header => entry[:name]))
        end
      end
      file
    end

    def write_scaffold_file(entries,file = Tempfile.new("scaffold").path)
      File.open(file,'w'){|tmp| tmp.print(YAML.dump(make_scaffold(entries)))}
      file
    end

    def make_scaffold(entries)
      entries.map do |entry|
        {'sequence' => {'source' => (entry['name'] || entry[:name]) }}
      end
    end

    def make_sequence(entries)
      entries.map do |entry|
        {:name => (entry['name'] || entry[:name]),
          :sequence => (entry['nucleotides'] || entry[:nucleotides]) }
      end.flatten
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scaffolder-test-helpers-0.1.0 lib/scaffolder/test/helpers.rb