Permalink
Browse files

Merge branch 'refactor/non-unique-attributes' into develop

  • Loading branch information...
michaelbarton committed Mar 4, 2013
2 parents d48233f + 7fe2917 commit 7c3105db2f06583c46c673b9698006bf63225624
@@ -302,3 +302,41 @@ Feature: Producing cds annotation view from a scaffold
"""
@disable-bundler
Scenario: A CDS entry with duplicate note attributes
Given I successfully run `genomer init project`
And I cd to "project"
And I write to "assembly/scaffold.yml" with:
"""
---
- sequence:
source: contig1
"""
And I write to "assembly/sequence.fna" with:
"""
>contig1
AAAAATTTTTGGGGGCCCCC
"""
And I write to "assembly/annotations.gff" with:
"""
##gff-version 3
contig1 . gene 1 3 . - 1 ID=gene1;Note=val1;Note=val2
"""
And I append to "Gemfile" with:
"""
gem 'genomer-plugin-view', :path => '../../../'
"""
When I run `genomer view table --identifier=genome --generate_encoded_features`
Then the exit status should be 0
And the output should contain:
"""
>Feature genome annotation_table
3 1 gene
locus_tag gene1
3 1 CDS
protein_id gene1
note val1
note val2
"""
@@ -2,7 +2,6 @@
module GenomerPluginView::GffRecordHelper
DEFAULT_GFF_MAPPING = {'product' => 'product', 'Note' => 'note' }
GFF_TO_TABLE = {
@@ -21,33 +21,37 @@ def run
def create_encoded_features(genes,prefix)
features = genes.map do |gene|
feature = gene.clone
attrs = Hash[feature.attributes]
attrs = feature.attributes.clone
if id = attrs['ID']
attrs['ID'] = (prefix.is_a?(String) ? prefix + id : id)
end
feature.feature = attrs['feature_type'] || 'CDS'
feature_type = attrs.detect{|k,v| k == 'feature_type'}
feature.feature = (feature_type ? feature_type.last : 'CDS')
unless SUPPORTED_FEATURE_TYPES.include?(feature.feature)
raise Genomer::Error, "Unknown feature_type '#{feature.feature}'"
end
attrs.map! do |(k,v)|
v = (k == 'ID' && prefix.instance_of?(String) ? prefix + v : v)
[k,v]
end
if feature.feature == "CDS"
name, prdt, ftn = attrs['Name'], attrs['product'], attrs['function']
if name
name = name.clone
name[0,1] = name[0,1].upcase
prdt, ftn = name,prdt
end
if attrs.detect{|(k,v)| k == 'Name' }
attrs.map! do |(k,v)|
v = v.clone
v[0,1] = v[0,1].upcase if k == 'Name'
attrs.delete('Name')
attrs['product'] = prdt
attrs['function'] = ftn
v = nil if k == 'function'
k = 'function' if k == 'product'
k = 'product' if k == 'Name'
[k,v]
end
end
#attrs.delete('Name')
end
feature.attributes = attrs.to_a.reject{|(_,value)| value.nil? }
feature.attributes = attrs.reject{|(_,value)| value.nil? }
feature
end
genes.zip(features).flatten
@@ -68,7 +68,7 @@
context "gene feature with attributes" do
let(:annotation) do
@attn.feature('gene').attributes('ID' => 'id')
@attn.feature('gene').attributes([['ID', 'id']])
end
it "should return a table entry" do
@@ -189,7 +189,7 @@
context "for a feature with an unknown attribute" do
let(:annotation) do
@attn.attributes('something' => 'else')
@attn.attributes([['something','else']])
end
it "should return an empty array" do
@@ -199,34 +199,34 @@
end
feature_keys = {
:gene => {
'Name' => 'gene',
'ID' => 'locus_tag' },
:tRNA => {
'product' => 'product',
'Note' => 'note'},
:rRNA => {
'product' => 'product',
'Note' => 'note'},
:miscRNA => {
'product' => 'product',
'Note' => 'note'},
:tmRNA => {
'product' => 'product',
'Note' => 'note'},
:CDS => {
'ec_number' => 'EC_number',
'function' => 'function',
'product' => 'product',
'Note' => 'note',
'ID' => 'protein_id' }}
:gene => [
['Name', 'gene'],
['ID', 'locus_tag']],
:tRNA => [
['product', 'product'],
['Note', 'note']],
:rRNA => [
['product', 'product'],
['Note', 'note']],
:miscRNA => [
['product', 'product'],
['Note', 'note']],
:tmRNA => [
['product', 'product'],
['Note', 'note']],
:CDS => [
['ec_number', 'EC_number'],
['function', 'function'],
['product', 'product'],
['Note', 'note'],
['ID', 'protein_id' ]]}
feature_keys.each do |type,mappings|
mappings.each do |a,b|
context "#{type.to_s} feature" do
let(:annotation) do
@attn.feature(type.to_s).attributes(a => :value)
@attn.feature(type.to_s).attributes([[a, :value]])
end
it "should return #{b} for the attribute #{a}" do
@@ -238,7 +238,6 @@
end
end
end
end
@@ -73,7 +73,7 @@
let(:flags){ {:generate_encoded_features => 'pre_'} }
let(:annotations){ [gene({:attributes => {'ID' => '1'}})] }
let(:annotations){ [gene({:attributes => [['ID', '1']]})] }
it "should call the to_genbank_features method " do
subject.run.should == <<-EOS.unindent
@@ -91,9 +91,9 @@
let(:flags){ {:generate_encoded_features => 'pre_'} }
let(:annotations){ [gene({:attributes => {'ID' => '1',
'feature_type' => 'tRNA',
'product' => 'tRNA-Gly'}})] }
let(:annotations){ [gene({:attributes => [['ID', '1'],
['feature_type', 'tRNA'],
['product', 'tRNA-Gly']]})] }
it "should call the to_genbank_features method " do
subject.run.should == <<-EOS.unindent
@@ -112,7 +112,7 @@
describe "#create_encoded_features" do
let(:prefix) do
nil
true
end
subject do
@@ -143,10 +143,26 @@
end
describe "passed a gene with an ID attributes" do
let(:attributes) do
[['ID', 'something']]
end
let(:annotations) do
[gene({:attributes => attributes})]
end
it "should not change the attributes" do
subject.attributes.should == attributes
end
end
describe "passed a gene with a known feature_type attribute" do
let(:attributes) do
{'feature_type' => 'tRNA'}
[['feature_type', 'tRNA']]
end
let(:annotations) do
@@ -162,7 +178,7 @@
describe "passed a gene with an unknown feature_type attribute" do
let(:attributes) do
{'feature_type' => 'unknown'}
[['feature_type', 'unknown']]
end
let(:annotations) do
@@ -176,26 +192,42 @@
end
describe "passed a gene with a duplicate attribute" do
let(:attributes) do
[['product', 'abcd'],['product', 'efgh']]
end
let(:annotations) do
[gene({:attributes => attributes})]
end
it "should not change attributes" do
subject.should have_identical_attributes cds({:attributes => attributes})
end
end
describe "passed a gene with a Name attribute" do
let(:attributes) do
{'Name' => 'abcD'}
[['Name', 'abcD']]
end
let(:annotations) do
[gene({:attributes => attributes})]
end
it "should set the capitalise value to the product key" do
subject.should have_identical_attributes cds({:attributes => {'product' => 'AbcD'}})
subject.should have_identical_attributes cds({:attributes => [['product', 'AbcD']]})
end
end
describe "passed a gene with a product attribute" do
let(:attributes) do
{'product' => 'abcd'}
[['product', 'abcd']]
end
let(:annotations) do
@@ -211,7 +243,7 @@
describe "passed a gene with a function attribute" do
let(:attributes) do
{'function' => 'abcd'}
[['function', 'abcd']]
end
let(:annotations) do
@@ -227,7 +259,7 @@
describe "passed a gene with product and function attributes" do
let(:attributes) do
{'product' => 'abcd', 'function' => 'efgh'}
[['product', 'abcd'], ['function', 'efgh']]
end
let(:annotations) do
@@ -243,7 +275,7 @@
describe "passed a gene with Name and product attributes" do
let(:attributes) do
{'Name' => 'abcD','product' => 'efgh'}
[['Name', 'abcD'], ['product', 'efgh']]
end
let(:annotations) do
@@ -252,15 +284,15 @@
it "should map Name to product and product to function" do
subject.should have_identical_attributes cds({:attributes =>
{'product' => 'AbcD','function' => 'efgh'}})
[['product', 'AbcD'], ['function', 'efgh']]})
end
end
describe "passed a gene with Name, product and function attributes" do
let(:attributes) do
{'Name' => 'abcD','product' => 'efgh', 'function' => 'ijkl'}
[['Name', 'abcD'], ['product', 'efgh'], ['function', 'ijkl']]
end
let(:annotations) do
@@ -269,7 +301,7 @@
it "should map Name to product and product to function" do
subject.should have_identical_attributes cds({:attributes =>
{'product' => 'AbcD','function' => 'efgh'}})
[['product', 'AbcD'], ['function', 'efgh']]})
end
end
View
@@ -22,7 +22,7 @@ def gene(opts = Hash.new)
:start => 1,
:end => 3,
:feature => 'gene',
:attributes => Hash.new}
:attributes => Array.new}
Annotation.new(default.merge(opts)).to_gff3_record
end

0 comments on commit 7c3105d

Please sign in to comment.