Class: Bio::PhyloXML::Taxonomy

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-phyloxml/phyloxml_elements.rb

Overview

Taxonomy class for PhyloXML

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTaxonomy

creates a new Bio::PhyloXML::Taxonomy object.



56
57
58
59
60
61
62
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 56

def initialize
  @common_names = []
  @synonyms = []

  # below attributes may be PhyloXML specific.
  @other = []
end

Instance Attribute Details

#authorityObject

is used to keep the authority, such as ‘J. G. Cooper, 1863’, associated with the ‘scientific_name’.



50
51
52
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 50

def authority
  @authority
end

#codeObject

pattern = [a-zA-Z0-9_]2,10 Can refer to any code/abbreviation/mnemonic, such as Bsu for Bacillus subtilis.



32
33
34
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 32

def code
  @code
end

#common_namesObject

An array of strings



37
38
39
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 37

def common_names
  @common_names
end

#id_sourceObject

Used to link other elements to a taxonomy (on the xml-level)



71
72
73
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 71

def id_source
  @id_source
end

#otherObject

Array of Other objects. Used to save additional information from other than PhyloXML namspace.



77
78
79
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 77

def other
  @other
end

#rankObject

value comes from list: domain kingdom, subkingdom, branch, infrakingdom, superphylum, phylum, subphylum, infraphylum, microphylum, superdivision, division, subdivision, infradivision, superclass, class, subclass, infraclass, superlegion, legion, sublegion, infralegion, supercohort, cohort, subcohort, infracohort, superorder, order, suborder, superfamily, family, subfamily, supertribe, tribe, subtribe, infratribe, genus, subgenus, superspecies, species, subspecies, variety, subvariety, form, subform, cultivar, unknown, other



47
48
49
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 47

def rank
  @rank
end

#scientific_nameObject

String.



35
36
37
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 35

def scientific_name
  @scientific_name
end

#synonymsObject

An array of strings. Holds synonyms for scientific names or common names.



53
54
55
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 53

def synonyms
  @synonyms
end

#taxonomy_idObject

String. Unique identifier of a taxon.



69
70
71
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 69

def taxonomy_id
  @taxonomy_id
end

#uriObject

Uri object



73
74
75
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 73

def uri
  @uri
end

Instance Method Details

#to_xmlObject

Converts elements to xml representation. Called by PhyloXML::Writer class.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bio-phyloxml/phyloxml_elements.rb', line 80

def to_xml
  taxonomy = LibXML::XML::Node.new('taxonomy')
  taxonomy["type"] = @type if (defined? @type) && @type
  taxonomy["id_source"] = @id_source if (defined? @id_source) && @id_source

  PhyloXML::Writer.generate_xml(taxonomy, self, [[:complex, 'id', (defined? @taxonomy_id) ? @taxonomy_id : nil],
    [:pattern, 'code', (defined? @code) ? @code : nil, Regexp.new("^[a-zA-Z0-9_]{2,10}$")],
    [:simple, 'scientific_name', (defined? @scientific_name) ? @scientific_name : nil],
    [:simple, 'authority', (defined? @authority) ? @authority : nil],
    [:simplearr, 'common_name', (defined? @common_names) ? @common_names : nil],
    [:simplearr, 'synonym', (defined? @synonyms) ? @synonyms : nil],
    [:simple, 'rank', (defined? @rank) ? @rank : nil],
    [:complex, 'uri',(defined? @uri) ? @uri : nil]])
    #@todo anything else


  return taxonomy
end