annotate rDiff/src/tools/intersect.m @ 2:233c30f91d66

updated python based GFF parsing module which will handle GTF/GFF/GFF3 file types
author vipints <vipin@cbio.mskcc.org>
date Tue, 08 Oct 2013 07:15:44 -0400
parents 0f80a5141704
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
1 %## Copyright (C) 2000-2012 Paul Kienzle
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
2 %## Copyright (C) 2008-2009 Jaroslav Hajek
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
3 %##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
4 %## This file is part of Octave.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
5 %##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
6 %## Octave is free software; you can redistribute it and/or modify it
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
7 %## under the terms of the GNU General Public License as published by
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
8 %## the Free Software Foundation; either version 3 of the License, or (at
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
9 %## your option) any later version.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
10 %##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
11 %## Octave is distributed in the hope that it will be useful, but
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
12 %## WITHOUT ANY WARRANTY; without even the implied warranty of
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
13 %## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ...
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
14 % GNU
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
15 %## General Public License for more details.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
16 %##
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
17 %## You should have received a copy of the GNU General Public ...
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
18 % License
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
19 %## along with Octave; see the file COPYING. If not, see
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
20 %## <http://www.gnu.org/licenses/>.
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
21
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
22 function [c, ia, ib] = intersect (a, b, varargin)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
23
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
24 if (nargin < 2 || nargin > 3)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
25 print_usage ();
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
26 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
27
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
28
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
29 if (isempty (a) || isempty (b))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
30 c = ia = ib = [];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
31 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
32 ## form a and b into sets
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
33 if (nargout > 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
34 [a, ja] = unique (a, varargin{:});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
35 [b, jb] = unique (b, varargin{:});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
36 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
37 a = unique (a, varargin{:});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
38 b = unique (b, varargin{:});
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
39 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
40
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
41 if (nargin > 2)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
42 c = [a; b];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
43 [c, ic] = sortrows (c);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
44 ii = find (all (c(1:end-1,:) == c(2:end,:), 2));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
45 c = c(ii,:);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
46 len_a = rows (a);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
47 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
48 c = [a(:); b(:)];
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
49 [c, ic] = sort (c); ## [a(:);b(:)](ic) == c
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
50 if (iscellstr (c))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
51 ii = find (strcmp (c(1:end-1), c(2:end)));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
52 else
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
53 ii = find (c(1:end-1) == c(2:end));
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
54 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
55 c = c(ii);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
56 len_a = length (a);
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
57 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
58
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
59 if (nargout > 1)
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
60 ia = ja(ic(ii)); ## a(ia) == c
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
61 ib = jb(ic(ii+1) - len_a); ## b(ib) == c
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
62 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
63
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
64 if (nargin == 2 && (size (b, 1) == 1 || size (a, 1) == 1))
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
65 c = c.';
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
66 end
0f80a5141704 version 0.3 uploaded
vipints
parents:
diff changeset
67 end