scaffolder-test-helpers 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -0,0 +1,34 @@
1
+ require 'scaffolder'
2
+
3
+ module Scaffolder::Test
4
+ class Annotation
5
+
6
+ [:seqname,:start,:end,:strand,:phase,:feature].each do |attribute|
7
+ define_method(attribute) do |*arg|
8
+ unless arg.first
9
+ return @options[attribute]
10
+ end
11
+ @options[attribute] = arg.first
12
+ return self
13
+ end
14
+ end
15
+
16
+ def initialize(options = Hash.new)
17
+ defaults = {:seqname => 'record', :start => 1, :end => 10,
18
+ :strand => '+', :phase => 1, :feature => 'CDS'}
19
+ @options = defaults.merge(options)
20
+ end
21
+
22
+ def initialize_copy(source)
23
+ super
24
+ @options = @options.dup
25
+ end
26
+
27
+ def to_gff3_record
28
+ Bio::GFF::GFF3::Record.new(
29
+ self.seqname, nil, self.feature, self.start,
30
+ self.end, nil, self.strand, self.phase)
31
+ end
32
+
33
+ end
34
+ end
@@ -4,6 +4,7 @@ require 'scaffolder'
4
4
 
5
5
  require 'scaffolder/test/sequence'
6
6
  require 'scaffolder/test/unresolved'
7
+ require 'scaffolder/test/annotation'
7
8
 
8
9
  module Scaffolder::Test
9
10
  module Helpers
@@ -28,6 +29,12 @@ module Scaffolder::Test
28
29
  file
29
30
  end
30
31
 
32
+ def generate_gff3_file(records,file = Tempfile.new("gff"))
33
+ gff = Bio::GFF::GFF3.new
34
+ gff.records = records.map{|r| r.to_gff3_record}
35
+ File.open(file.path,'w'){|out| out.print(gff) }
36
+ file
37
+ end
31
38
 
32
39
  end
33
40
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{scaffolder-test-helpers}
8
- s.version = "0.3.0"
8
+ s.version = "0.4.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-06-02}
12
+ s.date = %q{2011-06-07}
13
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 = [
@@ -23,10 +23,12 @@ Gem::Specification.new do |s|
23
23
  "README.rdoc",
24
24
  "Rakefile",
25
25
  "VERSION",
26
+ "lib/scaffolder/test/annotation.rb",
26
27
  "lib/scaffolder/test/helpers.rb",
27
28
  "lib/scaffolder/test/sequence.rb",
28
29
  "lib/scaffolder/test/unresolved.rb",
29
30
  "scaffolder-test-helpers.gemspec",
31
+ "spec/scaffolder/test/annotation_spec.rb",
30
32
  "spec/scaffolder/test/helpers_spec.rb",
31
33
  "spec/scaffolder/test/sequence_spec.rb",
32
34
  "spec/scaffolder/test/unresolved_spec.rb",
@@ -37,7 +39,7 @@ Gem::Specification.new do |s|
37
39
  s.require_paths = ["lib"]
38
40
  s.rubygems_version = %q{1.3.7}
39
41
  s.summary = %q{Methods and classes for testing scaffolder.}
40
- s.test_files = ["spec/scaffolder/test/helpers_spec.rb", "spec/scaffolder/test/sequence_spec.rb", "spec/scaffolder/test/unresolved_spec.rb", "spec/spec_helper.rb"]
42
+ s.test_files = ["spec/scaffolder/test/annotation_spec.rb", "spec/scaffolder/test/helpers_spec.rb", "spec/scaffolder/test/sequence_spec.rb", "spec/scaffolder/test/unresolved_spec.rb", "spec/spec_helper.rb"]
41
43
 
42
44
  if s.respond_to? :specification_version then
43
45
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__),'..','..','spec_helper')
2
+
3
+ describe Scaffolder::Test::Annotation do
4
+
5
+ describe "initialization" do
6
+
7
+ context "with all parameters" do
8
+ subject do
9
+ described_class.new(
10
+ :seqname => 'c1', :start => 4, :end => 6,
11
+ :strand => '+', :phase => 1, :feature => 'CDS')
12
+ end
13
+
14
+ its(:seqname){should == 'c1'}
15
+ its(:start) {should == 4}
16
+ its(:end) {should == 6}
17
+ its(:strand) {should == '+'}
18
+ its(:phase) {should == 1}
19
+ its(:feature){should == 'CDS'}
20
+ end
21
+
22
+ context "using default parameters" do
23
+ subject do
24
+ described_class.new
25
+ end
26
+
27
+ its(:seqname){should == 'record'}
28
+ its(:start) {should == 1}
29
+ its(:end) {should == 10}
30
+ its(:strand) {should == '+'}
31
+ its(:phase) {should == 1}
32
+ its(:feature){should == 'CDS'}
33
+ end
34
+
35
+ end
36
+
37
+ describe "#to_gff3_record" do
38
+
39
+ subject do
40
+ described_class.new.to_gff3_record
41
+ end
42
+
43
+ it "should generate a Bio::GFF::GFF3::Record" do
44
+ expected = Bio::GFF::GFF3::Record.new(
45
+ subject.seqname, nil, subject.feature, subject.start,
46
+ subject.end, nil, subject.strand, subject.phase)
47
+ subject.should == expected
48
+ end
49
+
50
+ end
51
+
52
+ describe "#clone" do
53
+
54
+ it "should duplicate the internal options state" do
55
+ a = described_class.new
56
+ b = a.clone
57
+
58
+ a.instance_variable_get("@options").
59
+ should_not equal(b.instance_variable_get("@options"))
60
+ end
61
+
62
+ end
63
+ end
@@ -2,70 +2,113 @@ require File.join(File.dirname(__FILE__),'..','..','spec_helper')
2
2
 
3
3
  describe Scaffolder::Test::Helpers, "#generate_scaffold_files method" do
4
4
 
5
- describe "pass an array with a single sequence" do
5
+ describe "#generate_scaffold_files" do
6
6
 
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
7
+ context "passed an array with a single sequence" do
11
8
 
12
- it "should create the corresponding scaffold file" do
13
- File.exists?(@scaf_file.path).should be_true
14
- scaffold = YAML.load(File.read(@scaf_file.path))
15
- scaffold.should == [{'sequence' => {'source' => 'c1'}}]
16
- end
9
+ before(:all) do
10
+ entries = [Sequence.new(:name => 'c1',:sequence => 'ATG')]
11
+ @scaf_file, @seq_file = described_class.generate_scaffold_files(entries)
12
+ end
13
+
14
+ it "should create the corresponding scaffold file" do
15
+ File.exists?(@scaf_file.path).should be_true
16
+ scaffold = YAML.load(File.read(@scaf_file.path))
17
+ scaffold.should == [{'sequence' => {'source' => 'c1'}}]
18
+ end
19
+
20
+ it "should create the corresponding sequence file" do
21
+ File.exists?(@seq_file.path).should be_true
22
+ sequence = File.read(@seq_file.path)
23
+ sequence.should == ">c1\nATG\n"
24
+ end
17
25
 
18
- it "should create the corresponding sequence file" do
19
- File.exists?(@seq_file.path).should be_true
20
- sequence = File.read(@seq_file.path)
21
- sequence.should == ">c1\nATG\n"
22
26
  end
23
27
 
24
- end
28
+ context "passed an array with two sequences" do
25
29
 
26
- describe "pass an array with two sequences" do
30
+ before(:all) do
31
+ entries = [Sequence.new(:name => 'c1',:sequence => 'ATG'),
32
+ Sequence.new(:name => 'c2',:sequence => 'ATG')]
33
+ @scaf_file, @seq_file = described_class.generate_scaffold_files(entries)
34
+ end
27
35
 
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
36
+ it "should create the corresponding scaffold file" do
37
+ File.exists?(@scaf_file.path).should be_true
38
+ scaffold = YAML.load(File.read(@scaf_file.path))
39
+ scaffold.should == [{'sequence' => {'source' => 'c1'}},
40
+ {'sequence' => {'source' => 'c2'}}]
41
+ end
42
+
43
+ it "should create the corresponding sequence file" do
44
+ File.exists?(@seq_file.path).should be_true
45
+ sequence = File.read(@seq_file.path)
46
+ sequence.should == ">c1\nATG\n>c2\nATG\n"
47
+ end
33
48
 
34
- it "should create the corresponding scaffold file" do
35
- File.exists?(@scaf_file.path).should be_true
36
- scaffold = YAML.load(File.read(@scaf_file.path))
37
- scaffold.should == [{'sequence' => {'source' => 'c1'}},
38
- {'sequence' => {'source' => 'c2'}}]
39
49
  end
40
50
 
41
- it "should create the corresponding sequence file" do
42
- File.exists?(@seq_file.path).should be_true
43
- sequence = File.read(@seq_file.path)
44
- sequence.should == ">c1\nATG\n>c2\nATG\n"
51
+ context "passed an array with a sequence and an unresolved region" do
52
+
53
+ before(:all) do
54
+ entries = [Sequence.new(:name => 'c1',:sequence => 'ATG'),
55
+ Unresolved.new(:length => 5)]
56
+ @scaf_file, @seq_file = generate_scaffold_files(entries)
57
+ end
58
+
59
+ it "should create the corresponding scaffold file" do
60
+ File.exists?(@scaf_file.path).should be_true
61
+ scaffold = YAML.load(File.read(@scaf_file.path))
62
+ scaffold.should == [{'sequence' => {'source' => 'c1'}},
63
+ {'unresolved' => {'length' => 5}}]
64
+ end
65
+
66
+ it "should create the corresponding sequence file" do
67
+ File.exists?(@seq_file.path).should be_true
68
+ sequence = File.read(@seq_file.path)
69
+ sequence.should == ">c1\nATG\n"
70
+ end
71
+
45
72
  end
46
73
 
47
74
  end
48
75
 
49
- describe "pass an array with a sequence and an unresolved region" do
76
+ describe "#generate_gff3_file" do
50
77
 
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)
78
+ subject do
79
+ described_class.generate_gff3_file(records)
55
80
  end
56
81
 
57
- it "should create the corresponding scaffold file" do
58
- File.exists?(@scaf_file.path).should be_true
59
- scaffold = YAML.load(File.read(@scaf_file.path))
60
- scaffold.should == [{'sequence' => {'source' => 'c1'}},
61
- {'unresolved' => {'length' => 5}}]
82
+ context "passed an empty array" do
83
+
84
+ let(:records){ [] }
85
+
86
+ it "should create a file" do
87
+ File.exists?(subject.path).should be_true
88
+ end
89
+
90
+ it "should generate an empty gff3 file" do
91
+ File.read(subject.path).should == "##gff-version 3\n"
92
+ end
93
+
62
94
  end
63
95
 
64
- it "should create the corresponding sequence file" do
65
- File.exists?(@seq_file.path).should be_true
66
- sequence = File.read(@seq_file.path)
67
- sequence.should == ">c1\nATG\n"
96
+ context "passed an array with a single record" do
97
+
98
+ let(:records){ [Annotation.new(
99
+ :seqname => 'c1', :start => 4, :end => 6, :strand => '+',:phase => 1)] }
100
+
101
+ it "should create a file" do
102
+ File.exists?(subject.path).should be_true
103
+ end
104
+
105
+ it "should generate an empty gff3 file" do
106
+ record = "c1\t.\tCDS\t4\t6\t.\t+\t1\t.\n"
107
+ File.read(subject.path).should == "##gff-version 3\n" + record
108
+ end
109
+
68
110
  end
69
111
 
70
112
  end
113
+
71
114
  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: 19
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
8
+ - 4
9
9
  - 0
10
- version: 0.3.0
10
+ version: 0.4.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-06-02 00:00:00 -04:00
18
+ date: 2011-06-07 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -124,10 +124,12 @@ files:
124
124
  - README.rdoc
125
125
  - Rakefile
126
126
  - VERSION
127
+ - lib/scaffolder/test/annotation.rb
127
128
  - lib/scaffolder/test/helpers.rb
128
129
  - lib/scaffolder/test/sequence.rb
129
130
  - lib/scaffolder/test/unresolved.rb
130
131
  - scaffolder-test-helpers.gemspec
132
+ - spec/scaffolder/test/annotation_spec.rb
131
133
  - spec/scaffolder/test/helpers_spec.rb
132
134
  - spec/scaffolder/test/sequence_spec.rb
133
135
  - spec/scaffolder/test/unresolved_spec.rb
@@ -167,6 +169,7 @@ signing_key:
167
169
  specification_version: 3
168
170
  summary: Methods and classes for testing scaffolder.
169
171
  test_files:
172
+ - spec/scaffolder/test/annotation_spec.rb
170
173
  - spec/scaffolder/test/helpers_spec.rb
171
174
  - spec/scaffolder/test/sequence_spec.rb
172
175
  - spec/scaffolder/test/unresolved_spec.rb