File: revcomp.cpp

package info (click to toggle)
pilercr 1.06%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 844 kB
  • sloc: cpp: 14,339; makefile: 67; sh: 36
file content (37 lines) | stat: -rwxr-xr-x 693 bytes parent folder | download | duplicates (2)
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
#include "types.h"

unsigned char CompMap[256];

static bool InitMap()
	{
	for (unsigned i = 0; i < 256; ++i)
		CompMap[i] = i;

	CompMap[(int) 'a'] = 't';
	CompMap[(int) 'c'] = 'g';
	CompMap[(int) 'g'] = 'c';
	CompMap[(int) 't'] = 'a';

	CompMap[(int) 'A'] = 'T';
	CompMap[(int) 'C'] = 'G';
	CompMap[(int) 'G'] = 'C';
	CompMap[(int) 'T'] = 'A';

	return true;
	}

static bool InitDone = InitMap();

void RevComp(char *S, unsigned L)
	{
	unsigned char *s = (unsigned char *) S;
	unsigned char *t = (unsigned char *) (S + L - 1);
	while (s < t)
		{	
		unsigned char c = *s;
		*s++ = CompMap[*t];
		*t-- = CompMap[c];
		}
	if (s == t)
		*s = CompMap[*s];
	}