1 # Copyright (C) 2007-2012 Martin A. Hansen.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # http://www.gnu.org/copyleft/gpl.html
19 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
21 # This software is part of the Biopieces framework (www.biopieces.org).
23 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
25 require 'maasha/align/match'
27 # Class containing methods for located all non-redundant Maximally Extended Matches (MEMs)
28 # between two strings.
30 # Class method to located all non-redudant MEMs bewteen two sequences within a given
31 # search space and seeded with kmers of a given size.
32 def self.find(q_seq, s_seq, q_min, s_min, q_max, s_max, kmer)
34 m.matches_find(q_seq, s_seq, q_min, s_min, q_max, s_max, kmer)
37 # Method that finds all maximally expanded non-redundant matches shared
38 # between two sequences inside a given search space.
39 def matches_find(q_seq, s_seq, q_min, s_min, q_max, s_max, kmer)
43 s_index = index_seq(s_seq, s_min, s_max, kmer)
47 while q_pos <= q_max - kmer + 1
48 q_oligo = q_seq[q_pos ... q_pos + kmer]
50 s_index[q_oligo].each do |s_pos|
51 match = Match.new(q_pos, s_pos, kmer)
53 unless redundant[match.q_beg * 1_000_000_000 + match.s_beg]
54 match.expand(q_seq, s_seq, q_min, s_min, q_max, s_max)
57 (0 ... match.length).each do |j|
58 redundant[(match.q_beg + j) * 1_000_000_000 + match.s_beg + j] = true
69 # Method that indexes a sequence within a given interval such that the
70 # index contains all oligos of a given kmer size and the positions where
71 # this oligo was located.
72 def index_seq(seq, min, max, kmer, step = 1)
73 index_hash = Hash.new { |h, k| h[k] = [] }
77 while pos <= max - kmer + 1
78 oligo = seq[pos ... pos + kmer]
79 index_hash[oligo] << pos