Permalink
Browse files

Merge branch 'release/0.0.6'

  • Loading branch information...
2 parents 0841433 + 5c1ebb9 commit 3031e3f0c2fe6c09a91cd4462eaca56c5d6f82c5 @michaelbarton committed Mar 11, 2013
View
@@ -10,3 +10,19 @@ Feature: Producing different views of a genomes scaffold
Then the exit status should be 0
And the output should contain a valid man page
And the output should contain "GENOMER-VIEW(1)"
+
+ @disable-bundler
+ Scenario: Running `genomer view` without a subcommand
+ Given I create a new genomer project
+ When I run `genomer view`
+ Then the exit status should be 0
+ And the output should contain:
+ """
+ Run `genomer man view COMMAND` to review available formats
+ Where COMMAND is one of the following:
+ agp
+ fasta
+ gff
+ mapping
+ table
+ """
@@ -302,3 +302,76 @@ Feature: Producing cds annotation view from a scaffold
"""
+ @disable-bundler
+ Scenario: A CDS entry with a single DBxref attribute
+ 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;DBxref=GO:000001
+ """
+ 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
+ db_xref GO:000001
+
+ """
+
+ @disable-bundler
+ Scenario: A CDS entry with multiple DBxref 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;DBxref=GO:000001;DBxref=InterPro:IPR000111
+ """
+ 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
+ db_xref GO:000001
+ db_xref InterPro:IPR000111
+ """
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
s.name = "genomer-plugin-view"
s.version = GenomerViewPlugin::VERSION
s.platform = Gem::Platform::RUBY
- s.homepage = "http://github.com/michaelbarton/genomer-plugin-view"
+ s.homepage = "http://next.gs"
s.license = "MIT"
s.authors = ["Michael Barton"]
s.email = ["mail@michaelbarton.me.uk"]
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = "~> 1.8.0"
s.rubyforge_project = "genomer-view-plugin"
- s.add_dependency "genomer", ">= 0.0.6"
+ s.add_dependency "genomer", ">= 0.0.10"
# Specs
s.add_development_dependency "rspec", "~> 2.9.0"
View
@@ -3,6 +3,7 @@
class GenomerPluginView < Genomer::Plugin
def run
+ return help if arguments.empty?
self.class.fetch_view(arguments.shift).new(arguments,flags).run
end
@@ -26,4 +27,19 @@ def self.convert_command_line_flags(flags)
end
end
+ def help
+ message = <<-STRING.unindent
+ Run `genomer man view COMMAND` to review available formats
+ Where COMMAND is one of the following:
+ STRING
+
+ message + Dir[File.dirname(__FILE__) + '/genomer-plugin-view/*.rb'].
+ map{|f| File.basename(f).gsub('.rb','')}.
+ delete_if{|i| i == 'version'}.
+ delete_if{|i| i == 'gff_record_helper'}.
+ sort.
+ map{|i| " " * 2 + i}.
+ join("\n") + "\n"
+ end
+
end
@@ -2,8 +2,7 @@
module GenomerPluginView::GffRecordHelper
-
- DEFAULT_GFF_MAPPING = {'product' => 'product', 'Note' => 'note' }
+ DEFAULT_GFF_MAPPING = {'product' => 'product', 'Note' => 'note', 'DBxref' => 'db_xref'}
GFF_TO_TABLE = {
'gene' => {
@@ -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
@@ -1,3 +1,3 @@
class GenomerViewPlugin
- VERSION = "0.0.5"
+ VERSION = "0.0.6"
end
View
@@ -68,6 +68,10 @@ begin with an upper case letter.
Used to populate the **Note** field for entries when the
`--generate_encoded_features` option is passed.
+ * `DBxref`: Used to link the annotation to other database references. This
+ field is added verbatim to generated output. Multiple entires of this
+ field may be used.
+
### GENOMER ATTRIBUTES
These attributes are specific to genomer and should begin with a lower case
@@ -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,38 @@
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 => [
+ ['DBxref', 'db_xref'],
+ ['product', 'product'],
+ ['Note', 'note']],
+ :rRNA => [
+ ['product', 'product'],
+ ['Note', 'note']],
+ :miscRNA => [
+ ['DBxref', 'db_xref'],
+ ['product', 'product'],
+ ['Note', 'note']],
+ :tmRNA => [
+ ['DBxref', 'db_xref'],
+ ['product', 'product'],
+ ['Note', 'note']],
+ :CDS => [
+ ['ec_number', 'EC_number'],
+ ['DBxref', '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
@@ -238,7 +242,6 @@
end
end
-
end
end
Oops, something went wrong.

0 comments on commit 3031e3f

Please sign in to comment.