Method: Bio::Alignment::OriginalAlignment#select

Defined in:
lib/bio/alignment.rb

#select(*arg) ⇒ Object

If block is given, it acts like Array#select (Enumerable#select). Returns a new alignment containing all sequences of the alignment for which return value of given block is not false nor nil.

If no block is given, it acts like the BioPerl’s AlignI::select. Returns a new alignment containing sequences of given keys.

The BioPerl’s AlignI::select-like action will be obsoleted.



1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
# File 'lib/bio/alignment.rb', line 1945

def select(*arg)
  #(original)
  na = self.new
  if block_given? then
    # 'arg' is ignored
    # nearly same action as Array#select (Enumerable#select)
    self.each_pair.each do |k, s|
      na.store(k, s) if yield(s)
    end
  else
    # BioPerl's AlignI::select like function
    arg.each do |k|
      if s = self[k] then
        na.store(k, s)
      end
    end
  end
  na
end