5 * Created by westcott on 11/10/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "getgroupscommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
13 #include "sharedutilities.h"
14 #include "inputdata.h"
16 //**********************************************************************************************************************
17 vector<string> GetGroupsCommand::setParameters(){
19 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(pfasta);
20 CommandParameter pshared("shared", "InputTypes", "", "", "none", "sharedGroup", "none",false,false); parameters.push_back(pshared);
21 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
22 CommandParameter pgroup("group", "InputTypes", "", "", "none", "sharedGroup", "FNGLT",false,false); parameters.push_back(pgroup);
23 CommandParameter pdesign("design", "InputTypes", "", "", "none", "sharedGroup", "FNGLT",false,false); parameters.push_back(pdesign);
24 CommandParameter plist("list", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(plist);
25 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "none", "FNGLT",false,false); parameters.push_back(ptaxonomy);
26 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
27 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
28 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
29 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
31 vector<string> myArray;
32 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
36 m->errorOut(e, "GetGroupsCommand", "setParameters");
40 //**********************************************************************************************************************
41 string GetGroupsCommand::getHelpString(){
43 string helpString = "";
44 helpString += "The get.groups command selects sequences from a specfic group or set of groups from the following file types: fasta, name, group, list, taxonomy, design or shared file.\n";
45 helpString += "It outputs a file containing the sequences in the those specified groups, or a sharedfile containing only those groups.\n";
46 helpString += "The get.groups command parameters are accnos, fasta, name, group, list, taxonomy, shared, design and groups. The group parameter is required, unless you have a current group file, or are using a shared file.\n";
47 helpString += "You must also provide an accnos containing the list of groups to get or set the groups parameter to the groups you wish to select.\n";
48 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like. You can separate group names with dashes.\n";
49 helpString += "The get.groups command should be in the following format: get.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n";
50 helpString += "Example get.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n";
51 helpString += "or get.groups(groups=pasture, fasta=amazon.fasta, group=amazon.groups).\n";
52 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
56 m->errorOut(e, "GetGroupsCommand", "getHelpString");
60 //**********************************************************************************************************************
61 GetGroupsCommand::GetGroupsCommand(){
63 abort = true; calledHelp = true;
65 vector<string> tempOutNames;
66 outputTypes["fasta"] = tempOutNames;
67 outputTypes["taxonomy"] = tempOutNames;
68 outputTypes["name"] = tempOutNames;
69 outputTypes["group"] = tempOutNames;
70 outputTypes["list"] = tempOutNames;
71 outputTypes["shared"] = tempOutNames;
72 outputTypes["design"] = tempOutNames;
75 m->errorOut(e, "GetGroupsCommand", "GetGroupsCommand");
79 //**********************************************************************************************************************
80 GetGroupsCommand::GetGroupsCommand(string option) {
82 abort = false; calledHelp = false;
84 //allow user to run help
85 if(option == "help") { help(); abort = true; calledHelp = true; }
86 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
89 vector<string> myArray = setParameters();
91 OptionParser parser(option);
92 map<string,string> parameters = parser.getParameters();
94 ValidParameters validParameter;
95 map<string,string>::iterator it;
97 //check to make sure all parameters are valid for command
98 for (it = parameters.begin(); it != parameters.end(); it++) {
99 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
102 //initialize outputTypes
103 vector<string> tempOutNames;
104 outputTypes["fasta"] = tempOutNames;
105 outputTypes["taxonomy"] = tempOutNames;
106 outputTypes["name"] = tempOutNames;
107 outputTypes["group"] = tempOutNames;
108 outputTypes["list"] = tempOutNames;
109 outputTypes["shared"] = tempOutNames;
110 outputTypes["design"] = tempOutNames;
113 //if the user changes the output directory command factory will send this info to us in the output parameter
114 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
116 //if the user changes the input directory command factory will send this info to us in the output parameter
117 string inputDir = validParameter.validFile(parameters, "inputdir", false);
118 if (inputDir == "not found"){ inputDir = ""; }
121 it = parameters.find("fasta");
122 //user has given a template file
123 if(it != parameters.end()){
124 path = m->hasPath(it->second);
125 //if the user has not given a path then, add inputdir. else leave path alone.
126 if (path == "") { parameters["fasta"] = inputDir + it->second; }
129 it = parameters.find("accnos");
130 //user has given a template file
131 if(it != parameters.end()){
132 path = m->hasPath(it->second);
133 //if the user has not given a path then, add inputdir. else leave path alone.
134 if (path == "") { parameters["accnos"] = inputDir + it->second; }
137 it = parameters.find("list");
138 //user has given a template file
139 if(it != parameters.end()){
140 path = m->hasPath(it->second);
141 //if the user has not given a path then, add inputdir. else leave path alone.
142 if (path == "") { parameters["list"] = inputDir + it->second; }
145 it = parameters.find("name");
146 //user has given a template file
147 if(it != parameters.end()){
148 path = m->hasPath(it->second);
149 //if the user has not given a path then, add inputdir. else leave path alone.
150 if (path == "") { parameters["name"] = inputDir + it->second; }
153 it = parameters.find("group");
154 //user has given a template file
155 if(it != parameters.end()){
156 path = m->hasPath(it->second);
157 //if the user has not given a path then, add inputdir. else leave path alone.
158 if (path == "") { parameters["group"] = inputDir + it->second; }
161 it = parameters.find("taxonomy");
162 //user has given a template file
163 if(it != parameters.end()){
164 path = m->hasPath(it->second);
165 //if the user has not given a path then, add inputdir. else leave path alone.
166 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
169 it = parameters.find("shared");
170 //user has given a template file
171 if(it != parameters.end()){
172 path = m->hasPath(it->second);
173 //if the user has not given a path then, add inputdir. else leave path alone.
174 if (path == "") { parameters["shared"] = inputDir + it->second; }
177 it = parameters.find("design");
178 //user has given a template file
179 if(it != parameters.end()){
180 path = m->hasPath(it->second);
181 //if the user has not given a path then, add inputdir. else leave path alone.
182 if (path == "") { parameters["design"] = inputDir + it->second; }
187 //check for required parameters
188 accnosfile = validParameter.validFile(parameters, "accnos", true);
189 if (accnosfile == "not open") { abort = true; }
190 else if (accnosfile == "not found") { accnosfile = ""; }
191 else { m->setAccnosFile(accnosfile); }
193 fastafile = validParameter.validFile(parameters, "fasta", true);
194 if (fastafile == "not open") { fastafile = ""; abort = true; }
195 else if (fastafile == "not found") { fastafile = ""; }
196 else { m->setFastaFile(fastafile); }
198 namefile = validParameter.validFile(parameters, "name", true);
199 if (namefile == "not open") { namefile = ""; abort = true; }
200 else if (namefile == "not found") { namefile = ""; }
201 else { m->setNameFile(namefile); }
203 groupfile = validParameter.validFile(parameters, "group", true);
204 if (groupfile == "not open") { groupfile = ""; abort = true; }
205 else if (groupfile == "not found") { groupfile = ""; }
206 else { m->setGroupFile(groupfile); }
208 listfile = validParameter.validFile(parameters, "list", true);
209 if (listfile == "not open") { abort = true; }
210 else if (listfile == "not found") { listfile = ""; }
211 else { m->setListFile(listfile); }
213 taxfile = validParameter.validFile(parameters, "taxonomy", true);
214 if (taxfile == "not open") { taxfile = ""; abort = true; }
215 else if (taxfile == "not found") { taxfile = ""; }
216 else { m->setTaxonomyFile(taxfile); }
218 groups = validParameter.validFile(parameters, "groups", false);
219 if (groups == "not found") { groups = ""; }
221 m->splitAtDash(groups, Groups);
222 m->setGroups(Groups);
225 sharedfile = validParameter.validFile(parameters, "shared", true);
226 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
227 else if (sharedfile == "not found") { sharedfile = ""; }
228 else { m->setSharedFile(sharedfile); }
230 groupfile = validParameter.validFile(parameters, "group", true);
231 if (groupfile == "not open") { groupfile = ""; abort = true; }
232 else if (groupfile == "not found") { groupfile = ""; }
233 else { m->setGroupFile(groupfile); }
235 designfile = validParameter.validFile(parameters, "design", true);
236 if (designfile == "not open") { designfile = ""; abort = true; }
237 else if (designfile == "not found") { designfile = ""; }
238 else { m->setDesignFile(designfile); }
240 if ((sharedfile == "") && (groupfile == "") && (designfile == "")) {
241 //is there are current file available for any of these?
242 if ((namefile != "") || (fastafile != "") || (listfile != "") || (taxfile != "")) {
243 //give priority to group, then shared
244 groupfile = m->getGroupFile();
245 if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
247 sharedfile = m->getSharedFile();
248 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
250 m->mothurOut("You have no current groupfile or sharedfile and one is required."); m->mothurOutEndLine(); abort = true;
254 //give priority to shared, then group
255 sharedfile = m->getSharedFile();
256 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
258 groupfile = m->getGroupFile();
259 if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
261 designfile = m->getDesignFile();
262 if (designfile != "") { m->mothurOut("Using " + designfile + " as input file for the design parameter."); m->mothurOutEndLine(); }
264 m->mothurOut("You have no current groupfile or sharedfile or designfile and one is required."); m->mothurOutEndLine(); abort = true;
271 if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; }
273 if ((fastafile == "") && (namefile == "") && (groupfile == "") && (designfile == "") && (sharedfile == "") && (listfile == "") && (taxfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, taxonomy, group, shared, design or list."); m->mothurOutEndLine(); abort = true; }
274 if ((groupfile == "") && ((namefile != "") || (fastafile != "") || (listfile != "") || (taxfile != ""))) { m->mothurOut("If using a fasta, name, taxonomy, group or list, then you must provide a group file."); m->mothurOutEndLine(); abort = true; }
276 if ((namefile == "") && ((fastafile != "") || (taxfile != ""))){
277 vector<string> files; files.push_back(fastafile); files.push_back(taxfile);
278 parser.getNameFile(files);
283 catch(exception& e) {
284 m->errorOut(e, "GetGroupsCommand", "GetGroupsCommand");
288 //**********************************************************************************************************************
290 int GetGroupsCommand::execute(){
293 if (abort == true) { if (calledHelp) { return 0; } return 2; }
295 //get groups you want to remove
296 if (accnosfile != "") { readAccnos(); }
298 if (groupfile != "") {
299 groupMap = new GroupMap(groupfile);
302 //make sure groups are valid
303 //takes care of user setting groupNames that are invalid or setting groups=all
304 SharedUtil* util = new SharedUtil();
305 vector<string> gNamesOfGroups = groupMap->getNamesOfGroups();
306 util->setGroups(Groups, gNamesOfGroups);
307 groupMap->setNamesOfGroups(gNamesOfGroups);
310 //fill names with names of sequences that are from the groups we want to remove
316 if (m->control_pressed) { return 0; }
318 //read through the correct file and output lines you want to keep
319 if (namefile != "") { readName(); }
320 if (fastafile != "") { readFasta(); }
321 if (groupfile != "") { readGroup(); }
322 if (listfile != "") { readList(); }
323 if (taxfile != "") { readTax(); }
324 if (sharedfile != "") { readShared(); }
325 if (designfile != "") { readDesign(); }
327 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
330 if (outputNames.size() != 0) {
331 m->mothurOutEndLine();
332 m->mothurOut("Output File names: "); m->mothurOutEndLine();
333 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
334 m->mothurOutEndLine();
336 //set fasta file as new current fastafile
338 itTypes = outputTypes.find("fasta");
339 if (itTypes != outputTypes.end()) {
340 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
343 itTypes = outputTypes.find("name");
344 if (itTypes != outputTypes.end()) {
345 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
348 itTypes = outputTypes.find("group");
349 if (itTypes != outputTypes.end()) {
350 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
353 itTypes = outputTypes.find("list");
354 if (itTypes != outputTypes.end()) {
355 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
358 itTypes = outputTypes.find("taxonomy");
359 if (itTypes != outputTypes.end()) {
360 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
363 itTypes = outputTypes.find("shared");
364 if (itTypes != outputTypes.end()) {
365 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setSharedFile(current); }
368 itTypes = outputTypes.find("design");
369 if (itTypes != outputTypes.end()) {
370 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setDesignFile(current); }
377 catch(exception& e) {
378 m->errorOut(e, "GetGroupsCommand", "execute");
383 //**********************************************************************************************************************
384 int GetGroupsCommand::readFasta(){
386 string thisOutputDir = outputDir;
387 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
388 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile);
391 m->openOutputFile(outputFileName, out);
394 m->openInputFile(fastafile, in);
397 bool wroteSomething = false;
398 int selectedCount = 0;
401 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
403 Sequence currSeq(in);
404 name = currSeq.getName();
407 //if this name is in the accnos file
408 if (names.count(name) != 0) {
409 wroteSomething = true;
411 currSeq.printSequence(out);
414 //if you are not in the accnos file check if you are a name that needs to be changed
415 map<string, string>::iterator it = uniqueToRedundant.find(name);
416 if (it != uniqueToRedundant.end()) {
417 wroteSomething = true;
418 currSeq.setName(it->second);
419 currSeq.printSequence(out);
429 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
430 outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
432 m->mothurOut("Selected " + toString(selectedCount) + " sequences from your fasta file."); m->mothurOutEndLine();
438 catch(exception& e) {
439 m->errorOut(e, "GetGroupsCommand", "readFasta");
443 //**********************************************************************************************************************
444 int GetGroupsCommand::readShared(){
446 string thisOutputDir = outputDir;
447 if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
449 InputData input(sharedfile, "sharedfile");
450 vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
452 bool wroteSomething = false;
454 while(lookup[0] != NULL) {
456 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile)) + lookup[0]->getLabel() + ".pick" + m->getExtension(sharedfile);
458 m->openOutputFile(outputFileName, out);
459 outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
461 if (m->control_pressed) { out.close(); m->mothurRemove(outputFileName); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; }
463 lookup[0]->printHeaders(out);
465 for (int i = 0; i < lookup.size(); i++) {
466 out << lookup[i]->getLabel() << '\t' << lookup[i]->getGroup() << '\t';
467 lookup[i]->print(out);
468 wroteSomething = true;
472 //get next line to process
473 //prevent memory leak
474 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
475 lookup = input.getSharedRAbundVectors();
480 if (wroteSomething == false) { m->mothurOut("Your file contains only the groups you wish to remove."); m->mothurOutEndLine(); }
482 string groupsString = "";
483 for (int i = 0; i < Groups.size()-1; i++) { groupsString += Groups[i] + ", "; }
484 groupsString += Groups[Groups.size()-1];
486 m->mothurOut("Selected groups: " + groupsString + " from your shared file."); m->mothurOutEndLine();
491 catch(exception& e) {
492 m->errorOut(e, "GetGroupsCommand", "readShared");
496 //**********************************************************************************************************************
497 int GetGroupsCommand::readList(){
499 string thisOutputDir = outputDir;
500 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
501 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" + m->getExtension(listfile);
504 m->openOutputFile(outputFileName, out);
507 m->openInputFile(listfile, in);
509 bool wroteSomething = false;
510 int selectedCount = 0;
516 //read in list vector
519 //make a new list vector
521 newList.setLabel(list.getLabel());
524 for (int i = 0; i < list.getNumBins(); i++) {
525 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
527 //parse out names that are in accnos file
528 string binnames = list.get(i);
530 string newNames = "";
531 while (binnames.find_first_of(',') != -1) {
532 string name = binnames.substr(0,binnames.find_first_of(','));
533 binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
535 //if that name is in the .accnos file, add it
536 if (names.count(name) != 0) { newNames += name + ","; selectedCount++; }
538 //if you are not in the accnos file check if you are a name that needs to be changed
539 map<string, string>::iterator it = uniqueToRedundant.find(name);
540 if (it != uniqueToRedundant.end()) {
541 newNames += it->second + ",";
548 if (names.count(binnames) != 0) { newNames += binnames + ","; selectedCount++; }
550 //if you are not in the accnos file check if you are a name that needs to be changed
551 map<string, string>::iterator it = uniqueToRedundant.find(binnames);
552 if (it != uniqueToRedundant.end()) {
553 newNames += it->second + ",";
558 //if there are names in this bin add to new list
559 if (newNames != "") {
560 newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
561 newList.push_back(newNames);
565 //print new listvector
566 if (newList.getNumBins() != 0) {
567 wroteSomething = true;
576 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
577 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
579 m->mothurOut("Selected " + toString(selectedCount) + " sequences from your list file."); m->mothurOutEndLine();
584 catch(exception& e) {
585 m->errorOut(e, "GetGroupsCommand", "readList");
589 //**********************************************************************************************************************
590 int GetGroupsCommand::readName(){
592 string thisOutputDir = outputDir;
593 if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
594 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile);
597 m->openOutputFile(outputFileName, out);
600 m->openInputFile(namefile, in);
601 string name, firstCol, secondCol;
603 bool wroteSomething = false;
604 int selectedCount = 0;
607 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
609 in >> firstCol; m->gobble(in);
612 vector<string> parsedNames;
613 m->splitAtComma(secondCol, parsedNames);
615 vector<string> validSecond; validSecond.clear();
616 for (int i = 0; i < parsedNames.size(); i++) {
617 if (names.count(parsedNames[i]) != 0) {
618 validSecond.push_back(parsedNames[i]);
622 selectedCount += validSecond.size();
624 //if the name in the first column is in the set then print it and any other names in second column also in set
625 if (names.count(firstCol) != 0) {
627 wroteSomething = true;
629 out << firstCol << '\t';
631 //you know you have at least one valid second since first column is valid
632 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
633 out << validSecond[validSecond.size()-1] << endl;
635 //make first name in set you come to first column and then add the remaining names to second column
638 //you want part of this row
639 if (validSecond.size() != 0) {
641 wroteSomething = true;
643 out << validSecond[0] << '\t';
645 //you know you have at least one valid second since first column is valid
646 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
647 out << validSecond[validSecond.size()-1] << endl;
648 uniqueToRedundant[firstCol] = validSecond[0];
657 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
658 outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName);
660 m->mothurOut("Selected " + toString(selectedCount) + " sequences from your name file."); m->mothurOutEndLine();
664 catch(exception& e) {
665 m->errorOut(e, "GetGroupsCommand", "readName");
670 //**********************************************************************************************************************
671 int GetGroupsCommand::readGroup(){
673 string thisOutputDir = outputDir;
674 if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
675 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
678 m->openOutputFile(outputFileName, out);
681 m->openInputFile(groupfile, in);
684 bool wroteSomething = false;
685 int selectedCount = 0;
688 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
690 in >> name; //read from first column
691 in >> group; //read from second column
693 //if this name is in the accnos file
694 if (names.count(name) != 0) {
695 wroteSomething = true;
696 out << name << '\t' << group << endl;
705 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
706 outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName);
708 m->mothurOut("Selected " + toString(selectedCount) + " sequences from your group file."); m->mothurOutEndLine();
712 catch(exception& e) {
713 m->errorOut(e, "GetGroupsCommand", "readGroup");
717 //**********************************************************************************************************************
718 int GetGroupsCommand::readDesign(){
720 string thisOutputDir = outputDir;
721 if (outputDir == "") { thisOutputDir += m->hasPath(designfile); }
722 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(designfile)) + "pick" + m->getExtension(designfile);
725 m->openOutputFile(outputFileName, out);
728 m->openInputFile(designfile, in);
731 bool wroteSomething = false;
732 int selectedCount = 0;
735 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
737 in >> name; //read from first column
738 in >> group; //read from second column
740 //if this name is in the accnos file
741 if (m->inUsersGroups(name, Groups)) {
742 wroteSomething = true;
743 out << name << '\t' << group << endl;
752 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain groups from the groups you wish to get."); m->mothurOutEndLine(); }
753 outputTypes["design"].push_back(outputFileName); outputNames.push_back(outputFileName);
755 m->mothurOut("Selected " + toString(selectedCount) + " groups from your design file."); m->mothurOutEndLine();
760 catch(exception& e) {
761 m->errorOut(e, "GetGroupsCommand", "readDesign");
767 //**********************************************************************************************************************
768 int GetGroupsCommand::readTax(){
770 string thisOutputDir = outputDir;
771 if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); }
772 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
774 m->openOutputFile(outputFileName, out);
777 m->openInputFile(taxfile, in);
780 bool wroteSomething = false;
783 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
785 in >> name; //read from first column
786 in >> tax; //read from second column
788 //if this name is in the accnos file
789 if (names.count(name) != 0) {
790 wroteSomething = true;
791 out << name << '\t' << tax << endl;
793 //if you are not in the accnos file check if you are a name that needs to be changed
794 map<string, string>::iterator it = uniqueToRedundant.find(name);
795 if (it != uniqueToRedundant.end()) {
796 wroteSomething = true;
797 out << it->second << '\t' << tax << endl;
806 if (wroteSomething == false) { m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine(); }
807 outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName);
811 catch(exception& e) {
812 m->errorOut(e, "GetGroupsCommand", "readTax");
816 //**********************************************************************************************************************
817 void GetGroupsCommand::readAccnos(){
822 m->openInputFile(accnosfile, in);
828 Groups.push_back(name);
834 m->setGroups(Groups);
837 catch(exception& e) {
838 m->errorOut(e, "GetGroupsCommand", "readAccnos");
842 //**********************************************************************************************************************
843 int GetGroupsCommand::fillNames(){
845 vector<string> seqs = groupMap->getNamesSeqs();
847 for (int i = 0; i < seqs.size(); i++) {
849 if (m->control_pressed) { return 0; }
851 string group = groupMap->getGroup(seqs[i]);
853 if (m->inUsersGroups(group, Groups)) {
854 names.insert(seqs[i]);
860 catch(exception& e) {
861 m->errorOut(e, "GetGroupsCommand", "fillNames");
866 //**********************************************************************************************************************