]> git.donarmstrong.com Git - mothur.git/blob - filters.h
working on pam
[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         if (filter.length() != alignmentLength) {  m->mothurOut("[ERROR]: Sequences are not all the same length as the filter, please correct.\n");  m->control_pressed = true; }
87         }
88
89         void getFreqs(Sequence seq) {
90         
91                 string curAligned = seq.getAligned();
92         
93                 for(int j=0;j<alignmentLength;j++){
94                         if(toupper(curAligned[j]) == 'A')                                                                               {       a[j]++;         }
95                         else if(toupper(curAligned[j]) == 'T' || toupper(curAligned[j]) == 'U') {       t[j]++;         }
96                         else if(toupper(curAligned[j]) == 'G')                                                                  {       g[j]++;         }
97                         else if(toupper(curAligned[j]) == 'C')                                                                  {       c[j]++;         }
98                         else if(curAligned[j] == '-' || curAligned[j] == '.')                                   {       gap[j]++;       }
99                 }
100         }
101                 
102 protected:
103         string filter;
104         int alignmentLength, numSeqs;
105         float soft;
106         char trump;
107         MothurOut* m;
108
109 };
110
111 /***********************************************************************/
112
113 #endif
114