File: cut_ranges.rb

package info (click to toggle)
ruby-bio 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 7,480 kB
  • ctags: 9,428
  • sloc: ruby: 74,117; xml: 3,383; makefile: 17; perl: 13; sh: 1
file content (46 lines) | stat: -rw-r--r-- 1,225 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# bio/util/restriction_enzyme/range/cut_ranges.rb - Container for many CutRange objects or CutRange child objects.
#
# Author::    Trevor Wennblom  <mailto:trevor@corevx.com>
# Copyright:: Copyright (c) 2005-2007 Midwinter Laboratories, LLC (http://midwinterlabs.com)
# License::   The Ruby License
#

module Bio

require 'bio/util/restriction_enzyme' unless const_defined?(:RestrictionEnzyme)

class RestrictionEnzyme
class Range
  
# Container for many CutRange objects or CutRange child objects.  Inherits from array.
#
class CutRanges < Array
  def min; self.collect{|a| a.min}.flatten.sort.first; end
  def max; self.collect{|a| a.max}.flatten.sort.last; end
  def include?(i); self.collect{|a| a.include?(i)}.include?(true); end
  
  def min_vertical
    vertical_min_max_helper( :min )
  end
  
  def max_vertical
    vertical_min_max_helper( :max )
  end
  
  protected
  
  def vertical_min_max_helper( sym_which )
    tmp = []
    self.each do |a|
      next unless a.class == Bio::RestrictionEnzyme::Range::VerticalCutRange
      tmp << a.send( sym_which )
    end
    z = (sym_which == :max) ? :last : :first
    tmp.flatten.sort.send(z)
  end
    
end # CutRanges
end # Range
end # RestrictionEnzyme
end # Bio