module Bio::Alignment::GAP

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

Public Class Methods

gapped_pos(seq, pos, gap_regexp) click to toggle source
position without gaps are translated into the position with gaps.
seq

sequence

pos

position with gaps

gap_regexp

regular expression to specify gaps

# File lib/bio/alignment.rb, line 2162
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) click to toggle source
position with gaps are translated into the position without gaps.
seq

sequence

pos

position with gaps

gap_regexp

regular expression to specify gaps

# File lib/bio/alignment.rb, line 2151
def ungapped_pos(seq, pos, gap_regexp)
  p = seq[0..pos].gsub(gap_regexp, '').length
  p -= 1 if p > 0
  p
end