]> git.donarmstrong.com Git - mothur.git/blob - filters.h
adding pretty confusion matrix
[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() { m = MothurOut::getInstance(); };
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 mergeFilter(string newFilter){
51                 for(int i=0;i<alignmentLength;i++){
52                         if(newFilter[i] == '0'){
53                                 filter[i] = 0;
54                         }
55                 }
56         }
57         
58         void doVertical() {
59
60                 for(int i=0;i<alignmentLength;i++){
61                         if(gap[i] == numSeqs)   {       filter[i] = '0';        }
62                 }
63         
64         }
65         
66         void doTrump(Sequence seq) {
67         
68                 string curAligned = seq.getAligned();
69
70                 for(int j = 0; j < alignmentLength; j++) {
71                         if(curAligned[j] == trump){
72                                 filter[j] = '0';
73                         }
74                 }
75
76         }
77
78         void doHard(string hard) {
79                 ifstream fileHandle;
80                 m->openInputFile(hard, fileHandle);
81         
82                 fileHandle >> filter;
83         
84                 fileHandle.close();
85         }
86
87         void getFreqs(Sequence seq) {
88         
89                 string curAligned = seq.getAligned();
90         
91                 for(int j=0;j<alignmentLength;j++){
92                         if(toupper(curAligned[j]) == 'A')                                                                               {       a[j]++;         }
93                         else if(toupper(curAligned[j]) == 'T' || toupper(curAligned[j]) == 'U') {       t[j]++;         }
94                         else if(toupper(curAligned[j]) == 'G')                                                                  {       g[j]++;         }
95                         else if(toupper(curAligned[j]) == 'C')                                                                  {       c[j]++;         }
96                         else if(curAligned[j] == '-' || curAligned[j] == '.')                                   {       gap[j]++;       }
97                 }
98         }
99                 
100 protected:
101         string filter;
102         int alignmentLength, numSeqs;
103         float soft;
104         char trump;
105         MothurOut* m;
106
107 };
108
109 /***********************************************************************/
110
111 #endif
112