2 * removelineagecommand.cpp
5 * Created by westcott on 9/24/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "removelineagecommand.h"
11 #include "sequence.hpp"
12 #include "listvector.hpp"
14 //**********************************************************************************************************************
15 vector<string> RemoveLineageCommand::setParameters(){
17 CommandParameter pfasta("fasta", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pfasta);
18 CommandParameter pname("name", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pname);
19 CommandParameter pgroup("group", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(pgroup);
20 CommandParameter plist("list", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(plist);
21 CommandParameter ptaxonomy("taxonomy", "InputTypes", "", "", "none", "FNGLT", "none",false,true); parameters.push_back(ptaxonomy);
22 CommandParameter palignreport("alignreport", "InputTypes", "", "", "none", "FNGLT", "none",false,false); parameters.push_back(palignreport);
23 CommandParameter ptaxon("taxon", "String", "", "", "", "", "",false,true); parameters.push_back(ptaxon);
24 CommandParameter pdups("dups", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pdups);
25 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
26 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
28 vector<string> myArray;
29 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
33 m->errorOut(e, "RemoveLineageCommand", "setParameters");
37 //**********************************************************************************************************************
38 string RemoveLineageCommand::getHelpString(){
40 string helpString = "";
41 helpString += "The remove.lineage command reads a taxonomy file and any of the following file types: fasta, name, group, list or alignreport file.\n";
42 helpString += "It outputs a file containing only the sequences from the taxonomy file that are not from the taxon you requested to be removed.\n";
43 helpString += "The remove.lineage command parameters are taxon, fasta, name, group, list, taxonomy, alignreport and dups. You must provide taxonomy unless you have a valid current taxonomy file.\n";
44 helpString += "The dups parameter allows you to add the entire line from a name file if you add any name from the line. default=false. \n";
45 helpString += "The taxon parameter allows you to select the taxons you would like to remove, and is required.\n";
46 helpString += "You may enter your taxons with confidence scores, doing so will remove only those sequences that belong to the taxonomy and whose cofidence scores fall below the scores you give.\n";
47 helpString += "If they belong to the taxonomy and have confidences above those you provide the sequence will not be removed.\n";
48 helpString += "The remove.lineage command should be in the following format: remove.lineage(taxonomy=yourTaxonomyFile, taxon=yourTaxons).\n";
49 helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon=Bacteria;Firmicutes;Bacilli;Lactobacillales;).\n";
50 helpString += "Note: If you are running mothur in script mode you must wrap the taxon in ' characters so mothur will ignore the ; in the taxon.\n";
51 helpString += "Example remove.lineage(taxonomy=amazon.silva.taxonomy, taxon='Bacteria;Firmicutes;Bacilli;Lactobacillales;').\n";
52 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
56 m->errorOut(e, "RemoveLineageCommand", "getHelpString");
60 //**********************************************************************************************************************
61 string RemoveLineageCommand::getOutputFileNameTag(string type, string inputName=""){
63 string outputFileName = "";
64 map<string, vector<string> >::iterator it;
66 //is this a type this command creates
67 it = outputTypes.find(type);
68 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
70 if (type == "fasta") { outputFileName = "pick" + m->getExtension(inputName); }
71 else if (type == "taxonomy") { outputFileName = "pick" + m->getExtension(inputName); }
72 else if (type == "name") { outputFileName = "pick" + m->getExtension(inputName); }
73 else if (type == "group") { outputFileName = "pick" + m->getExtension(inputName); }
74 else if (type == "list") { outputFileName = "pick" + m->getExtension(inputName); }
75 else if (type == "alignreport") { outputFileName = "pick.align.report"; }
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, "RemoveLineageCommand", "getOutputFileNameTag");
85 //**********************************************************************************************************************
86 RemoveLineageCommand::RemoveLineageCommand(){
88 abort = true; calledHelp = true;
90 vector<string> tempOutNames;
91 outputTypes["fasta"] = tempOutNames;
92 outputTypes["taxonomy"] = tempOutNames;
93 outputTypes["name"] = tempOutNames;
94 outputTypes["group"] = tempOutNames;
95 outputTypes["alignreport"] = tempOutNames;
96 outputTypes["list"] = tempOutNames;
99 m->errorOut(e, "RemoveLineageCommand", "RemoveLineageCommand");
103 //**********************************************************************************************************************
104 RemoveLineageCommand::RemoveLineageCommand(string option) {
106 abort = false; calledHelp = false;
108 //allow user to run help
109 if(option == "help") { help(); abort = true; calledHelp = true; }
110 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
113 vector<string> myArray = setParameters();
115 OptionParser parser(option);
116 map<string,string> parameters = parser.getParameters();
118 ValidParameters validParameter;
119 map<string,string>::iterator it;
121 //check to make sure all parameters are valid for command
122 for (it = parameters.begin(); it != parameters.end(); it++) {
123 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
126 //initialize outputTypes
127 vector<string> tempOutNames;
128 outputTypes["fasta"] = tempOutNames;
129 outputTypes["taxonomy"] = tempOutNames;
130 outputTypes["name"] = tempOutNames;
131 outputTypes["group"] = tempOutNames;
132 outputTypes["alignreport"] = tempOutNames;
133 outputTypes["list"] = tempOutNames;
135 //if the user changes the output directory command factory will send this info to us in the output parameter
136 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
138 //if the user changes the input directory command factory will send this info to us in the output parameter
139 string inputDir = validParameter.validFile(parameters, "inputdir", false);
140 if (inputDir == "not found"){ inputDir = ""; }
143 it = parameters.find("alignreport");
144 //user has given a template file
145 if(it != parameters.end()){
146 path = m->hasPath(it->second);
147 //if the user has not given a path then, add inputdir. else leave path alone.
148 if (path == "") { parameters["alignreport"] = inputDir + it->second; }
151 it = parameters.find("fasta");
152 //user has given a template file
153 if(it != parameters.end()){
154 path = m->hasPath(it->second);
155 //if the user has not given a path then, add inputdir. else leave path alone.
156 if (path == "") { parameters["fasta"] = inputDir + it->second; }
159 it = parameters.find("list");
160 //user has given a template file
161 if(it != parameters.end()){
162 path = m->hasPath(it->second);
163 //if the user has not given a path then, add inputdir. else leave path alone.
164 if (path == "") { parameters["list"] = inputDir + it->second; }
167 it = parameters.find("name");
168 //user has given a template file
169 if(it != parameters.end()){
170 path = m->hasPath(it->second);
171 //if the user has not given a path then, add inputdir. else leave path alone.
172 if (path == "") { parameters["name"] = inputDir + it->second; }
175 it = parameters.find("group");
176 //user has given a template file
177 if(it != parameters.end()){
178 path = m->hasPath(it->second);
179 //if the user has not given a path then, add inputdir. else leave path alone.
180 if (path == "") { parameters["group"] = inputDir + it->second; }
183 it = parameters.find("taxonomy");
184 //user has given a template file
185 if(it != parameters.end()){
186 path = m->hasPath(it->second);
187 //if the user has not given a path then, add inputdir. else leave path alone.
188 if (path == "") { parameters["taxonomy"] = inputDir + it->second; }
193 //check for required parameters
194 fastafile = validParameter.validFile(parameters, "fasta", true);
195 if (fastafile == "not open") { fastafile = ""; abort = true; }
196 else if (fastafile == "not found") { fastafile = ""; }
197 else { m->setFastaFile(fastafile); }
199 namefile = validParameter.validFile(parameters, "name", true);
200 if (namefile == "not open") { namefile = ""; abort = true; }
201 else if (namefile == "not found") { namefile = ""; }
202 else { m->setNameFile(namefile); }
204 groupfile = validParameter.validFile(parameters, "group", true);
205 if (groupfile == "not open") { abort = true; }
206 else if (groupfile == "not found") { groupfile = ""; }
207 else { m->setGroupFile(groupfile); }
209 alignfile = validParameter.validFile(parameters, "alignreport", true);
210 if (alignfile == "not open") { abort = true; }
211 else if (alignfile == "not found") { alignfile = ""; }
213 listfile = validParameter.validFile(parameters, "list", true);
214 if (listfile == "not open") { abort = true; }
215 else if (listfile == "not found") { listfile = ""; }
216 else { m->setListFile(listfile); }
218 taxfile = validParameter.validFile(parameters, "taxonomy", true);
219 if (taxfile == "not open") { taxfile = ""; abort = true; }
220 else if (taxfile == "not found") {
221 taxfile = m->getTaxonomyFile();
222 if (taxfile != "") { m->mothurOut("Using " + taxfile + " as input file for the taxonomy parameter."); m->mothurOutEndLine(); }
223 else { m->mothurOut("You have no current taxonomy file and the taxonomy parameter is required."); m->mothurOutEndLine(); abort = true; }
224 }else { m->setTaxonomyFile(taxfile); }
226 string usedDups = "true";
227 string temp = validParameter.validFile(parameters, "dups", false);
228 if (temp == "not found") {
229 if (namefile != "") { temp = "true"; }
230 else { temp = "false"; usedDups = ""; }
232 dups = m->isTrue(temp);
234 taxons = validParameter.validFile(parameters, "taxon", false);
235 if (taxons == "not found") { taxons = ""; m->mothurOut("No taxons given, please correct."); m->mothurOutEndLine(); abort = true; }
238 if (taxons[0] == '\'') { taxons = taxons.substr(1); }
239 if (taxons[(taxons.length()-1)] == '\'') { taxons = taxons.substr(0, (taxons.length()-1)); }
241 m->splitAtChar(taxons, listOfTaxons, '-');
243 if ((fastafile == "") && (namefile == "") && (groupfile == "") && (alignfile == "") && (listfile == "") && (taxfile == "")) { m->mothurOut("You must provide one of the following: fasta, name, group, alignreport, taxonomy or listfile."); m->mothurOutEndLine(); abort = true; }
245 if ((usedDups != "") && (namefile == "")) { m->mothurOut("You may only use dups with the name option."); m->mothurOutEndLine(); abort = true; }
247 if ((namefile == "") && ((fastafile != "") || (taxfile != ""))){
248 vector<string> files; files.push_back(fastafile); files.push_back(taxfile);
249 parser.getNameFile(files);
255 catch(exception& e) {
256 m->errorOut(e, "RemoveLineageCommand", "RemoveLineageCommand");
260 //**********************************************************************************************************************
262 int RemoveLineageCommand::execute(){
265 if (abort == true) { if (calledHelp) { return 0; } return 2; }
267 if (m->control_pressed) { return 0; }
269 //read through the correct file and output lines you want to keep
270 if (taxfile != "") { readTax(); } //fills the set of names to remove
271 if (namefile != "") { readName(); }
272 if (fastafile != "") { readFasta(); }
273 if (groupfile != "") { readGroup(); }
274 if (alignfile != "") { readAlign(); }
275 if (listfile != "") { readList(); }
278 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
280 if (outputNames.size() != 0) {
281 m->mothurOutEndLine();
282 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
283 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
284 m->mothurOutEndLine();
286 //set fasta file as new current fastafile
288 itTypes = outputTypes.find("fasta");
289 if (itTypes != outputTypes.end()) {
290 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
293 itTypes = outputTypes.find("name");
294 if (itTypes != outputTypes.end()) {
295 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setNameFile(current); }
298 itTypes = outputTypes.find("group");
299 if (itTypes != outputTypes.end()) {
300 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setGroupFile(current); }
303 itTypes = outputTypes.find("list");
304 if (itTypes != outputTypes.end()) {
305 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setListFile(current); }
308 itTypes = outputTypes.find("taxonomy");
309 if (itTypes != outputTypes.end()) {
310 if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setTaxonomyFile(current); }
317 catch(exception& e) {
318 m->errorOut(e, "RemoveLineageCommand", "execute");
323 //**********************************************************************************************************************
324 int RemoveLineageCommand::readFasta(){
326 string thisOutputDir = outputDir;
327 if (outputDir == "") { thisOutputDir += m->hasPath(fastafile); }
328 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(fastafile)) + getOutputFileNameTag("fasta", fastafile);
330 m->openOutputFile(outputFileName, out);
333 m->openInputFile(fastafile, in);
336 bool wroteSomething = false;
339 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
341 Sequence currSeq(in);
342 name = currSeq.getName();
345 //if this name is in the accnos file
346 if (names.count(name) == 0) {
347 wroteSomething = true;
349 currSeq.printSequence(out);
357 if (wroteSomething == false) { m->mothurOut("Your fasta file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
358 outputNames.push_back(outputFileName); outputTypes["fasta"].push_back(outputFileName);
363 catch(exception& e) {
364 m->errorOut(e, "RemoveLineageCommand", "readFasta");
368 //**********************************************************************************************************************
369 int RemoveLineageCommand::readList(){
371 string thisOutputDir = outputDir;
372 if (outputDir == "") { thisOutputDir += m->hasPath(listfile); }
373 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(listfile)) + getOutputFileNameTag("list", listfile);
375 m->openOutputFile(outputFileName, out);
378 m->openInputFile(listfile, in);
380 bool wroteSomething = false;
383 //read in list vector
386 //make a new list vector
388 newList.setLabel(list.getLabel());
391 for (int i = 0; i < list.getNumBins(); i++) {
392 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
394 //parse out names that are in accnos file
395 string binnames = list.get(i);
397 string newNames = "";
398 while (binnames.find_first_of(',') != -1) {
399 string name = binnames.substr(0,binnames.find_first_of(','));
400 binnames = binnames.substr(binnames.find_first_of(',')+1, binnames.length());
402 //if that name is in the .accnos file, add it
403 if (names.count(name) == 0) { newNames += name + ","; }
407 if (names.count(binnames) == 0) { newNames += binnames + ","; }
409 //if there are names in this bin add to new list
410 if (newNames != "") {
411 newNames = newNames.substr(0, newNames.length()-1); //rip off extra comma
412 newList.push_back(newNames);
416 //print new listvector
417 if (newList.getNumBins() != 0) {
418 wroteSomething = true;
427 if (wroteSomething == false) { m->mothurOut("Your list file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
428 outputNames.push_back(outputFileName); outputTypes["list"].push_back(outputFileName);
433 catch(exception& e) {
434 m->errorOut(e, "RemoveLineageCommand", "readList");
438 //**********************************************************************************************************************
439 int RemoveLineageCommand::readName(){
441 string thisOutputDir = outputDir;
442 if (outputDir == "") { thisOutputDir += m->hasPath(namefile); }
443 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(namefile)) + getOutputFileNameTag("name", namefile);
445 m->openOutputFile(outputFileName, out);
448 m->openInputFile(namefile, in);
449 string name, firstCol, secondCol;
451 bool wroteSomething = false;
454 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
459 vector<string> parsedNames;
460 m->splitAtComma(secondCol, parsedNames);
462 vector<string> validSecond; validSecond.clear();
463 for (int i = 0; i < parsedNames.size(); i++) {
464 if (names.count(parsedNames[i]) == 0) {
465 validSecond.push_back(parsedNames[i]);
469 if ((dups) && (validSecond.size() != parsedNames.size())) { //if dups is true and we want to get rid of anyone, get rid of everyone
470 for (int i = 0; i < parsedNames.size(); i++) { names.insert(parsedNames[i]); }
472 //if the name in the first column is in the set then print it and any other names in second column also in set
473 if (names.count(firstCol) == 0) {
475 wroteSomething = true;
477 out << firstCol << '\t';
479 //you know you have at least one valid second since first column is valid
480 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
481 out << validSecond[validSecond.size()-1] << endl;
483 //make first name in set you come to first column and then add the remaining names to second column
486 //you want part of this row
487 if (validSecond.size() != 0) {
489 wroteSomething = true;
491 out << validSecond[0] << '\t';
493 //you know you have at least one valid second since first column is valid
494 for (int i = 0; i < validSecond.size()-1; i++) { out << validSecond[i] << ','; }
495 out << validSecond[validSecond.size()-1] << endl;
504 if (wroteSomething == false) { m->mothurOut("Your name file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
505 outputNames.push_back(outputFileName); outputTypes["name"].push_back(outputFileName);
509 catch(exception& e) {
510 m->errorOut(e, "RemoveLineageCommand", "readName");
515 //**********************************************************************************************************************
516 int RemoveLineageCommand::readGroup(){
518 string thisOutputDir = outputDir;
519 if (outputDir == "") { thisOutputDir += m->hasPath(groupfile); }
520 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(groupfile)) + getOutputFileNameTag("group", groupfile);
522 m->openOutputFile(outputFileName, out);
525 m->openInputFile(groupfile, in);
528 bool wroteSomething = false;
531 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
533 in >> name; //read from first column
534 in >> group; //read from second column
536 //if this name is in the accnos file
537 if (names.count(name) == 0) {
538 wroteSomething = true;
539 out << name << '\t' << group << endl;
547 if (wroteSomething == false) { m->mothurOut("Your group file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
548 outputNames.push_back(outputFileName); outputTypes["group"].push_back(outputFileName);
552 catch(exception& e) {
553 m->errorOut(e, "RemoveLineageCommand", "readGroup");
557 //**********************************************************************************************************************
558 int RemoveLineageCommand::readTax(){
560 string thisOutputDir = outputDir;
561 if (outputDir == "") { thisOutputDir += m->hasPath(taxfile); }
562 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(taxfile)) + getOutputFileNameTag("taxonomy", taxfile);
564 m->openOutputFile(outputFileName, out);
567 m->openInputFile(taxfile, in);
570 bool wroteSomething = false;
572 vector<bool> taxonsHasConfidence; taxonsHasConfidence.resize(listOfTaxons.size(), false);
573 vector< vector< map<string, float> > > searchTaxons; searchTaxons.resize(listOfTaxons.size());
574 vector<string> noConfidenceTaxons; noConfidenceTaxons.resize(listOfTaxons.size(), "");
576 for (int i = 0; i < listOfTaxons.size(); i++) {
577 noConfidenceTaxons[i] = listOfTaxons[i];
578 int hasConPos = listOfTaxons[i].find_first_of('(');
579 if (hasConPos != string::npos) {
580 taxonsHasConfidence[i] = true;
581 searchTaxons[i] = getTaxons(listOfTaxons[i]);
582 noConfidenceTaxons[i] = listOfTaxons[i];
583 m->removeConfidences(noConfidenceTaxons[i]);
590 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
592 in >> name; //read from first column
593 in >> tax; //read from second column
597 for (int j = 0; j < listOfTaxons.size(); j++) {
600 //if the users file contains confidence scores we want to ignore them when searching for the taxons, unless the taxon has them
601 if (!taxonsHasConfidence[j]) {
603 int hasConfidences = tax.find_first_of('(');
604 if (hasConfidences != string::npos) {
606 m->removeConfidences(newtax);
609 int pos = newtax.find(noConfidenceTaxons[j]);
611 if (pos == string::npos) {
612 //wroteSomething = true;
613 //out << name << '\t' << tax << endl;
614 }else{ //this sequence contains the taxon the user wants to remove
619 }else{//if taxons has them and you don't them remove taxons
620 int hasConfidences = tax.find_first_of('(');
621 if (hasConfidences == string::npos) {
623 int pos = newtax.find(noConfidenceTaxons[j]);
625 if (pos == string::npos) {
626 //wroteSomething = true;
627 //out << name << '\t' << tax << endl;
628 }else{ //this sequence contains the taxon the user wants to remove
632 }else { //both have confidences so we want to make sure the users confidences are greater then or equal to the taxons
633 //first remove confidences from both and see if the taxonomy exists
635 string noNewTax = tax;
636 int hasConfidences = tax.find_first_of('(');
637 if (hasConfidences != string::npos) {
639 m->removeConfidences(noNewTax);
642 int pos = noNewTax.find(noConfidenceTaxons[j]);
644 if (pos != string::npos) { //if yes, then are the confidences okay
646 vector< map<string, float> > usersTaxon = getTaxons(newtax);
648 //the usersTaxon is most likely longer than the searchTaxons, and searchTaxon[0] may relate to userTaxon[4]
649 //we want to "line them up", so we will find the the index where the searchstring starts
651 for (int i = 0; i < usersTaxon.size(); i++) {
653 if (usersTaxon[i].begin()->first == searchTaxons[j][0].begin()->first) {
656 bool goodspot = true;
657 //is this really the start, or are we dealing with a taxon of the same name?
658 while ((spot < searchTaxons[j].size()) && ((i+spot) < usersTaxon.size())) {
659 if (usersTaxon[i+spot].begin()->first != searchTaxons[j][spot].begin()->first) { goodspot = false; break; }
663 if (goodspot) { break; }
667 for (int i = 0; i < searchTaxons[j].size(); i++) {
669 if ((i+index) < usersTaxon.size()) { //just in case, should never be false
670 if (usersTaxon[i+index].begin()->second < searchTaxons[j][i].begin()->second) { //is the users cutoff less than the search taxons
680 //passed the test so remove you
685 //wroteSomething = true;
686 //out << name << '\t' << tax << endl;
689 //wroteSomething = true;
690 //out << name << '\t' << tax << endl;
697 if (!remove) { wroteSomething = true; out << name << '\t' << tax << endl; }
703 if (!wroteSomething) { m->mothurOut("Your taxonomy file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
704 outputNames.push_back(outputFileName); outputTypes["taxonomy"].push_back(outputFileName);
709 catch(exception& e) {
710 m->errorOut(e, "RemoveLineageCommand", "readTax");
714 /**************************************************************************************************/
715 vector< map<string, float> > RemoveLineageCommand::getTaxons(string tax) {
718 vector< map<string, float> > t;
720 int taxLength = tax.length();
721 for(int i=0;i<taxLength;i++){
724 int openParen = taxon.find_first_of('(');
725 int closeParen = taxon.find_last_of(')');
727 string newtaxon, confidence;
728 if ((openParen != string::npos) && (closeParen != string::npos)) {
729 newtaxon = taxon.substr(0, openParen); //rip off confidence
730 confidence = taxon.substr((openParen+1), (closeParen-openParen-1));
736 convert(confidence, con);
738 map<string, float> temp;
739 temp[newtaxon] = con;
751 catch(exception& e) {
752 m->errorOut(e, "RemoveLineageCommand", "getTaxons");
756 //**********************************************************************************************************************
757 //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
758 int RemoveLineageCommand::readAlign(){
760 string thisOutputDir = outputDir;
761 if (outputDir == "") { thisOutputDir += m->hasPath(alignfile); }
762 string outputFileName = thisOutputDir + m->getRootName(m->getSimpleName(alignfile)) + getOutputFileNameTag("alignreport");
765 m->openOutputFile(outputFileName, out);
768 m->openInputFile(alignfile, in);
771 bool wroteSomething = false;
773 //read column headers
774 for (int i = 0; i < 16; i++) {
775 if (!in.eof()) { in >> junk; out << junk << '\t'; }
781 if (m->control_pressed) { in.close(); out.close(); m->mothurRemove(outputFileName); return 0; }
783 in >> name; //read from first column
785 //if this name is in the accnos file
786 if (names.count(name) == 0) {
787 wroteSomething = true;
792 for (int i = 0; i < 15; i++) {
793 if (!in.eof()) { in >> junk; out << junk << '\t'; }
798 }else {//still read just don't do anything with it
801 for (int i = 0; i < 15; i++) {
802 if (!in.eof()) { in >> junk; }
812 if (wroteSomething == false) { m->mothurOut("Your align file contains only sequences from " + taxons + "."); m->mothurOutEndLine(); }
813 outputNames.push_back(outputFileName); outputTypes["alignreport"].push_back(outputFileName);
818 catch(exception& e) {
819 m->errorOut(e, "RemoveLineageCommand", "readAlign");
823 //**********************************************************************************************************************