File: testsharedrabundvectors.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (254 lines) | stat: -rw-r--r-- 8,439 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
//
//  testsharedrabundvectors.cpp
//  Mothur
//
//  Created by Sarah Westcott on 8/10/18.
//  Copyright © 2018 Schloss Lab. All rights reserved.
//

#include "testsharedrabundvectors.hpp"
#include "dataset.h"

/**************************************************************************************************/
TestSharedRabundVectors::TestSharedRabundVectors() : SharedRAbundVectors() {  //setup
    m = MothurOut::getInstance();
    
    TestDataSet data; sharedFile = data.getSharedFile();
}
/**************************************************************************************************/
TestSharedRabundVectors::~TestSharedRabundVectors() {}//teardown
/**************************************************************************************************/

TEST(Test_Container_SharedRabundVectors, Constructors) {
    TestSharedRabundVectors test;
    
    SharedRAbundVectors temp;
    EXPECT_EQ(temp.getNumBins(), 0);
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    EXPECT_EQ(nextLabel, "");
    EXPECT_EQ(labelTag, "Otu");
    EXPECT_EQ(userGroups[0], "F003D000");
    
    SharedRAbundVectors copy(fileRead);
    EXPECT_EQ(copy.getLabel(), "0.03");
    EXPECT_EQ(labelTag, "Otu");
    EXPECT_EQ(userGroups[0], "F003D000");

}

TEST(Test_Container_SharedRabundVectors, GetsSets) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    EXPECT_EQ(nextLabel, "");
    EXPECT_EQ(labelTag, "Otu");
    EXPECT_EQ(userGroups[0], "F003D000");
    
    //setLabels
    fileRead.setLabels("0.99");
    EXPECT_EQ(fileRead.getLabel(), "0.99");
    
    //getOTUTotal
    EXPECT_EQ(fileRead.getOTUTotal(4), 12);
    
    //getOTU
    vector<int> otu5 = fileRead.getOTU(4);
    EXPECT_EQ(otu5[0], 0);
    EXPECT_EQ(otu5[1], 2);
    
    //get
    EXPECT_EQ(fileRead.get(4, "F003D000"), 0);
    EXPECT_EQ(fileRead.get(4, "F003D002"), 2);
    EXPECT_EQ(fileRead.get(0, "F003D142"), 6);
    
    //set
    fileRead.set(4, 10, "F003D000");
    EXPECT_EQ(fileRead.get(4, "F003D000"), 10);
    fileRead.set(4, 15, "F003D002");
    EXPECT_EQ(fileRead.get(4, "F003D002"), 15);
    fileRead.set(0, 3, "F003D142");
    EXPECT_EQ(fileRead.get(0, "F003D142"), 3);
    
    //getOTUNames
    vector<string> otuNames = fileRead.getOTUNames();
    EXPECT_EQ(otuNames[10], "Otu11");
    
    //setOTUNames
    otuNames[5] = "Otu99";
    fileRead.setOTUNames(otuNames);
    EXPECT_EQ(fileRead.getOTUNames()[5], "Otu99");
    EXPECT_EQ(fileRead.getOTUName(5), "Otu99");
    fileRead.setOTUName(5, "Otu6");
    EXPECT_EQ(fileRead.getOTUName(5), "Otu6");
    
    //getNumBins
    EXPECT_EQ(fileRead.getNumBins(), 58);
    
    //getNumSeqsSmallestGroup
    EXPECT_EQ(fileRead.getNumSeqsSmallestGroup(), 15);
    
    //getNamesGroups
    EXPECT_EQ(fileRead.getNamesGroups()[1], "F003D002");
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 10);
    
    //getNumSeqs
    EXPECT_EQ(fileRead.getNumSeqs("F003D002"), 31);
    
}

TEST(Test_Container_SharedRabundVectors, PushBack) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 10);
    
    vector<int> abunds(58, 5);
    SharedRAbundVector* temp = new SharedRAbundVector(abunds);
    temp->setGroup("myabunds");
    fileRead.push_back(temp);
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 11);
    
    vector<int> otuAbunds(11, 2); string otuLabel = "Otu59";
    fileRead.push_back(otuAbunds, otuLabel);
    EXPECT_EQ(fileRead.getNumBins(), 59);
}

TEST(Test_Container_SharedRabundVectors, eliminateZeroOTUS) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    EXPECT_EQ(fileRead.getNumBins(), 58);
    
    fileRead.set(16, 0, "F003D142");
    EXPECT_EQ(fileRead.get(16, "F003D142"), 0); //zero out bin
    fileRead.eliminateZeroOTUS(); //remove zeroed out bin
    
    EXPECT_EQ(fileRead.getNumBins(), 57);
    
}

TEST(Test_Container_SharedRabundVectors, Removes) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    EXPECT_EQ(fileRead.getNumBins(), 58);
    EXPECT_EQ(fileRead.removeOTU(16), 2);
    EXPECT_EQ(fileRead.getNumBins(), 57);
    
    vector<string> groups;
    groups.push_back("F003D142");
    groups.push_back("F003D002");
    groups.push_back("F003D004");
    groups.push_back("F003D006");
    fileRead.removeGroups(groups);
    
    EXPECT_EQ(fileRead.getNumBins(), 41);
    EXPECT_EQ(fileRead.getNumSeqsSmallestGroup(), 15);
    fileRead.removeGroups(20); //remove groups with abundance less than 20
    EXPECT_EQ(fileRead.getNumGroups(), 4);
}

TEST(Test_Container_SharedRabundVectors, SizeClear) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    EXPECT_EQ(fileRead.size(), 10);
    fileRead.clear();
    EXPECT_EQ(fileRead.getNumBins(), 0);
}

TEST(Test_Container_SharedRabundVectors, GetRabundVector) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    
    RAbundVector temp = fileRead.getRAbundVector();
    EXPECT_EQ(temp.get(0), 24);
    
    RAbundVector temp2 = fileRead.getRAbundVector("F003D142");
    EXPECT_EQ(temp2.get(0), 6);
}

TEST(Test_Container_SharedRabundVectors, GetSabundVector) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    
    SAbundVector temp = fileRead.getSAbundVector();
    EXPECT_EQ(temp.get(5), 1); //number of OTUs with abundance of 5
    EXPECT_EQ(temp.get(1), 35); //number of OTUs with abundance of 1
    EXPECT_EQ(temp.getMaxRank(), 24);
}

TEST(Test_Container_SharedRabundVectors, GetSharedRAbundVectors) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    
    vector<SharedRAbundVector*> temp = fileRead.getSharedRAbundVectors();
    EXPECT_EQ(temp[0]->get(5), 0); //first groups abundance of OTU5
    EXPECT_EQ(temp[1]->get(5), 2); //first groups abundance of OTU5
    EXPECT_EQ(temp[0]->get(0), 1); //first groups abundance of OTU1
    
}

TEST(Test_Container_SharedRabundVectors, GetSharedRAbundFloatVectors) {
    TestSharedRabundVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.sharedFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    
    vector<SharedRAbundFloatVector*> temp = fileRead.getSharedRAbundFloatVectors();
    EXPECT_EQ(temp[0]->get(5), 0.0); //first groups abundance of OTU5 as a float. This is not the same as if we ran get.relabund() command
    EXPECT_EQ(temp[1]->get(5), 2.0); //first groups abundance of OTU5 as a float. This is not the same as if we ran get.relabund() command
    EXPECT_EQ(temp[0]->get(0), 1.0); //first groups abundance of OTU1 as a float. This is not the same as if we ran get.relabund() command
    
}


/**************************************************************************************************/