genomer-plugin-view 0.0.5 → 0.0.6

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.
@@ -10,3 +10,19 @@ Feature: Producing different views of a genomes scaffold
10
10
  Then the exit status should be 0
11
11
  And the output should contain a valid man page
12
12
  And the output should contain "GENOMER-VIEW(1)"
13
+
14
+ @disable-bundler
15
+ Scenario: Running `genomer view` without a subcommand
16
+ Given I create a new genomer project
17
+ When I run `genomer view`
18
+ Then the exit status should be 0
19
+ And the output should contain:
20
+ """
21
+ Run `genomer man view COMMAND` to review available formats
22
+ Where COMMAND is one of the following:
23
+ agp
24
+ fasta
25
+ gff
26
+ mapping
27
+ table
28
+ """
@@ -302,3 +302,76 @@ Feature: Producing cds annotation view from a scaffold
302
302
 
303
303
  """
304
304
 
305
+ @disable-bundler
306
+ Scenario: A CDS entry with a single DBxref attribute
307
+ Given I successfully run `genomer init project`
308
+ And I cd to "project"
309
+ And I write to "assembly/scaffold.yml" with:
310
+ """
311
+ ---
312
+ - sequence:
313
+ source: contig1
314
+ """
315
+ And I write to "assembly/sequence.fna" with:
316
+ """
317
+ >contig1
318
+ AAAAATTTTTGGGGGCCCCC
319
+ """
320
+ And I write to "assembly/annotations.gff" with:
321
+ """
322
+ ##gff-version 3
323
+ contig1 . gene 1 3 . - 1 ID=gene1;DBxref=GO:000001
324
+ """
325
+ And I append to "Gemfile" with:
326
+ """
327
+ gem 'genomer-plugin-view', :path => '../../../'
328
+ """
329
+ When I run `genomer view table --identifier=genome --generate_encoded_features`
330
+ Then the exit status should be 0
331
+ And the output should contain:
332
+ """
333
+ >Feature genome annotation_table
334
+ 3 1 gene
335
+ locus_tag gene1
336
+ 3 1 CDS
337
+ protein_id gene1
338
+ db_xref GO:000001
339
+
340
+ """
341
+
342
+ @disable-bundler
343
+ Scenario: A CDS entry with multiple DBxref attributes
344
+ Given I successfully run `genomer init project`
345
+ And I cd to "project"
346
+ And I write to "assembly/scaffold.yml" with:
347
+ """
348
+ ---
349
+ - sequence:
350
+ source: contig1
351
+ """
352
+ And I write to "assembly/sequence.fna" with:
353
+ """
354
+ >contig1
355
+ AAAAATTTTTGGGGGCCCCC
356
+ """
357
+ And I write to "assembly/annotations.gff" with:
358
+ """
359
+ ##gff-version 3
360
+ contig1 . gene 1 3 . - 1 ID=gene1;DBxref=GO:000001;DBxref=InterPro:IPR000111
361
+ """
362
+ And I append to "Gemfile" with:
363
+ """
364
+ gem 'genomer-plugin-view', :path => '../../../'
365
+ """
366
+ When I run `genomer view table --identifier=genome --generate_encoded_features`
367
+ Then the exit status should be 0
368
+ And the output should contain:
369
+ """
370
+ >Feature genome annotation_table
371
+ 3 1 gene
372
+ locus_tag gene1
373
+ 3 1 CDS
374
+ protein_id gene1
375
+ db_xref GO:000001
376
+ db_xref InterPro:IPR000111
377
+ """
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "genomer-plugin-view"
7
7
  s.version = GenomerViewPlugin::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.homepage = "http://github.com/michaelbarton/genomer-plugin-view"
9
+ s.homepage = "http://next.gs"
10
10
  s.license = "MIT"
11
11
  s.authors = ["Michael Barton"]
12
12
  s.email = ["mail@michaelbarton.me.uk"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.required_rubygems_version = "~> 1.8.0"
17
17
  s.rubyforge_project = "genomer-view-plugin"
18
18
 
19
- s.add_dependency "genomer", ">= 0.0.6"
19
+ s.add_dependency "genomer", ">= 0.0.10"
20
20
 
21
21
  # Specs
22
22
  s.add_development_dependency "rspec", "~> 2.9.0"
@@ -2,8 +2,7 @@ require 'bio'
2
2
 
3
3
  module GenomerPluginView::GffRecordHelper
4
4
 
5
-
6
- DEFAULT_GFF_MAPPING = {'product' => 'product', 'Note' => 'note' }
5
+ DEFAULT_GFF_MAPPING = {'product' => 'product', 'Note' => 'note', 'DBxref' => 'db_xref'}
7
6
 
8
7
  GFF_TO_TABLE = {
9
8
  'gene' => {
@@ -21,33 +21,37 @@ class GenomerPluginView::Table < Genomer::Plugin
21
21
  def create_encoded_features(genes,prefix)
22
22
  features = genes.map do |gene|
23
23
  feature = gene.clone
24
- attrs = Hash[feature.attributes]
24
+ attrs = feature.attributes.clone
25
25
 
26
- if id = attrs['ID']
27
- attrs['ID'] = (prefix.is_a?(String) ? prefix + id : id)
28
- end
29
-
30
- feature.feature = attrs['feature_type'] || 'CDS'
26
+ feature_type = attrs.detect{|k,v| k == 'feature_type'}
27
+ feature.feature = (feature_type ? feature_type.last : 'CDS')
31
28
 
32
29
  unless SUPPORTED_FEATURE_TYPES.include?(feature.feature)
33
30
  raise Genomer::Error, "Unknown feature_type '#{feature.feature}'"
34
31
  end
35
32
 
33
+ attrs.map! do |(k,v)|
34
+ v = (k == 'ID' && prefix.instance_of?(String) ? prefix + v : v)
35
+ [k,v]
36
+ end
37
+
36
38
  if feature.feature == "CDS"
37
- name, prdt, ftn = attrs['Name'], attrs['product'], attrs['function']
38
39
 
39
- if name
40
- name = name.clone
41
- name[0,1] = name[0,1].upcase
42
- prdt, ftn = name,prdt
43
- end
40
+ if attrs.detect{|(k,v)| k == 'Name' }
41
+ attrs.map! do |(k,v)|
42
+ v = v.clone
43
+ v[0,1] = v[0,1].upcase if k == 'Name'
44
44
 
45
- attrs.delete('Name')
46
- attrs['product'] = prdt
47
- attrs['function'] = ftn
45
+ v = nil if k == 'function'
46
+ k = 'function' if k == 'product'
47
+ k = 'product' if k == 'Name'
48
+ [k,v]
49
+ end
50
+ end
51
+ #attrs.delete('Name')
48
52
  end
49
53
 
50
- feature.attributes = attrs.to_a.reject{|(_,value)| value.nil? }
54
+ feature.attributes = attrs.reject{|(_,value)| value.nil? }
51
55
  feature
52
56
  end
53
57
  genes.zip(features).flatten
@@ -1,3 +1,3 @@
1
1
  class GenomerViewPlugin
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,6 +3,7 @@ require 'genomer'
3
3
  class GenomerPluginView < Genomer::Plugin
4
4
 
5
5
  def run
6
+ return help if arguments.empty?
6
7
  self.class.fetch_view(arguments.shift).new(arguments,flags).run
7
8
  end
8
9
 
@@ -26,4 +27,19 @@ class GenomerPluginView < Genomer::Plugin
26
27
  end
27
28
  end
28
29
 
30
+ def help
31
+ message = <<-STRING.unindent
32
+ Run `genomer man view COMMAND` to review available formats
33
+ Where COMMAND is one of the following:
34
+ STRING
35
+
36
+ message + Dir[File.dirname(__FILE__) + '/genomer-plugin-view/*.rb'].
37
+ map{|f| File.basename(f).gsub('.rb','')}.
38
+ delete_if{|i| i == 'version'}.
39
+ delete_if{|i| i == 'gff_record_helper'}.
40
+ sort.
41
+ map{|i| " " * 2 + i}.
42
+ join("\n") + "\n"
43
+ end
44
+
29
45
  end
@@ -68,6 +68,10 @@ begin with an upper case letter.
68
68
  Used to populate the **Note** field for entries when the
69
69
  `--generate_encoded_features` option is passed.
70
70
 
71
+ * `DBxref`: Used to link the annotation to other database references. This
72
+ field is added verbatim to generated output. Multiple entires of this
73
+ field may be used.
74
+
71
75
  ### GENOMER ATTRIBUTES
72
76
 
73
77
  These attributes are specific to genomer and should begin with a lower case
@@ -68,7 +68,7 @@ describe GenomerPluginView::GffRecordHelper do
68
68
  context "gene feature with attributes" do
69
69
 
70
70
  let(:annotation) do
71
- @attn.feature('gene').attributes('ID' => 'id')
71
+ @attn.feature('gene').attributes([['ID', 'id']])
72
72
  end
73
73
 
74
74
  it "should return a table entry" do
@@ -189,7 +189,7 @@ describe GenomerPluginView::GffRecordHelper do
189
189
  context "for a feature with an unknown attribute" do
190
190
 
191
191
  let(:annotation) do
192
- @attn.attributes('something' => 'else')
192
+ @attn.attributes([['something','else']])
193
193
  end
194
194
 
195
195
  it "should return an empty array" do
@@ -199,34 +199,38 @@ describe GenomerPluginView::GffRecordHelper do
199
199
  end
200
200
 
201
201
  feature_keys = {
202
- :gene => {
203
- 'Name' => 'gene',
204
- 'ID' => 'locus_tag' },
205
- :tRNA => {
206
- 'product' => 'product',
207
- 'Note' => 'note'},
208
- :rRNA => {
209
- 'product' => 'product',
210
- 'Note' => 'note'},
211
- :miscRNA => {
212
- 'product' => 'product',
213
- 'Note' => 'note'},
214
- :tmRNA => {
215
- 'product' => 'product',
216
- 'Note' => 'note'},
217
- :CDS => {
218
- 'ec_number' => 'EC_number',
219
- 'function' => 'function',
220
- 'product' => 'product',
221
- 'Note' => 'note',
222
- 'ID' => 'protein_id' }}
202
+ :gene => [
203
+ ['Name', 'gene'],
204
+ ['ID', 'locus_tag']],
205
+ :tRNA => [
206
+ ['DBxref', 'db_xref'],
207
+ ['product', 'product'],
208
+ ['Note', 'note']],
209
+ :rRNA => [
210
+ ['product', 'product'],
211
+ ['Note', 'note']],
212
+ :miscRNA => [
213
+ ['DBxref', 'db_xref'],
214
+ ['product', 'product'],
215
+ ['Note', 'note']],
216
+ :tmRNA => [
217
+ ['DBxref', 'db_xref'],
218
+ ['product', 'product'],
219
+ ['Note', 'note']],
220
+ :CDS => [
221
+ ['ec_number', 'EC_number'],
222
+ ['DBxref', 'db_xref'],
223
+ ['function', 'function'],
224
+ ['product', 'product'],
225
+ ['Note', 'note'],
226
+ ['ID', 'protein_id' ]]}
223
227
 
224
228
  feature_keys.each do |type,mappings|
225
229
  mappings.each do |a,b|
226
230
  context "#{type.to_s} feature" do
227
231
 
228
232
  let(:annotation) do
229
- @attn.feature(type.to_s).attributes(a => :value)
233
+ @attn.feature(type.to_s).attributes([[a, :value]])
230
234
  end
231
235
 
232
236
  it "should return #{b} for the attribute #{a}" do
@@ -238,7 +242,6 @@ describe GenomerPluginView::GffRecordHelper do
238
242
  end
239
243
  end
240
244
 
241
-
242
245
  end
243
246
 
244
247
  end
@@ -73,7 +73,7 @@ describe GenomerPluginView::Table do
73
73
 
74
74
  let(:flags){ {:generate_encoded_features => 'pre_'} }
75
75
 
76
- let(:annotations){ [gene({:attributes => {'ID' => '1'}})] }
76
+ let(:annotations){ [gene({:attributes => [['ID', '1']]})] }
77
77
 
78
78
  it "should call the to_genbank_features method " do
79
79
  subject.run.should == <<-EOS.unindent
@@ -91,9 +91,9 @@ describe GenomerPluginView::Table do
91
91
 
92
92
  let(:flags){ {:generate_encoded_features => 'pre_'} }
93
93
 
94
- let(:annotations){ [gene({:attributes => {'ID' => '1',
95
- 'feature_type' => 'tRNA',
96
- 'product' => 'tRNA-Gly'}})] }
94
+ let(:annotations){ [gene({:attributes => [['ID', '1'],
95
+ ['feature_type', 'tRNA'],
96
+ ['product', 'tRNA-Gly']]})] }
97
97
 
98
98
  it "should call the to_genbank_features method " do
99
99
  subject.run.should == <<-EOS.unindent
@@ -112,7 +112,7 @@ describe GenomerPluginView::Table do
112
112
  describe "#create_encoded_features" do
113
113
 
114
114
  let(:prefix) do
115
- nil
115
+ true
116
116
  end
117
117
 
118
118
  subject do
@@ -143,10 +143,26 @@ describe GenomerPluginView::Table do
143
143
 
144
144
  end
145
145
 
146
+ describe "passed a gene with an ID attributes" do
147
+
148
+ let(:attributes) do
149
+ [['ID', 'something']]
150
+ end
151
+
152
+ let(:annotations) do
153
+ [gene({:attributes => attributes})]
154
+ end
155
+
156
+ it "should not change the attributes" do
157
+ subject.attributes.should == attributes
158
+ end
159
+
160
+ end
161
+
146
162
  describe "passed a gene with a known feature_type attribute" do
147
163
 
148
164
  let(:attributes) do
149
- {'feature_type' => 'tRNA'}
165
+ [['feature_type', 'tRNA']]
150
166
  end
151
167
 
152
168
  let(:annotations) do
@@ -162,7 +178,7 @@ describe GenomerPluginView::Table do
162
178
  describe "passed a gene with an unknown feature_type attribute" do
163
179
 
164
180
  let(:attributes) do
165
- {'feature_type' => 'unknown'}
181
+ [['feature_type', 'unknown']]
166
182
  end
167
183
 
168
184
  let(:annotations) do
@@ -176,10 +192,26 @@ describe GenomerPluginView::Table do
176
192
 
177
193
  end
178
194
 
195
+ describe "passed a gene with a duplicate attribute" do
196
+
197
+ let(:attributes) do
198
+ [['product', 'abcd'],['product', 'efgh']]
199
+ end
200
+
201
+ let(:annotations) do
202
+ [gene({:attributes => attributes})]
203
+ end
204
+
205
+ it "should not change attributes" do
206
+ subject.should have_identical_attributes cds({:attributes => attributes})
207
+ end
208
+
209
+ end
210
+
179
211
  describe "passed a gene with a Name attribute" do
180
212
 
181
213
  let(:attributes) do
182
- {'Name' => 'abcD'}
214
+ [['Name', 'abcD']]
183
215
  end
184
216
 
185
217
  let(:annotations) do
@@ -187,7 +219,7 @@ describe GenomerPluginView::Table do
187
219
  end
188
220
 
189
221
  it "should set the capitalise value to the product key" do
190
- subject.should have_identical_attributes cds({:attributes => {'product' => 'AbcD'}})
222
+ subject.should have_identical_attributes cds({:attributes => [['product', 'AbcD']]})
191
223
  end
192
224
 
193
225
  end
@@ -195,7 +227,7 @@ describe GenomerPluginView::Table do
195
227
  describe "passed a gene with a product attribute" do
196
228
 
197
229
  let(:attributes) do
198
- {'product' => 'abcd'}
230
+ [['product', 'abcd']]
199
231
  end
200
232
 
201
233
  let(:annotations) do
@@ -211,7 +243,7 @@ describe GenomerPluginView::Table do
211
243
  describe "passed a gene with a function attribute" do
212
244
 
213
245
  let(:attributes) do
214
- {'function' => 'abcd'}
246
+ [['function', 'abcd']]
215
247
  end
216
248
 
217
249
  let(:annotations) do
@@ -227,7 +259,7 @@ describe GenomerPluginView::Table do
227
259
  describe "passed a gene with product and function attributes" do
228
260
 
229
261
  let(:attributes) do
230
- {'product' => 'abcd', 'function' => 'efgh'}
262
+ [['product', 'abcd'], ['function', 'efgh']]
231
263
  end
232
264
 
233
265
  let(:annotations) do
@@ -243,7 +275,7 @@ describe GenomerPluginView::Table do
243
275
  describe "passed a gene with Name and product attributes" do
244
276
 
245
277
  let(:attributes) do
246
- {'Name' => 'abcD','product' => 'efgh'}
278
+ [['Name', 'abcD'], ['product', 'efgh']]
247
279
  end
248
280
 
249
281
  let(:annotations) do
@@ -252,7 +284,7 @@ describe GenomerPluginView::Table do
252
284
 
253
285
  it "should map Name to product and product to function" do
254
286
  subject.should have_identical_attributes cds({:attributes =>
255
- {'product' => 'AbcD','function' => 'efgh'}})
287
+ [['product', 'AbcD'], ['function', 'efgh']]})
256
288
  end
257
289
 
258
290
  end
@@ -260,7 +292,7 @@ describe GenomerPluginView::Table do
260
292
  describe "passed a gene with Name, product and function attributes" do
261
293
 
262
294
  let(:attributes) do
263
- {'Name' => 'abcD','product' => 'efgh', 'function' => 'ijkl'}
295
+ [['Name', 'abcD'], ['product', 'efgh'], ['function', 'ijkl']]
264
296
  end
265
297
 
266
298
  let(:annotations) do
@@ -269,11 +301,42 @@ describe GenomerPluginView::Table do
269
301
 
270
302
  it "should map Name to product and product to function" do
271
303
  subject.should have_identical_attributes cds({:attributes =>
272
- {'product' => 'AbcD','function' => 'efgh'}})
304
+ [['product', 'AbcD'], ['function', 'efgh']]})
273
305
  end
274
306
 
275
307
  end
276
308
 
309
+ describe "passed a gene with a single db_xref attribute" do
310
+
311
+ let(:attributes) do
312
+ {'db_xref' => 'InterPro:IPR000111'}
313
+ end
314
+
315
+ let(:annotations) do
316
+ [gene({:attributes => attributes})]
317
+ end
318
+
319
+ it "should not change attributes" do
320
+ subject.should have_identical_attributes cds({:attributes => attributes})
321
+ end
322
+
323
+ end
324
+
325
+ describe "passed a gene with multiple db_xref attribute" do
326
+
327
+ let(:attributes) do
328
+ {'db_xref' => 'InterPro:IPR000111','db_xref' => 'GO:000001'}
329
+ end
330
+
331
+ let(:annotations) do
332
+ [gene({:attributes => attributes})]
333
+ end
334
+
335
+ it "should not change attributes" do
336
+ subject.should have_identical_attributes cds({:attributes => attributes})
337
+ end
338
+
339
+ end
277
340
  end
278
341
 
279
342
  end
@@ -16,18 +16,38 @@ describe GenomerPluginView do
16
16
  GenomerPluginView::Example = Class.new(GenomerPluginView)
17
17
  end
18
18
 
19
- before do
20
- mock(described_class).fetch_view('example') do
21
- example
19
+ context "with a view argument passed" do
20
+
21
+ before do
22
+ mock(described_class).fetch_view('example') do
23
+ example
24
+ end
22
25
  end
26
+
27
+ it "should initialize and run the required view plugin" do
28
+ mock.proxy(example).new([:arg],:flags) do |instance|
29
+ mock(instance).run
30
+ end
31
+
32
+ described_class.new(['example',:arg],:flags).run
33
+ end
34
+
23
35
  end
24
36
 
25
- it "should initialize and run the required view plugin" do
26
- mock.proxy(example).new([:arg],:flags) do |instance|
27
- mock(instance).run
37
+ context "with no argument passed" do
38
+
39
+ it "should return help information" do
40
+ described_class.new([],[]).run.should ==<<-STRING.unindent
41
+ Run `genomer man view COMMAND` to review available formats
42
+ Where COMMAND is one of the following:
43
+ agp
44
+ fasta
45
+ gff
46
+ mapping
47
+ table
48
+ STRING
28
49
  end
29
50
 
30
- described_class.new(['example',:arg],:flags).run
31
51
  end
32
52
 
33
53
  end
data/spec/spec_helper.rb CHANGED
@@ -22,7 +22,7 @@ RSpec.configure do |config|
22
22
  :start => 1,
23
23
  :end => 3,
24
24
  :feature => 'gene',
25
- :attributes => Hash.new}
25
+ :attributes => Array.new}
26
26
  Annotation.new(default.merge(opts)).to_gff3_record
27
27
  end
28
28
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: genomer-plugin-view
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-25 00:00:00.000000000 Z
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: genomer
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.0.6
21
+ version: 0.0.10
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.0.6
29
+ version: 0.0.10
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rspec
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -172,7 +172,7 @@ files:
172
172
  - spec/genomer-view-plugin/table_spec.rb
173
173
  - spec/genomer-view-plugin_spec.rb
174
174
  - spec/spec_helper.rb
175
- homepage: http://github.com/michaelbarton/genomer-plugin-view
175
+ homepage: http://next.gs
176
176
  licenses:
177
177
  - MIT
178
178
  post_install_message:
@@ -187,7 +187,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  segments:
189
189
  - 0
190
- hash: -207727351507926591
190
+ hash: 390518256786568765
191
191
  required_rubygems_version: !ruby/object:Gem::Requirement
192
192
  none: false
193
193
  requirements:
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: 1.8.0
197
197
  requirements: []
198
198
  rubyforge_project: genomer-view-plugin
199
- rubygems_version: 1.8.23
199
+ rubygems_version: 1.8.25
200
200
  signing_key:
201
201
  specification_version: 3
202
202
  summary: Provide different views of scaffold.