class Bio::BioAlignment::Alignment
Attributes
rows[RW]
sequences[RW]
tree[R]
Public Class Methods
new(seqs = nil, ids = nil)
click to toggle source
Create alignment. seqs can be a list of sequences. If these are String types, they get converted to the library Sequence
container
# File lib/bio-alignment/alignment.rb, line 24 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
Public Instance Methods
<<(seq)
click to toggle source
# File lib/bio-alignment/alignment.rb, line 60 def << seq @sequences << seq end
[](index)
click to toggle source
Return a sequence by index
# File lib/bio-alignment/alignment.rb, line 56 def [] index rows[index] end
attach_tree(tree)
click to toggle source
extend BioAlignment
with Tree
functionality - this method adds a tree and pulls in the functionality of the Tree
module. Returns the tree traverser
# File lib/bio-alignment/alignment.rb, line 114 def attach_tree tree extend Tree @tree = Tree::init(tree,self) @tree end
clone()
click to toggle source
Return a deep cloned alignment. This method clones sequences, and the state objects
Calls superclass method
# File lib/bio-alignment/alignment.rb, line 98 def clone aln = super # clone the sequences aln.sequences = [] each do | seq | aln.sequences << seq.clone end aln.clone_columns! if @columns # clone the tree @tree = @tree.clone if @tree aln end
each() { |seq| ... }
click to toggle source
# File lib/bio-alignment/alignment.rb, line 64 def each rows.each { | seq | yield seq } self end
each_element() { |e| ... }
click to toggle source
# File lib/bio-alignment/alignment.rb, line 69 def each_element each { |seq| seq.each { |e| yield e }} self end
find(name)
click to toggle source
# File lib/bio-alignment/alignment.rb, line 74 def find name each do | seq | return seq if Coerce::fetch_id(seq) == name end raise "ERROR: Sequence not found by its name, looking for <#{name}>" end
ids()
click to toggle source
return an array of sequence ids
# File lib/bio-alignment/alignment.rb, line 47 def ids rows.map { |r| Coerce::fetch_id(r) } end
size()
click to toggle source
# File lib/bio-alignment/alignment.rb, line 51 def size rows.size end
to_bioruby_alignment()
click to toggle source
# File lib/bio-alignment/bioruby.rb, line 25 def to_bioruby_alignment Bio::Alignment.new(self) end
to_s()
click to toggle source
# File lib/bio-alignment/alignment.rb, line 88 def to_s res = "" res += "\t" + columns_to_s + "\n" if @columns # fetch each sequence in turn res += map{ |seq| Coerce::fetch_id(seq).to_s + "\t" + Coerce::fetch_seq_string(seq) }.join("\n") res end
tree_reduce(new_tree)
click to toggle source
Reduce an alignment, based on the new tree
# File lib/bio-alignment/alignment.rb, line 121 def tree_reduce new_tree names = new_tree.map { | node | node.name }.compact # p names nrows = [] names.each do | name | nrows << find(name).clone end new_aln = Alignment.new(nrows) new_aln.attach_tree(new_tree.clone) new_aln end
update_each_element() { |e| ... }
click to toggle source
copy alignment and allow updating elements. Returns alignment.
# File lib/bio-alignment/alignment.rb, line 82 def update_each_element aln = self.clone aln.each { |seq| seq.each_with_index { |e,i| seq.seq[i] = yield e }} aln end