5 * Created by westcott on 10/27/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "subsamplecommand.h"
11 #include "sharedutilities.h"
13 //**********************************************************************************************************************
14 vector<string> SubSampleCommand::setParameters(){
16 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pfasta);
17 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
18 CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup);
19 CommandParameter plist("list", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(plist);
20 CommandParameter pshared("shared", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(pshared);
21 CommandParameter prabund("rabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(prabund);
22 CommandParameter psabund("sabund", "InputTypes", "", "", "none", "FLSSR", "none",false,false); parameters.push_back(psabund);
23 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
24 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
25 CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize);
26 CommandParameter ppersample("persample", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(ppersample);
27 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
28 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
30 vector<string> myArray;
31 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
35 m->errorOut(e, "SubSampleCommand", "setParameters");
39 //**********************************************************************************************************************
40 string SubSampleCommand::getHelpString(){
42 string helpString = "";
43 helpString += "The sub.sample command is designed to be used as a way to normalize your data, or create a smaller set from your original set.\n";
44 helpString += "The sub.sample command parameters are fasta, name, list, group, rabund, sabund, shared, groups, size, persample and label. You must provide a fasta, list, sabund, rabund or shared file as an input file.\n";
45 helpString += "The namefile is only used with the fasta file, not with the listfile, because the list file should contain all sequences.\n";
46 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included. The group names are separated by dashes.\n";
47 helpString += "The label parameter allows you to select what distance levels you would like, and are also separated by dashes.\n";
48 helpString += "The size parameter allows you indicate the size of your subsample.\n";
49 helpString += "The persample parameter allows you indicate you want to select subsample of the same size from each of your groups, default=false. It is only used with the list and fasta files if a groupfile is given.\n";
50 helpString += "persample=false will select a random set of sequences of the size you select, but the number of seqs from each group may differ.\n";
51 helpString += "The size parameter is not set: with shared file size=number of seqs in smallest sample, with all other files if a groupfile is given and persample=true, then size=number of seqs in smallest sample, otherwise size=10% of number of seqs.\n";
52 helpString += "The sub.sample command should be in the following format: sub.sample(list=yourListFile, group=yourGroupFile, groups=yourGroups, label=yourLabels).\n";
53 helpString += "Example sub.sample(list=abrecovery.fn.list, group=abrecovery.groups, groups=B-C, size=20).\n";
54 helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
55 helpString += "The sub.sample command outputs a .subsample file.\n";
56 helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
60 m->errorOut(e, "SubSampleCommand", "getHelpString");
64 //**********************************************************************************************************************
65 SubSampleCommand::SubSampleCommand(){
67 abort = true; calledHelp = true;
69 vector<string> tempOutNames;
70 outputTypes["shared"] = tempOutNames;
71 outputTypes["list"] = tempOutNames;
72 outputTypes["rabund"] = tempOutNames;
73 outputTypes["sabund"] = tempOutNames;
74 outputTypes["fasta"] = tempOutNames;
75 outputTypes["name"] = tempOutNames;
76 outputTypes["group"] = tempOutNames;
79 m->errorOut(e, "SubSampleCommand", "GetRelAbundCommand");
83 //**********************************************************************************************************************
84 SubSampleCommand::SubSampleCommand(string option) {
86 abort = false; calledHelp = false;
89 //allow user to run help
90 if(option == "help") { help(); abort = true; calledHelp = true; }
93 vector<string> myArray = setParameters();
95 OptionParser parser(option);
96 map<string,string> parameters = parser.getParameters();
98 ValidParameters validParameter;
100 //check to make sure all parameters are valid for command
101 map<string,string>::iterator it;
102 for (it = parameters.begin(); it != parameters.end(); it++) {
103 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
106 //initialize outputTypes
107 vector<string> tempOutNames;
108 outputTypes["shared"] = tempOutNames;
109 outputTypes["list"] = tempOutNames;
110 outputTypes["rabund"] = tempOutNames;
111 outputTypes["sabund"] = tempOutNames;
112 outputTypes["fasta"] = tempOutNames;
113 outputTypes["name"] = tempOutNames;
114 outputTypes["group"] = tempOutNames;
116 //if the user changes the output directory command factory will send this info to us in the output parameter
117 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
119 //if the user changes the input directory command factory will send this info to us in the output parameter
120 string inputDir = validParameter.validFile(parameters, "inputdir", false);
121 if (inputDir == "not found"){ inputDir = ""; }
124 it = parameters.find("list");
125 //user has given a template file
126 if(it != parameters.end()){
127 path = m->hasPath(it->second);
128 //if the user has not given a path then, add inputdir. else leave path alone.
129 if (path == "") { parameters["list"] = inputDir + it->second; }
132 it = parameters.find("fasta");
133 //user has given a template file
134 if(it != parameters.end()){
135 path = m->hasPath(it->second);
136 //if the user has not given a path then, add inputdir. else leave path alone.
137 if (path == "") { parameters["fasta"] = inputDir + it->second; }
140 it = parameters.find("shared");
141 //user has given a template file
142 if(it != parameters.end()){
143 path = m->hasPath(it->second);
144 //if the user has not given a path then, add inputdir. else leave path alone.
145 if (path == "") { parameters["shared"] = inputDir + it->second; }
148 it = parameters.find("group");
149 //user has given a template file
150 if(it != parameters.end()){
151 path = m->hasPath(it->second);
152 //if the user has not given a path then, add inputdir. else leave path alone.
153 if (path == "") { parameters["group"] = inputDir + it->second; }
156 it = parameters.find("sabund");
157 //user has given a template file
158 if(it != parameters.end()){
159 path = m->hasPath(it->second);
160 //if the user has not given a path then, add inputdir. else leave path alone.
161 if (path == "") { parameters["sabund"] = inputDir + it->second; }
164 it = parameters.find("rabund");
165 //user has given a template file
166 if(it != parameters.end()){
167 path = m->hasPath(it->second);
168 //if the user has not given a path then, add inputdir. else leave path alone.
169 if (path == "") { parameters["rabund"] = inputDir + it->second; }
172 it = parameters.find("name");
173 //user has given a template file
174 if(it != parameters.end()){
175 path = m->hasPath(it->second);
176 //if the user has not given a path then, add inputdir. else leave path alone.
177 if (path == "") { parameters["name"] = inputDir + it->second; }
181 //check for required parameters
182 listfile = validParameter.validFile(parameters, "list", true);
183 if (listfile == "not open") { listfile = ""; abort = true; }
184 else if (listfile == "not found") { listfile = ""; }
186 sabundfile = validParameter.validFile(parameters, "sabund", true);
187 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
188 else if (sabundfile == "not found") { sabundfile = ""; }
190 rabundfile = validParameter.validFile(parameters, "rabund", true);
191 if (rabundfile == "not open") { rabundfile = ""; abort = true; }
192 else if (rabundfile == "not found") { rabundfile = ""; }
194 fastafile = validParameter.validFile(parameters, "fasta", true);
195 if (fastafile == "not open") { fastafile = ""; abort = true; }
196 else if (fastafile == "not found") { fastafile = ""; }
198 sharedfile = validParameter.validFile(parameters, "shared", true);
199 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
200 else if (sharedfile == "not found") { sharedfile = ""; }
202 namefile = validParameter.validFile(parameters, "name", true);
203 if (namefile == "not open") { namefile = ""; abort = true; }
204 else if (namefile == "not found") { namefile = ""; }
206 groupfile = validParameter.validFile(parameters, "group", true);
207 if (groupfile == "not open") { groupfile = ""; abort = true; }
208 else if (groupfile == "not found") { groupfile = ""; }
211 //check for optional parameter and set defaults
212 // ...at some point should added some additional type checking...
213 label = validParameter.validFile(parameters, "label", false);
214 if (label == "not found") { label = ""; }
216 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
217 else { allLines = 1; }
220 groups = validParameter.validFile(parameters, "groups", false);
221 if (groups == "not found") { groups = ""; pickedGroups = false; }
224 m->splitAtDash(groups, Groups);
228 string temp = validParameter.validFile(parameters, "size", false); if (temp == "not found"){ temp = "0"; }
231 temp = validParameter.validFile(parameters, "persample", false); if (temp == "not found"){ temp = "f"; }
232 persample = m->isTrue(temp);
234 if (groupfile == "") { persample = false; }
236 if ((namefile != "") && (fastafile == "")) { m->mothurOut("You may only use a namefile with a fastafile."); m->mothurOutEndLine(); abort = true; }
238 if ((fastafile == "") && (listfile == "") && (sabundfile == "") && (rabundfile == "") && (sharedfile == "")) {
239 m->mothurOut("You must provide a fasta, list, sabund, rabund or shared file as an input file."); m->mothurOutEndLine(); abort = true; }
241 if (pickedGroups && ((groupfile == "") && (sharedfile == ""))) {
242 m->mothurOut("You cannot pick groups without a valid group file or shared file."); m->mothurOutEndLine(); abort = true; }
244 if ((groupfile != "") && ((fastafile == "") && (listfile == ""))) {
245 m->mothurOut("Group file only valid with listfile or fastafile."); m->mothurOutEndLine(); abort = true; }
247 if ((groupfile != "") && ((fastafile != "") && (listfile != ""))) {
248 m->mothurOut("A new group file can only be made from the subsample of a listfile or fastafile, not both. Please correct."); m->mothurOutEndLine(); abort = true; }
253 catch(exception& e) {
254 m->errorOut(e, "SubSampleCommand", "SubSampleCommand");
258 //**********************************************************************************************************************
260 int SubSampleCommand::execute(){
263 if (abort == true) { if (calledHelp) { return 0; } return 2; }
265 if (sharedfile != "") { getSubSampleShared(); }
266 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); return 0; } }
268 if (listfile != "") { getSubSampleList(); }
269 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); return 0; } }
271 if (rabundfile != "") { getSubSampleRabund(); }
272 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); return 0; } }
274 if (sabundfile != "") { getSubSampleSabund(); }
275 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); return 0; } }
277 if (fastafile != "") { getSubSampleFasta(); }
278 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); return 0; } }
280 //set fasta file as new current fastafile
282 itTypes = outputTypes.find("fasta");
283 if (itTypes != outputTypes.end()) {
284 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
287 itTypes = outputTypes.find("name");
288 if (itTypes != outputTypes.end()) {
289 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
292 itTypes = outputTypes.find("group");
293 if (itTypes != outputTypes.end()) {
294 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
297 itTypes = outputTypes.find("list");
298 if (itTypes != outputTypes.end()) {
299 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
302 itTypes = outputTypes.find("shared");
303 if (itTypes != outputTypes.end()) {
304 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
307 itTypes = outputTypes.find("rabund");
308 if (itTypes != outputTypes.end()) {
309 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); }
312 itTypes = outputTypes.find("sabund");
313 if (itTypes != outputTypes.end()) {
314 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); }
318 m->mothurOutEndLine();
319 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
320 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
321 m->mothurOutEndLine();
325 catch(exception& e) {
326 m->errorOut(e, "SubSampleCommand", "execute");
330 //**********************************************************************************************************************
331 int SubSampleCommand::getSubSampleFasta() {
334 if (namefile != "") { readNames(); } //fills names with all names in namefile.
335 else { getNames(); }//no name file, so get list of names to pick from
338 if (groupfile != "") {
340 groupMap = new GroupMap(groupfile);
343 //takes care of user setting groupNames that are invalid or setting groups=all
344 SharedUtil* util = new SharedUtil();
345 util->setGroups(Groups, groupMap->namesOfGroups);
349 if (names.size() != groupMap->getNumSeqs()) {
350 m->mothurOut("[ERROR]: your fasta file contains " + toString(names.size()) + " sequences, and your groupfile contains " + toString(groupMap->getNumSeqs()) + ", please correct.");
351 m->mothurOutEndLine();
357 if (m->control_pressed) { return 0; }
360 //make sure that if your picked groups size is not too big
361 int thisSize = names.size();
363 if (size == 0) { //user has not set size, set size = smallest samples size
364 size = groupMap->getNumSeqs(Groups[0]);
365 for (int i = 1; i < Groups.size(); i++) {
366 int thisSize = groupMap->getNumSeqs(Groups[i]);
368 if (thisSize < size) { size = thisSize; }
370 }else { //make sure size is not too large
371 vector<string> newGroups;
372 for (int i = 0; i < Groups.size(); i++) {
373 int thisSize = groupMap->getNumSeqs(Groups[i]);
375 if (thisSize >= size) { newGroups.push_back(Groups[i]); }
376 else { m->mothurOut("You have selected a size that is larger than " + Groups[i] + " number of sequences, removing " + Groups[i] + "."); m->mothurOutEndLine(); }
381 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
385 for(int i = 0; i < Groups.size(); i++) {
386 total += groupMap->getNumSeqs(Groups[i]);
389 if (size == 0) { //user has not set size, set size = 10% samples size
390 size = int (total * 0.10);
395 m->mothurOut("Your size is too large for the number of groups you selected. Adjusting to " + toString(int (total * 0.10)) + "."); m->mothurOutEndLine();
397 size = int (total * 0.10);
400 m->mothurOut("Sampling " + toString(size) + " from " + toString(total) + "."); m->mothurOutEndLine();
403 if (size == 0) { //user has not set size, set size = 10% samples size
404 size = int (names.size() * 0.10);
407 if (size > thisSize) { m->mothurOut("Your fasta file only contains " + toString(thisSize) + " sequences. Setting size to " + toString(thisSize) + "."); m->mothurOutEndLine();
411 if (!pickedGroups) { m->mothurOut("Sampling " + toString(size) + " from " + toString(thisSize) + "."); m->mothurOutEndLine(); }
414 random_shuffle(names.begin(), names.end());
416 set<string> subset; //dont want repeat sequence names added
418 for (int i = 0; i < Groups.size(); i++) {
420 //randomly select a subset of those names from this group to include in the subsample
421 for (int j = 0; j < size; j++) {
423 if (m->control_pressed) { return 0; }
425 //get random sequence to add, making sure we have not already added it
429 myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
431 if (subset.count(names[myrand]) == 0) {
433 string group = groupMap->getGroup(names[myrand]);
434 if (group == "not found") { m->mothurOut("[ERROR]: " + names[myrand] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
436 if (group == Groups[i]) { subset.insert(names[myrand]); break; }
443 //randomly select a subset of those names to include in the subsample
444 for (int j = 0; j < size; j++) {
446 if (m->control_pressed) { return 0; }
448 //get random sequence to add, making sure we have not already added it
452 myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
454 if (subset.count(names[myrand]) == 0) {
456 if (groupfile != "") { //if there is a groupfile given fill in group info
457 string group = groupMap->getGroup(names[myrand]);
458 if (group == "not found") { m->mothurOut("[ERROR]: " + names[myrand] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
460 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
461 if (m->inUsersGroups(group, Groups)) {
462 subset.insert(names[myrand]); break;
465 subset.insert(names[myrand]); break;
467 }else{ //save everyone, group
468 subset.insert(names[myrand]); break;
475 if (subset.size() == 0) { m->mothurOut("The size you selected is too large, skipping fasta file."); m->mothurOutEndLine(); return 0; }
477 string thisOutputDir = outputDir;
478 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
479 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "subsample" + m->getExtension(fastafile);
482 m->openOutputFile(outputFileName, out);
483 outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
485 //read through fasta file outputting only the names on the subsample list
487 m->openInputFile(fastafile, in);
491 map<string, vector<string> >::iterator itNameMap;
495 if (m->control_pressed) { in.close(); out.close(); return 0; }
497 Sequence currSeq(in);
498 thisname = currSeq.getName();
500 if (thisname != "") {
502 //does the subset contain a sequence that this sequence represents
503 itNameMap = nameMap.find(thisname);
504 if (itNameMap != nameMap.end()) {
505 vector<string> nameRepresents = itNameMap->second;
507 for (int i = 0; i < nameRepresents.size(); i++){
508 if (subset.count(nameRepresents[i]) != 0) {
509 out << ">" << nameRepresents[i] << endl << currSeq.getAligned() << endl;
514 m->mothurOut("[ERROR]: " + thisname + " is not in your namefile, please correct."); m->mothurOutEndLine();
522 if (count != subset.size()) {
523 m->mothurOut("[ERROR]: The subset selected contained " + toString(subset.size()) + " sequences, but I only found " + toString(count) + " of those in the fastafile."); m->mothurOutEndLine();
526 //if a groupfile is provided read through the group file only outputting the names on the subsample list
527 if (groupfile != "") {
529 string groupOutputDir = outputDir;
530 if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); }
531 string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "subsample" + m->getExtension(groupfile);
534 m->openOutputFile(groupOutputFileName, outGroup);
535 outputTypes["group"].push_back(groupOutputFileName); outputNames.push_back(groupOutputFileName);
538 m->openInputFile(groupfile, inGroup);
541 while(!inGroup.eof()){
543 if (m->control_pressed) { inGroup.close(); outGroup.close(); return 0; }
545 inGroup >> name; m->gobble(inGroup); //read from first column
546 inGroup >> group; //read from second column
548 //if this name is in the accnos file
549 if (subset.count(name) != 0) {
550 outGroup << name << '\t' << group << endl;
560 if (subset.size() != 0) {
561 m->mothurOut("Your groupfile does not match your fasta file."); m->mothurOutEndLine();
562 for (set<string>::iterator it = subset.begin(); it != subset.end(); it++) {
563 m->mothurOut("[ERROR]: " + *it + " is missing from your groupfile."); m->mothurOutEndLine();
571 catch(exception& e) {
572 m->errorOut(e, "SubSampleCommand", "getSubSampleFasta");
576 //**********************************************************************************************************************
577 int SubSampleCommand::getNames() {
581 m->openInputFile(fastafile, in);
586 if (m->control_pressed) { in.close(); return 0; }
588 Sequence currSeq(in);
589 thisname = currSeq.getName();
591 if (thisname != "") {
592 vector<string> temp; temp.push_back(thisname);
593 nameMap[thisname] = temp;
594 names.push_back(thisname);
603 catch(exception& e) {
604 m->errorOut(e, "SubSampleCommand", "getNames");
608 //**********************************************************************************************************************
609 int SubSampleCommand::readNames() {
613 m->openInputFile(namefile, in);
615 string thisname, repnames;
616 map<string, vector<string> >::iterator it;
620 if (m->control_pressed) { in.close(); return 0; }
622 in >> thisname; m->gobble(in); //read from first column
623 in >> repnames; //read from second column
625 it = nameMap.find(thisname);
626 if (it == nameMap.end()) {
628 vector<string> splitRepNames;
629 m->splitAtComma(repnames, splitRepNames);
631 nameMap[thisname] = splitRepNames;
632 for (int i = 0; i < splitRepNames.size(); i++) { names.push_back(splitRepNames[i]); }
634 }else{ m->mothurOut(thisname + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); }
643 catch(exception& e) {
644 m->errorOut(e, "SubSampleCommand", "readNames");
648 //**********************************************************************************************************************
649 int SubSampleCommand::getSubSampleShared() {
652 InputData* input = new InputData(sharedfile, "sharedfile");
653 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
654 string lastLabel = lookup[0]->getLabel();
656 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
657 set<string> processedLabels;
658 set<string> userLabels = labels;
660 if (size == 0) { //user has not set size, set size = smallest samples size
661 size = lookup[0]->getNumSeqs();
662 for (int i = 1; i < lookup.size(); i++) {
663 int thisSize = lookup[i]->getNumSeqs();
665 if (thisSize < size) { size = thisSize; }
669 vector<SharedRAbundVector*> temp;
670 for (int i = 0; i < lookup.size(); i++) {
671 if (lookup[i]->getNumSeqs() < size) {
672 m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
675 m->Groups.push_back(lookup[i]->getGroup());
676 temp.push_back(lookup[i]);
683 if (lookup.size() == 0) { m->mothurOut("The size you selected is too large, skipping shared file."); m->mothurOutEndLine(); delete input; return 0; }
685 string thisOutputDir = outputDir;
686 if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
687 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "subsample" + m->getExtension(sharedfile);
690 m->openOutputFile(outputFileName, out);
691 outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
694 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
696 //as long as you are not at the end of the file or done wih the lines you want
697 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
698 if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } out.close(); return 0; }
700 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
702 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
704 processShared(lookup, out);
706 processedLabels.insert(lookup[0]->getLabel());
707 userLabels.erase(lookup[0]->getLabel());
710 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
711 string saveLabel = lookup[0]->getLabel();
713 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
715 lookup = input->getSharedRAbundVectors(lastLabel);
716 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
718 processShared(lookup, out);
720 processedLabels.insert(lookup[0]->getLabel());
721 userLabels.erase(lookup[0]->getLabel());
723 //restore real lastlabel to save below
724 lookup[0]->setLabel(saveLabel);
727 lastLabel = lookup[0]->getLabel();
728 //prevent memory leak
729 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
731 //get next line to process
732 lookup = input->getSharedRAbundVectors();
736 if (m->control_pressed) { out.close(); return 0; }
738 //output error messages about any remaining user labels
739 set<string>::iterator it;
740 bool needToRun = false;
741 for (it = userLabels.begin(); it != userLabels.end(); it++) {
742 m->mothurOut("Your file does not include the label " + *it);
743 if (processedLabels.count(lastLabel) != 1) {
744 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
747 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
751 //run last label if you need to
752 if (needToRun == true) {
753 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
754 lookup = input->getSharedRAbundVectors(lastLabel);
756 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
758 processShared(lookup, out);
760 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
769 catch(exception& e) {
770 m->errorOut(e, "SubSampleCommand", "getSubSampleShared");
774 //**********************************************************************************************************************
775 int SubSampleCommand::processShared(vector<SharedRAbundVector*>& thislookup, ofstream& out) {
778 int numBins = thislookup[0]->getNumBins();
779 for (int i = 0; i < thislookup.size(); i++) {
780 int thisSize = thislookup[i]->getNumSeqs();
782 if (thisSize != size) {
784 string thisgroup = thislookup[i]->getGroup();
786 OrderVector* order = new OrderVector();
787 for(int p=0;p<numBins;p++){
788 for(int j=0;j<thislookup[i]->getAbundance(p);j++){
792 random_shuffle(order->begin(), order->end());
794 SharedRAbundVector* temp = new SharedRAbundVector(numBins);
795 temp->setLabel(thislookup[i]->getLabel());
796 temp->setGroup(thislookup[i]->getGroup());
798 delete thislookup[i];
799 thislookup[i] = temp;
802 for (int j = 0; j < size; j++) {
804 if (m->control_pressed) { delete order; return 0; }
806 //get random number to sample from order between 0 and thisSize-1.
807 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
809 int bin = order->get(myrand);
811 int abund = thislookup[i]->getAbundance(bin);
812 thislookup[i]->set(bin, (abund+1), thisgroup);
818 //subsampling may have created some otus with no sequences in them
819 eliminateZeroOTUS(thislookup);
821 if (m->control_pressed) { return 0; }
823 for (int i = 0; i < thislookup.size(); i++) {
824 out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
825 thislookup[i]->print(out);
831 catch(exception& e) {
832 m->errorOut(e, "SubSampleCommand", "processShared");
836 //**********************************************************************************************************************
837 int SubSampleCommand::getSubSampleList() {
840 string thisOutputDir = outputDir;
841 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
842 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "subsample" + m->getExtension(listfile);
845 m->openOutputFile(outputFileName, out);
846 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
848 InputData* input = new InputData(listfile, "list");
849 ListVector* list = input->getListVector();
850 string lastLabel = list->getLabel();
852 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
853 set<string> processedLabels;
854 set<string> userLabels = labels;
858 if (groupfile != "") {
860 groupMap = new GroupMap(groupfile);
863 //takes care of user setting groupNames that are invalid or setting groups=all
864 SharedUtil* util = new SharedUtil();
865 util->setGroups(Groups, groupMap->namesOfGroups);
869 string groupOutputDir = outputDir;
870 if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); }
871 string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "subsample" + m->getExtension(groupfile);
873 m->openOutputFile(groupOutputFileName, outGroup);
874 outputTypes["group"].push_back(groupOutputFileName); outputNames.push_back(groupOutputFileName);
877 if (list->getNumSeqs() != groupMap->getNumSeqs()) {
878 m->mothurOut("[ERROR]: your list file contains " + toString(list->getNumSeqs()) + " sequences, and your groupfile contains " + toString(groupMap->getNumSeqs()) + ", please correct.");
879 m->mothurOutEndLine();
889 //make sure that if your picked groups size is not too big
891 if (size == 0) { //user has not set size, set size = smallest samples size
892 size = groupMap->getNumSeqs(Groups[0]);
893 for (int i = 1; i < Groups.size(); i++) {
894 int thisSize = groupMap->getNumSeqs(Groups[i]);
896 if (thisSize < size) { size = thisSize; }
898 }else { //make sure size is not too large
899 vector<string> newGroups;
900 for (int i = 0; i < Groups.size(); i++) {
901 int thisSize = groupMap->getNumSeqs(Groups[i]);
903 if (thisSize >= size) { newGroups.push_back(Groups[i]); }
904 else { m->mothurOut("You have selected a size that is larger than " + Groups[i] + " number of sequences, removing " + Groups[i] + "."); m->mothurOutEndLine(); }
909 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
913 for(int i = 0; i < Groups.size(); i++) {
914 total += groupMap->getNumSeqs(Groups[i]);
917 if (size == 0) { //user has not set size, set size = 10% samples size
918 size = int (total * 0.10);
922 m->mothurOut("Your size is too large for the number of groups you selected. Adjusting to " + toString(int (total * 0.10)) + "."); m->mothurOutEndLine();
923 size = int (total * 0.10);
926 m->mothurOut("Sampling " + toString(size) + " from " + toString(total) + "."); m->mothurOutEndLine();
929 if (size == 0) { //user has not set size, set size = 10% samples size
930 size = int (list->getNumSeqs() * 0.10);
933 int thisSize = list->getNumSeqs();
934 if (size > thisSize) { m->mothurOut("Your list file only contains " + toString(thisSize) + " sequences. Setting size to " + toString(thisSize) + "."); m->mothurOutEndLine();
938 m->mothurOut("Sampling " + toString(size) + " from " + toString(list->getNumSeqs()) + "."); m->mothurOutEndLine();
944 for (int i = 0; i < list->getNumBins(); i++) {
945 string binnames = list->get(i);
948 string individual = "";
949 int length = binnames.length();
950 for(int j=0;j<length;j++){
951 if(binnames[j] == ','){
953 if (groupfile != "") { //if there is a groupfile given fill in group info
954 string group = groupMap->getGroup(individual);
955 if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
957 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
958 if (m->inUsersGroups(group, Groups)) {
959 names.push_back(individual);
962 names.push_back(individual);
964 }else{ //save everyone, group
965 names.push_back(individual);
970 individual += binnames[j];
974 if (groupfile != "") { //if there is a groupfile given fill in group info
975 string group = groupMap->getGroup(individual);
976 if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
978 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
979 if (m->inUsersGroups(group, Groups)) {
980 names.push_back(individual);
983 names.push_back(individual);
985 }else{ //save everyone, group
986 names.push_back(individual);
990 random_shuffle(names.begin(), names.end());
992 //randomly select a subset of those names to include in the subsample
993 set<string> subset; //dont want repeat sequence names added
995 for (int i = 0; i < Groups.size(); i++) {
997 for (int j = 0; j < size; j++) {
999 if (m->control_pressed) { break; }
1001 //get random sequence to add, making sure we have not already added it
1005 myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
1007 if (subset.count(names[myrand]) == 0) { //you are not already added
1008 if (groupMap->getGroup(names[myrand]) == Groups[i]) { subset.insert(names[myrand]); break; }
1014 for (int j = 0; j < size; j++) {
1016 if (m->control_pressed) { break; }
1018 //get random sequence to add, making sure we have not already added it
1022 myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
1024 if (subset.count(names[myrand]) == 0) { subset.insert(names[myrand]); break; }
1029 if (groupfile != "") {
1030 //write out new groupfile
1031 for (set<string>::iterator it = subset.begin(); it != subset.end(); it++) {
1032 string group = groupMap->getGroup(*it);
1033 if (group == "not found") { group = "NOTFOUND"; }
1035 outGroup << *it << '\t' << group << endl;
1037 outGroup.close(); delete groupMap;
1041 //as long as you are not at the end of the file or done wih the lines you want
1042 while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1044 if (m->control_pressed) { delete list; delete input; out.close(); return 0; }
1046 if(allLines == 1 || labels.count(list->getLabel()) == 1){
1048 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1050 processList(list, out, subset);
1052 processedLabels.insert(list->getLabel());
1053 userLabels.erase(list->getLabel());
1056 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1057 string saveLabel = list->getLabel();
1061 list = input->getListVector(lastLabel);
1062 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1064 processList(list, out, subset);
1066 processedLabels.insert(list->getLabel());
1067 userLabels.erase(list->getLabel());
1069 //restore real lastlabel to save below
1070 list->setLabel(saveLabel);
1073 lastLabel = list->getLabel();
1075 delete list; list = NULL;
1077 //get next line to process
1078 list = input->getListVector();
1082 if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); return 0; }
1084 //output error messages about any remaining user labels
1085 set<string>::iterator it;
1086 bool needToRun = false;
1087 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1088 m->mothurOut("Your file does not include the label " + *it);
1089 if (processedLabels.count(lastLabel) != 1) {
1090 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1093 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1097 //run last label if you need to
1098 if (needToRun == true) {
1099 if (list != NULL) { delete list; }
1101 list = input->getListVector(lastLabel);
1103 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1105 processList(list, out, subset);
1107 delete list; list = NULL;
1111 if (list != NULL) { delete list; }
1117 catch(exception& e) {
1118 m->errorOut(e, "SubSampleCommand", "getSubSampleList");
1122 //**********************************************************************************************************************
1123 int SubSampleCommand::processList(ListVector*& list, ofstream& out, set<string>& subset) {
1126 int numBins = list->getNumBins();
1128 ListVector* temp = new ListVector();
1129 temp->setLabel(list->getLabel());
1131 for (int i = 0; i < numBins; i++) {
1133 if (m->control_pressed) { break; }
1135 string binnames = list->get(i);
1138 string individual = "";
1139 string newNames = "";
1140 int length = binnames.length();
1141 for(int j=0;j<length;j++){
1142 if(binnames[j] == ','){
1143 if (subset.count(individual) != 0) { newNames += individual + ","; }
1146 individual += binnames[j];
1149 if (subset.count(individual) != 0) { newNames += individual; }
1152 //if there are names in this bin add to new list
1153 if (newNames != "") {
1154 newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
1155 temp->push_back(newNames);
1162 if (m->control_pressed) { return 0; }
1169 catch(exception& e) {
1170 m->errorOut(e, "SubSampleCommand", "processList");
1174 //**********************************************************************************************************************
1175 int SubSampleCommand::getSubSampleRabund() {
1177 InputData* input = new InputData(rabundfile, "rabund");
1178 RAbundVector* rabund = input->getRAbundVector();
1179 string lastLabel = rabund->getLabel();
1181 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
1182 set<string> processedLabels;
1183 set<string> userLabels = labels;
1185 if (size == 0) { //user has not set size, set size = 10%
1186 size = int((rabund->getNumSeqs()) * 0.10);
1187 }else if (size > rabund->getNumSeqs()) { m->mothurOut("The size you selected is too large, skipping rabund file."); m->mothurOutEndLine(); delete input; delete rabund; return 0; }
1189 m->mothurOut("Sampling " + toString(size) + " from " + toString(rabund->getNumSeqs()) + "."); m->mothurOutEndLine();
1191 string thisOutputDir = outputDir;
1192 if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); }
1193 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "subsample" + m->getExtension(rabundfile);
1196 m->openOutputFile(outputFileName, out);
1197 outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
1199 //as long as you are not at the end of the file or done wih the lines you want
1200 while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1201 if (m->control_pressed) { delete input; delete rabund; out.close(); return 0; }
1203 if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
1205 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1207 processRabund(rabund, out);
1209 processedLabels.insert(rabund->getLabel());
1210 userLabels.erase(rabund->getLabel());
1213 if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1214 string saveLabel = rabund->getLabel();
1218 rabund = input->getRAbundVector(lastLabel);
1219 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1221 processRabund(rabund, out);
1223 processedLabels.insert(rabund->getLabel());
1224 userLabels.erase(rabund->getLabel());
1226 //restore real lastlabel to save below
1227 rabund->setLabel(saveLabel);
1230 lastLabel = rabund->getLabel();
1232 //prevent memory leak
1233 delete rabund; rabund = NULL;
1235 //get next line to process
1236 rabund = input->getRAbundVector();
1240 if (m->control_pressed) { out.close(); return 0; }
1242 //output error messages about any remaining user labels
1243 set<string>::iterator it;
1244 bool needToRun = false;
1245 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1246 m->mothurOut("Your file does not include the label " + *it);
1247 if (processedLabels.count(lastLabel) != 1) {
1248 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1251 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1255 //run last label if you need to
1256 if (needToRun == true) {
1257 if (rabund != NULL) { delete rabund; }
1259 rabund = input->getRAbundVector(lastLabel);
1261 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1263 processRabund(rabund, out);
1274 catch(exception& e) {
1275 m->errorOut(e, "SubSampleCommand", "getSubSampleRabund");
1279 //**********************************************************************************************************************
1280 int SubSampleCommand::processRabund(RAbundVector*& rabund, ofstream& out) {
1283 int numBins = rabund->getNumBins();
1284 int thisSize = rabund->getNumSeqs();
1286 if (thisSize != size) {
1288 OrderVector* order = new OrderVector();
1289 for(int p=0;p<numBins;p++){
1290 for(int j=0;j<rabund->get(p);j++){
1291 order->push_back(p);
1294 random_shuffle(order->begin(), order->end());
1296 RAbundVector* temp = new RAbundVector(numBins);
1297 temp->setLabel(rabund->getLabel());
1302 for (int j = 0; j < size; j++) {
1304 if (m->control_pressed) { delete order; return 0; }
1306 //get random number to sample from order between 0 and thisSize-1.
1307 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
1309 int bin = order->get(myrand);
1311 int abund = rabund->get(bin);
1312 rabund->set(bin, (abund+1));
1318 if (m->control_pressed) { return 0; }
1325 catch(exception& e) {
1326 m->errorOut(e, "SubSampleCommand", "processRabund");
1330 //**********************************************************************************************************************
1331 int SubSampleCommand::getSubSampleSabund() {
1334 InputData* input = new InputData(sabundfile, "sabund");
1335 SAbundVector* sabund = input->getSAbundVector();
1336 string lastLabel = sabund->getLabel();
1338 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
1339 set<string> processedLabels;
1340 set<string> userLabels = labels;
1342 if (size == 0) { //user has not set size, set size = 10%
1343 size = int((sabund->getNumSeqs()) * 0.10);
1344 }else if (size > sabund->getNumSeqs()) { m->mothurOut("The size you selected is too large, skipping sabund file."); m->mothurOutEndLine(); delete input; delete sabund; return 0; }
1347 m->mothurOut("Sampling " + toString(size) + " from " + toString(sabund->getNumSeqs()) + "."); m->mothurOutEndLine();
1349 string thisOutputDir = outputDir;
1350 if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); }
1351 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "subsample" + m->getExtension(sabundfile);
1354 m->openOutputFile(outputFileName, out);
1355 outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
1358 //as long as you are not at the end of the file or done wih the lines you want
1359 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1360 if (m->control_pressed) { delete input; delete sabund; out.close(); return 0; }
1362 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
1364 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1366 processSabund(sabund, out);
1368 processedLabels.insert(sabund->getLabel());
1369 userLabels.erase(sabund->getLabel());
1372 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1373 string saveLabel = sabund->getLabel();
1377 sabund = input->getSAbundVector(lastLabel);
1378 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1380 processSabund(sabund, out);
1382 processedLabels.insert(sabund->getLabel());
1383 userLabels.erase(sabund->getLabel());
1385 //restore real lastlabel to save below
1386 sabund->setLabel(saveLabel);
1389 lastLabel = sabund->getLabel();
1391 //prevent memory leak
1392 delete sabund; sabund = NULL;
1394 //get next line to process
1395 sabund = input->getSAbundVector();
1399 if (m->control_pressed) { out.close(); return 0; }
1401 //output error messages about any remaining user labels
1402 set<string>::iterator it;
1403 bool needToRun = false;
1404 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1405 m->mothurOut("Your file does not include the label " + *it);
1406 if (processedLabels.count(lastLabel) != 1) {
1407 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1410 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1414 //run last label if you need to
1415 if (needToRun == true) {
1416 if (sabund != NULL) { delete sabund; }
1418 sabund = input->getSAbundVector(lastLabel);
1420 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1422 processSabund(sabund, out);
1433 catch(exception& e) {
1434 m->errorOut(e, "SubSampleCommand", "getSubSampleSabund");
1438 //**********************************************************************************************************************
1439 int SubSampleCommand::processSabund(SAbundVector*& sabund, ofstream& out) {
1442 RAbundVector* rabund = new RAbundVector();
1443 *rabund = sabund->getRAbundVector();
1445 int numBins = rabund->getNumBins();
1446 int thisSize = rabund->getNumSeqs();
1448 if (thisSize != size) {
1450 OrderVector* order = new OrderVector();
1451 for(int p=0;p<numBins;p++){
1452 for(int j=0;j<rabund->get(p);j++){
1453 order->push_back(p);
1456 random_shuffle(order->begin(), order->end());
1458 RAbundVector* temp = new RAbundVector(numBins);
1459 temp->setLabel(rabund->getLabel());
1464 for (int j = 0; j < size; j++) {
1466 if (m->control_pressed) { delete order; return 0; }
1468 //get random number to sample from order between 0 and thisSize-1.
1469 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
1471 int bin = order->get(myrand);
1473 int abund = rabund->get(bin);
1474 rabund->set(bin, (abund+1));
1480 if (m->control_pressed) { return 0; }
1483 sabund = new SAbundVector();
1484 *sabund = rabund->getSAbundVector();
1492 catch(exception& e) {
1493 m->errorOut(e, "SubSampleCommand", "processSabund");
1497 //**********************************************************************************************************************
1498 int SubSampleCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
1501 vector<SharedRAbundVector*> newLookup;
1502 for (int i = 0; i < thislookup.size(); i++) {
1503 SharedRAbundVector* temp = new SharedRAbundVector();
1504 temp->setLabel(thislookup[i]->getLabel());
1505 temp->setGroup(thislookup[i]->getGroup());
1506 newLookup.push_back(temp);
1510 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
1511 if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
1513 //look at each sharedRabund and make sure they are not all zero
1514 bool allZero = true;
1515 for (int j = 0; j < thislookup.size(); j++) {
1516 if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; }
1519 //if they are not all zero add this bin
1521 for (int j = 0; j < thislookup.size(); j++) {
1522 newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
1527 for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
1530 thislookup = newLookup;
1535 catch(exception& e) {
1536 m->errorOut(e, "SubSampleCommand", "eliminateZeroOTUS");
1541 //**********************************************************************************************************************