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; }
91 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
94 vector<string> myArray = setParameters();
96 OptionParser parser(option);
97 map<string,string> parameters = parser.getParameters();
99 ValidParameters validParameter;
101 //check to make sure all parameters are valid for command
102 map<string,string>::iterator it;
103 for (it = parameters.begin(); it != parameters.end(); it++) {
104 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
107 //initialize outputTypes
108 vector<string> tempOutNames;
109 outputTypes["shared"] = tempOutNames;
110 outputTypes["list"] = tempOutNames;
111 outputTypes["rabund"] = tempOutNames;
112 outputTypes["sabund"] = tempOutNames;
113 outputTypes["fasta"] = tempOutNames;
114 outputTypes["name"] = tempOutNames;
115 outputTypes["group"] = tempOutNames;
117 //if the user changes the output directory command factory will send this info to us in the output parameter
118 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
120 //if the user changes the input directory command factory will send this info to us in the output parameter
121 string inputDir = validParameter.validFile(parameters, "inputdir", false);
122 if (inputDir == "not found"){ inputDir = ""; }
125 it = parameters.find("list");
126 //user has given a template file
127 if(it != parameters.end()){
128 path = m->hasPath(it->second);
129 //if the user has not given a path then, add inputdir. else leave path alone.
130 if (path == "") { parameters["list"] = inputDir + it->second; }
133 it = parameters.find("fasta");
134 //user has given a template file
135 if(it != parameters.end()){
136 path = m->hasPath(it->second);
137 //if the user has not given a path then, add inputdir. else leave path alone.
138 if (path == "") { parameters["fasta"] = inputDir + it->second; }
141 it = parameters.find("shared");
142 //user has given a template file
143 if(it != parameters.end()){
144 path = m->hasPath(it->second);
145 //if the user has not given a path then, add inputdir. else leave path alone.
146 if (path == "") { parameters["shared"] = inputDir + it->second; }
149 it = parameters.find("group");
150 //user has given a template file
151 if(it != parameters.end()){
152 path = m->hasPath(it->second);
153 //if the user has not given a path then, add inputdir. else leave path alone.
154 if (path == "") { parameters["group"] = inputDir + it->second; }
157 it = parameters.find("sabund");
158 //user has given a template file
159 if(it != parameters.end()){
160 path = m->hasPath(it->second);
161 //if the user has not given a path then, add inputdir. else leave path alone.
162 if (path == "") { parameters["sabund"] = inputDir + it->second; }
165 it = parameters.find("rabund");
166 //user has given a template file
167 if(it != parameters.end()){
168 path = m->hasPath(it->second);
169 //if the user has not given a path then, add inputdir. else leave path alone.
170 if (path == "") { parameters["rabund"] = inputDir + it->second; }
173 it = parameters.find("name");
174 //user has given a template file
175 if(it != parameters.end()){
176 path = m->hasPath(it->second);
177 //if the user has not given a path then, add inputdir. else leave path alone.
178 if (path == "") { parameters["name"] = inputDir + it->second; }
182 //check for required parameters
183 listfile = validParameter.validFile(parameters, "list", true);
184 if (listfile == "not open") { listfile = ""; abort = true; }
185 else if (listfile == "not found") { listfile = ""; }
186 else { m->setListFile(listfile); }
188 sabundfile = validParameter.validFile(parameters, "sabund", true);
189 if (sabundfile == "not open") { sabundfile = ""; abort = true; }
190 else if (sabundfile == "not found") { sabundfile = ""; }
191 else { m->setSabundFile(sabundfile); }
193 rabundfile = validParameter.validFile(parameters, "rabund", true);
194 if (rabundfile == "not open") { rabundfile = ""; abort = true; }
195 else if (rabundfile == "not found") { rabundfile = ""; }
196 else { m->setRabundFile(rabundfile); }
198 fastafile = validParameter.validFile(parameters, "fasta", true);
199 if (fastafile == "not open") { fastafile = ""; abort = true; }
200 else if (fastafile == "not found") { fastafile = ""; }
201 else { m->setFastaFile(fastafile); }
203 sharedfile = validParameter.validFile(parameters, "shared", true);
204 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
205 else if (sharedfile == "not found") { sharedfile = ""; }
206 else { m->setSharedFile(sharedfile); }
208 namefile = validParameter.validFile(parameters, "name", true);
209 if (namefile == "not open") { namefile = ""; abort = true; }
210 else if (namefile == "not found") { namefile = ""; }
211 else { m->setNameFile(namefile); }
213 groupfile = validParameter.validFile(parameters, "group", true);
214 if (groupfile == "not open") { groupfile = ""; abort = true; }
215 else if (groupfile == "not found") { groupfile = ""; }
216 else { m->setGroupFile(groupfile); }
218 //check for optional parameter and set defaults
219 // ...at some point should added some additional type checking...
220 label = validParameter.validFile(parameters, "label", false);
221 if (label == "not found") { label = ""; }
223 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
224 else { allLines = 1; }
227 groups = validParameter.validFile(parameters, "groups", false);
228 if (groups == "not found") { groups = ""; pickedGroups = false; }
231 m->splitAtDash(groups, Groups);
235 string temp = validParameter.validFile(parameters, "size", false); if (temp == "not found"){ temp = "0"; }
238 temp = validParameter.validFile(parameters, "persample", false); if (temp == "not found"){ temp = "f"; }
239 persample = m->isTrue(temp);
241 if (groupfile == "") { persample = false; }
243 if ((namefile != "") && (fastafile == "")) { m->mothurOut("You may only use a namefile with a fastafile."); m->mothurOutEndLine(); abort = true; }
245 if ((fastafile == "") && (listfile == "") && (sabundfile == "") && (rabundfile == "") && (sharedfile == "")) {
246 m->mothurOut("You must provide a fasta, list, sabund, rabund or shared file as an input file."); m->mothurOutEndLine(); abort = true; }
248 if (pickedGroups && ((groupfile == "") && (sharedfile == ""))) {
249 m->mothurOut("You cannot pick groups without a valid group file or shared file."); m->mothurOutEndLine(); abort = true; }
251 if ((groupfile != "") && ((fastafile == "") && (listfile == ""))) {
252 m->mothurOut("Group file only valid with listfile or fastafile."); m->mothurOutEndLine(); abort = true; }
254 if ((groupfile != "") && ((fastafile != "") && (listfile != ""))) {
255 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; }
260 catch(exception& e) {
261 m->errorOut(e, "SubSampleCommand", "SubSampleCommand");
265 //**********************************************************************************************************************
267 int SubSampleCommand::execute(){
270 if (abort == true) { if (calledHelp) { return 0; } return 2; }
272 if (sharedfile != "") { getSubSampleShared(); }
273 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); return 0; } }
275 if (listfile != "") { getSubSampleList(); }
276 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); return 0; } }
278 if (rabundfile != "") { getSubSampleRabund(); }
279 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); return 0; } }
281 if (sabundfile != "") { getSubSampleSabund(); }
282 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); return 0; } }
284 if (fastafile != "") { getSubSampleFasta(); }
285 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); return 0; } }
287 //set fasta file as new current fastafile
289 itTypes = outputTypes.find("fasta");
290 if (itTypes != outputTypes.end()) {
291 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
294 itTypes = outputTypes.find("name");
295 if (itTypes != outputTypes.end()) {
296 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
299 itTypes = outputTypes.find("group");
300 if (itTypes != outputTypes.end()) {
301 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
304 itTypes = outputTypes.find("list");
305 if (itTypes != outputTypes.end()) {
306 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
309 itTypes = outputTypes.find("shared");
310 if (itTypes != outputTypes.end()) {
311 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
314 itTypes = outputTypes.find("rabund");
315 if (itTypes != outputTypes.end()) {
316 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setRabundFile(current); }
319 itTypes = outputTypes.find("sabund");
320 if (itTypes != outputTypes.end()) {
321 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSabundFile(current); }
325 m->mothurOutEndLine();
326 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
327 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
328 m->mothurOutEndLine();
332 catch(exception& e) {
333 m->errorOut(e, "SubSampleCommand", "execute");
337 //**********************************************************************************************************************
338 int SubSampleCommand::getSubSampleFasta() {
341 if (namefile != "") { readNames(); } //fills names with all names in namefile.
342 else { getNames(); }//no name file, so get list of names to pick from
345 if (groupfile != "") {
347 groupMap = new GroupMap(groupfile);
350 //takes care of user setting groupNames that are invalid or setting groups=all
351 SharedUtil* util = new SharedUtil();
352 util->setGroups(Groups, groupMap->namesOfGroups);
356 if (names.size() != groupMap->getNumSeqs()) {
357 m->mothurOut("[ERROR]: your fasta file contains " + toString(names.size()) + " sequences, and your groupfile contains " + toString(groupMap->getNumSeqs()) + ", please correct.");
358 m->mothurOutEndLine();
364 if (m->control_pressed) { return 0; }
367 //make sure that if your picked groups size is not too big
368 int thisSize = names.size();
370 if (size == 0) { //user has not set size, set size = smallest samples size
371 size = groupMap->getNumSeqs(Groups[0]);
372 for (int i = 1; i < Groups.size(); i++) {
373 int thisSize = groupMap->getNumSeqs(Groups[i]);
375 if (thisSize < size) { size = thisSize; }
377 }else { //make sure size is not too large
378 vector<string> newGroups;
379 for (int i = 0; i < Groups.size(); i++) {
380 int thisSize = groupMap->getNumSeqs(Groups[i]);
382 if (thisSize >= size) { newGroups.push_back(Groups[i]); }
383 else { m->mothurOut("You have selected a size that is larger than " + Groups[i] + " number of sequences, removing " + Groups[i] + "."); m->mothurOutEndLine(); }
388 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
392 for(int i = 0; i < Groups.size(); i++) {
393 total += groupMap->getNumSeqs(Groups[i]);
396 if (size == 0) { //user has not set size, set size = 10% samples size
397 size = int (total * 0.10);
402 m->mothurOut("Your size is too large for the number of groups you selected. Adjusting to " + toString(int (total * 0.10)) + "."); m->mothurOutEndLine();
404 size = int (total * 0.10);
407 m->mothurOut("Sampling " + toString(size) + " from " + toString(total) + "."); m->mothurOutEndLine();
410 if (size == 0) { //user has not set size, set size = 10% samples size
411 size = int (names.size() * 0.10);
414 if (size > thisSize) { m->mothurOut("Your fasta file only contains " + toString(thisSize) + " sequences. Setting size to " + toString(thisSize) + "."); m->mothurOutEndLine();
418 if (!pickedGroups) { m->mothurOut("Sampling " + toString(size) + " from " + toString(thisSize) + "."); m->mothurOutEndLine(); }
421 random_shuffle(names.begin(), names.end());
423 set<string> subset; //dont want repeat sequence names added
425 for (int i = 0; i < Groups.size(); i++) {
427 //randomly select a subset of those names from this group to include in the subsample
428 for (int j = 0; j < size; j++) {
430 if (m->control_pressed) { return 0; }
432 //get random sequence to add, making sure we have not already added it
436 myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
438 if (subset.count(names[myrand]) == 0) {
440 string group = groupMap->getGroup(names[myrand]);
441 if (group == "not found") { m->mothurOut("[ERROR]: " + names[myrand] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
443 if (group == Groups[i]) { subset.insert(names[myrand]); break; }
450 //randomly select a subset of those names to include in the subsample
451 for (int j = 0; j < size; j++) {
453 if (m->control_pressed) { return 0; }
455 //get random sequence to add, making sure we have not already added it
459 myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
461 if (subset.count(names[myrand]) == 0) {
463 if (groupfile != "") { //if there is a groupfile given fill in group info
464 string group = groupMap->getGroup(names[myrand]);
465 if (group == "not found") { m->mothurOut("[ERROR]: " + names[myrand] + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
467 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
468 if (m->inUsersGroups(group, Groups)) {
469 subset.insert(names[myrand]); break;
472 subset.insert(names[myrand]); break;
474 }else{ //save everyone, group
475 subset.insert(names[myrand]); break;
482 if (subset.size() == 0) { m->mothurOut("The size you selected is too large, skipping fasta file."); m->mothurOutEndLine(); return 0; }
484 string thisOutputDir = outputDir;
485 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
486 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "subsample" + m->getExtension(fastafile);
489 m->openOutputFile(outputFileName, out);
490 outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
492 //read through fasta file outputting only the names on the subsample list
494 m->openInputFile(fastafile, in);
498 map<string, vector<string> >::iterator itNameMap;
502 if (m->control_pressed) { in.close(); out.close(); return 0; }
504 Sequence currSeq(in);
505 thisname = currSeq.getName();
507 if (thisname != "") {
509 //does the subset contain a sequence that this sequence represents
510 itNameMap = nameMap.find(thisname);
511 if (itNameMap != nameMap.end()) {
512 vector<string> nameRepresents = itNameMap->second;
514 for (int i = 0; i < nameRepresents.size(); i++){
515 if (subset.count(nameRepresents[i]) != 0) {
516 out << ">" << nameRepresents[i] << endl << currSeq.getAligned() << endl;
521 m->mothurOut("[ERROR]: " + thisname + " is not in your namefile, please correct."); m->mothurOutEndLine();
529 if (count != subset.size()) {
530 m->mothurOut("[ERROR]: The subset selected contained " + toString(subset.size()) + " sequences, but I only found " + toString(count) + " of those in the fastafile."); m->mothurOutEndLine();
533 //if a groupfile is provided read through the group file only outputting the names on the subsample list
534 if (groupfile != "") {
536 string groupOutputDir = outputDir;
537 if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); }
538 string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "subsample" + m->getExtension(groupfile);
541 m->openOutputFile(groupOutputFileName, outGroup);
542 outputTypes["group"].push_back(groupOutputFileName); outputNames.push_back(groupOutputFileName);
545 m->openInputFile(groupfile, inGroup);
548 while(!inGroup.eof()){
550 if (m->control_pressed) { inGroup.close(); outGroup.close(); return 0; }
552 inGroup >> name; m->gobble(inGroup); //read from first column
553 inGroup >> group; //read from second column
555 //if this name is in the accnos file
556 if (subset.count(name) != 0) {
557 outGroup << name << '\t' << group << endl;
567 if (subset.size() != 0) {
568 m->mothurOut("Your groupfile does not match your fasta file."); m->mothurOutEndLine();
569 for (set<string>::iterator it = subset.begin(); it != subset.end(); it++) {
570 m->mothurOut("[ERROR]: " + *it + " is missing from your groupfile."); m->mothurOutEndLine();
578 catch(exception& e) {
579 m->errorOut(e, "SubSampleCommand", "getSubSampleFasta");
583 //**********************************************************************************************************************
584 int SubSampleCommand::getNames() {
588 m->openInputFile(fastafile, in);
593 if (m->control_pressed) { in.close(); return 0; }
595 Sequence currSeq(in);
596 thisname = currSeq.getName();
598 if (thisname != "") {
599 vector<string> temp; temp.push_back(thisname);
600 nameMap[thisname] = temp;
601 names.push_back(thisname);
610 catch(exception& e) {
611 m->errorOut(e, "SubSampleCommand", "getNames");
615 //**********************************************************************************************************************
616 int SubSampleCommand::readNames() {
620 m->openInputFile(namefile, in);
622 string thisname, repnames;
623 map<string, vector<string> >::iterator it;
627 if (m->control_pressed) { in.close(); return 0; }
629 in >> thisname; m->gobble(in); //read from first column
630 in >> repnames; //read from second column
632 it = nameMap.find(thisname);
633 if (it == nameMap.end()) {
635 vector<string> splitRepNames;
636 m->splitAtComma(repnames, splitRepNames);
638 nameMap[thisname] = splitRepNames;
639 for (int i = 0; i < splitRepNames.size(); i++) { names.push_back(splitRepNames[i]); }
641 }else{ m->mothurOut(thisname + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); }
650 catch(exception& e) {
651 m->errorOut(e, "SubSampleCommand", "readNames");
655 //**********************************************************************************************************************
656 int SubSampleCommand::getSubSampleShared() {
659 InputData* input = new InputData(sharedfile, "sharedfile");
660 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
661 string lastLabel = lookup[0]->getLabel();
663 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
664 set<string> processedLabels;
665 set<string> userLabels = labels;
667 if (size == 0) { //user has not set size, set size = smallest samples size
668 size = lookup[0]->getNumSeqs();
669 for (int i = 1; i < lookup.size(); i++) {
670 int thisSize = lookup[i]->getNumSeqs();
672 if (thisSize < size) { size = thisSize; }
676 vector<SharedRAbundVector*> temp;
677 for (int i = 0; i < lookup.size(); i++) {
678 if (lookup[i]->getNumSeqs() < size) {
679 m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
682 m->Groups.push_back(lookup[i]->getGroup());
683 temp.push_back(lookup[i]);
690 if (lookup.size() == 0) { m->mothurOut("The size you selected is too large, skipping shared file."); m->mothurOutEndLine(); delete input; return 0; }
692 string thisOutputDir = outputDir;
693 if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
694 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + "subsample" + m->getExtension(sharedfile);
697 m->openOutputFile(outputFileName, out);
698 outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
701 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
703 //as long as you are not at the end of the file or done wih the lines you want
704 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
705 if (m->control_pressed) { delete input; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; } out.close(); return 0; }
707 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
709 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
711 if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
712 processShared(lookup, out);
714 processedLabels.insert(lookup[0]->getLabel());
715 userLabels.erase(lookup[0]->getLabel());
718 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
719 string saveLabel = lookup[0]->getLabel();
721 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
723 lookup = input->getSharedRAbundVectors(lastLabel);
724 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
726 if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
727 processShared(lookup, out);
729 processedLabels.insert(lookup[0]->getLabel());
730 userLabels.erase(lookup[0]->getLabel());
732 //restore real lastlabel to save below
733 lookup[0]->setLabel(saveLabel);
736 lastLabel = lookup[0]->getLabel();
737 //prevent memory leak
738 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
740 //get next line to process
741 lookup = input->getSharedRAbundVectors();
745 if (m->control_pressed) { out.close(); return 0; }
747 //output error messages about any remaining user labels
748 set<string>::iterator it;
749 bool needToRun = false;
750 for (it = userLabels.begin(); it != userLabels.end(); it++) {
751 m->mothurOut("Your file does not include the label " + *it);
752 if (processedLabels.count(lastLabel) != 1) {
753 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
756 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
760 //run last label if you need to
761 if (needToRun == true) {
762 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }
763 lookup = input->getSharedRAbundVectors(lastLabel);
765 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
767 if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
768 processShared(lookup, out);
770 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
779 catch(exception& e) {
780 m->errorOut(e, "SubSampleCommand", "getSubSampleShared");
784 //**********************************************************************************************************************
785 int SubSampleCommand::processShared(vector<SharedRAbundVector*>& thislookup, ofstream& out) {
788 int numBins = thislookup[0]->getNumBins();
789 for (int i = 0; i < thislookup.size(); i++) {
790 int thisSize = thislookup[i]->getNumSeqs();
792 if (thisSize != size) {
794 string thisgroup = thislookup[i]->getGroup();
796 OrderVector* order = new OrderVector();
797 for(int p=0;p<numBins;p++){
798 for(int j=0;j<thislookup[i]->getAbundance(p);j++){
802 random_shuffle(order->begin(), order->end());
804 SharedRAbundVector* temp = new SharedRAbundVector(numBins);
805 temp->setLabel(thislookup[i]->getLabel());
806 temp->setGroup(thislookup[i]->getGroup());
808 delete thislookup[i];
809 thislookup[i] = temp;
812 for (int j = 0; j < size; j++) {
814 if (m->control_pressed) { delete order; return 0; }
816 //get random number to sample from order between 0 and thisSize-1.
817 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
819 int bin = order->get(myrand);
821 int abund = thislookup[i]->getAbundance(bin);
822 thislookup[i]->set(bin, (abund+1), thisgroup);
828 //subsampling may have created some otus with no sequences in them
829 eliminateZeroOTUS(thislookup);
831 if (m->control_pressed) { return 0; }
833 for (int i = 0; i < thislookup.size(); i++) {
834 out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
835 thislookup[i]->print(out);
841 catch(exception& e) {
842 m->errorOut(e, "SubSampleCommand", "processShared");
846 //**********************************************************************************************************************
847 int SubSampleCommand::getSubSampleList() {
850 string thisOutputDir = outputDir;
851 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
852 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "subsample" + m->getExtension(listfile);
855 m->openOutputFile(outputFileName, out);
856 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
858 InputData* input = new InputData(listfile, "list");
859 ListVector* list = input->getListVector();
860 string lastLabel = list->getLabel();
862 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
863 set<string> processedLabels;
864 set<string> userLabels = labels;
868 if (groupfile != "") {
870 groupMap = new GroupMap(groupfile);
873 //takes care of user setting groupNames that are invalid or setting groups=all
874 SharedUtil* util = new SharedUtil();
875 util->setGroups(Groups, groupMap->namesOfGroups);
879 string groupOutputDir = outputDir;
880 if (outputDir == "") { groupOutputDir += m->hasPath(groupfile); }
881 string groupOutputFileName = groupOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "subsample" + m->getExtension(groupfile);
883 m->openOutputFile(groupOutputFileName, outGroup);
884 outputTypes["group"].push_back(groupOutputFileName); outputNames.push_back(groupOutputFileName);
887 if (list->getNumSeqs() != groupMap->getNumSeqs()) {
888 m->mothurOut("[ERROR]: your list file contains " + toString(list->getNumSeqs()) + " sequences, and your groupfile contains " + toString(groupMap->getNumSeqs()) + ", please correct.");
889 m->mothurOutEndLine();
899 //make sure that if your picked groups size is not too big
901 if (size == 0) { //user has not set size, set size = smallest samples size
902 size = groupMap->getNumSeqs(Groups[0]);
903 for (int i = 1; i < Groups.size(); i++) {
904 int thisSize = groupMap->getNumSeqs(Groups[i]);
906 if (thisSize < size) { size = thisSize; }
908 }else { //make sure size is not too large
909 vector<string> newGroups;
910 for (int i = 0; i < Groups.size(); i++) {
911 int thisSize = groupMap->getNumSeqs(Groups[i]);
913 if (thisSize >= size) { newGroups.push_back(Groups[i]); }
914 else { m->mothurOut("You have selected a size that is larger than " + Groups[i] + " number of sequences, removing " + Groups[i] + "."); m->mothurOutEndLine(); }
919 m->mothurOut("Sampling " + toString(size) + " from each group."); m->mothurOutEndLine();
923 for(int i = 0; i < Groups.size(); i++) {
924 total += groupMap->getNumSeqs(Groups[i]);
927 if (size == 0) { //user has not set size, set size = 10% samples size
928 size = int (total * 0.10);
932 m->mothurOut("Your size is too large for the number of groups you selected. Adjusting to " + toString(int (total * 0.10)) + "."); m->mothurOutEndLine();
933 size = int (total * 0.10);
936 m->mothurOut("Sampling " + toString(size) + " from " + toString(total) + "."); m->mothurOutEndLine();
939 if (size == 0) { //user has not set size, set size = 10% samples size
940 size = int (list->getNumSeqs() * 0.10);
943 int thisSize = list->getNumSeqs();
944 if (size > thisSize) { m->mothurOut("Your list file only contains " + toString(thisSize) + " sequences. Setting size to " + toString(thisSize) + "."); m->mothurOutEndLine();
948 m->mothurOut("Sampling " + toString(size) + " from " + toString(list->getNumSeqs()) + "."); m->mothurOutEndLine();
954 for (int i = 0; i < list->getNumBins(); i++) {
955 string binnames = list->get(i);
958 string individual = "";
959 int length = binnames.length();
960 for(int j=0;j<length;j++){
961 if(binnames[j] == ','){
963 if (groupfile != "") { //if there is a groupfile given fill in group info
964 string group = groupMap->getGroup(individual);
965 if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
967 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
968 if (m->inUsersGroups(group, Groups)) {
969 names.push_back(individual);
972 names.push_back(individual);
974 }else{ //save everyone, group
975 names.push_back(individual);
980 individual += binnames[j];
984 if (groupfile != "") { //if there is a groupfile given fill in group info
985 string group = groupMap->getGroup(individual);
986 if (group == "not found") { m->mothurOut("[ERROR]: " + individual + " is not in your groupfile. please correct."); m->mothurOutEndLine(); group = "NOTFOUND"; }
988 if (pickedGroups) { //if hte user picked groups, we only want to keep the names of sequences from those groups
989 if (m->inUsersGroups(group, Groups)) {
990 names.push_back(individual);
993 names.push_back(individual);
995 }else{ //save everyone, group
996 names.push_back(individual);
1000 random_shuffle(names.begin(), names.end());
1002 //randomly select a subset of those names to include in the subsample
1003 set<string> subset; //dont want repeat sequence names added
1005 for (int i = 0; i < Groups.size(); i++) {
1007 for (int j = 0; j < size; j++) {
1009 if (m->control_pressed) { break; }
1011 //get random sequence to add, making sure we have not already added it
1015 myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
1017 if (subset.count(names[myrand]) == 0) { //you are not already added
1018 if (groupMap->getGroup(names[myrand]) == Groups[i]) { subset.insert(names[myrand]); break; }
1024 for (int j = 0; j < size; j++) {
1026 if (m->control_pressed) { break; }
1028 //get random sequence to add, making sure we have not already added it
1032 myrand = int((float)(names.size()) * (float)(rand()) / ((float)RAND_MAX+1.0));
1034 if (subset.count(names[myrand]) == 0) { subset.insert(names[myrand]); break; }
1039 if (groupfile != "") {
1040 //write out new groupfile
1041 for (set<string>::iterator it = subset.begin(); it != subset.end(); it++) {
1042 string group = groupMap->getGroup(*it);
1043 if (group == "not found") { group = "NOTFOUND"; }
1045 outGroup << *it << '\t' << group << endl;
1047 outGroup.close(); delete groupMap;
1051 //as long as you are not at the end of the file or done wih the lines you want
1052 while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1054 if (m->control_pressed) { delete list; delete input; out.close(); return 0; }
1056 if(allLines == 1 || labels.count(list->getLabel()) == 1){
1058 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1060 processList(list, out, subset);
1062 processedLabels.insert(list->getLabel());
1063 userLabels.erase(list->getLabel());
1066 if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1067 string saveLabel = list->getLabel();
1071 list = input->getListVector(lastLabel);
1072 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1074 processList(list, out, subset);
1076 processedLabels.insert(list->getLabel());
1077 userLabels.erase(list->getLabel());
1079 //restore real lastlabel to save below
1080 list->setLabel(saveLabel);
1083 lastLabel = list->getLabel();
1085 delete list; list = NULL;
1087 //get next line to process
1088 list = input->getListVector();
1092 if (m->control_pressed) { if (list != NULL) { delete list; } delete input; out.close(); return 0; }
1094 //output error messages about any remaining user labels
1095 set<string>::iterator it;
1096 bool needToRun = false;
1097 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1098 m->mothurOut("Your file does not include the label " + *it);
1099 if (processedLabels.count(lastLabel) != 1) {
1100 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1103 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1107 //run last label if you need to
1108 if (needToRun == true) {
1109 if (list != NULL) { delete list; }
1111 list = input->getListVector(lastLabel);
1113 m->mothurOut(list->getLabel()); m->mothurOutEndLine();
1115 processList(list, out, subset);
1117 delete list; list = NULL;
1121 if (list != NULL) { delete list; }
1127 catch(exception& e) {
1128 m->errorOut(e, "SubSampleCommand", "getSubSampleList");
1132 //**********************************************************************************************************************
1133 int SubSampleCommand::processList(ListVector*& list, ofstream& out, set<string>& subset) {
1136 int numBins = list->getNumBins();
1138 ListVector* temp = new ListVector();
1139 temp->setLabel(list->getLabel());
1141 for (int i = 0; i < numBins; i++) {
1143 if (m->control_pressed) { break; }
1145 string binnames = list->get(i);
1148 string individual = "";
1149 string newNames = "";
1150 int length = binnames.length();
1151 for(int j=0;j<length;j++){
1152 if(binnames[j] == ','){
1153 if (subset.count(individual) != 0) { newNames += individual + ","; }
1156 individual += binnames[j];
1159 if (subset.count(individual) != 0) { newNames += individual + ","; }
1162 //if there are names in this bin add to new list
1163 if (newNames != "") {
1164 newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
1165 temp->push_back(newNames);
1172 if (m->control_pressed) { return 0; }
1179 catch(exception& e) {
1180 m->errorOut(e, "SubSampleCommand", "processList");
1184 //**********************************************************************************************************************
1185 int SubSampleCommand::getSubSampleRabund() {
1187 InputData* input = new InputData(rabundfile, "rabund");
1188 RAbundVector* rabund = input->getRAbundVector();
1189 string lastLabel = rabund->getLabel();
1191 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
1192 set<string> processedLabels;
1193 set<string> userLabels = labels;
1195 if (size == 0) { //user has not set size, set size = 10%
1196 size = int((rabund->getNumSeqs()) * 0.10);
1197 }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; }
1199 m->mothurOut("Sampling " + toString(size) + " from " + toString(rabund->getNumSeqs()) + "."); m->mothurOutEndLine();
1201 string thisOutputDir = outputDir;
1202 if (outputDir == "") { thisOutputDir += m->hasPath(rabundfile); }
1203 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(rabundfile)) + "subsample" + m->getExtension(rabundfile);
1206 m->openOutputFile(outputFileName, out);
1207 outputTypes["rabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
1209 //as long as you are not at the end of the file or done wih the lines you want
1210 while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1211 if (m->control_pressed) { delete input; delete rabund; out.close(); return 0; }
1213 if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
1215 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1217 processRabund(rabund, out);
1219 processedLabels.insert(rabund->getLabel());
1220 userLabels.erase(rabund->getLabel());
1223 if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1224 string saveLabel = rabund->getLabel();
1228 rabund = input->getRAbundVector(lastLabel);
1229 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1231 processRabund(rabund, out);
1233 processedLabels.insert(rabund->getLabel());
1234 userLabels.erase(rabund->getLabel());
1236 //restore real lastlabel to save below
1237 rabund->setLabel(saveLabel);
1240 lastLabel = rabund->getLabel();
1242 //prevent memory leak
1243 delete rabund; rabund = NULL;
1245 //get next line to process
1246 rabund = input->getRAbundVector();
1250 if (m->control_pressed) { out.close(); return 0; }
1252 //output error messages about any remaining user labels
1253 set<string>::iterator it;
1254 bool needToRun = false;
1255 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1256 m->mothurOut("Your file does not include the label " + *it);
1257 if (processedLabels.count(lastLabel) != 1) {
1258 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1261 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1265 //run last label if you need to
1266 if (needToRun == true) {
1267 if (rabund != NULL) { delete rabund; }
1269 rabund = input->getRAbundVector(lastLabel);
1271 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
1273 processRabund(rabund, out);
1284 catch(exception& e) {
1285 m->errorOut(e, "SubSampleCommand", "getSubSampleRabund");
1289 //**********************************************************************************************************************
1290 int SubSampleCommand::processRabund(RAbundVector*& rabund, ofstream& out) {
1293 int numBins = rabund->getNumBins();
1294 int thisSize = rabund->getNumSeqs();
1296 if (thisSize != size) {
1298 OrderVector* order = new OrderVector();
1299 for(int p=0;p<numBins;p++){
1300 for(int j=0;j<rabund->get(p);j++){
1301 order->push_back(p);
1304 random_shuffle(order->begin(), order->end());
1306 RAbundVector* temp = new RAbundVector(numBins);
1307 temp->setLabel(rabund->getLabel());
1312 for (int j = 0; j < size; j++) {
1314 if (m->control_pressed) { delete order; return 0; }
1316 //get random number to sample from order between 0 and thisSize-1.
1317 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
1319 int bin = order->get(myrand);
1321 int abund = rabund->get(bin);
1322 rabund->set(bin, (abund+1));
1328 if (m->control_pressed) { return 0; }
1335 catch(exception& e) {
1336 m->errorOut(e, "SubSampleCommand", "processRabund");
1340 //**********************************************************************************************************************
1341 int SubSampleCommand::getSubSampleSabund() {
1344 InputData* input = new InputData(sabundfile, "sabund");
1345 SAbundVector* sabund = input->getSAbundVector();
1346 string lastLabel = sabund->getLabel();
1348 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
1349 set<string> processedLabels;
1350 set<string> userLabels = labels;
1352 if (size == 0) { //user has not set size, set size = 10%
1353 size = int((sabund->getNumSeqs()) * 0.10);
1354 }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; }
1357 m->mothurOut("Sampling " + toString(size) + " from " + toString(sabund->getNumSeqs()) + "."); m->mothurOutEndLine();
1359 string thisOutputDir = outputDir;
1360 if (outputDir == "") { thisOutputDir += m->hasPath(sabundfile); }
1361 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sabundfile)) + "subsample" + m->getExtension(sabundfile);
1364 m->openOutputFile(outputFileName, out);
1365 outputTypes["sabund"].push_back(outputFileName); outputNames.push_back(outputFileName);
1368 //as long as you are not at the end of the file or done wih the lines you want
1369 while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
1370 if (m->control_pressed) { delete input; delete sabund; out.close(); return 0; }
1372 if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
1374 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1376 processSabund(sabund, out);
1378 processedLabels.insert(sabund->getLabel());
1379 userLabels.erase(sabund->getLabel());
1382 if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
1383 string saveLabel = sabund->getLabel();
1387 sabund = input->getSAbundVector(lastLabel);
1388 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1390 processSabund(sabund, out);
1392 processedLabels.insert(sabund->getLabel());
1393 userLabels.erase(sabund->getLabel());
1395 //restore real lastlabel to save below
1396 sabund->setLabel(saveLabel);
1399 lastLabel = sabund->getLabel();
1401 //prevent memory leak
1402 delete sabund; sabund = NULL;
1404 //get next line to process
1405 sabund = input->getSAbundVector();
1409 if (m->control_pressed) { out.close(); return 0; }
1411 //output error messages about any remaining user labels
1412 set<string>::iterator it;
1413 bool needToRun = false;
1414 for (it = userLabels.begin(); it != userLabels.end(); it++) {
1415 m->mothurOut("Your file does not include the label " + *it);
1416 if (processedLabels.count(lastLabel) != 1) {
1417 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
1420 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
1424 //run last label if you need to
1425 if (needToRun == true) {
1426 if (sabund != NULL) { delete sabund; }
1428 sabund = input->getSAbundVector(lastLabel);
1430 m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
1432 processSabund(sabund, out);
1443 catch(exception& e) {
1444 m->errorOut(e, "SubSampleCommand", "getSubSampleSabund");
1448 //**********************************************************************************************************************
1449 int SubSampleCommand::processSabund(SAbundVector*& sabund, ofstream& out) {
1452 RAbundVector* rabund = new RAbundVector();
1453 *rabund = sabund->getRAbundVector();
1455 int numBins = rabund->getNumBins();
1456 int thisSize = rabund->getNumSeqs();
1458 if (thisSize != size) {
1460 OrderVector* order = new OrderVector();
1461 for(int p=0;p<numBins;p++){
1462 for(int j=0;j<rabund->get(p);j++){
1463 order->push_back(p);
1466 random_shuffle(order->begin(), order->end());
1468 RAbundVector* temp = new RAbundVector(numBins);
1469 temp->setLabel(rabund->getLabel());
1474 for (int j = 0; j < size; j++) {
1476 if (m->control_pressed) { delete order; return 0; }
1478 //get random number to sample from order between 0 and thisSize-1.
1479 int myrand = int((float)(thisSize) * (float)(rand()) / ((float)RAND_MAX+1.0));
1481 int bin = order->get(myrand);
1483 int abund = rabund->get(bin);
1484 rabund->set(bin, (abund+1));
1490 if (m->control_pressed) { return 0; }
1493 sabund = new SAbundVector();
1494 *sabund = rabund->getSAbundVector();
1502 catch(exception& e) {
1503 m->errorOut(e, "SubSampleCommand", "processSabund");
1507 //**********************************************************************************************************************
1508 int SubSampleCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thislookup) {
1511 vector<SharedRAbundVector*> newLookup;
1512 for (int i = 0; i < thislookup.size(); i++) {
1513 SharedRAbundVector* temp = new SharedRAbundVector();
1514 temp->setLabel(thislookup[i]->getLabel());
1515 temp->setGroup(thislookup[i]->getGroup());
1516 newLookup.push_back(temp);
1520 for (int i = 0; i < thislookup[0]->getNumBins(); i++) {
1521 if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; }
1523 //look at each sharedRabund and make sure they are not all zero
1524 bool allZero = true;
1525 for (int j = 0; j < thislookup.size(); j++) {
1526 if (thislookup[j]->getAbundance(i) != 0) { allZero = false; break; }
1529 //if they are not all zero add this bin
1531 for (int j = 0; j < thislookup.size(); j++) {
1532 newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup());
1537 for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
1540 thislookup = newLookup;
1545 catch(exception& e) {
1546 m->errorOut(e, "SubSampleCommand", "eliminateZeroOTUS");
1551 //**********************************************************************************************************************