Help save net neutrality! Learn more.
Close

Diff of /inst/aa2int.m [000000] .. [3f48a5]  Maximize  Restore

Switch to unified view

a b/inst/aa2int.m
1
## Copyright (C) 2008 Bill Denney
2
##
3
## This software is free software; you can redistribute it and/or modify it
4
## under the terms of the GNU General Public License as published by
5
## the Free Software Foundation; either version 3 of the License, or (at
6
## your option) any later version.
7
##
8
## This software is distributed in the hope that it will be useful, but
9
## WITHOUT ANY WARRANTY; without even the implied warranty of
10
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
## General Public License for more details.
12
##
13
## You should have received a copy of the GNU General Public License
14
## along with this software; see the file COPYING.  If not, see
15
## <http://www.gnu.org/licenses/>.
16
17
## -*- texinfo -*-
18
## @deftypefn {Function File} {@var{sequenceint} =} aa2int (@var{sequencechar})
19
## Convert amino acid characters into integers.  See @code{aminolookup}
20
## for the listing of numbers and their corresponding characters.
21
## @seealso{aminolookup,int2aa,int2nt,nt2int}
22
## @end deftypefn
23
24
## Author: Bill Denney <bill@denney.ws>
25
26
function seqi = aa2int (seqc=0)
27
28
  if (! ischar (seqc))
29
    print_usage ();
30
  endif
31
  sequences = aminolookup ("code", []);
32
33
  seqi = -ones (size (seqc));
34
  seqc = upper (seqc);
35
  for i = 1:numel (sequences)
36
    seqi(sequences(i) == seqc) = i;
37
  endfor
38
  if any (seqi(:) < 0)
39
    idx = find (seqi(:) < 0, 1);
40
    error ("aa2int: unrecognised character (%s) in sequence input at position (%d)",
41
           seqc(idx), idx)
42
  endif
43
44
endfunction
45
46
## Tests
47
%!assert (aa2int ("a"), 1)
48
%!assert (aa2int ("ar"), [1 2])
49
%!assert (aa2int (["ar"]'), [1;2])