1 # Copyright (C) 2007-2013 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 # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
27 # Class for describing a match between two sequences q and s.
29 attr_accessor :q_beg, :s_beg, :length, :score
31 def initialize(q_beg, s_beg, length)
46 # Method to expand a match as far as possible to the left and right
47 # within a given search space.
48 def expand(q_seq, s_seq, q_space_beg, s_space_beg, q_space_end, s_space_end)
49 length = expand_left_C(q_seq, s_seq, @q_beg, @s_beg, q_space_beg, s_space_beg)
54 length = expand_right_C(q_seq, s_seq, q_end, s_end, q_space_end, s_space_end)
61 s = "q: #{@q_beg}, s: #{@s_beg}, l: #{@length}, s: #{@score}"
62 s << " #{seq[@q_beg .. q_end]}" if seq
70 # Method to expand a match as far as possible to the left within a given
82 unsigned char *q_seq = (unsigned char *) StringValuePtr(_q_seq);
83 unsigned char *s_seq = (unsigned char *) StringValuePtr(_s_seq);
84 unsigned int q_beg = NUM2UINT(_q_beg);
85 unsigned int s_beg = NUM2UINT(_s_beg);
86 unsigned int q_space_beg = NUM2UINT(_q_space_beg);
87 unsigned int s_space_beg = NUM2UINT(_s_space_beg);
91 while (q_beg > q_space_beg && s_beg > s_space_beg && q_seq[q_beg - 1] == s_seq[s_beg - 1])
103 VALUE expand_right_C(
112 unsigned char *q_seq = (unsigned char *) StringValuePtr(_q_seq);
113 unsigned char *s_seq = (unsigned char *) StringValuePtr(_s_seq);
114 unsigned int q_end = NUM2UINT(_q_end);
115 unsigned int s_end = NUM2UINT(_s_end);
116 unsigned int q_space_end = NUM2UINT(_q_space_end);
117 unsigned int s_space_end = NUM2UINT(_s_space_end);
119 unsigned int len = 0;
121 while (q_end + 1 <= q_space_end && s_end + 1 <= s_space_end && q_seq[q_end + 1] == s_seq[s_end + 1])
128 return UINT2NUM(len);