Module: Bio::Alignment::GAP

Defined in:
lib/bio/alignment.rb

Overview

Bio::Alignment::GAP is a set of class methods for gap-related position translation.

Class Method Summary collapse

Class Method Details

.gapped_pos(seq, pos, gap_regexp) ⇒ Object

position without gaps are translated into the position with gaps.

seq

sequence

pos

position with gaps

gap_regexp

regular expression to specify gaps



2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
# File 'lib/bio/alignment.rb', line 2168

def gapped_pos(seq, pos, gap_regexp)
  olen = seq.gsub(gap_regexp, '').length
  pos = olen if pos >= olen
  pos = olen + pos if pos < 0
  
  i = 0
  l = pos + 1
  while l > 0 and i < seq.length
    x = seq[i, l].gsub(gap_regexp, '').length
    i += l
    l -= x
  end
  i -= 1 if i > 0
  i
end

.ungapped_pos(seq, pos, gap_regexp) ⇒ Object

position with gaps are translated into the position without gaps.

seq

sequence

pos

position with gaps

gap_regexp

regular expression to specify gaps



2157
2158
2159
2160
2161
# File 'lib/bio/alignment.rb', line 2157

def ungapped_pos(seq, pos, gap_regexp)
  p = seq[0..pos].gsub(gap_regexp, '').length
  p -= 1 if p > 0
  p
end