Class: Bio::PhyloXML::Sequence

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

Overview

Description

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSequence

Returns a new instance of Sequence.



545
546
547
548
# File 'lib/bio/phyloxml/elements.rb', line 545

def initialize
  @annotations = []
  @other = []
end

Instance Attribute Details

#accessionObject

Accession object. Holds source and identifier for the sequence.



522
523
524
# File 'lib/bio/phyloxml/elements.rb', line 522

def accession
  @accession
end

#annotationsObject

Array of Annotation objects. Annotations of molecular sequence.



537
538
539
# File 'lib/bio/phyloxml/elements.rb', line 537

def annotations
  @annotations
end

#domain_architectureObject

DomainArchitecture object. Describes domain architecture of a protein.



539
540
541
# File 'lib/bio/phyloxml/elements.rb', line 539

def domain_architecture
  @domain_architecture
end

#id_refObject

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.



517
518
519
# File 'lib/bio/phyloxml/elements.rb', line 517

def id_ref
  @id_ref
end

#id_sourceObject

String. Used to link with other elements.



513
514
515
# File 'lib/bio/phyloxml/elements.rb', line 513

def id_source
  @id_source
end

#is_alignedObject

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)



532
533
534
# File 'lib/bio/phyloxml/elements.rb', line 532

def is_aligned
  @is_aligned
end

#locationObject

String. Location of a sequence on a genome/chromosome



524
525
526
# File 'lib/bio/phyloxml/elements.rb', line 524

def location
  @location
end

#mol_seqObject

String. The actual sequence is stored here.



526
527
528
# File 'lib/bio/phyloxml/elements.rb', line 526

def mol_seq
  @mol_seq
end

#nameObject

Full name (e.g. muscle Actin )



510
511
512
# File 'lib/bio/phyloxml/elements.rb', line 510

def name
  @name
end

#otherObject

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



543
544
545
# File 'lib/bio/phyloxml/elements.rb', line 543

def other
  @other
end

#symbolObject

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



520
521
522
# File 'lib/bio/phyloxml/elements.rb', line 520

def symbol
  @symbol
end

#typeObject

Type of sequence (rna, dna, protein)



507
508
509
# File 'lib/bio/phyloxml/elements.rb', line 507

def type
  @type
end

#uriObject

Uri object



535
536
537
# File 'lib/bio/phyloxml/elements.rb', line 535

def uri
  @uri
end

Instance Method Details

#is_aligned?Boolean

Returns:

  • (Boolean)


560
561
562
# File 'lib/bio/phyloxml/elements.rb', line 560

def is_aligned?
  @is_aligned
end

#to_biosequenceObject

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


Returns

Bio::Sequence



611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/bio/phyloxml/elements.rb', line 611

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 @uri != nil
    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_xmlObject

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



573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# File 'lib/bio/phyloxml/elements.rb', line 573

def to_xml
  
  seq = LibXML::XML::Node.new('sequence')
  if @type != nil
    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', @symbol, Regexp.new("^\\S{1,10}$")],
      [:complex, 'accession', @accession],
      [:simple, 'name', @name],
      [:simple, 'location', @location]])

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

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