Class: Bio::PhyloXML::Node

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

Overview

Description

Class to hold clade element of phyloXML.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



221
222
223
224
225
226
227
228
229
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 221

def initialize
  @confidences = []
  @sequences = []
  @taxonomies = []
  @distributions = []
  @references = []
  @properties = []
  @other = []
end

Instance Attribute Details

#binary_charactersObject

BinaryCharacters object. The names and/or counts of binary characters present, gained, and lost at the root of a clade.



203
204
205
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 203

def binary_characters
  @binary_characters
end

#colorObject

BranchColor object. Apply for the whole clade unless overwritten in sub-clade.



194
195
196
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 194

def color
  @color
end

#confidencesObject

Array of Confidence objects. Indicates the support for a clade/parent branch.



191
192
193
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 191

def confidences
  @confidences
end

#dateObject

Date object. A date associated with a clade/node.



209
210
211
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 209

def date
  @date
end

#distributionsObject

Array of Distribution objects. The geographic distribution of the items of a clade (species, sequences), intended for phylogeographic applications.



206
207
208
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 206

def distributions
  @distributions
end

#eventsObject

Events at the root node of a clade (e.g. one gene duplication).



172
173
174
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 172

def events
  @events
end

#id_sourceObject

String. Used to link other elements to a clade (node) (on the xml-level).



175
176
177
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 175

def id_source
  @id_source
end

#nameObject

String. Name of the node.



178
179
180
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 178

def name
  @name
end

#node_idObject

Id object



197
198
199
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 197

def node_id
  @node_id
end

#otherObject

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



219
220
221
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 219

def other
  @other
end

#propertiesObject

An array of Property objects, for example depth for sea animals.



215
216
217
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 215

def properties
  @properties
end

#referencesObject

Array of Reference objects. A literature reference for a clade.



212
213
214
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 212

def references
  @references
end

#sequencesObject

Array of Sequence objects. Represents a molecular sequence (Protein, DNA, RNA) associated with a node.



200
201
202
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 200

def sequences
  @sequences
end

#taxonomiesObject

Array of Taxonomy objects. Describes taxonomic information for a clade.



188
189
190
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 188

def taxonomies
  @taxonomies
end

#widthObject

Float. Branch width for this node (including parent branch). Applies for the whole clade unless overwritten in sub-clades.



181
182
183
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 181

def width
  @width
end

Instance Method Details

#extract_biosequence(seq_i = 0) ⇒ Object

Extracts the relevant information from node (specifically taxonomy and sequence) to create Bio::Sequence object. Node can have several sequences, so parameter to this method is to specify which sequence to extract.


Returns

Bio::Sequence



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 269

def extract_biosequence(seq_i=0)

  seq = @sequences[seq_i].to_biosequence
  seq.classification = []
  @taxonomies.each do |t|
    seq.classification << t.scientific_name
    if t.rank == "species"
      seq.species = t.scientific_name
    end
  end

  #seq.division => .. http://www.ebi.ac.uk/embl/Documentation/User_manual/usrman.html#3_2
  # It doesn't seem there is anything in PhyloXML corresponding to this.

  return seq
end

#to_biotreenodeObject

Converts to a Bio::Tree::Node object. If it contains several taxonomies Bio::Tree::Node#scientific name will get the scientific name of the first taxonomy.

If there are several confidence values, the first with bootstrap type will be returned as Bio::Tree::Node#bootstrap

tree = phyloxmlparser.next_tree

node = tree.get_node_by_name(“A”).to_biotreenode


Returns

Bio::Tree::Node



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 245

def to_biotreenode
  node = Bio::Tree::Node.new
  node.name = @name
  node.scientific_name = @taxonomies[0].scientific_name if not @taxonomies.empty?
  #@todo what if there are more?
  node.taxonomy_id = @taxonomies[0].taxononmy_id if @taxonomies[0] != nil

  if not @confidences.empty?
    @confidences.each do |confidence|
      if confidence.type == "bootstrap"
        node.bootstrap = confidence.value
        break
      end
    end
  end      
  return node
end

#to_xml(branch_length, write_branch_length_as_subelement) ⇒ Object

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



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/bio/db/phyloxml/phyloxml_elements.rb', line 287

def to_xml(branch_length,  write_branch_length_as_subelement)
  clade = LibXML::XML::Node.new('clade')
  
  PhyloXML::Writer.generate_xml(clade, self, [[:simple, 'name', @name]])

  if branch_length != nil       
    if write_branch_length_as_subelement
      clade << LibXML::XML::Node.new('branch_length', branch_length.to_s)
    else
      clade["branch_length"] = branch_length.to_s
    end
  end

  #generate all elements, except clade
  PhyloXML::Writer.generate_xml(clade, self, [
      [:attr, "id_source"],
      [:objarr, 'confidence', 'confidences'],
      [:simple, 'width', @width],
      [:complex, 'branch_color', @branch_color],
      [:simple, 'node_id', @node_id],
      [:objarr, 'taxonomy', 'taxonomies'],
      [:objarr, 'sequence', 'sequences'],
      [:complex, 'events', @events],
      [:complex, 'binary_characters', @binary_characters],          
      [:objarr, 'distribution', 'distributions'],
      [:complex, 'date', @date],          
      [:objarr, 'reference', 'references'],
      [:objarr, 'propery', 'properties']])
 
  return clade
end