module Bio::Alignment::HashExtension
Bio::Alignment::HashExtension is a set of useful methods for multiple sequence alignment. It is designed to be extended to hash objects or included in your own classes which inherit Hash. (It can also be included in Hash, though not recommended.)
It possesses all methods defined in EnumerableExtension. For usage of methods, please refer to EnumerableExtension.
Because #alignment_collect is redefined, some methods' return value's class are changed to SequenceHash instead of SequenceArray.
Because the order of the objects in a hash is inconstant, some methods strictly affected with the order of objects might not work correctly, e.g. Bio::Alignment::EnumerableExtension#convert_match and convert_unmatch.
Public Instance Methods
Iterates over each sequence and each results running block are collected and returns a new alignment as a Bio::Alignment::SequenceHash object.
Note that it would be redefined if you want to change return value's class.
# File lib/bio/alignment.rb, line 1390 def alignment_collect a = SequenceHash.new a.set_all_property(get_all_property) each_pair do |key, str| a.store(key, yield(str)) end a end
Concatenates the given alignment. If align is a Hash (or SequenceHash), sequences of same keys are
concatenated. Otherwise, align must have each_seq
or
each
method and works same as Bio::Alignment::EnumerableExtension#alignment_concat.
Returns self.
Note that it is a destructive method.
# File lib/bio/alignment.rb, line 1410 def alignment_concat(align) flag = nil begin align.each_pair do |key, seq| flag = true if origseq = self[key] origseq.concat(seq) end end return self rescue NoMethodError, ArgumentError =>evar raise evar if flag end a = values i = 0 begin align.each_seq do |seq| flag = true a[i].concat(seq) if a[i] and seq i += 1 end return self rescue NoMethodError, ArgumentError => evar raise evar if flag end align.each do |seq| a[i].concat(seq) if a[i] and seq i += 1 end self end
Iterates over each sequences. Yields a sequence.
It works the same as Hash#each_value.
# File lib/bio/alignment.rb, line 1378 def each_seq #:yields: seq #each_value(&block) each_key { |k| yield self[k] } end
Returns number of sequences in this alignment.
# File lib/bio/alignment.rb, line 1443 def number_of_sequences self.size end
Returns an array of sequence names. The order of the names must be the same
as the order of each_seq
.
# File lib/bio/alignment.rb, line 1450 def sequence_names self.keys end