class Bio::PhyloXML::Sequence

Description

Element Sequence is used to represent a molecular sequence (Protein, DNA, RNA) associated with a node.

Attributes

accession[RW]

Accession object. Holds source and identifier for the sequence.

annotations[RW]

Array of Annotation objects. Annotations of molecular sequence.

domain_architecture[RW]

DomainArchitecture object. Describes domain architecture of a protein.

id_ref[RW]

String. One intended use for 'id_ref' is to link a sequence to a taxonomy (via the taxonomy's 'id_source') in the case of multiple sequences and taxonomies per node.

id_source[RW]

String. Used to link with other elements.

is_aligned[R]

Boolean. used to indicated that this molecular sequence is aligned with all other sequences in the same phylogeny for which 'is aligned' is true as well (which, in most cases, means that gaps were introduced, and that all sequences for which 'is aligned' is true must have the same length)

location[RW]

String. Location of a sequence on a genome/chromosome

mol_seq[R]

String. The actual sequence is stored here.

name[RW]

Full name (e.g. muscle Actin )

other[RW]

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

symbol[RW]

short (maximal ten characters) symbol of the sequence (e.g. 'ACTM')

type[RW]

Type of sequence (rna, dna, protein)

uri[RW]

Uri object

Public Class Methods

new() click to toggle source
# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 562
def initialize
  @annotations = []
  @other = []
end

Public Instance Methods

is_aligned=(str) click to toggle source
# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 567
def is_aligned=(str)
  if str=='true'
    @is_aligned=true
  elsif str=='false'
    @is_aligned = false
  else
    @is_aligned = nil
  end
end
is_aligned?() click to toggle source
# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 577
def is_aligned?
  @is_aligned
end
mol_seq=(str) click to toggle source
# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 581
def mol_seq=(str)
  if str =~ /^[a-zA-Z\.\-\?\*_]+$/
    @mol_seq = str
  else
    raise "mol_seq element of Sequence does not follow the pattern."
  end
end
to_biosequence() click to toggle source

converts Bio::PhyloXML:Sequence to Bio::Sequence object.


Returns

Bio::Sequence

# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 628
def to_biosequence
  #type is not a required attribute in phyloxml (nor any other Sequence
  #element) it might not hold any value, so we will not check what type it is.
  seq = Bio::Sequence.auto(@mol_seq)

  seq.id_namespace = @accession.source
  seq.entry_id = @accession.value
  # seq.primary_accession = @accession.value could be this
  seq.definition = @name
  #seq.comments = @name //this one?
  if (defined? @uri) && @uri
    h = {'url' => @uri.uri,
      'title' => @uri.desc }
    ref = Bio::Reference.new(h)
    seq.references << ref
  end
  seq.molecule_type = 'RNA' if @type == 'rna'
  seq.molecule_type = 'DNA' if @type == 'dna'

  #@todo deal with the properties. There might be properties which look
  #like bio sequence attributes or features
  return seq
end
to_xml() click to toggle source

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

# File lib/bio/db/phyloxml/phyloxml_elements.rb, line 590
def to_xml
  
  seq = LibXML::XML::Node.new('sequence')
  if (defined? @type) && @type
    if ["dna", "rna", "protein"].include?(@type)
      seq["type"] = @type
    else 
      raise "Type attribute of Sequence has to be one of dna, rna or a."
    end
  end
  
  PhyloXML::Writer.generate_xml(seq, self, [
      [:attr, 'id_source'],
      [:attr, 'id_ref'],
      [:pattern, 'symbol', (defined? @symbol) ? @symbol : nil, Regexp.new("^\\S{1,10}$")],
      [:complex, 'accession', (defined? @accession) ? @accession : nil],
      [:simple, 'name', (defined? @name) ? @name : nil],
      [:simple, 'location', (defined? @location) ? @location : nil]])

  if (defined? @mol_seq) && @mol_seq
    molseq = LibXML::XML::Node.new('mol_seq', @mol_seq)
    molseq["is_aligned"] = @is_aligned.to_s if (defined? @is_aligned) && @is_aligned != nil
    seq << molseq
  end

  PhyloXML::Writer.generate_xml(seq, self, [
      #[:pattern, 'mol_seq', @mol_seq, Regexp.new("^[a-zA-Z\.\-\?\*_]+$")],
      [:complex, 'uri', (defined? @uri) ? @uri : nil],
      [:objarr, 'annotation', 'annotations'],
      [:complex, 'domain_architecture', (defined? @domain_architecture) ? @domain_architecture : nil]])
      #@todo test domain_architecture
  #any
  return seq
end