]> git.donarmstrong.com Git - mothur.git/blob - shared.cpp
c8a1d5e8e6a061edf8cdf00a6f2025b6b8a8c53c
[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(int index, SharedListVector* list) {
20                 string label, group;
21                 int i,j;
22                 label = list->getLabel();
23                 
24                 sharedGroups.clear();  //removes old info.
25                 
26                 //initalize sharedGroups 
27                 for (j=0; j<globaldata->gGroupmap->getNumGroups(); j++) {//for each group
28                         group = globaldata->gGroupmap->namesOfGroups[j];
29                         sharedGroups[group] = new SharedRAbundVector();
30                         sharedGroups[group]->setLabel(label);
31                         for (i = 0; i<list->size(); i++) { //for each otu
32                                 sharedGroups[group]->push_back(0, i, group); //initialize to 0.
33                         }
34                 }
35                         
36                 //fills sharedGroups
37                 for (i = 0; i<list->size(); i++) {
38                         parse(i, list);
39                 }
40                 
41                 //updates sharedVector
42                 sharedRAbund.push_back(sharedGroups);
43 }
44
45
46
47 /***********************************************************************/
48 void Shared::parse(int index, SharedListVector* list) {
49
50                 string prefix, suffix, groupsName;
51                 suffix = list->get(index);
52         
53                 while (suffix.find_first_of(',') != -1) {//while you still have sequences
54                         prefix = suffix.substr(0,suffix.find_first_of(','));
55                         if ((suffix.find_first_of(',')+1) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
56                                 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
57                         }
58                         groupsName = globaldata->gGroupmap->getGroup(prefix);
59                         if (groupsName != "not found") {
60                                 sharedGroups[groupsName]->set(index, (sharedGroups[groupsName]->getAbundance(index) + 1), groupsName); //increment shared vector for that group
61                         }else {
62                                 cerr << "Error: Sequence '" << prefix << "' was not found in the group file, please correct\n";
63                         }
64                 }
65                 
66                 //save last name after comma
67                 groupsName = globaldata->gGroupmap->getGroup(suffix);
68                 if (groupsName != "not found") {
69                         sharedGroups[groupsName]->set(index, ((sharedGroups[groupsName]->getAbundance(index)) + 1), groupsName); //increment shared vector for that group
70                 }else {
71                         cerr << "Error: Sequence '" << suffix << "' was not found in the group file, please correct\n";
72                 }
73         }