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 protein_id gene1
db_xref GO:000001 db_xref GO:000001
db_xref InterPro:IPR000111 db_xref InterPro:IPR000111
""" """
@@ -21,33 +21,37 @@ def run
def create_encoded_features(genes,prefix) def create_encoded_features(genes,prefix)
features = genes.map do |gene| features = genes.map do |gene|
feature = gene.clone feature = gene.clone
attrs = Hash[feature.attributes] attrs = feature.attributes.clone
if id = attrs['ID'] feature_type = attrs.detect{|k,v| k == 'feature_type'}
attrs['ID'] = (prefix.is_a?(String) ? prefix + id : id) feature.feature = (feature_type ? feature_type.last : 'CDS')
end
feature.feature = attrs['feature_type'] || 'CDS'
unless SUPPORTED_FEATURE_TYPES.include?(feature.feature) unless SUPPORTED_FEATURE_TYPES.include?(feature.feature)
raise Genomer::Error, "Unknown feature_type '#{feature.feature}'" raise Genomer::Error, "Unknown feature_type '#{feature.feature}'"
end end
attrs.map! do |(k,v)|
v = (k == 'ID' && prefix.instance_of?(String) ? prefix + v : v)
[k,v]
end
if feature.feature == "CDS" if feature.feature == "CDS"
name, prdt, ftn = attrs['Name'], attrs['product'], attrs['function']
if name if attrs.detect{|(k,v)| k == 'Name' }
name = name.clone attrs.map! do |(k,v)|
name[0,1] = name[0,1].upcase v = v.clone
prdt, ftn = name,prdt v[0,1] = v[0,1].upcase if k == 'Name'
end
attrs.delete('Name') v = nil if k == 'function'
attrs['product'] = prdt k = 'function' if k == 'product'
attrs['function'] = ftn k = 'product' if k == 'Name'
[k,v]
end
end
#attrs.delete('Name')
end end
feature.attributes = attrs.to_a.reject{|(_,value)| value.nil? } feature.attributes = attrs.reject{|(_,value)| value.nil? }
feature feature
end end
genes.zip(features).flatten genes.zip(features).flatten
@@ -68,7 +68,7 @@
context "gene feature with attributes" do context "gene feature with attributes" do
let(:annotation) do let(:annotation) do
@attn.feature('gene').attributes('ID' => 'id') @attn.feature('gene').attributes([['ID', 'id']])
end end
it "should return a table entry" do it "should return a table entry" do
@@ -189,7 +189,7 @@
context "for a feature with an unknown attribute" do context "for a feature with an unknown attribute" do
let(:annotation) do let(:annotation) do
@attn.attributes('something' => 'else') @attn.attributes([['something','else']])
end end
it "should return an empty array" do it "should return an empty array" do
@@ -199,35 +199,35 @@
end end
feature_keys = { feature_keys = {
:gene => { :gene => [
'Name' => 'gene', ['Name', 'gene'],
'ID' => 'locus_tag' }, ['ID', 'locus_tag']],
:tRNA => { :tRNA => [
'product' => 'product', ['product', 'product'],
'Note' => 'note'}, ['Note', 'note']],
:rRNA => { :rRNA => [
'product' => 'product', ['product', 'product'],
'Note' => 'note'}, ['Note', 'note']],
:miscRNA => { :miscRNA => [
'product' => 'product', ['product', 'product'],
'Note' => 'note'}, ['Note', 'note']],
:tmRNA => { :tmRNA => [
'product' => 'product', ['product', 'product'],
'Note' => 'note'}, ['Note', 'note']],
:CDS => { :CDS => [
'ec_number' => 'EC_number', ['ec_number', 'EC_number'],
'function' => 'function', ['db_xref', 'db_xref'],
'db_xref' => 'db_xref', ['function', 'function'],
'product' => 'product', ['product', 'product'],
'Note' => 'note', ['Note', 'note'],
'ID' => 'protein_id' }} ['ID', 'protein_id' ]]}
feature_keys.each do |type,mappings| feature_keys.each do |type,mappings|
mappings.each do |a,b| mappings.each do |a,b|
context "#{type.to_s} feature" do context "#{type.to_s} feature" do
let(:annotation) do let(:annotation) do
@attn.feature(type.to_s).attributes(a => :value) @attn.feature(type.to_s).attributes([[a, :value]])
end end
it "should return #{b} for the attribute #{a}" do it "should return #{b} for the attribute #{a}" do
@@ -69,30 +69,11 @@
end 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 describe "with one gene annotation and the CDS prefix flag" do
let(:flags){ {:generate_encoded_features => 'pre_'} } 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 it "should call the to_genbank_features method " do
subject.run.should == <<-EOS.unindent subject.run.should == <<-EOS.unindent
@@ -110,9 +91,9 @@
let(:flags){ {:generate_encoded_features => 'pre_'} } let(:flags){ {:generate_encoded_features => 'pre_'} }
let(:annotations){ [gene({:attributes => {'ID' => '1', let(:annotations){ [gene({:attributes => [['ID', '1'],
'feature_type' => 'tRNA', ['feature_type', 'tRNA'],
'product' => 'tRNA-Gly'}})] } ['product', 'tRNA-Gly']]})] }
it "should call the to_genbank_features method " do it "should call the to_genbank_features method " do
subject.run.should == <<-EOS.unindent subject.run.should == <<-EOS.unindent
@@ -131,7 +112,7 @@
describe "#create_encoded_features" do describe "#create_encoded_features" do
let(:prefix) do let(:prefix) do
nil true
end end
subject do subject do
@@ -162,10 +143,26 @@
end 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 describe "passed a gene with a known feature_type attribute" do
let(:attributes) do let(:attributes) do
{'feature_type' => 'tRNA'} [['feature_type', 'tRNA']]
end end
let(:annotations) do let(:annotations) do
@@ -181,7 +178,7 @@
describe "passed a gene with an unknown feature_type attribute" do describe "passed a gene with an unknown feature_type attribute" do
let(:attributes) do let(:attributes) do
{'feature_type' => 'unknown'} [['feature_type', 'unknown']]
end end
let(:annotations) do let(:annotations) do
@@ -195,26 +192,42 @@
end 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 describe "passed a gene with a Name attribute" do
let(:attributes) do let(:attributes) do
{'Name' => 'abcD'} [['Name', 'abcD']]
end end
let(:annotations) do let(:annotations) do
[gene({:attributes => attributes})] [gene({:attributes => attributes})]
end end
it "should set the capitalise value to the product key" do 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
end end
describe "passed a gene with a product attribute" do describe "passed a gene with a product attribute" do
let(:attributes) do let(:attributes) do
{'product' => 'abcd'} [['product', 'abcd']]
end end
let(:annotations) do let(:annotations) do
@@ -230,7 +243,7 @@
describe "passed a gene with a function attribute" do describe "passed a gene with a function attribute" do
let(:attributes) do let(:attributes) do
{'function' => 'abcd'} [['function', 'abcd']]
end end
let(:annotations) do let(:annotations) do
@@ -246,7 +259,7 @@
describe "passed a gene with product and function attributes" do describe "passed a gene with product and function attributes" do
let(:attributes) do let(:attributes) do
{'product' => 'abcd', 'function' => 'efgh'} [['product', 'abcd'], ['function', 'efgh']]
end end
let(:annotations) do let(:annotations) do
@@ -262,7 +275,7 @@
describe "passed a gene with Name and product attributes" do describe "passed a gene with Name and product attributes" do
let(:attributes) do let(:attributes) do
{'Name' => 'abcD','product' => 'efgh'} [['Name', 'abcD'], ['product', 'efgh']]
end end
let(:annotations) do let(:annotations) do
@@ -271,15 +284,15 @@
it "should map Name to product and product to function" do it "should map Name to product and product to function" do
subject.should have_identical_attributes cds({:attributes => subject.should have_identical_attributes cds({:attributes =>
{'product' => 'AbcD','function' => 'efgh'}}) [['product', 'AbcD'], ['function', 'efgh']]})
end end
end end
describe "passed a gene with Name, product and function attributes" do describe "passed a gene with Name, product and function attributes" do
let(:attributes) do let(:attributes) do
{'Name' => 'abcD','product' => 'efgh', 'function' => 'ijkl'} [['Name', 'abcD'], ['product', 'efgh'], ['function', 'ijkl']]
end end
let(:annotations) do let(:annotations) do
@@ -288,7 +301,7 @@
it "should map Name to product and product to function" do it "should map Name to product and product to function" do
subject.should have_identical_attributes cds({:attributes => subject.should have_identical_attributes cds({:attributes =>
{'product' => 'AbcD','function' => 'efgh'}}) [['product', 'AbcD'], ['function', 'efgh']]})
end end
end end
View
@@ -22,7 +22,7 @@ def gene(opts = Hash.new)
:start => 1, :start => 1,
:end => 3, :end => 3,
:feature => 'gene', :feature => 'gene',
:attributes => Hash.new} :attributes => Array.new}
Annotation.new(default.merge(opts)).to_gff3_record Annotation.new(default.merge(opts)).to_gff3_record
end end

0 comments on commit 8deed8a

Please sign in to comment.