Permalink
Browse files

Merge branch 'develop' into feature/dbxref

Conflicts:
	features/table/cds_entries.feature
	lib/genomer-plugin-view/gff_record_helper.rb
	spec/genomer-view-plugin/gff_record_helper_spec.rb

Signed-off-by: Michael Barton <mail@michaelbarton.me.uk>
  • Loading branch information...
michaelbarton committed Mar 4, 2013
2 parents 051daea + 7c3105d commit 8deed8a77e7645aed1f02222c2f12f721347f8cc
@@ -374,6 +374,4 @@ Feature: Producing cds annotation view from a scaffold
protein_id gene1
db_xref GO:000001
db_xref InterPro:IPR000111
"""
@@ -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,35 +199,35 @@
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',
'db_xref' => 'db_xref',
'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'],
['db_xref', 'db_xref'],
['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
@@ -69,30 +69,11 @@
end
describe "with one gene annotation and the CDS flag and dbxref attributes" do
let(:flags){ {:generate_encoded_features => true} }
let(:annotations){ [gene({:attributes => {'db_xref' => 'ref1',
'db_xref' => 'ref2'}})] }
it "should call the to_genbank_features method " do
subject.run.should == <<-EOS.unindent
>Feature\t\tannotation_table
1\t3\tgene
1\t3\tCDS
\t\t\tdb_xref\tref1
\t\t\tdb_xref\tref2
EOS
end
end
describe "with one gene annotation and the CDS prefix flag" do
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
@@ -110,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
@@ -131,7 +112,7 @@
describe "#create_encoded_features" do
let(:prefix) do
nil
true
end
subject do
@@ -162,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
@@ -181,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
@@ -195,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
@@ -230,7 +243,7 @@
describe "passed a gene with a function attribute" do
let(:attributes) do
{'function' => 'abcd'}
[['function', 'abcd']]
end
let(:annotations) do
@@ -246,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
@@ -262,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
@@ -271,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
@@ -288,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
@@ -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 8deed8a

Please sign in to comment.