]> git.donarmstrong.com Git - mothur.git/blob - parsimony.h
working on pam
[mothur.git] / parsimony.h
1 #ifndef PARSIMONY_H
2 #define PARSIMONY_H
3
4
5 /*
6  *  parsimony.h
7  *  Mothur
8  *
9  *  Created by Sarah Westcott on 1/26/09.
10  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
11  *
12  */
13
14 #include "treecalculator.h"
15 #include "counttable.h"
16
17 /***********************************************************************/
18
19 class Parsimony : public TreeCalculator  {
20         
21         public:
22                 Parsimony() {};
23                 ~Parsimony() {};
24                 EstOutput getValues(Tree*, int, string);
25                 
26         private:
27                 struct linePair {
28                         int start;
29                         int num;
30                         linePair(int i, int j) : start(i), num(j) {}
31                 };
32                 vector<linePair> lines;
33         
34                 EstOutput data;
35                 int processors;
36                 string outputDir;
37         
38                 EstOutput driver(Tree*, vector< vector<string> >, int, int, CountTable*); 
39                 EstOutput createProcesses(Tree*, vector< vector<string> >, CountTable*);
40 };
41 /***********************************************************************/
42 struct parsData {
43     int start;
44         int num;
45         MothurOut* m;
46     EstOutput results;
47     vector< vector<string> > namesOfGroupCombos;
48     Tree* t;
49     CountTable* ct;
50     
51         parsData(){}
52         parsData(MothurOut* mout, int st, int en, vector< vector<string> > ngc, Tree* tree, CountTable* count) {
53         m = mout;
54                 start = st;
55                 num = en;
56         namesOfGroupCombos = ngc;
57         t = tree;
58         ct = count;
59         }
60 };
61
62 /**************************************************************************************************/
63 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
64 #else
65 static DWORD WINAPI MyParsimonyThreadFunction(LPVOID lpParam){
66         parsData* pDataArray;
67         pDataArray = (parsData*)lpParam;
68         try {
69         
70         pDataArray->results.resize(pDataArray->num);
71                 
72                 Tree* copyTree = new Tree(pDataArray->ct);
73                 int count = 0;
74                 
75                 for (int h = pDataArray->start; h < (pDataArray->start+pDataArray->num); h++) {
76             
77                         if (pDataArray->m->control_pressed) { delete copyTree; return 0; }
78             
79                         int score = 0;
80                         
81                         //groups in this combo
82                         vector<string> groups = pDataArray->namesOfGroupCombos[h];
83                         
84                         //copy users tree so that you can redo pgroups
85                         copyTree->getCopy(pDataArray->t);
86                         
87                         //create pgroups that reflect the groups the user want to use
88                         for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
89                                 copyTree->tree[i].pGroups = (copyTree->mergeUserGroups(i, groups));
90                         }
91                         
92                         for(int i=copyTree->getNumLeaves();i<copyTree->getNumNodes();i++){
93                                 
94                                 if (pDataArray->m->control_pressed) { return 0; }
95                                 
96                                 int lc = copyTree->tree[i].getLChild();
97                                 int rc = copyTree->tree[i].getRChild();
98                                 
99                                 int iSize = copyTree->tree[i].pGroups.size();
100                                 int rcSize = copyTree->tree[rc].pGroups.size();
101                                 int lcSize = copyTree->tree[lc].pGroups.size();
102                                 
103                                 //if isize are 0 then that branch is to be ignored
104                                 if (iSize == 0) { }
105                                 else if ((rcSize == 0) || (lcSize == 0)) { }
106                                 //if you have more groups than either of your kids then theres been a change.
107                                 else if(iSize > rcSize || iSize > lcSize){
108                                         score++;
109                                 }
110                         }
111                         
112                         pDataArray->results[count] = score;
113                         count++;
114                 }
115         
116                 delete copyTree;
117         
118         return 0;
119         
120     }
121         catch(exception& e) {
122                 pDataArray->m->errorOut(e, "Parsimony", "MyParsimonyThreadFunction");
123                 exit(1);
124         }
125 }
126 #endif
127
128 #endif