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 SequenceHash#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. EnumerableExtension#convert_match and convert_unmatch.

Public Instance Methods

alignment_collect() { |str| ... } click to toggle source

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
1390 def alignment_collect
1391   a =
1392   a.set_all_property(get_all_property)
1393   each_pair do |key, str|
1394, yield(str))
1395   end
1396   a
1397 end
alignment_concat(align) click to toggle source

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 EnumerableExtension#alignment_concat.

Returns self.

Note that it is a destructive method.

     # File lib/bio/alignment.rb
1410 def alignment_concat(align)
1411   flag = nil
1412   begin
1413     align.each_pair do |key, seq|
1414       flag = true
1415       if origseq = self[key]
1416         origseq.concat(seq)
1417       end
1418     end
1419     return self
1420   rescue NoMethodError, ArgumentError =>evar
1421     raise evar if flag
1422   end
1423   a = values
1424   i = 0
1425   begin
1426     align.each_seq do |seq|
1427       flag = true
1428       a[i].concat(seq) if a[i] and seq
1429       i += 1
1430     end
1431     return self
1432   rescue NoMethodError, ArgumentError => evar
1433     raise evar if flag
1434   end
1435   align.each do |seq|
1436     a[i].concat(seq) if a[i] and seq
1437     i += 1
1438   end
1439   self
1440 end
each_seq() { |seq| ... } click to toggle source

Iterates over each sequences. Yields a sequence.

It works the same as Hash#each_value.

     # File lib/bio/alignment.rb
1378 def each_seq #:yields: seq
1379   #each_value(&block)
1380   each_key { |k| yield self[k] }
1381 end
number_of_sequences() click to toggle source

Returns number of sequences in this alignment.

     # File lib/bio/alignment.rb
1443 def number_of_sequences
1444   self.size
1445 end
sequence_names() click to toggle source

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
1450 def sequence_names
1451   self.keys
1452 end