initial commit
[jalview.git] / forester / archive / RIO / others / hmmer / squid / revcomp.c
1 /*****************************************************************
2  * HMMER - Biological sequence analysis with profile HMMs
3  * Copyright (C) 1992-1999 Washington University School of Medicine
4  * All Rights Reserved
5  * 
6  *     This source code is distributed under the terms of the
7  *     GNU General Public License. See the files COPYING and LICENSE
8  *     for details.
9  *****************************************************************/
10
11 /* revcomp.c
12  * 
13  * Reverse complement of a IUPAC character string
14  * RCS $Id: revcomp.c,v 1.1.1.1 2005/03/22 08:34:16 cmzmasek Exp $
15  */
16
17 #include <stdio.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include "squid.h"
21
22
23 #ifdef MEMDEBUG
24 #include "dbmalloc.h"
25 #endif
26
27
28 char *
29 revcomp(char *comp, char *seq)
30 {
31   long  bases;
32   char *bckp, *fwdp;
33   int   idx;
34   long  pos;
35   int   c;
36
37   if (comp == NULL) return NULL;
38   if (seq == NULL)  return NULL;
39   bases = strlen(seq);
40
41   fwdp = comp;
42   bckp = seq + bases -1;
43   for (pos = 0; pos < bases; pos++)
44     {
45       c = *bckp;
46       c = sre_toupper(c);
47       for (idx = 0; c != iupac[idx].sym && idx < IUPACSYMNUM; idx++);
48       if (idx == IUPACSYMNUM)
49         {
50           Warn("Can't reverse complement an %c, pal. Using N.", c);
51           *fwdp = 'N';
52         }
53       else
54         *fwdp = iupac[idx].symcomp;
55       if (islower((int) *bckp)) *fwdp = (char) sre_tolower((int) *fwdp);
56       fwdp++;
57       bckp--;
58     }
59   *fwdp = '\0';
60   return comp;
61 }
62