Class: Bio::NeXML::Nexml

Inherits:
Object
  • Object
show all
Includes:
Mapper, Enumerable
Defined in:
lib/bio/db/nexml.rb

Overview

end module Base

Constant Summary collapse

@@writer =
Bio::NeXML::Writer.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mapper

#properties

Constructor Details

#initialize(version = '0.9', generator = 'bioruby') ⇒ Nexml

Returns a new instance of Nexml.



39
40
41
42
# File 'lib/bio/db/nexml.rb', line 39

def initialize( version = '0.9', generator = 'bioruby' )
  @version = version
  @generator = generator
end

Instance Attribute Details

#generatorObject

Returns the value of attribute generator.



33
34
35
# File 'lib/bio/db/nexml.rb', line 33

def generator
  @generator
end

#versionObject

Returns the value of attribute version.



32
33
34
# File 'lib/bio/db/nexml.rb', line 32

def version
  @version
end

Instance Method Details

#<<(element) ⇒ Object

Append a Otus, Trees, or Characters object to any Nexml object.



46
47
48
49
50
51
52
53
54
55
# File 'lib/bio/db/nexml.rb', line 46

def <<( element )
  case element
  when Otus
    add_otus element
  when Trees
    add_trees element
  when Characters
    add_characters element
  end
end

#create_characters(type = "Dna", verbose = false, options = {}) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/bio/db/nexml.rb', line 69

def create_characters( type = "Dna", verbose = false, options = {} )
  subtype = verbose ? "Cells" : "Seqs"
  klass_name = "#{type.to_s.capitalize}#{subtype}"
  klass = NeXML.const_get( klass_name )
  characters = klass.new( Bio::NeXML.generate_id( klass ), options )
  self << characters
  characters
end

#create_otus(options = {}) ⇒ Object



57
58
59
60
61
# File 'lib/bio/db/nexml.rb', line 57

def create_otus( options = {} )
  otus = Otus.new( Bio::NeXML.generate_id( Otus ), options )
  self << otus
  otus        
end

#create_trees(options) ⇒ Object



63
64
65
66
67
# File 'lib/bio/db/nexml.rb', line 63

def create_trees( options )
  trees = Trees.new( Bio::NeXML.generate_id( Trees ), options )
  self << trees
  trees
end

#to_xmlObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/bio/db/nexml.rb', line 78

def to_xml
  node = @@writer.create_node( "nex:nexml", :"xsi:schemaLocation" => "http://www.nexml.org/2009 http://www.nexml.org/2009/xsd/nexml.xsd", :generator => generator, :version => version )
  node.namespaces = { nil => "http://www.nexml.org/2009", :xsi => "http://www.w3.org/2001/XMLSchema-instance", :xlink => "http://www.w3.org/1999/xlink", :nex => "http://www.nexml.org/2009" }
  self.each_otus do |otus|
      node << otus.to_xml
  end
  self.each_characters do |characters|
      node << characters.to_xml
  end
  self.each_trees do |trees|
      node << trees.to_xml
  end        
  node
end