Class: Bio::Transmembrane::TransmembraneDomainDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/transmembrane.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = nil, stop = nil) ⇒ TransmembraneDomainDefinition

A new TMD. The length is stop-start+1, so start and stop are ‘inclusive’



81
82
83
84
# File 'lib/bio/transmembrane.rb', line 81

def initialize(start=nil, stop=nil)
  @start = start
  @stop = stop
end

Instance Attribute Details

#startObject

Returns the value of attribute start.



77
78
79
# File 'lib/bio/transmembrane.rb', line 77

def start
  @start
end

#stopObject

Returns the value of attribute stop.



77
78
79
# File 'lib/bio/transmembrane.rb', line 77

def stop
  @stop
end

Instance Method Details

#<=>(other) ⇒ Object



90
91
92
# File 'lib/bio/transmembrane.rb', line 90

def <=>(other)
  length <=> other.length
end

#==(other) ⇒ Object



94
95
96
97
# File 'lib/bio/transmembrane.rb', line 94

def ==(other)
  start == other.start and
  stop == other.stop
end

#intersection(another_transmembrane_domain_defintion) ⇒ Object Also known as: overlap

Return a range representing the overlap of this transmembrane domain with another

Code inspired by billsiggelkow.com/2008/8/29/ruby-range-intersection



118
119
120
121
# File 'lib/bio/transmembrane.rb', line 118

def intersection(another_transmembrane_domain_defintion)
  res = (@start..@stop).to_a & (another_transmembrane_domain_defintion.start..another_transmembrane_domain_defintion.stop).to_a
  res.empty? ? nil : (res.first..res.last)
end

#lengthObject



86
87
88
# File 'lib/bio/transmembrane.rb', line 86

def length
  @stop-@start+1
end

#overlap_length(another_transmembrane_domain_defintion) ⇒ Object

Return the number of amino acids that overlap with another transmembrane domain, or 0 if none are found



110
111
112
# File 'lib/bio/transmembrane.rb', line 110

def overlap_length(another_transmembrane_domain_defintion)
  intersection(another_transmembrane_domain_defintion).to_a.length
end

#sequence(protein_sequence_string, nterm_offset = 0, cterm_offset = 0) ⇒ Object



99
100
101
102
103
104
105
106
# File 'lib/bio/transmembrane.rb', line 99

def sequence(protein_sequence_string, nterm_offset=0, cterm_offset=0)
  one = start+nterm_offset-1
  one = 0 if one < 0
  two = stop+cterm_offset-1
  two = 0 if two < 0
  
  protein_sequence_string[(one)..(two)]
end