2 * removeseqscommand.cpp
5 * Created by Sarah Westcott on 7/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "removeseqscommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
13 #include "counttable.h"
15 //**********************************************************************************************************************
16 vector<string> RemoveSeqsCommand::setParameters(){
18 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
19 CommandParameter pname("name", "InputTypes", "", "", "NameCount", "FNGLT", "none",false,false); parameters.push_back(pname);
20 CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "FNGLT", "none",false,false); parameters.push_back(pcount);
21 CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "FNGLT", "none",false,false); parameters.push_back(pgroup);
22 CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist);
23 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(ptaxonomy);
24 CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport);
25 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pqfile);
26 CommandParameter paccnos("accnos", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(paccnos);
27 CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups);
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, "RemoveSeqsCommand", "setParameters");
40 //**********************************************************************************************************************
41 string RemoveSeqsCommand::getHelpString(){
43 string helpString = "";
44 helpString += "The remove.seqs command reads an .accnos file and at least one of the following file types: fasta, name, group, count, list, taxonomy, quality or alignreport file.\n";
45 helpString += "It outputs a file containing the sequences NOT in the .accnos file.\n";
46 helpString += "The remove.seqs command parameters are accnos, fasta, name, group, count, list, taxonomy, qfile, alignreport and dups. You must provide accnos and at least one of the file parameters.\n";
47 helpString += "The dups parameter allows you to remove the entire line from a name file if you remove any name from the line. default=true. \n";
48 helpString += "The remove.seqs command should be in the following format: remove.seqs(accnos=yourAccnos, fasta=yourFasta).\n";
49 helpString += "Example remove.seqs(accnos=amazon.accnos, fasta=amazon.fasta).\n";
50 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
54 m->errorOut(e, "RemoveSeqsCommand", "getHelpString");
58 //**********************************************************************************************************************
59 string RemoveSeqsCommand::getOutputFileNameTag(string type, string inputName=""){
61 string outputFileName = "";
62 map<string, vector<string> >::iterator it;
64 //is this a type this command creates
65 it = outputTypes.find(type);
66 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
68 if (type == "fasta") { outputFileName = "pick" + m->getExtension(inputName); }
69 else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); }
70 else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); }
71 else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); }
72 else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); }
73 else if (type == "qfile") { outputFileName = "pick" + m->getExtension(inputName); }
74 else if (type == "alignreport") { outputFileName = "pick.align.report"; }
75 else if (type == "count") { outputFileName = "pick.count_table"; }
76 else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
78 return outputFileName;
81 m->errorOut(e, "RemoveSeqsCommand", "getOutputFileNameTag");
86 //**********************************************************************************************************************
87 RemoveSeqsCommand::RemoveSeqsCommand(){
89 abort = true; calledHelp = true;
91 vector<string> tempOutNames;
92 outputTypes["fasta"] = tempOutNames;
93 outputTypes["taxonomy"] = tempOutNames;
94 outputTypes["name"] = tempOutNames;
95 outputTypes["group"] = tempOutNames;
96 outputTypes["alignreport"] = tempOutNames;
97 outputTypes["list"] = tempOutNames;
98 outputTypes["qfile"] = tempOutNames;
99 outputTypes["count"] = tempOutNames;
101 catch(exception& e) {
102 m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand");
106 //**********************************************************************************************************************
107 RemoveSeqsCommand::RemoveSeqsCommand(string option) {
109 abort = false; calledHelp = false;
111 //allow user to run help
112 if(option == "help") { help(); abort = true; calledHelp = true; }
113 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
116 vector<string> myArray = setParameters();
118 OptionParser parser(option);
119 map<string,string> parameters = parser.getParameters();
121 ValidParameters validParameter;
122 map<string,string>::iterator it;
124 //check to make sure all parameters are valid for command
125 for (it = parameters.begin(); it != parameters.end(); it++) {
126 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
129 //initialize outputTypes
130 vector<string> tempOutNames;
131 outputTypes["fasta"] = tempOutNames;
132 outputTypes["taxonomy"] = tempOutNames;
133 outputTypes["name"] = tempOutNames;
134 outputTypes["group"] = tempOutNames;
135 outputTypes["alignreport"] = tempOutNames;
136 outputTypes["list"] = tempOutNames;
137 outputTypes["qfile"] = tempOutNames;
138 outputTypes["count"] = tempOutNames;
140 //if the user changes the output directory command factory will send this info to us in the output parameter
141 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
143 //if the user changes the input directory command factory will send this info to us in the output parameter
144 string inputDir = validParameter.validFile(parameters, "inputdir", false);
145 if (inputDir == "not found"){ inputDir = ""; }
148 it = parameters.find("alignreport");
149 //user has given a template file
150 if(it != parameters.end()){
151 path = m->hasPath(it->second);
152 //if the user has not given a path then, add inputdir. else leave path alone.
153 if (path == "") { parameters["alignreport"] = inputDir + it->second; }
156 it = parameters.find("fasta");
157 //user has given a template file
158 if(it != parameters.end()){
159 path = m->hasPath(it->second);
160 //if the user has not given a path then, add inputdir. else leave path alone.
161 if (path == "") { parameters["fasta"] = inputDir + it->second; }
164 it = parameters.find("accnos");
165 //user has given a template file
166 if(it != parameters.end()){
167 path = m->hasPath(it->second);
168 //if the user has not given a path then, add inputdir. else leave path alone.
169 if (path == "") { parameters["accnos"] = inputDir + it->second; }
172 it = parameters.find("list");
173 //user has given a template file
174 if(it != parameters.end()){
175 path = m->hasPath(it->second);
176 //if the user has not given a path then, add inputdir. else leave path alone.
177 if (path == "") { parameters["list"] = inputDir + it->second; }
180 it = parameters.find("name");
181 //user has given a template file
182 if(it != parameters.end()){
183 path = m->hasPath(it->second);
184 //if the user has not given a path then, add inputdir. else leave path alone.
185 if (path == "") { parameters["name"] = inputDir + it->second; }
188 it = parameters.find("group");
189 //user has given a template file
190 if(it != parameters.end()){
191 path = m->hasPath(it->second);
192 //if the user has not given a path then, add inputdir. else leave path alone.
193 if (path == "") { parameters["group"] = inputDir + it->second; }
196 it = parameters.find("taxonomy");
197 //user has given a template file
198 if(it != parameters.end()){
199 path = m->hasPath(it->second);
200 //if the user has not given a path then, add inputdir. else leave path alone.
201 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
204 it = parameters.find("qfile");
205 //user has given a template file
206 if(it != parameters.end()){
207 path = m->hasPath(it->second);
208 //if the user has not given a path then, add inputdir. else leave path alone.
209 if (path == "") { parameters["qfile"] = inputDir + it->second; }
212 it = parameters.find("count");
213 //user has given a template file
214 if(it != parameters.end()){
215 path = m->hasPath(it->second);
216 //if the user has not given a path then, add inputdir. else leave path alone.
217 if (path == "") { parameters["count"] = inputDir + it->second; }
222 //check for required parameters
223 accnosfile = validParameter.validFile(parameters, "accnos", true);
224 if (accnosfile == "not open") { abort = true; }
225 else if (accnosfile == "not found") {
226 accnosfile = m->getAccnosFile();
227 if (accnosfile != "") { m->mothurOut("Using " + accnosfile + " as input file for the accnos parameter."); m->mothurOutEndLine(); }
229 m->mothurOut("You have no valid accnos file and accnos is required."); m->mothurOutEndLine();
232 }else { m->setAccnosFile(accnosfile); }
234 fastafile = validParameter.validFile(parameters, "fasta", true);
235 if (fastafile == "not open") { fastafile = ""; abort = true; }
236 else if (fastafile == "not found") { fastafile = ""; }
237 else { m->setFastaFile(fastafile); }
239 namefile = validParameter.validFile(parameters, "name", true);
240 if (namefile == "not open") { namefile = ""; abort = true; }
241 else if (namefile == "not found") { namefile = ""; }
242 else { m->setNameFile(namefile); }
244 groupfile = validParameter.validFile(parameters, "group", true);
245 if (groupfile == "not open") { abort = true; }
246 else if (groupfile == "not found") { groupfile = ""; }
247 else { m->setGroupFile(groupfile); }
249 alignfile = validParameter.validFile(parameters, "alignreport", true);
250 if (alignfile == "not open") { abort = true; }
251 else if (alignfile == "not found") { alignfile = ""; }
253 listfile = validParameter.validFile(parameters, "list", true);
254 if (listfile == "not open") { abort = true; }
255 else if (listfile == "not found") { listfile = ""; }
256 else { m->setListFile(listfile); }
258 taxfile = validParameter.validFile(parameters, "taxonomy", true);
259 if (taxfile == "not open") { abort = true; }
260 else if (taxfile == "not found") { taxfile = ""; }
261 else { m->setTaxonomyFile(taxfile); }
263 qualfile = validParameter.validFile(parameters, "qfile", true);
264 if (qualfile == "not open") { abort = true; }
265 else if (qualfile == "not found") { qualfile = ""; }
266 else { m->setQualFile(qualfile); }
268 string usedDups = "true";
269 string temp = validParameter.validFile(parameters, "dups", false);
270 if (temp == "not found") {
271 if (namefile != "") { temp = "true"; }
272 else { temp = "false"; usedDups = ""; }
274 dups = m->isTrue(temp);
276 countfile = validParameter.validFile(parameters, "count", true);
277 if (countfile == "not open") { countfile = ""; abort = true; }
278 else if (countfile == "not found") { countfile = ""; }
279 else { m->setCountTableFile(countfile); }
281 if ((namefile != "") && (countfile != "")) {
282 m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true;
285 if ((groupfile != "") && (countfile != "")) {
286 m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true;
289 if ((countfile == "") && (fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "") && (qualfile == "")) { m->mothurOut("You must provide at least one of the following: fasta, name, group, taxonomy, quality, alignreport or list."); m->mothurOutEndLine(); abort = true; }
291 if (countfile == "") {
292 if ((fastafile != "") && (namefile == "")) {
293 vector<string> files; files.push_back(fastafile);
294 parser.getNameFile(files);
300 catch(exception& e) {
301 m->errorOut(e, "RemoveSeqsCommand", "RemoveSeqsCommand");
305 //**********************************************************************************************************************
307 int RemoveSeqsCommand::execute(){
310 if (abort == true) { if (calledHelp) { return 0; } return 2; }
312 //get names you want to keep
313 names = m->readAccnos(accnosfile);
315 if (m->control_pressed) { return 0; }
317 if (countfile != "") {
318 if ((fastafile != "") || (listfile != "") || (taxfile != "")) {
319 m->mothurOut("\n[NOTE]: The count file should contain only unique names, so mothur assumes your fasta, list and taxonomy files also contain only uniques.\n\n");
323 //read through the correct file and output lines you want to keep
324 if (namefile != "") { readName(); }
325 if (fastafile != "") { readFasta(); }
326 if (groupfile != "") { readGroup(); }
327 if (alignfile != "") { readAlign(); }
328 if (listfile != "") { readList(); }
329 if (taxfile != "") { readTax(); }
330 if (qualfile != "") { readQual(); }
331 if (countfile != "") { readCount(); }
333 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
335 if (outputNames.size() != 0) {
336 m->mothurOutEndLine();
337 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
338 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
339 m->mothurOutEndLine();
341 //set fasta file as new current fastafile
343 itTypes = outputTypes.find("fasta");
344 if (itTypes != outputTypes.end()) {
345 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
348 itTypes = outputTypes.find("name");
349 if (itTypes != outputTypes.end()) {
350 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
353 itTypes = outputTypes.find("group");
354 if (itTypes != outputTypes.end()) {
355 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
358 itTypes = outputTypes.find("list");
359 if (itTypes != outputTypes.end()) {
360 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
363 itTypes = outputTypes.find("taxonomy");
364 if (itTypes != outputTypes.end()) {
365 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
368 itTypes = outputTypes.find("qfile");
369 if (itTypes != outputTypes.end()) {
370 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setQualFile(current); }
373 itTypes = outputTypes.find("count");
374 if (itTypes != outputTypes.end()) {
375 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setCountTableFile(current); }
382 catch(exception& e) {
383 m->errorOut(e, "RemoveSeqsCommand", "execute");
388 //**********************************************************************************************************************
389 int RemoveSeqsCommand::readFasta(){
391 string thisOutputDir = outputDir;
392 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
393 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile);
396 m->openOutputFile(outputFileName, out);
399 m->openInputFile(fastafile, in);
402 bool wroteSomething = false;
403 int removedCount = 0;
406 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
408 Sequence currSeq(in);
409 name = currSeq.getName();
412 //if this name is in the accnos file
413 if (names.count(name) == 0) {
414 wroteSomething = true;
416 currSeq.printSequence(out);
417 }else { removedCount++; }
424 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
425 outputTypes["fasta"].push_back(outputFileName); outputNames.push_back(outputFileName);
427 m->mothurOut("Removed " + toString(removedCount) + " sequences from your fasta file."); m->mothurOutEndLine();
432 catch(exception& e) {
433 m->errorOut(e, "RemoveSeqsCommand", "readFasta");
437 //**********************************************************************************************************************
438 int RemoveSeqsCommand::readQual(){
440 string thisOutputDir = outputDir;
441 if (outputDir == "") { thisOutputDir += m->hasPath(qualfile); }
442 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(qualfile)) + getOutputFileNameTag("qfile", qualfile);
444 m->openOutputFile(outputFileName, out);
448 m->openInputFile(qualfile, in);
451 bool wroteSomething = false;
452 int removedCount = 0;
456 string saveName = "";
462 if (name.length() != 0) {
463 saveName = name.substr(1);
466 if (c == 10 || c == 13){ break; }
473 char letter= in.get();
474 if(letter == '>'){ in.putback(letter); break; }
475 else{ scores += letter; }
480 if (names.count(saveName) == 0) {
481 wroteSomething = true;
483 out << name << endl << scores;
484 }else { removedCount++; }
492 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
493 outputNames.push_back(outputFileName); outputTypes["qfile"].push_back(outputFileName);
495 m->mothurOut("Removed " + toString(removedCount) + " sequences from your quality file."); m->mothurOutEndLine();
500 catch(exception& e) {
501 m->errorOut(e, "RemoveSeqsCommand", "readQual");
505 //**********************************************************************************************************************
506 int RemoveSeqsCommand::readCount(){
509 string thisOutputDir = outputDir;
510 if (outputDir == "") { thisOutputDir += m->hasPath(countfile); }
511 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(countfile)) + getOutputFileNameTag("count", countfile);
514 m->openOutputFile(outputFileName, out);
517 m->openInputFile(countfile, in);
519 bool wroteSomething = false;
520 int removedCount = 0;
522 string headers = m->getline(in); m->gobble(in);
523 out << headers << endl;
525 string name, rest; int thisTotal;
528 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
530 in >> name; m->gobble(in);
531 in >> thisTotal; m->gobble(in);
532 rest = m->getline(in); m->gobble(in);
533 if (m->debug) { m->mothurOut("[DEBUG]: " + name + '\t' + rest + "\n"); }
535 if (names.count(name) == 0) {
536 out << name << '\t' << thisTotal << '\t' << rest << endl;
537 wroteSomething = true;
538 }else { removedCount += thisTotal; }
543 //check for groups that have been eliminated
545 if (ct.testGroups(outputFileName)) {
546 ct.readTable(outputFileName);
547 ct.printTable(outputFileName);
551 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
552 outputTypes["count"].push_back(outputFileName); outputNames.push_back(outputFileName);
554 m->mothurOut("Removed " + toString(removedCount) + " sequences from your count file."); m->mothurOutEndLine();
558 catch(exception& e) {
559 m->errorOut(e, "RemoveSeqsCommand", "readCount");
563 //**********************************************************************************************************************
564 int RemoveSeqsCommand::readList(){
566 string thisOutputDir = outputDir;
567 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
568 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
570 m->openOutputFile(outputFileName, out);
573 m->openInputFile(listfile, in);
575 bool wroteSomething = false;
576 int removedCount = 0;
582 //read in list vector
585 //make a new list vector
587 newList.setLabel(list.getLabel());
590 for (int i = 0; i < list.getNumBins(); i++) {
591 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
593 //parse out names that are in accnos file
594 string binnames = list.get(i);
596 string newNames = "";
597 while (binnames.find_first_of(',') != -1) {
598 string name = binnames.substr(0,binnames.find_first_of(','));
599 binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
601 //if that name is in the .accnos file, add it
602 if (names.count(name) == 0) { newNames += name + ","; }
603 else { removedCount++; }
607 if (names.count(binnames) == 0) { newNames += binnames + ","; }
608 else { removedCount++; }
610 //if there are names in this bin add to new list
611 if (newNames != "") {
612 newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
613 newList.push_back(newNames);
617 //print new listvector
618 if (newList.getNumBins() != 0) {
619 wroteSomething = true;
628 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
629 outputTypes["list"].push_back(outputFileName); outputNames.push_back(outputFileName);
631 m->mothurOut("Removed " + toString(removedCount) + " sequences from your list file."); m->mothurOutEndLine();
636 catch(exception& e) {
637 m->errorOut(e, "RemoveSeqsCommand", "readList");
641 //**********************************************************************************************************************
642 int RemoveSeqsCommand::readName(){
644 string thisOutputDir = outputDir;
645 if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
646 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile);
648 m->openOutputFile(outputFileName, out);
651 m->openInputFile(namefile, in);
652 string name, firstCol, secondCol;
654 bool wroteSomething = false;
655 int removedCount = 0;
658 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
660 in >> firstCol; m->gobble(in);
663 vector<string> parsedNames;
664 m->splitAtComma(secondCol, parsedNames);
666 vector<string> validSecond; validSecond.clear();
667 for (int i = 0; i < parsedNames.size(); i++) {
668 if (names.count(parsedNames[i]) == 0) {
669 validSecond.push_back(parsedNames[i]);
673 if ((dups) && (validSecond.size() != parsedNames.size())) { //if dups is true and we want to get rid of anyone, get rid of everyone
674 for (int i = 0; i < parsedNames.size(); i++) { names.insert(parsedNames[i]); }
675 removedCount += parsedNames.size();
677 removedCount += parsedNames.size()-validSecond.size();
678 //if the name in the first column is in the set then print it and any other names in second column also in set
679 if (names.count(firstCol) == 0) {
681 wroteSomething = true;
683 out << firstCol << '\t';
685 //you know you have at least one valid second since first column is valid
686 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
687 out << validSecond[validSecond.size()-1] << endl;
689 //make first name in set you come to first column and then add the remaining names to second column
692 //you want part of this row
693 if (validSecond.size() != 0) {
695 wroteSomething = true;
697 out << validSecond[0] << '\t';
699 //you know you have at least one valid second since first column is valid
700 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
701 out << validSecond[validSecond.size()-1] << endl;
710 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
711 outputTypes["name"].push_back(outputFileName); outputNames.push_back(outputFileName);
713 m->mothurOut("Removed " + toString(removedCount) + " sequences from your name file."); m->mothurOutEndLine();
717 catch(exception& e) {
718 m->errorOut(e, "RemoveSeqsCommand", "readName");
723 //**********************************************************************************************************************
724 int RemoveSeqsCommand::readGroup(){
726 string thisOutputDir = outputDir;
727 if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
728 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);
730 m->openOutputFile(outputFileName, out);
733 m->openInputFile(groupfile, in);
736 bool wroteSomething = false;
737 int removedCount = 0;
740 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
742 in >> name; //read from first column
743 in >> group; //read from second column
745 //if this name is in the accnos file
746 if (names.count(name) == 0) {
747 wroteSomething = true;
748 out << name << '\t' << group << endl;
749 }else { removedCount++; }
756 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
757 outputTypes["group"].push_back(outputFileName); outputNames.push_back(outputFileName);
759 m->mothurOut("Removed " + toString(removedCount) + " sequences from your group file."); m->mothurOutEndLine();
764 catch(exception& e) {
765 m->errorOut(e, "RemoveSeqsCommand", "readGroup");
769 //**********************************************************************************************************************
770 int RemoveSeqsCommand::readTax(){
772 string thisOutputDir = outputDir;
773 if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); }
774 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile);
776 m->openOutputFile(outputFileName, out);
779 m->openInputFile(taxfile, in);
782 bool wroteSomething = false;
783 int removedCount = 0;
786 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
788 in >> name; //read from first column
789 in >> tax; //read from second column
791 //if this name is in the accnos file
792 if (names.count(name) == 0) {
793 wroteSomething = true;
794 out << name << '\t' << tax << endl;
795 }else { removedCount++; }
802 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
803 outputTypes["taxonomy"].push_back(outputFileName); outputNames.push_back(outputFileName);
805 m->mothurOut("Removed " + toString(removedCount) + " sequences from your taxonomy file."); m->mothurOutEndLine();
809 catch(exception& e) {
810 m->errorOut(e, "RemoveSeqsCommand", "readTax");
814 //**********************************************************************************************************************
815 //alignreport file has a column header line then all other lines contain 16 columns. we just want the first column since that contains the name
816 int RemoveSeqsCommand::readAlign(){
818 string thisOutputDir = outputDir;
819 if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); }
820 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport");
823 m->openOutputFile(outputFileName, out);
826 m->openInputFile(alignfile, in);
829 bool wroteSomething = false;
830 int removedCount = 0;
832 //read column headers
833 for (int i = 0; i < 16; i++) {
834 if (!in.eof()) { in >> junk; out << junk << '\t'; }
840 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
842 in >> name; //read from first column
844 //if this name is in the accnos file
845 if (names.count(name) == 0) {
846 wroteSomething = true;
851 for (int i = 0; i < 15; i++) {
852 if (!in.eof()) { in >> junk; out << junk << '\t'; }
857 }else {//still read just don't do anything with it
861 for (int i = 0; i < 15; i++) {
862 if (!in.eof()) { in >> junk; }
872 if (wroteSomething == false) { m->mothurOut("Your file contains only sequences from the .accnos file."); m->mothurOutEndLine(); }
873 outputTypes["alignreport"].push_back(outputFileName); outputNames.push_back(outputFileName);
875 m->mothurOut("Removed " + toString(removedCount) + " sequences from your alignreport file."); m->mothurOutEndLine();
881 catch(exception& e) {
882 m->errorOut(e, "RemoveSeqsCommand", "readAlign");
886 //**********************************************************************************************************************