]> git.donarmstrong.com Git - mothur.git/blob - getgroupscommand.cpp
rewrote metastats command in c++, added mothurRemove function to handle ~ error....
[mothur.git] / getgroupscommand.cpp
1 /*
2  *  getgroupscommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 11/10/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "getgroupscommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
13 #include "sharedutilities.h"
14
15 //**********************************************************************************************************************
16 vector<string> GetGroupsCommand::setParameters(){       
17         try {
18                 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
19                 CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname);
20                 CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(pgroup);
21                 CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist);
22                 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy);
23                 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paccnos);
24                 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
25                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
26                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
27                 
28                 vector<string> myArray;
29                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
30                 return myArray;
31         }
32         catch(exception& e) {
33                 m->errorOut(e, "GetGroupsCommand", "setParameters");
34                 exit(1);
35         }
36 }
37 //**********************************************************************************************************************
38 string GetGroupsCommand::getHelpString(){       
39         try {
40                 string helpString = "";
41                 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.\n";
42                 helpString += "It outputs a file containing the sequences in the those specified groups.\n";
43                 helpString += "The get.groups command parameters are accnos, fasta, name, group, list, taxonomy and groups. The group parameter is required, unless you have a current group file.\n";
44                 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";
45                 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";
46                 helpString += "The get.groups command should be in the following format: get.groups(accnos=yourAccnos, fasta=yourFasta, group=yourGroupFile).\n";
47                 helpString += "Example get.groups(accnos=amazon.accnos, fasta=amazon.fasta, group=amazon.groups).\n";
48                 helpString += "or get.groups(groups=pasture, fasta=amazon.fasta, group=amazon.groups).\n";
49                 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
50                 return helpString;
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "GetGroupsCommand", "getHelpString");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 GetGroupsCommand::GetGroupsCommand(){   
59         try {
60                 abort = true; calledHelp = true;
61                 setParameters();
62                 vector<string> tempOutNames;
63                 outputTypes["fasta"] = tempOutNames;
64                 outputTypes["taxonomy"] = tempOutNames;
65                 outputTypes["name"] = tempOutNames;
66                 outputTypes["group"] = tempOutNames;
67                 outputTypes["list"] = tempOutNames;
68         }
69         catch(exception& e) {
70                 m->errorOut(e, "GetGroupsCommand", "GetGroupsCommand");
71                 exit(1);
72         }
73 }
74 //**********************************************************************************************************************
75 GetGroupsCommand::GetGroupsCommand(string option)  {
76         try {
77                 abort = false; calledHelp = false;   
78                 
79                 //allow user to run help
80                 if(option == "help") { help(); abort = true; calledHelp = true; }
81                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
82                 
83                 else {
84                         vector<string> myArray = setParameters();
85                         
86                         OptionParser parser(option);
87                         map<string,string> parameters = parser.getParameters();
88                         
89                         ValidParameters validParameter;
90                         map<string,string>::iterator it;
91                         
92                         //check to make sure all parameters are valid for command
93                         for (it = parameters.begin(); it != parameters.end(); it++) { 
94                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
95                         }
96                         
97                         //initialize outputTypes
98                         vector<string> tempOutNames;
99                         outputTypes["fasta"] = tempOutNames;
100                         outputTypes["taxonomy"] = tempOutNames;
101                         outputTypes["name"] = tempOutNames;
102                         outputTypes["group"] = tempOutNames;
103                         outputTypes["list"] = tempOutNames;
104                         
105                         
106                         //if the user changes the output directory command factory will send this info to us in the output parameter 
107                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
108                         
109                         //if the user changes the input directory command factory will send this info to us in the output parameter 
110                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
111                         if (inputDir == "not found"){   inputDir = "";          }
112                         else {
113                                 string path;
114                                 it = parameters.find("fasta");
115                                 //user has given a template file
116                                 if(it != parameters.end()){ 
117                                         path = m->hasPath(it->second);
118                                         //if the user has not given a path then, add inputdir. else leave path alone.
119                                         if (path == "") {       parameters["fasta"] = inputDir + it->second;            }
120                                 }
121                                 
122                                 it = parameters.find("accnos");
123                                 //user has given a template file
124                                 if(it != parameters.end()){ 
125                                         path = m->hasPath(it->second);
126                                         //if the user has not given a path then, add inputdir. else leave path alone.
127                                         if (path == "") {       parameters["accnos"] = inputDir + it->second;           }
128                                 }
129                                 
130                                 it = parameters.find("list");
131                                 //user has given a template file
132                                 if(it != parameters.end()){ 
133                                         path = m->hasPath(it->second);
134                                         //if the user has not given a path then, add inputdir. else leave path alone.
135                                         if (path == "") {       parameters["list"] = inputDir + it->second;             }
136                                 }
137                                 
138                                 it = parameters.find("name");
139                                 //user has given a template file
140                                 if(it != parameters.end()){ 
141                                         path = m->hasPath(it->second);
142                                         //if the user has not given a path then, add inputdir. else leave path alone.
143                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
144                                 }
145                                 
146                                 it = parameters.find("group");
147                                 //user has given a template file
148                                 if(it != parameters.end()){ 
149                                         path = m->hasPath(it->second);
150                                         //if the user has not given a path then, add inputdir. else leave path alone.
151                                         if (path == "") {       parameters["group"] = inputDir + it->second;            }
152                                 }
153                                 
154                                 it = parameters.find("taxonomy");
155                                 //user has given a template file
156                                 if(it != parameters.end()){ 
157                                         path = m->hasPath(it->second);
158                                         //if the user has not given a path then, add inputdir. else leave path alone.
159                                         if (path == "") {       parameters["taxonomy"] = inputDir + it->second;         }
160                                 }
161                         }
162                         
163                         
164                         //check for required parameters
165                         accnosfile = validParameter.validFile(parameters, "accnos", true);
166                         if (accnosfile == "not open") { abort = true; }
167                         else if (accnosfile == "not found") {  accnosfile = ""; }
168                         else { m->setAccnosFile(accnosfile); }
169                         
170                         fastafile = validParameter.validFile(parameters, "fasta", true);
171                         if (fastafile == "not open") { abort = true; }
172                         else if (fastafile == "not found") {  fastafile = "";  }
173                         else { m->setFastaFile(fastafile); }
174                         
175                         namefile = validParameter.validFile(parameters, "name", true);
176                         if (namefile == "not open") { abort = true; }
177                         else if (namefile == "not found") {  namefile = "";  }  
178                         else { m->setNameFile(namefile); }
179                         
180                         groupfile = validParameter.validFile(parameters, "group", true);
181                         if (groupfile == "not open") { abort = true; }
182                         else if (groupfile == "not found") {  
183                                 //if there is a current group file, use it
184                                 groupfile = m->getGroupFile(); 
185                                 if (groupfile != "") { m->mothurOut("Using " + groupfile + " as input file for the group parameter."); m->mothurOutEndLine(); }
186                                 else {  m->mothurOut("You have no current groupfile and the group parameter is required."); m->mothurOutEndLine(); abort = true; }
187                         }else { m->setGroupFile(groupfile); }   
188                         
189                         listfile = validParameter.validFile(parameters, "list", true);
190                         if (listfile == "not open") { abort = true; }
191                         else if (listfile == "not found") {  listfile = "";  }
192                         else { m->setListFile(listfile); }
193                         
194                         taxfile = validParameter.validFile(parameters, "taxonomy", true);
195                         if (taxfile == "not open") { abort = true; }
196                         else if (taxfile == "not found") {  taxfile = "";  }
197                         else { m->setTaxonomyFile(taxfile); }
198                         
199                         groups = validParameter.validFile(parameters, "groups", false);                 
200                         if (groups == "not found") { groups = "all"; }
201                         m->splitAtDash(groups, Groups);
202                         
203                         
204                         if ((accnosfile == "") && (Groups.size() == 0)) { m->mothurOut("You must provide an accnos file or specify groups using the groups parameter."); m->mothurOutEndLine(); abort = true; }
205                         
206                         if ((fastafile == "") && (namefile == "") && (groupfile == "")  && (listfile == "") && (taxfile == ""))  { m->mothurOut("You must provide at least one of the following: fasta, name, taxonomy, group or list."); m->mothurOutEndLine(); abort = true; }
207                 }
208                 
209         }
210         catch(exception& e) {
211                 m->errorOut(e, "GetGroupsCommand", "GetGroupsCommand");
212                 exit(1);
213         }
214 }
215 //**********************************************************************************************************************
216
217 int GetGroupsCommand::execute(){
218         try {
219                 
220                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
221                 
222                 groupMap = new GroupMap(groupfile);
223                 groupMap->readMap();
224                 
225                 //get groups you want to remove
226                 if (accnosfile != "") { readAccnos(); }
227                 
228                 //make sure groups are valid
229                 //takes care of user setting groupNames that are invalid or setting groups=all
230                 SharedUtil* util = new SharedUtil();
231                 util->setGroups(Groups, groupMap->namesOfGroups);
232                 delete util;
233                 
234                 //fill names with names of sequences that are from the groups we want to remove 
235                 fillNames();
236                 
237                 if (m->control_pressed) { delete groupMap; return 0; }
238                 
239                 //read through the correct file and output lines you want to keep
240                 if (namefile != "")                     {               readName();             }
241                 if (fastafile != "")            {               readFasta();    }
242                 if (groupfile != "")            {               readGroup();    }
243                 if (listfile != "")                     {               readList();             }
244                 if (taxfile != "")                      {               readTax();              }
245                 
246                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]); } return 0; }
247                 
248                 m->mothurOut("Selected " + toString(names.size()) + " sequences. From the groups: "); m->mothurOutEndLine();
249                 for (int i = 0; i < Groups.size(); i++) {       m->mothurOut(Groups[i]); m->mothurOut("\t" + toString(groupMap->getNumSeqs(Groups[i]))); m->mothurOutEndLine(); }
250                 m->mothurOutEndLine();
251                 
252                 if (outputNames.size() != 0) {
253                         m->mothurOutEndLine();
254                         m->mothurOut("Output File names: "); m->mothurOutEndLine();
255                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
256                         m->mothurOutEndLine();
257                         
258                         //set fasta file as new current fastafile
259                         string current = "";
260                         itTypes = outputTypes.find("fasta");
261                         if (itTypes != outputTypes.end()) {
262                                 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
263                         }
264                         
265                         itTypes = outputTypes.find("name");
266                         if (itTypes != outputTypes.end()) {
267                                 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
268                         }
269                         
270                         itTypes = outputTypes.find("group");
271                         if (itTypes != outputTypes.end()) {
272                                 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
273                         }
274                         
275                         itTypes = outputTypes.find("list");
276                         if (itTypes != outputTypes.end()) {
277                                 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
278                         }
279                         
280                         itTypes = outputTypes.find("taxonomy");
281                         if (itTypes != outputTypes.end()) {
282                                 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
283                         }
284                 }
285                 
286                 return 0;               
287         }
288         
289         catch(exception& e) {
290                 m->errorOut(e, "GetGroupsCommand", "execute");
291                 exit(1);
292         }
293 }
294
295 //**********************************************************************************************************************
296 int GetGroupsCommand::readFasta(){
297         try {
298                 string thisOutputDir = outputDir;
299                 if (outputDir == "") {  thisOutputDir += m->hasPath(fastafile);  }
300                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + "pick" + m->getExtension(fastafile);
301                 
302                 ofstream out;
303                 m->openOutputFile(outputFileName, out);
304                 
305                 ifstream in;
306                 m->openInputFile(fastafile, in);
307                 string name;
308                 
309                 bool wroteSomething = false;
310                 
311                 while(!in.eof()){
312                         if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
313                         
314                         Sequence currSeq(in);
315                         name = currSeq.getName();
316                         
317                         if (name != "") {
318                                 //if this name is in the accnos file
319                                 if (names.count(name) != 0) {
320                                         wroteSomething = true;
321                                         
322                                         currSeq.printSequence(out);
323                                 }
324                         }
325                         m->gobble(in);
326                 }
327                 in.close();     
328                 out.close();
329                 
330                 if (wroteSomething == false) {  m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine();  }
331                 outputTypes["fasta"].push_back(outputFileName);  outputNames.push_back(outputFileName);
332                 
333                 return 0;
334                 
335         }
336         catch(exception& e) {
337                 m->errorOut(e, "GetGroupsCommand", "readFasta");
338                 exit(1);
339         }
340 }
341
342 //**********************************************************************************************************************
343 int GetGroupsCommand::readList(){
344         try {
345                 string thisOutputDir = outputDir;
346                 if (outputDir == "") {  thisOutputDir += m->hasPath(listfile);  }
347                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + "pick" +  m->getExtension(listfile);
348                 
349                 ofstream out;
350                 m->openOutputFile(outputFileName, out);
351                 
352                 ifstream in;
353                 m->openInputFile(listfile, in);
354                 
355                 bool wroteSomething = false;
356                 
357                 while(!in.eof()){
358                         //read in list vector
359                         ListVector list(in);
360                         
361                         //make a new list vector
362                         ListVector newList;
363                         newList.setLabel(list.getLabel());
364                         
365                         //for each bin
366                         for (int i = 0; i < list.getNumBins(); i++) {
367                                 if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
368                                 
369                                 //parse out names that are in accnos file
370                                 string binnames = list.get(i);
371                                 
372                                 string newNames = "";
373                                 while (binnames.find_first_of(',') != -1) { 
374                                         string name = binnames.substr(0,binnames.find_first_of(','));
375                                         binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
376                                         
377                                         //if that name is in the .accnos file, add it
378                                         if (names.count(name) != 0) {  newNames += name + ",";  }
379                                 }
380                                 
381                                 //get last name
382                                 if (names.count(binnames) != 0) {  newNames += binnames + ",";  }
383                                 
384                                 //if there are names in this bin add to new list
385                                 if (newNames != "") {  
386                                         newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
387                                         newList.push_back(newNames);    
388                                 }
389                         }
390                         
391                         //print new listvector
392                         if (newList.getNumBins() != 0) {
393                                 wroteSomething = true;
394                                 newList.print(out);
395                         }
396                         
397                         m->gobble(in);
398                 }
399                 in.close();     
400                 out.close();
401                 
402                 if (wroteSomething == false) {  m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine();  }
403                 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
404                 
405                 return 0;
406                 
407         }
408         catch(exception& e) {
409                 m->errorOut(e, "GetGroupsCommand", "readList");
410                 exit(1);
411         }
412 }
413 //**********************************************************************************************************************
414 int GetGroupsCommand::readName(){
415         try {
416                 string thisOutputDir = outputDir;
417                 if (outputDir == "") {  thisOutputDir += m->hasPath(namefile);  }
418                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + "pick" + m->getExtension(namefile);
419                 
420                 ofstream out;
421                 m->openOutputFile(outputFileName, out);
422                 
423                 ifstream in;
424                 m->openInputFile(namefile, in);
425                 string name, firstCol, secondCol;
426                 
427                 bool wroteSomething = false;
428                 
429                 while(!in.eof()){
430                         if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
431                         
432                         in >> firstCol;         m->gobble(in);          
433                         in >> secondCol;                        
434                         
435                         vector<string> parsedNames;
436                         m->splitAtComma(secondCol, parsedNames);
437                         
438                         vector<string> validSecond;  validSecond.clear();
439                         for (int i = 0; i < parsedNames.size(); i++) {
440                                 if (names.count(parsedNames[i]) != 0) {
441                                         validSecond.push_back(parsedNames[i]);
442                                 }
443                         }
444                         
445                         //if the name in the first column is in the set then print it and any other names in second column also in set
446                         if (names.count(firstCol) != 0) {
447                                 
448                                 wroteSomething = true;
449                                 
450                                 out << firstCol << '\t';
451                                 
452                                 //you know you have at least one valid second since first column is valid
453                                 for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
454                                 out << validSecond[validSecond.size()-1] << endl;
455                                 
456                                 //make first name in set you come to first column and then add the remaining names to second column
457                         }else {
458                                 
459                                 //you want part of this row
460                                 if (validSecond.size() != 0) {
461                                         
462                                         wroteSomething = true;
463                                         
464                                         out << validSecond[0] << '\t';
465                                         
466                                         //you know you have at least one valid second since first column is valid
467                                         for (int i = 0; i < validSecond.size()-1; i++) {  out << validSecond[i] << ',';  }
468                                         out << validSecond[validSecond.size()-1] << endl;
469                                 }
470                         }
471                         
472                         m->gobble(in);
473                 }
474                 in.close();
475                 out.close();
476                 
477                 if (wroteSomething == false) {  m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine();  }
478                 outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName);
479                 
480                 return 0;
481         }
482         catch(exception& e) {
483                 m->errorOut(e, "GetGroupsCommand", "readName");
484                 exit(1);
485         }
486 }
487
488 //**********************************************************************************************************************
489 int GetGroupsCommand::readGroup(){
490         try {
491                 string thisOutputDir = outputDir;
492                 if (outputDir == "") {  thisOutputDir += m->hasPath(groupfile);  }
493                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + "pick" + m->getExtension(groupfile);
494                 
495                 ofstream out;
496                 m->openOutputFile(outputFileName, out);
497                 
498                 ifstream in;
499                 m->openInputFile(groupfile, in);
500                 string name, group;
501                 
502                 bool wroteSomething = false;
503                 
504                 while(!in.eof()){
505                         if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
506                         
507                         in >> name;                             //read from first column
508                         in >> group;                    //read from second column
509                         
510                         //if this name is in the accnos file
511                         if (names.count(name) != 0) {
512                                 wroteSomething = true;
513                                 out << name << '\t' << group << endl;
514                         }
515                         
516                         m->gobble(in);
517                 }
518                 in.close();
519                 out.close();
520                 
521                 if (wroteSomething == false) {  m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine();  }
522                 outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName);
523                 
524                 return 0;
525         }
526         catch(exception& e) {
527                 m->errorOut(e, "GetGroupsCommand", "readGroup");
528                 exit(1);
529         }
530 }
531 //**********************************************************************************************************************
532 int GetGroupsCommand::readTax(){
533         try {
534                 string thisOutputDir = outputDir;
535                 if (outputDir == "") {  thisOutputDir += m->hasPath(taxfile);  }
536                 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + "pick" + m->getExtension(taxfile);
537                 ofstream out;
538                 m->openOutputFile(outputFileName, out);
539                 
540                 ifstream in;
541                 m->openInputFile(taxfile, in);
542                 string name, tax;
543                 
544                 bool wroteSomething = false;
545                 
546                 while(!in.eof()){
547                         if (m->control_pressed) { in.close();  out.close();  m->mothurRemove(outputFileName);  return 0; }
548                         
549                         in >> name;                             //read from first column
550                         in >> tax;                      //read from second column
551                         
552                         //if this name is in the accnos file
553                         if (names.count(name) != 0) {
554                                 wroteSomething = true;
555                                 out << name << '\t' << tax << endl;
556                         }
557                         
558                         m->gobble(in);
559                 }
560                 in.close();
561                 out.close();
562                 
563                 if (wroteSomething == false) {  m->mothurOut("Your file does NOT contain sequences from the groups you wish to get."); m->mothurOutEndLine();  }
564                 outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName);
565                 
566                 return 0;
567         }
568         catch(exception& e) {
569                 m->errorOut(e, "GetGroupsCommand", "readTax");
570                 exit(1);
571         }
572 }
573 //**********************************************************************************************************************
574 void GetGroupsCommand::readAccnos(){
575         try {
576                 Groups.clear();
577                 
578                 ifstream in;
579                 m->openInputFile(accnosfile, in);
580                 string name;
581                 
582                 while(!in.eof()){
583                         in >> name;
584                         
585                         Groups.push_back(name);
586                         
587                         m->gobble(in);
588                 }
589                 in.close();             
590                 
591         }
592         catch(exception& e) {
593                 m->errorOut(e, "GetGroupsCommand", "readAccnos");
594                 exit(1);
595         }
596 }
597 //**********************************************************************************************************************
598 int GetGroupsCommand::fillNames(){
599         try {
600                 vector<string> seqs = groupMap->getNamesSeqs();
601                 
602                 for (int i = 0; i < seqs.size(); i++) {
603                         
604                         if (m->control_pressed) { return 0; }
605                         
606                         string group = groupMap->getGroup(seqs[i]);
607                         
608                         if (m->inUsersGroups(group, Groups)) {
609                                 names.insert(seqs[i]);
610                         }
611                 }
612                 
613                 return 0;
614         }
615         catch(exception& e) {
616                 m->errorOut(e, "GetGroupsCommand", "fillNames");
617                 exit(1);
618         }
619 }
620
621 //**********************************************************************************************************************
622
623