File: testsharedrabundfloatvectors.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 (241 lines) | stat: -rw-r--r-- 8,467 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
//
//  testsharedrabundfloatvectors.cpp
//  Mothur
//
//  Created by Sarah Westcott on 8/14/18.
//  Copyright © 2018 Schloss Lab. All rights reserved.
//

#include "testsharedrabundfloatvectors.hpp"
#include "dataset.h"

/**************************************************************************************************/
TestSharedRabundFloatVectors::TestSharedRabundFloatVectors() : SharedRAbundFloatVectors() {  //setup
    m = MothurOut::getInstance();
    
    TestDataSet data; relabundFile = data.getRelabundFile();
}
/**************************************************************************************************/
TestSharedRabundFloatVectors::~TestSharedRabundFloatVectors() {}//teardown
/**************************************************************************************************/

TEST(Test_Container_SharedRabundFloatVectors, Constructors) {
    TestSharedRabundFloatVectors test;
    
    SharedRAbundFloatVectors temp;
    EXPECT_EQ(temp.getNumBins(), 0);
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    EXPECT_EQ(nextLabel, "");
    EXPECT_EQ(labelTag, "Otu");
    EXPECT_EQ(userGroups[0], "F003D000");
    
    SharedRAbundFloatVectors copy(fileRead);
    EXPECT_EQ(copy.getLabel(), "0.03");
    EXPECT_EQ(labelTag, "Otu");
    EXPECT_EQ(userGroups[0], "F003D000");
    
}

TEST(Test_Container_SharedRabundFloatVectors, GetsSets) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors 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
    ASSERT_NEAR(fileRead.getOTUTotal(4), 0.615171, 0.001);
    
    //getOTU
    vector<float> otu5 = fileRead.getOTU(4);
    ASSERT_NEAR(otu5[0], 0.0, 0.001);
    ASSERT_NEAR(otu5[2], 0.055556, 0.001);
    
    //get
    ASSERT_NEAR(fileRead.get(4, "F003D000"), 0.0, 0.001);
    ASSERT_NEAR(fileRead.get(4, "F003D002"), 0.111111, 0.001);
    ASSERT_NEAR(fileRead.get(0, "F003D142"), 0.222222, 0.001);
    
    //set
    fileRead.set(4, 0.25, "F003D000");
    ASSERT_NEAR(fileRead.get(4, "F003D000"), 0.25, 0.001);
    fileRead.set(4, 0.1234, "F003D002");
    ASSERT_NEAR(fileRead.get(4, "F003D002"), 0.1234, 0.001);
    fileRead.set(0, 0.456, "F003D142");
    ASSERT_NEAR(fileRead.get(0, "F003D142"), 0.456, 0.001);
    
    //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
    ASSERT_NEAR(fileRead.getNumSeqsSmallestGroup(), 1.0, 0.001);
    
    //getNamesGroups
    EXPECT_EQ(fileRead.getNamesGroups()[1], "F003D002");
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 10);
    
    //getNumSeqs
    ASSERT_NEAR(fileRead.getNumSeqs("F003D002"), 1.1234, 0.001); //1.0 + 0.1234 (set from above)
}

TEST(Test_Container_SharedRabundFloatVectors, PushBack) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 10);
    
    vector<float> abunds(58, 0.5);
    SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(abunds);
    temp->setGroup("myabunds");
    fileRead.push_back(temp);
    
    //getNumGroups
    EXPECT_EQ(fileRead.getNumGroups(), 11);
}


TEST(Test_Container_SharedRabundFloatVectors, eliminateZeroOTUS) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors 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_SharedRabundFloatVectors, Removes) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    EXPECT_EQ(fileRead.getNumBins(), 58);
    ASSERT_NEAR(fileRead.removeOTU(16), 0.074074, 0.001);
    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);
    ASSERT_NEAR(fileRead.getNumSeqsSmallestGroup(), 0.999999, 0.001);
    fileRead.removeGroups(20); //remove groups with abundance less than 20
    EXPECT_EQ(fileRead.getNumGroups(), 0);
}

TEST(Test_Container_SharedRabundFloatVectors, SizeClear) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    EXPECT_EQ(fileRead.size(), 10);
    fileRead.clear();
    EXPECT_EQ(fileRead.getNumBins(), 0);
}

TEST(Test_Container_SharedRabundFloatVectors, GetRabundVector) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    
    RAbundVector temp = fileRead.getRAbundVector();
    EXPECT_EQ(temp.get(0), 1);
    
}

TEST(Test_Container_SharedRabundFloatVectors, GetSabundVector) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors fileRead(in, userGroups, nextLabel, labelTag);
    
    SAbundVector temp = fileRead.getSAbundVector();
    EXPECT_EQ(temp.get(0), 0); //number of OTUs with abundance of 5
    EXPECT_EQ(temp.get(1), 1); //number of OTUs with abundance of 1
    EXPECT_EQ(temp.getMaxRank(), 1);
}

TEST(Test_Container_SharedRabundFloatVectors, GetSharedRAbundVectors) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors 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), 0); //first groups abundance of OTU5
    EXPECT_EQ(temp[0]->get(0), 0); //first groups abundance of OTU1
}

TEST(Test_Container_SharedRabundFloatVectors, GetSharedRAbundFloatVectors) {
    TestSharedRabundFloatVectors test;
    
    ifstream in;
    Utils util; util.openInputFile(test.relabundFile, in);
    vector<string> userGroups; string nextLabel, labelTag;
    SharedRAbundFloatVectors 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.
    ASSERT_NEAR(temp[1]->get(5), 0.111111, 0.001); //first groups abundance of OTU5 as a float.
    ASSERT_NEAR(temp[0]->get(0), 0.05, 0.001); //first groups abundance of OTU1 as a float.
}
/**************************************************************************************************/