scaffolder-test-helpers 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/scaffolder/test/helpers.rb +14 -18
- data/lib/scaffolder/test/sequence.rb +33 -0
- data/lib/scaffolder/test/unresolved.rb +17 -0
- data/scaffolder-test-helpers.gemspec +10 -6
- data/spec/scaffolder/test/helpers_spec.rb +62 -5
- data/spec/scaffolder/test/sequence_spec.rb +52 -0
- data/spec/scaffolder/test/unresolved_spec.rb +14 -0
- data/spec/spec_helper.rb +4 -6
- metadata +12 -8
- data/.rspec +0 -1
- data/lib/scaffolder/test/cucumber_steps.rb +0 -24
data/Rakefile
CHANGED
@@ -21,8 +21,8 @@ Jeweler::Tasks.new do |gem|
|
|
21
21
|
gem.name = "scaffolder-test-helpers"
|
22
22
|
gem.homepage = "http://github.com/michaelbarton/scaffolder-test-helpers"
|
23
23
|
gem.license = "MIT"
|
24
|
-
gem.summary = %Q{
|
25
|
-
gem.description = %Q{Helper methods and
|
24
|
+
gem.summary = %Q{Methods and classes for testing scaffolder.}
|
25
|
+
gem.description = %Q{Useful Helper methods and classes for testing scaffolder.}
|
26
26
|
gem.email = "mail@michaelbarton.me.uk"
|
27
27
|
gem.authors = ["Michael Barton"]
|
28
28
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -2,36 +2,32 @@ require 'tempfile'
|
|
2
2
|
require 'bio'
|
3
3
|
require 'scaffolder'
|
4
4
|
|
5
|
+
require 'scaffolder/test/sequence'
|
6
|
+
require 'scaffolder/test/unresolved'
|
7
|
+
|
5
8
|
module Scaffolder::Test
|
6
9
|
module Helpers
|
7
10
|
|
8
|
-
def
|
9
|
-
|
10
|
-
make_sequence(entries).each do |entry|
|
11
|
-
seq = Bio::Sequence.new(entry[:sequence])
|
12
|
-
tmp.print(seq.output(:fasta,:header => entry[:name]))
|
13
|
-
end
|
14
|
-
end
|
15
|
-
file
|
11
|
+
def generate_scaffold_files(entries)
|
12
|
+
[write_scaffold_file(entries),write_sequence_file(entries)]
|
16
13
|
end
|
17
14
|
|
18
15
|
def write_scaffold_file(entries,file = Tempfile.new("scaffold").path)
|
19
|
-
File.open(file,'w')
|
16
|
+
File.open(file,'w') do |tmp|
|
17
|
+
tmp.print(YAML.dump(entries.map{|e| e.to_hash }))
|
18
|
+
end
|
20
19
|
file
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
22
|
+
def write_sequence_file(entries,file = Tempfile.new("sequence").path)
|
23
|
+
File.open(file,'w') do |tmp|
|
24
|
+
entries.each do |entry|
|
25
|
+
tmp.puts(entry.to_fasta) if entry.respond_to? :to_fasta
|
26
|
+
end
|
26
27
|
end
|
28
|
+
file
|
27
29
|
end
|
28
30
|
|
29
|
-
def make_sequence(entries)
|
30
|
-
entries.map do |entry|
|
31
|
-
{:name => (entry['name'] || entry[:name]),
|
32
|
-
:sequence => (entry['nucleotides'] || entry[:nucleotides]) }
|
33
|
-
end.flatten
|
34
|
-
end
|
35
31
|
|
36
32
|
end
|
37
33
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'scaffolder'
|
2
|
+
|
3
|
+
module Scaffolder::Test
|
4
|
+
class Sequence
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
[:name,:sequence,:reverse,:start,:stop].each do |attribute|
|
11
|
+
define_method(attribute) do |*arg|
|
12
|
+
unless arg.first
|
13
|
+
return @options[attribute]
|
14
|
+
end
|
15
|
+
@options[attribute] = arg.first
|
16
|
+
return self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_hash
|
21
|
+
hash = {'source' => name}
|
22
|
+
[:start,:stop,:reverse].each do |attribute|
|
23
|
+
hash[attribute.to_s] = @options[attribute] if @options[attribute]
|
24
|
+
end
|
25
|
+
{'sequence' => hash}
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_fasta
|
29
|
+
Bio::Sequence.new(sequence).output(:fasta,:header => name).strip
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{scaffolder-test-helpers}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Michael Barton"]
|
12
|
-
s.date = %q{2011-
|
13
|
-
s.description = %q{Helper methods and
|
12
|
+
s.date = %q{2011-04-03}
|
13
|
+
s.description = %q{Useful Helper methods and classes for testing scaffolder.}
|
14
14
|
s.email = %q{mail@michaelbarton.me.uk}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
@@ -18,25 +18,29 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
-
".rspec",
|
22
21
|
"Gemfile",
|
23
22
|
"LICENSE.txt",
|
24
23
|
"README.rdoc",
|
25
24
|
"Rakefile",
|
26
25
|
"VERSION",
|
27
|
-
"lib/scaffolder/test/cucumber_steps.rb",
|
28
26
|
"lib/scaffolder/test/helpers.rb",
|
27
|
+
"lib/scaffolder/test/sequence.rb",
|
28
|
+
"lib/scaffolder/test/unresolved.rb",
|
29
29
|
"scaffolder-test-helpers.gemspec",
|
30
30
|
"spec/scaffolder/test/helpers_spec.rb",
|
31
|
+
"spec/scaffolder/test/sequence_spec.rb",
|
32
|
+
"spec/scaffolder/test/unresolved_spec.rb",
|
31
33
|
"spec/spec_helper.rb"
|
32
34
|
]
|
33
35
|
s.homepage = %q{http://github.com/michaelbarton/scaffolder-test-helpers}
|
34
36
|
s.licenses = ["MIT"]
|
35
37
|
s.require_paths = ["lib"]
|
36
38
|
s.rubygems_version = %q{1.3.7}
|
37
|
-
s.summary = %q{
|
39
|
+
s.summary = %q{Methods and classes for testing scaffolder.}
|
38
40
|
s.test_files = [
|
39
41
|
"spec/scaffolder/test/helpers_spec.rb",
|
42
|
+
"spec/scaffolder/test/sequence_spec.rb",
|
43
|
+
"spec/scaffolder/test/unresolved_spec.rb",
|
40
44
|
"spec/spec_helper.rb"
|
41
45
|
]
|
42
46
|
|
@@ -1,14 +1,71 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__),'..','..','spec_helper')
|
2
2
|
|
3
|
-
describe Scaffolder::Test::Helpers do
|
3
|
+
describe Scaffolder::Test::Helpers, "#generate_scaffold_files method" do
|
4
4
|
|
5
|
-
|
5
|
+
describe "pass an array with a single sequence" do
|
6
6
|
|
7
|
-
|
7
|
+
before(:all) do
|
8
|
+
entries = [Sequence.new(:name => 'c1',:sequence => 'ATG')]
|
9
|
+
@scaf_file, @seq_file = described_class.generate_scaffold_files(entries)
|
10
|
+
end
|
8
11
|
|
9
|
-
it
|
10
|
-
|
12
|
+
it "should create the corresponding scaffold file" do
|
13
|
+
File.exists?(@scaf_file).should be_true
|
14
|
+
scaffold = YAML.load(File.read(@scaf_file))
|
15
|
+
scaffold.should == [{'sequence' => {'source' => 'c1'}}]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create the corresponding sequence file" do
|
19
|
+
File.exists?(@seq_file).should be_true
|
20
|
+
sequence = File.read(@seq_file)
|
21
|
+
sequence.should == ">c1\nATG\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "pass an array with two sequences" do
|
27
|
+
|
28
|
+
before(:all) do
|
29
|
+
entries = [Sequence.new(:name => 'c1',:sequence => 'ATG'),
|
30
|
+
Sequence.new(:name => 'c2',:sequence => 'ATG')]
|
31
|
+
@scaf_file, @seq_file = described_class.generate_scaffold_files(entries)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should create the corresponding scaffold file" do
|
35
|
+
File.exists?(@scaf_file).should be_true
|
36
|
+
scaffold = YAML.load(File.read(@scaf_file))
|
37
|
+
scaffold.should == [{'sequence' => {'source' => 'c1'}},
|
38
|
+
{'sequence' => {'source' => 'c2'}}]
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should create the corresponding sequence file" do
|
42
|
+
File.exists?(@seq_file).should be_true
|
43
|
+
sequence = File.read(@seq_file)
|
44
|
+
sequence.should == ">c1\nATG\n>c2\nATG\n"
|
45
|
+
end
|
11
46
|
|
12
47
|
end
|
13
48
|
|
49
|
+
describe "pass an array with a sequence and an unresolved region" do
|
50
|
+
|
51
|
+
before(:all) do
|
52
|
+
entries = [Sequence.new(:name => 'c1',:sequence => 'ATG'),
|
53
|
+
Unresolved.new(:length => 5)]
|
54
|
+
@scaf_file, @seq_file = generate_scaffold_files(entries)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should create the corresponding scaffold file" do
|
58
|
+
File.exists?(@scaf_file).should be_true
|
59
|
+
scaffold = YAML.load(File.read(@scaf_file))
|
60
|
+
scaffold.should == [{'sequence' => {'source' => 'c1'}},
|
61
|
+
{'unresolved' => {'length' => 5}}]
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should create the corresponding sequence file" do
|
65
|
+
File.exists?(@seq_file).should be_true
|
66
|
+
sequence = File.read(@seq_file)
|
67
|
+
sequence.should == ">c1\nATG\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
14
71
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','..','spec_helper')
|
2
|
+
|
3
|
+
describe Scaffolder::Test::Sequence do
|
4
|
+
|
5
|
+
describe "basic instance" do
|
6
|
+
subject do
|
7
|
+
described_class.new(:name => 'contig1',:sequence => 'ATGCCC')
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:name) {should == 'contig1'}
|
11
|
+
its(:sequence){should == 'ATGCCC'}
|
12
|
+
|
13
|
+
its(:to_fasta){should == ">contig1\nATGCCC"}
|
14
|
+
its(:to_hash) {should == {'sequence' => {'source' => 'contig1'}} }
|
15
|
+
end
|
16
|
+
|
17
|
+
[:start,:stop,:reverse].each do |attribute|
|
18
|
+
|
19
|
+
describe "instance with #{attribute} attribute" do
|
20
|
+
|
21
|
+
let(:value){:value}
|
22
|
+
subject do
|
23
|
+
described_class.new(:name => 'contig1',:sequence => 'ATGCCC',
|
24
|
+
attribute => value)
|
25
|
+
end
|
26
|
+
|
27
|
+
its(:name) {should == 'contig1'}
|
28
|
+
its(:sequence){should == 'ATGCCC'}
|
29
|
+
its(attribute){should == value}
|
30
|
+
|
31
|
+
its(:to_fasta){should == ">contig1\nATGCCC"}
|
32
|
+
its(:to_hash) do
|
33
|
+
should == {'sequence' => {'source' => 'contig1', attribute.to_s => value}}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "chaining instance attributes" do
|
39
|
+
|
40
|
+
let(:value){:value}
|
41
|
+
subject do
|
42
|
+
instance = described_class.new(:name => 'contig1',:sequence => 'ATGCCC')
|
43
|
+
instance.send(attribute,value)
|
44
|
+
end
|
45
|
+
|
46
|
+
its(attribute){should == value}
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'..','..','spec_helper')
|
2
|
+
|
3
|
+
describe Scaffolder::Test::Unresolved do
|
4
|
+
|
5
|
+
describe "basic instance" do
|
6
|
+
subject do
|
7
|
+
described_class.new(:length => 5)
|
8
|
+
end
|
9
|
+
|
10
|
+
its(:length) {should == 5}
|
11
|
+
its(:to_hash){should == {'unresolved' => {'length' => 5}} }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
2
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
3
|
|
4
|
+
require 'rspec'
|
5
5
|
require 'scaffolder/test/helpers'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RSpec.configure do |config|
|
7
|
+
RSpec.configure do
|
8
|
+
include Scaffolder::Test
|
9
|
+
include Scaffolder::Test::Helpers
|
12
10
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scaffolder-test-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael Barton
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-03 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -123,7 +123,7 @@ dependencies:
|
|
123
123
|
name: yard
|
124
124
|
prerelease: false
|
125
125
|
version_requirements: *id007
|
126
|
-
description: Helper methods and
|
126
|
+
description: Useful Helper methods and classes for testing scaffolder.
|
127
127
|
email: mail@michaelbarton.me.uk
|
128
128
|
executables: []
|
129
129
|
|
@@ -134,16 +134,18 @@ extra_rdoc_files:
|
|
134
134
|
- README.rdoc
|
135
135
|
files:
|
136
136
|
- .document
|
137
|
-
- .rspec
|
138
137
|
- Gemfile
|
139
138
|
- LICENSE.txt
|
140
139
|
- README.rdoc
|
141
140
|
- Rakefile
|
142
141
|
- VERSION
|
143
|
-
- lib/scaffolder/test/cucumber_steps.rb
|
144
142
|
- lib/scaffolder/test/helpers.rb
|
143
|
+
- lib/scaffolder/test/sequence.rb
|
144
|
+
- lib/scaffolder/test/unresolved.rb
|
145
145
|
- scaffolder-test-helpers.gemspec
|
146
146
|
- spec/scaffolder/test/helpers_spec.rb
|
147
|
+
- spec/scaffolder/test/sequence_spec.rb
|
148
|
+
- spec/scaffolder/test/unresolved_spec.rb
|
147
149
|
- spec/spec_helper.rb
|
148
150
|
has_rdoc: true
|
149
151
|
homepage: http://github.com/michaelbarton/scaffolder-test-helpers
|
@@ -178,7 +180,9 @@ rubyforge_project:
|
|
178
180
|
rubygems_version: 1.3.7
|
179
181
|
signing_key:
|
180
182
|
specification_version: 3
|
181
|
-
summary:
|
183
|
+
summary: Methods and classes for testing scaffolder.
|
182
184
|
test_files:
|
183
185
|
- spec/scaffolder/test/helpers_spec.rb
|
186
|
+
- spec/scaffolder/test/sequence_spec.rb
|
187
|
+
- spec/scaffolder/test/unresolved_spec.rb
|
184
188
|
- spec/spec_helper.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'scaffolder/test/helpers'
|
2
|
-
require 'cucumber'
|
3
|
-
|
4
|
-
World(Scaffolder::Test::Helpers)
|
5
|
-
|
6
|
-
Given /^the scaffold is composed of the sequences:$/ do |sequences|
|
7
|
-
@entries = sequences.hashes.map do |seq|
|
8
|
-
{'sequence' => {'source' => seq['name']}}
|
9
|
-
end
|
10
|
-
@sequences = sequences.hashes.map do |seq|
|
11
|
-
{:name => seq['name'], :sequence => seq['nucleotides']}
|
12
|
-
end
|
13
|
-
|
14
|
-
@sequence_file = write_sequence_file(@sequences)
|
15
|
-
@scaffold_file = write_scaffold_file(@entries)
|
16
|
-
end
|
17
|
-
|
18
|
-
Given /^the scaffold file is called "([^"]*)"$/ do |file|
|
19
|
-
FileUtils.mv(@scaffold_file,file)
|
20
|
-
end
|
21
|
-
|
22
|
-
Given /^the sequence file is called "([^"]*)"$/ do |file|
|
23
|
-
FileUtils.mv(@sequence_file,file)
|
24
|
-
end
|