Class: Bio::Transmembrane::TransmembraneDomainDefinition
- Inherits:
-
Object
- Object
- Bio::Transmembrane::TransmembraneDomainDefinition
- Defined in:
- lib/bio/transmembrane.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(start = nil, stop = nil) ⇒ TransmembraneDomainDefinition
constructor
A new TMD.
-
#intersection(another_transmembrane_domain_defintion) ⇒ Object
(also: #overlap)
Return a range representing the overlap of this transmembrane domain with another.
- #length ⇒ Object
-
#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.
- #sequence(protein_sequence_string, nterm_offset = 0, cterm_offset = 0) ⇒ Object
Constructor Details
#initialize(start = nil, stop = nil) ⇒ TransmembraneDomainDefinition
A new TMD. The length is stop-start+1, so start and stop are ‘inclusive’
123 124 125 126 |
# File 'lib/bio/transmembrane.rb', line 123 def initialize(start=nil, stop=nil) @start = start @stop = stop end |
Instance Attribute Details
#start ⇒ Object
Returns the value of attribute start.
119 120 121 |
# File 'lib/bio/transmembrane.rb', line 119 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
119 120 121 |
# File 'lib/bio/transmembrane.rb', line 119 def stop @stop end |
Instance Method Details
#<=>(other) ⇒ Object
132 133 134 |
# File 'lib/bio/transmembrane.rb', line 132 def <=>(other) length <=> other.length end |
#==(other) ⇒ Object
136 137 138 139 |
# File 'lib/bio/transmembrane.rb', line 136 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
160 161 162 163 |
# File 'lib/bio/transmembrane.rb', line 160 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 |
#length ⇒ Object
128 129 130 |
# File 'lib/bio/transmembrane.rb', line 128 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
152 153 154 |
# File 'lib/bio/transmembrane.rb', line 152 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
141 142 143 144 145 146 147 148 |
# File 'lib/bio/transmembrane.rb', line 141 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 |