-
Notifications
You must be signed in to change notification settings - Fork 0
/
revcomp.c
61 lines (52 loc) · 1.14 KB
/
revcomp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* SQUID - A C function library for biological sequence analysis
* Copyright (C) 1992-1995 Sean R. Eddy
*
* This source code is distributed under terms of the
* GNU General Public License. See the files COPYING
* and GNULICENSE for further details.
*
*/
/* revcomp.c
*
* Reverse complement of a IUPAC character string
*
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "squid.h"
#ifdef MEMDEBUG
#include "dbmalloc.h"
#endif
char *
revcomp(char *comp, char *seq)
{
long bases;
char *bckp, *fwdp;
int idx;
long pos;
int c;
if (comp == NULL) return NULL;
if (seq == NULL) return NULL;
bases = strlen(seq);
fwdp = comp;
bckp = seq + bases -1;
for (pos = 0; pos < bases; pos++)
{
c = *bckp;
c = sre_toupper(c);
for (idx = 0; c != iupac[idx].sym && idx < IUPACSYMNUM; idx++);
if (idx == IUPACSYMNUM)
{
Warn("Can't reverse complement an %c, pal. Using N.", c);
*fwdp = 'N';
}
else
*fwdp = iupac[idx].symcomp;
if (islower((int) *bckp)) *fwdp = sre_tolower((int) *fwdp);
fwdp++;
bckp--;
}
*fwdp = '\0';
return comp;
}