File: gdna.cpp

package info (click to toggle)
cufflinks 1.3.0-2
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 3,864 kB
  • sloc: cpp: 48,999; ansic: 12,297; sh: 3,381; python: 432; makefile: 209
file content (53 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download
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
#include "gdna.h"
#include <string.h>

#define IUPAC_DEFS "AaCcTtGgUuMmRrWwSsYyKkVvHhDdBbNnXx-*"
#define IUPAC_COMP "TtGgAaCcAaKkYyWwSsRrMmBbDdHhVvNnXx-*"

unsigned char ntCompTable[256];

static bool gdna_ntCompTableReady=ntCompTableInit();

char ntComplement(char c) {
 return ntCompTable[(int)c];
 }

//in place reverse complement of nucleotide (sub)sequence
char* reverseComplement(char* seq, int slen) {
   if (slen==0) slen=strlen(seq);
   //reverseChars(seq,len);
   int l=0;
   int r=slen-1;
   register char c;
   while (l<r) {
      c=seq[l];seq[l]=seq[r];
      seq[r]=c;   //this was: swap(str[l],str[r]);
      l++;r--;
      }
   for (int i=0;i<slen;i++) seq[i]=ntComplement(seq[i]);
   return seq;
 }

bool ntCompTableInit() {
       //if (gdna_ntCompTableReady) return true;
       char n[]=IUPAC_DEFS;
       char c[]=IUPAC_COMP;
       int l=strlen(IUPAC_DEFS);
       ntCompTable[0]=0;
       for (int ch=1;ch<256;ch++) {
          ntCompTable[ch]=0;
          for (int i=0;i<l;i++)
                if (ch==n[i]) {
                  ntCompTable[ch]=c[i];
                  break;
                  }
          if (ntCompTable[ch]==0)
              ntCompTable[ch]='N';
          }
      //gdna_ntCompTableReady=true;
      return true;
     }