1 /*****************************************************************
2 * SQUID - a library of functions for biological sequence analysis
3 * Copyright (C) 1992-2002 Washington University School of Medicine
5 * This source code is freely distributed under the terms of the
6 * GNU General Public License. See the files COPYRIGHT and LICENSE
8 *****************************************************************/
12 * Routines for creating and manipulating encoded sequence strings.
13 * RCS $Id: seqencode.c 217 2011-03-19 10:27:10Z andreas $ (Original squid RCS Id: seqencode.c,v 1.3 1999/05/02 21:55:27 eddy Exp)
26 mismatch number otherwise */
28 seqcmp(char *s1, char *s2, int allow)
32 while ((*s1 != NTEND) && (*s2 != NTEND) && (mmat <= allow))
34 if (!(ntmatch(*s1, *s2)))
39 while ((*s1++ != NTEND) && (mmat <= allow))
44 same as seqcmp but it looks at,
45 at most, n positions */
47 seqncmp(char *s1, char *s2, int n, int allow)
51 while ((*s2 != NTEND) &&
54 if ((!(ntmatch(*s1, *s2))) &&
60 while ((n-- != 0) && (*s1++ != NTEND) && (mmat <= allow))
66 given a character text string str (A,C,G,T),
67 convert to an encoded seq string;
68 return 1 for success, 0 if fail */
70 seqencode(char *codeseq, /* pre-allocated space for answer */
71 char *str) /* character string to convert */
79 if (islower((int) (*str))) *str = (char) toupper((int) (*str));
80 for (idx = 0; *str != iupac[idx].sym && idx <= IUPACSYMNUM; idx++)
82 if (idx > IUPACSYMNUM)
88 *ptr = iupac[idx].code;
98 coded_revcomp(char *comp, char *seq)
108 bckp = seq + bases -1;
109 for (pos = 0; pos < bases; pos++)
111 for (idx = 0; *bckp != iupac[idx].code && idx < IUPACSYMNUM; idx++);
112 if (idx > IUPACSYMNUM)
118 *fwdp = iupac[idx].comp;
127 seqdecode(char *str, char *codeseq)
133 while (*codeseq != NTEND)
135 for (idx = 0; *codeseq != iupac[idx].code && idx < IUPACSYMNUM; idx++)
137 if (idx > IUPACSYMNUM)
143 str[pos] = iupac[idx].sym;
153 char *str, /* pre-allocated string to write into */
154 char *codeseq, /* sequence to decode */
155 int n) /* how many bases to decode */
162 for (idx = 0; *codeseq != iupac[idx].code && idx < IUPACSYMNUM; idx++);
163 if (idx > IUPACSYMNUM)
169 str[pos] = iupac[idx].sym;