]> git.donarmstrong.com Git - mothur.git/blob - filters.h
4c396070a911000018710a3b652f2f81439e1db7
[mothur.git] / filters.h
1 #ifndef FILTERS_H
2 #define FILTERS_H
3
4 /*
5  *  filters.h
6  *  Mothur
7  *
8  *  Created by Sarah Westcott on 6/29/09.
9  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10  *
11  */
12
13 #include "mothur.h"
14 #include "sequence.hpp"
15
16
17 /***********************************************************************/
18
19 class Filters {
20
21 public:
22         Filters() {};
23         ~Filters(){};
24                 
25         string getFilter()                      {       return filter;          }
26         void setFilter(string s)        {  filter = s;                  }
27         void setLength(int l)           { alignmentLength = l;  }
28         void setSoft(float s)           {               soft = s;               }
29         void setTrump(float t)          {               trump = t;              }
30         void setNumSeqs(int num)        {       numSeqs = num;          }
31         
32         void initialize() {
33                 a.assign(alignmentLength, 0);
34                 t.assign(alignmentLength, 0);
35                 g.assign(alignmentLength, 0);
36                 c.assign(alignmentLength, 0);
37                 gap.assign(alignmentLength, 0);
38         }
39
40         void doSoft() { 
41                 int threshold = int (soft * numSeqs);
42         
43                 for(int i=0;i<alignmentLength;i++){
44                         if(a[i] < threshold && t[i] < threshold && g[i] < threshold && c[i] < threshold){       filter[i] = 0;  }
45                 }
46         }
47         
48         void doVertical() {
49
50                 for(int i=0;i<alignmentLength;i++){
51                         if(gap[i] == numSeqs)   {       filter[i] = '0';        }
52                 }
53         
54         }
55         
56         void doTrump(Sequence seq) {
57         
58                 string curAligned = seq.getAligned();
59
60                 for(int j = 0; j < alignmentLength; j++) {
61                         if(curAligned[j] == trump){
62                                 filter[j] = '0';
63                         }
64                 }
65
66         }
67
68         void doHard(string hard) {
69                 ifstream fileHandle;
70                 openInputFile(hard, fileHandle);
71         
72                 fileHandle >> filter;
73         
74                 fileHandle.close();
75         }
76
77         void getFreqs(Sequence seq) {
78         
79                 string curAligned = seq.getAligned();
80         
81                 for(int j=0;j<alignmentLength;j++){
82                         if(toupper(curAligned[j]) == 'A')                                                                               {       a[j]++;         }
83                         else if(toupper(curAligned[j]) == 'T' || toupper(curAligned[j]) == 'U') {       t[j]++;         }
84                         else if(toupper(curAligned[j]) == 'G')                                                                  {       g[j]++;         }
85                         else if(toupper(curAligned[j]) == 'C')                                                                  {       c[j]++;         }
86                         else if(curAligned[j] == '-' || curAligned[j] == '.')                                   {       gap[j]++;       }
87                 }
88         }
89                 
90 protected:
91         string filter;
92         vector<int> a, t, g, c, gap;
93         int alignmentLength, numSeqs;
94         float soft;
95         char trump;
96
97 };
98
99 /***********************************************************************/
100
101 #endif
102