]> git.donarmstrong.com Git - mothur.git/blob - filters.h
testing mpi
[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         vector<int> a, t, g, c, gap;
32         
33         
34         void initialize() {
35                 a.assign(alignmentLength, 0);
36                 t.assign(alignmentLength, 0);
37                 g.assign(alignmentLength, 0);
38                 c.assign(alignmentLength, 0);
39                 gap.assign(alignmentLength, 0);
40         }
41
42         void doSoft() { 
43                 int threshold = int (soft * numSeqs);
44         
45                 for(int i=0;i<alignmentLength;i++){
46                         if(a[i] < threshold && t[i] < threshold && g[i] < threshold && c[i] < threshold){       filter[i] = 0;  }
47                 }
48         }
49         
50         void doVertical() {
51
52                 for(int i=0;i<alignmentLength;i++){
53                         if(gap[i] == numSeqs)   {       filter[i] = '0';        }
54                 }
55         
56         }
57         
58         void doTrump(Sequence seq) {
59         
60                 string curAligned = seq.getAligned();
61
62                 for(int j = 0; j < alignmentLength; j++) {
63                         if(curAligned[j] == trump){
64                                 filter[j] = '0';
65                         }
66                 }
67
68         }
69
70         void doHard(string hard) {
71                 ifstream fileHandle;
72                 openInputFile(hard, fileHandle);
73         
74                 fileHandle >> filter;
75         
76                 fileHandle.close();
77         }
78
79         void getFreqs(Sequence seq) {
80         
81                 string curAligned = seq.getAligned();
82         
83                 for(int j=0;j<alignmentLength;j++){
84                         if(toupper(curAligned[j]) == 'A')                                                                               {       a[j]++;         }
85                         else if(toupper(curAligned[j]) == 'T' || toupper(curAligned[j]) == 'U') {       t[j]++;         }
86                         else if(toupper(curAligned[j]) == 'G')                                                                  {       g[j]++;         }
87                         else if(toupper(curAligned[j]) == 'C')                                                                  {       c[j]++;         }
88                         else if(curAligned[j] == '-' || curAligned[j] == '.')                                   {       gap[j]++;       }
89                 }
90         }
91                 
92 protected:
93         string filter;
94         int alignmentLength, numSeqs;
95         float soft;
96         char trump;
97
98 };
99
100 /***********************************************************************/
101
102 #endif
103