Class: Bio::BioAlignment::Alignment
- Inherits:
-
Object
- Object
- Bio::BioAlignment::Alignment
- Defined in:
- lib/bio-alignment/bioruby.rb,
lib/bio-alignment/alignment.rb
Instance Attribute Summary collapse
-
#sequences ⇒ Object
(also: #rows)
Returns the value of attribute sequences.
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#attach_tree(tree) ⇒ Object
extend BioAlignment with Tree functionality - this method adds a tree and pulls in the functionality of the Tree module.
-
#clone ⇒ Object
Return a deep cloned alignment.
- #each ⇒ Object
- #each_element ⇒ Object
- #find(name) ⇒ Object
-
#initialize(seqs = nil, ids = nil) ⇒ Alignment
constructor
Create alignment.
- #to_bioruby_alignment ⇒ Object
- #to_s ⇒ Object
-
#update_each_element ⇒ Object
clopy alignment and allow updating elements.
Methods included from Columns
#clone_columns!, #columns, #columns_to_s, #columns_where, #num_columns
Methods included from Rows
Methods included from Pal2Nal
Constructor Details
#initialize(seqs = nil, ids = nil) ⇒ Alignment
Create alignment. seqs can be a list of sequences. If these are String types, they get converted to the library Sequence container
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bio-alignment/alignment.rb', line 22 def initialize seqs = nil, ids = nil @sequences = [] if seqs num = 0 seqs.each_with_index do | seq, i | next if seq == nil or seq.to_s.strip == "" id = num id = ids[i] if ids and ids[i] @sequences << if seq.kind_of?(String) seq1 = Sequence.new(id,seq.strip) seq1 else seq end num += 1 end end end |
Instance Attribute Details
#sequences ⇒ Object Also known as: rows
Returns the value of attribute sequences.
17 18 19 |
# File 'lib/bio-alignment/alignment.rb', line 17 def sequences @sequences end |
Instance Method Details
#[](index) ⇒ Object
44 45 46 |
# File 'lib/bio-alignment/alignment.rb', line 44 def [] index rows[index] end |
#attach_tree(tree) ⇒ Object
extend BioAlignment with Tree functionality - this method adds a tree and pulls in the functionality of the Tree module. Returns the tree traverser
94 95 96 97 98 |
# File 'lib/bio-alignment/alignment.rb', line 94 def attach_tree tree extend Tree @tree = Tree::init(tree) @tree end |
#clone ⇒ Object
Return a deep cloned alignment. This method clones sequences, and the state objects
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bio-alignment/alignment.rb', line 80 def clone aln = super # clone the sequences aln.sequences = [] each do | seq | aln.sequences << seq.clone end aln.clone_columns! if @columns aln end |
#each ⇒ Object
48 49 50 51 |
# File 'lib/bio-alignment/alignment.rb', line 48 def each rows.each { | seq | yield seq } self end |
#each_element ⇒ Object
53 54 55 56 |
# File 'lib/bio-alignment/alignment.rb', line 53 def each_element each { |seq| seq.each { |e| yield e }} self end |
#find(name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/bio-alignment/alignment.rb', line 58 def find name each do | seq | return seq if seq.id == name end raise "ERROR: Sequence not found by its name #{name}" end |
#to_bioruby_alignment ⇒ Object
25 26 27 |
# File 'lib/bio-alignment/bioruby.rb', line 25 def to_bioruby_alignment Bio::Alignment.new(self) end |
#to_s ⇒ Object
71 72 73 74 75 76 |
# File 'lib/bio-alignment/alignment.rb', line 71 def to_s res = "" res += "\t" + columns_to_s + "\n" if @columns res += map{ |seq| seq.id.to_s + "\t" + seq.to_s }.join("\n") res end |
#update_each_element ⇒ Object
clopy alignment and allow updating elements
66 67 68 69 |
# File 'lib/bio-alignment/alignment.rb', line 66 def update_each_element aln = self.clone aln.each { |seq| seq.each_with_index { |e,i| seq.seq[i] = yield e }} end |