]> git.donarmstrong.com Git - mothur.git/blob - shared.cpp
b15ef93f32b58f7b294704cbe44aaa90472cf349
[mothur.git] / shared.cpp
1 /*
2  *  shared.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 12/5/08.
6  *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "shared.h"
11
12 /**************************************************************************************************/
13
14 Shared::Shared(){
15    globaldata = GlobalData::getInstance();
16 }
17
18 /**************************************************************************************************/
19 void Shared::getSharedVectors(SharedListVector* list) {
20                 string label, group;
21                 int i,j;
22                 label = list->getLabel();
23                 
24                 for (it = sharedGroups.begin(); it != sharedGroups.end(); it++) {  delete it->second;  }
25                 sharedGroups.clear();  //removes old info.
26                 
27                 //initalize sharedGroups 
28                 for (j=0; j<globaldata->gGroupmap->getNumGroups(); j++) {//for each group
29                         group = globaldata->gGroupmap->namesOfGroups[j];
30                         sharedGroups[group] = new SharedRAbundVector();
31                         sharedGroups[group]->setLabel(label);
32                         for (i = 0; i<list->size(); i++) { //for each otu
33                                 sharedGroups[group]->push_back(0, i, group); //initialize to 0.
34                         }
35                 }
36                         
37                 //fills sharedGroups
38                 for (i = 0; i<list->size(); i++) {
39                         parse(i, list);
40                 }
41                 
42                 //updates sharedVector
43                 //sharedRAbund.push_back(sharedGroups);
44 }
45
46
47
48 /***********************************************************************/
49 void Shared::parse(int index, SharedListVector* list) {
50
51                 string prefix, suffix, groupsName;
52                 suffix = list->get(index);
53         
54                 while (suffix.find_first_of(',') != -1) {//while you still have sequences
55                         prefix = suffix.substr(0,suffix.find_first_of(','));
56                         if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
57                                 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
58                         }
59                         groupsName = globaldata->gGroupmap->getGroup(prefix);
60                         if (groupsName != "not found") {
61                                 sharedGroups[groupsName]->set(index, (sharedGroups[groupsName]->getAbundance(index) + 1), groupsName); //increment shared vector for that group
62                         }else {
63                                 cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
64                         }
65                 }
66                 
67                 //save last name after comma
68                 groupsName = globaldata->gGroupmap->getGroup(suffix);
69                 if (groupsName != "not found") {
70                         sharedGroups[groupsName]->set(index, ((sharedGroups[groupsName]->getAbundance(index)) + 1), groupsName); //increment shared vector for that group
71                 }else {
72                         cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
73                 }
74         }