genomer-plugin-view 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,279 @@
1
+ require 'spec_helper'
2
+ require 'genomer-plugin-view/table'
3
+
4
+ describe GenomerPluginView::Table do
5
+
6
+ describe "#run" do
7
+
8
+ let(:annotations){ [] }
9
+
10
+ let(:flags){ {} }
11
+
12
+ before(:each) do
13
+ stub(subject).annotations do
14
+ annotations
15
+ end
16
+ stub(subject).flags do
17
+ flags
18
+ end
19
+ end
20
+
21
+ subject do
22
+ described_class.new([],{})
23
+ end
24
+
25
+ describe "with no annotations or flags" do
26
+
27
+ it "should return an empty header line" do
28
+ subject.run.should == ">Feature\t\tannotation_table\n"
29
+ end
30
+
31
+ end
32
+
33
+ describe "with no annotations and the identifier flag" do
34
+
35
+ let(:flags){ {:identifier => 'id'} }
36
+
37
+ it "should add ID to the header line" do
38
+ subject.run.should == ">Feature\tid\tannotation_table\n"
39
+ end
40
+
41
+ end
42
+
43
+ describe "with one gene annotation" do
44
+
45
+ let(:annotations){ [gene] }
46
+
47
+ it "should call the to_genbank_features method " do
48
+ subject.run.should == <<-EOS.unindent
49
+ >Feature\t\tannotation_table
50
+ 1\t3\tgene
51
+ EOS
52
+ end
53
+
54
+ end
55
+
56
+ describe "with one gene annotation and the CDS flag" do
57
+
58
+ let(:flags){ {:generate_encoded_features => true} }
59
+
60
+ let(:annotations){ [gene] }
61
+
62
+ it "should call the to_genbank_features method " do
63
+ subject.run.should == <<-EOS.unindent
64
+ >Feature\t\tannotation_table
65
+ 1\t3\tgene
66
+ 1\t3\tCDS
67
+ EOS
68
+ end
69
+
70
+ end
71
+
72
+ describe "with one gene annotation and the CDS prefix flag" do
73
+
74
+ let(:flags){ {:generate_encoded_features => 'pre_'} }
75
+
76
+ let(:annotations){ [gene({:attributes => {'ID' => '1'}})] }
77
+
78
+ it "should call the to_genbank_features method " do
79
+ subject.run.should == <<-EOS.unindent
80
+ >Feature\t\tannotation_table
81
+ 1\t3\tgene
82
+ \t\t\tlocus_tag\t1
83
+ 1\t3\tCDS
84
+ \t\t\tprotein_id\tpre_1
85
+ EOS
86
+ end
87
+
88
+ end
89
+
90
+ describe "with one tRNA gene annotation and the CDS prefix flag" do
91
+
92
+ let(:flags){ {:generate_encoded_features => 'pre_'} }
93
+
94
+ let(:annotations){ [gene({:attributes => {'ID' => '1',
95
+ 'feature_type' => 'tRNA',
96
+ 'product' => 'tRNA-Gly'}})] }
97
+
98
+ it "should call the to_genbank_features method " do
99
+ subject.run.should == <<-EOS.unindent
100
+ >Feature\t\tannotation_table
101
+ 1\t3\tgene
102
+ \t\t\tlocus_tag\t1
103
+ 1\t3\ttRNA
104
+ \t\t\tproduct\ttRNA-Gly
105
+ EOS
106
+ end
107
+
108
+ end
109
+
110
+ end
111
+
112
+ describe "#create_encoded_features" do
113
+
114
+ let(:prefix) do
115
+ nil
116
+ end
117
+
118
+ subject do
119
+ described_class.new([],{}).create_encoded_features(annotations,prefix).last
120
+ end
121
+
122
+ describe "passed an empty array" do
123
+
124
+ let(:annotations) do
125
+ []
126
+ end
127
+
128
+ it "should return an empty array" do
129
+ subject.should be_nil
130
+ end
131
+
132
+ end
133
+
134
+ describe "passed a gene with no attributes" do
135
+
136
+ let(:annotations) do
137
+ [gene]
138
+ end
139
+
140
+ it "should return a CDS feature" do
141
+ subject.should == cds
142
+ end
143
+
144
+ end
145
+
146
+ describe "passed a gene with a known feature_type attribute" do
147
+
148
+ let(:attributes) do
149
+ {'feature_type' => 'tRNA'}
150
+ end
151
+
152
+ let(:annotations) do
153
+ [gene({:attributes => attributes})]
154
+ end
155
+
156
+ it "should return a tRNA feature" do
157
+ subject.should == gene({:feature => 'tRNA',:attributes => attributes})
158
+ end
159
+
160
+ end
161
+
162
+ describe "passed a gene with an unknown feature_type attribute" do
163
+
164
+ let(:attributes) do
165
+ {'feature_type' => 'unknown'}
166
+ end
167
+
168
+ let(:annotations) do
169
+ [gene({:attributes => attributes})]
170
+ end
171
+
172
+ it "should raise a Genomer::Error" do
173
+ lambda{ subject.call }.should raise_error Genomer::Error,
174
+ "Unknown feature_type 'unknown'"
175
+ end
176
+
177
+ end
178
+
179
+ describe "passed a gene with a Name attribute" do
180
+
181
+ let(:attributes) do
182
+ {'Name' => 'abcD'}
183
+ end
184
+
185
+ let(:annotations) do
186
+ [gene({:attributes => attributes})]
187
+ end
188
+
189
+ it "should set the capitalise value to the product key" do
190
+ subject.should == cds({:attributes => {'product' => 'AbcD'}})
191
+ end
192
+
193
+ end
194
+
195
+ describe "passed a gene with a product attribute" do
196
+
197
+ let(:attributes) do
198
+ {'product' => 'abcd'}
199
+ end
200
+
201
+ let(:annotations) do
202
+ [gene({:attributes => attributes})]
203
+ end
204
+
205
+ it "should not change attributes" do
206
+ subject.should == cds({:attributes => attributes})
207
+ end
208
+
209
+ end
210
+
211
+ describe "passed a gene with a function attribute" do
212
+
213
+ let(:attributes) do
214
+ {'function' => 'abcd'}
215
+ end
216
+
217
+ let(:annotations) do
218
+ [gene({:attributes => attributes})]
219
+ end
220
+
221
+ it "should not change attributes" do
222
+ subject.should == cds({:attributes => attributes})
223
+ end
224
+
225
+ end
226
+
227
+ describe "passed a gene with product and function attributes" do
228
+
229
+ let(:attributes) do
230
+ {'product' => 'abcd','function' => 'efgh'}
231
+ end
232
+
233
+ let(:annotations) do
234
+ [gene({:attributes => attributes})]
235
+ end
236
+
237
+ it "should not change attributes" do
238
+ subject.should == cds({:attributes => attributes})
239
+ end
240
+
241
+ end
242
+
243
+ describe "passed a gene with Name and product attributes" do
244
+
245
+ let(:attributes) do
246
+ {'Name' => 'abcD','product' => 'efgh'}
247
+ end
248
+
249
+ let(:annotations) do
250
+ [gene({:attributes => attributes})]
251
+ end
252
+
253
+ it "should map Name to product and product to function" do
254
+ subject.should == cds({:attributes =>
255
+ {'product' => 'AbcD','function' => 'efgh'}})
256
+ end
257
+
258
+ end
259
+
260
+ describe "passed a gene with Name, product and function attributes" do
261
+
262
+ let(:attributes) do
263
+ {'Name' => 'abcD','product' => 'efgh', 'function' => 'ijkl'}
264
+ end
265
+
266
+ let(:annotations) do
267
+ [gene({:attributes => attributes})]
268
+ end
269
+
270
+ it "should map Name to product and product to function" do
271
+ subject.should == cds({:attributes =>
272
+ {'product' => 'AbcD','function' => 'efgh'}})
273
+ end
274
+
275
+ end
276
+
277
+ end
278
+
279
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe GenomerPluginView do
4
+
5
+ describe "#fetch_view" do
6
+
7
+ it "should return the required view plugin class" do
8
+ GenomerPluginView.fetch_view('fasta').should == GenomerPluginView::Fasta
9
+ end
10
+
11
+ end
12
+
13
+ describe "#run" do
14
+
15
+ let(:example) do
16
+ GenomerPluginView::Example = Class.new(GenomerPluginView)
17
+ end
18
+
19
+ before do
20
+ mock(described_class).fetch_view('example') do
21
+ example
22
+ end
23
+ end
24
+
25
+ it "should initialize and run the required view plugin" do
26
+ mock.proxy(example).new([:arg],:flags) do |instance|
27
+ mock(instance).run
28
+ end
29
+
30
+ described_class.new(['example',:arg],:flags).run
31
+ end
32
+
33
+ end
34
+
35
+ describe '#convert_command_line_flags' do
36
+
37
+ subject do
38
+ described_class.convert_command_line_flags(flags)
39
+ end
40
+
41
+ describe "with no command line arguments" do
42
+
43
+ let(:flags) do
44
+ {}
45
+ end
46
+
47
+ it "should return an empty hash" do
48
+ subject.should == {}
49
+ end
50
+
51
+ end
52
+
53
+ describe "with an unrelated command line argument" do
54
+
55
+ let(:flags) do
56
+ {:something => :unknown}
57
+ end
58
+
59
+ it "should return an empty hash" do
60
+ subject.should == {}
61
+ end
62
+
63
+ end
64
+
65
+ describe "with the prefix command line argument" do
66
+
67
+ let(:flags) do
68
+ {:prefix => 'pre_'}
69
+ end
70
+
71
+ it "should return the prefix argument" do
72
+ subject.should == {:prefix => 'pre_'}
73
+ end
74
+
75
+ end
76
+
77
+ describe "with the generate_encoded_features command line argument" do
78
+
79
+ let(:flags) do
80
+ {:'generate_encoded_features' => true}
81
+ end
82
+
83
+ it "should return the prefix argument" do
84
+ subject.should == {:encoded => true}
85
+ end
86
+
87
+ end
88
+
89
+ describe "with the reset_locus_numbering command line argument" do
90
+
91
+ let(:flags) do
92
+ {:reset_locus_numbering => true}
93
+ end
94
+
95
+ it "should map this to the the reset argument" do
96
+ subject.should == {:reset => true}
97
+ end
98
+
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,32 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'heredoc_unindent'
5
+ require 'scaffolder/test/helpers'
6
+ require 'genomer-plugin-view'
7
+ require 'genomer-plugin-view/gff_record_helper'
8
+
9
+ # Requires supporting files with custom matchers and macros, etc,
10
+ # in ./support/ and its subdirectories.
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :rr
15
+
16
+ include Scaffolder::Test
17
+ Scaffolder::Test::Annotation.send(:include, GenomerPluginView::GffRecordHelper)
18
+
19
+ def gene(opts = Hash.new)
20
+ default = {
21
+ :seqname => 'seq1',
22
+ :start => 1,
23
+ :end => 3,
24
+ :feature => 'gene',
25
+ :attributes => Hash.new}
26
+ Annotation.new(default.merge(opts)).to_gff3_record
27
+ end
28
+
29
+ def cds(opts = Hash.new)
30
+ gene({:feature => 'CDS'}.merge(opts))
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,192 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genomer-plugin-view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Barton
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: genomer
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.0.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.0.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.9.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.9.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rr
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.4
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.4
62
+ - !ruby/object:Gem::Dependency
63
+ name: scaffolder-test-helpers
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: heredoc_unindent
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 1.1.2
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 1.1.2
94
+ - !ruby/object:Gem::Dependency
95
+ name: cucumber
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.1.9
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.1.9
110
+ - !ruby/object:Gem::Dependency
111
+ name: aruba
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 0.4.11
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 0.4.11
126
+ description: Convert genome scaffold into different sequence format views
127
+ email:
128
+ - mail@michaelbarton.me.uk
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .document
134
+ - .gitignore
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.rdoc
138
+ - Rakefile
139
+ - features/agp/generation.feature
140
+ - features/fasta/contigs.feature
141
+ - features/fasta/single_sequence.feature
142
+ - features/mappings/core.feature
143
+ - features/support/env.rb
144
+ - features/table/cds_entries.feature
145
+ - features/table/core.feature
146
+ - features/table/feature_type.feature
147
+ - genomer-plugin-view.gemspec
148
+ - lib/genomer-plugin-view.rb
149
+ - lib/genomer-plugin-view/agp.rb
150
+ - lib/genomer-plugin-view/fasta.rb
151
+ - lib/genomer-plugin-view/gff_record_helper.rb
152
+ - lib/genomer-plugin-view/mapping.rb
153
+ - lib/genomer-plugin-view/table.rb
154
+ - lib/genomer-plugin-view/version.rb
155
+ - man/genomer-view-agp.ronn
156
+ - man/genomer-view.ronn
157
+ - spec/genomer-view-plugin/agp_spec.rb
158
+ - spec/genomer-view-plugin/fasta_spec.rb
159
+ - spec/genomer-view-plugin/gff_record_helper_spec.rb
160
+ - spec/genomer-view-plugin/mapping_spec.rb
161
+ - spec/genomer-view-plugin/table_spec.rb
162
+ - spec/genomer-view-plugin_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: http://github.com/michaelbarton/genomer-plugin-view
165
+ licenses:
166
+ - MIT
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ segments:
178
+ - 0
179
+ hash: 3613905158544904544
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ~>
184
+ - !ruby/object:Gem::Version
185
+ version: 1.8.0
186
+ requirements: []
187
+ rubyforge_project: genomer-view-plugin
188
+ rubygems_version: 1.8.23
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: Provide different views of scaffold.
192
+ test_files: []