Class: Taxonifi::Export::OboNomenclature

Inherits:
Base
  • Object
show all
Defined in:
lib/taxonifi/export/format/obo_nomenclature.rb

Overview

Writes a OBO formatted file for all names in a name collection. !! Does not write synonyms out. Follows the TTO example.

Constant Summary

Constants inherited from Base

Base::EXPORT_BASE, Base::TAXRANKS

Instance Attribute Summary collapse

Attributes inherited from Base

#base_export_path, #export_folder

Instance Method Summary collapse

Methods inherited from Base

#configure_folders, #export_path, #new_output_file, #sanitize, #sql_insert_statement, #sqlize, #write_file

Constructor Details

#initialize(options = {}) ⇒ OboNomenclature

Returns a new instance of OboNomenclature.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 11

def initialize(options = {})
  opts = {
    :nc => Taxonifi::Model::NameCollection.new,
    :export_folder => 'obo_nomenclature',
    :starting_id => 1,
    :namespace => 'XYZ'
  }.merge!(options)

  super(opts)
  raise Taxonifi::Export::ExportError, 'NameCollection not passed to OboNomenclature export.' if ! opts[:nc].class == Taxonifi::Model::NameCollection
  @name_collection = opts[:nc]
  @namespace = opts[:namespace]
  @time = Time.now.strftime("%D %T").gsub('/',":") 
  @empty_quotes = "" 
end

Instance Attribute Details

#name_collectionObject

Returns the value of attribute name_collection.



9
10
11
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 9

def name_collection
  @name_collection
end

#namespaceObject

Returns the value of attribute namespace.



9
10
11
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 9

def namespace
  @namespace
end

Instance Method Details

#exportObject

Writes the file.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 28

def export()
  super
  f = new_output_file('obo_nomenclature.obo') 
 
  # header 
  f.puts 'format-version: 1.2'
  f.puts "date: #{@time}"
  f.puts 'saved-by: someone'
  f.puts 'auto-generated-by: Taxonifi'
  f.puts 'synonymtypedef: COMMONNAME "common name"'
  f.puts 'synonymtypedef: MISSPELLING "misspelling" EXACT'
  f.puts 'synonymtypedef: TAXONNAMEUSAGE "name with (author year)" NARROW'
  f.puts "default-namespace: #{@namespace}"
  f.puts "ontology: FIX-ME-taxonifi-ontology\n\n" 

  # terms
  @name_collection.collection.each do |n|
    f.puts '[Term]'
    f.puts "id: #{id_string(n)}"
    f.puts "name: #{n.name}"
    f.puts "is_a: #{id_string(n.parent)} ! #{n.parent.name}" if n.parent
    f.puts "property_value: has_rank #{rank_string(n)}"
    f.puts
  end

  # typedefs
  f.puts "[Typedef]"
  f.puts "id: has_rank"
  f.puts "name: has taxonomic rank"
  f.puts "is_metadata_tag: true"

  true
end

#id_string(name) ⇒ Object



66
67
68
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 66

def id_string(name)
  "#{@namespace}:#{name.id.to_s.rjust(7,"0")}"
end

#rank_string(name) ⇒ Object



62
63
64
# File 'lib/taxonifi/export/format/obo_nomenclature.rb', line 62

def rank_string(name)    
  "TAXRANK:#{TAXRANKS[name.rank].to_s.rjust(7,"0")}"
end